Skip to content

Commit

Permalink
eth/tracers: add canonical hash check in API.blockByHash
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Mar 6, 2024
1 parent 086bfcc commit 4f76df8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ func (api *API) blockByHash(ctx context.Context, hash common.Hash) (*types.Block
if block == nil {
return nil, fmt.Errorf("block %s not found", hash.Hex())
}

number := block.NumberU64()
canonical := rawdb.ReadCanonicalHash(api.backend.ChainDb(), number)
if canonical == (common.Hash{}) {
return nil, fmt.Errorf("canonical hash for block %s not found", hash.Hex())
}
if hash.Cmp(canonical) != 0 {
return nil, fmt.Errorf("canonical hash doesn't match requested hash, hash %s, canonical %s, block #%d", hash.Hex(), canonical.Hex(), number)
}
return block, nil
}

Expand Down

0 comments on commit 4f76df8

Please sign in to comment.