Skip to content

Commit

Permalink
Reject the block if the block hash changes in the Append
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Oct 25, 2023
1 parent 49e5c31 commit 7b2948c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ var (

// ErrPendingHeaderNotInCache is returned when a coord gives an update but the slice has not yet created the referenced ph
ErrPendingHeaderNotInCache = errors.New("no pending header found in cache")

// ErrBlockHashChanged is returned when the block is mutated in the Append
ErrBlockHashChanged = errors.New("rejecting the block because block hash changed during append")
)

// List of evm-call-message pre-checking errors. All state transition messages will
Expand Down
11 changes: 11 additions & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func NewSlice(db ethdb.Database, config *Config, txConfig *TxPoolConfig, txLooku
func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, domTerminus common.Hash, domOrigin bool, newInboundEtxs types.Transactions) (types.Transactions, bool, bool, error) {
start := time.Now()

blockHash := header.Hash()

if header.Hash() == sl.config.GenesisHash {
return nil, false, false, nil
}
Expand Down Expand Up @@ -316,6 +318,15 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do
time9 = common.PrettyDuration(time.Since(start))

}

// If block hash at the beginning of the append is not the same as before
// modifying the phCache and Batch write we need to reject the block. This
// check can be removed after fixing the block hash mutation bug observed in
// testnet
if block.Hash() != blockHash {
return nil, false, false, ErrBlockHashChanged
}

sl.updatePhCache(pendingHeaderWithTermini, true, nil, subReorg, common.NodeLocation)

var updateDom bool
Expand Down

0 comments on commit 7b2948c

Please sign in to comment.