From 23fa1bbabec05189fc81272ef9cb7be53c6cbf54 Mon Sep 17 00:00:00 2001 From: lightclient <14004106+lightclient@users.noreply.github.com> Date: Mon, 13 Mar 2023 04:51:23 -0600 Subject: [PATCH] eth: return error if 'safe' or 'finalized' tag used pre-merge (#26862) Co-authored-by: Martin Holst Swende Co-authored-by: Felix Lange --- eth/api_backend.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/eth/api_backend.go b/eth/api_backend.go index 78b9b08ecb32..643f6369df0e 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -75,6 +75,9 @@ 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 @@ -82,6 +85,9 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb 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 @@ -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 }