Skip to content

Commit

Permalink
add check for recent block in StateAndHeaderByNumberOrHash
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Mar 12, 2024
1 parent f0a0807 commit 57fcba9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arbitrum/apibackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ func (a *APIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.Bloc

func (a *APIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) {
header, err := a.HeaderByNumberOrHash(ctx, blockNrOrHash)
hash, ishash := blockNrOrHash.Hash()
bc := a.BlockChain()
if ishash && header.Number.Cmp(bc.CurrentBlock().Number) > 0 && bc.GetCanonicalHash(header.Number.Uint64()) != hash {
return nil, nil, errors.New("requested block ahead of current block and the hash is not currently canonical")
}
return a.stateAndHeaderFromHeader(ctx, header, err)
}

Expand Down

0 comments on commit 57fcba9

Please sign in to comment.