forked from cerc-io/ipld-eth-server
(VDB-68) Verify log block hash matches header block hash
- Delete header on conflict to prompt data refresh (cascade deletes all data associated with that block) - Derive header hash from rpc payload rather than computing it from data (prevents hash mismatch between blockchain and cache)
This commit is contained in:
@@ -26,7 +26,7 @@ type DealRepository struct {
|
||||
db *postgres.DB
|
||||
}
|
||||
|
||||
func (repository DealRepository) Create(headerId int64, models []interface{}) error {
|
||||
func (repository DealRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -39,10 +39,16 @@ func (repository DealRepository) Create(headerId int64, models []interface{}) er
|
||||
return fmt.Errorf("model of type %T, not %T", model, DealModel{})
|
||||
}
|
||||
|
||||
err = shared.ValidateHeaderConsistency(headerID, dealModel.Raw, repository.db)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(
|
||||
`INSERT into maker.deal (header_id, bid_id, contract_address, log_idx, tx_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4, $5, $6)`,
|
||||
headerId, dealModel.BidId, dealModel.ContractAddress, dealModel.LogIndex, dealModel.TransactionIndex, dealModel.Raw,
|
||||
headerID, dealModel.BidId, dealModel.ContractAddress, dealModel.LogIndex, dealModel.TransactionIndex, dealModel.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
@@ -50,7 +56,7 @@ func (repository DealRepository) Create(headerId int64, models []interface{}) er
|
||||
}
|
||||
}
|
||||
|
||||
err = shared.MarkHeaderCheckedInTransaction(headerId, tx, constants.DealChecked)
|
||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DealChecked)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user