Skip to content

Commit

Permalink
eth: return error if 'safe' or 'finalized' tag used pre-merge (ethere…
Browse files Browse the repository at this point in the history
…um#26862)


Co-authored-by: Martin Holst Swende <[email protected]>
Co-authored-by: Felix Lange <[email protected]>
  • Loading branch information
3 people authored and mmsqe committed Dec 7, 2023
1 parent e944d30 commit 23fa1bb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
return b.eth.blockchain.CurrentBlock(), nil
}
if number == rpc.FinalizedBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'finalized' tag not supported on pre-merge network")
}
block := b.eth.blockchain.CurrentFinalBlock()
if block != nil {
return block, nil
}
return nil, errors.New("finalized block not found")
}
if number == rpc.SafeBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'safe' tag not supported on pre-merge network")
}
block := b.eth.blockchain.CurrentSafeBlock()
if block != nil {
return block, nil
Expand Down Expand Up @@ -124,10 +130,16 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
if number == rpc.FinalizedBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'finalized' tag not supported on pre-merge network")
}
header := b.eth.blockchain.CurrentFinalBlock()
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
if number == rpc.SafeBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'safe' tag not supported on pre-merge network")
}
header := b.eth.blockchain.CurrentSafeBlock()
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
Expand Down

0 comments on commit 23fa1bb

Please sign in to comment.