mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/api_backend: return error code for PoS tag requests before merge
This commit is contained in:
parent
4e1e37323d
commit
54f840a40a
1 changed files with 29 additions and 5 deletions
|
|
@ -42,7 +42,31 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EthAPIBackend implements ethapi.Backend and tracers.Backend for full nodes
|
// rpcError returns error messages with an error code that can be encoded in the
|
||||||
|
// RPC response.
|
||||||
|
type rpcError struct {
|
||||||
|
code int
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *rpcError) Error() string {
|
||||||
|
return e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *rpcError) ErrorCode() int {
|
||||||
|
return e.code
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *rpcError) With(msg string) *rpcError {
|
||||||
|
e.msg = msg
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
// posTagBeforeMerge is returned if a block is requested using either "safe" or
|
||||||
|
// "finalized" before the chain has fully transitioned to PoS.
|
||||||
|
var posTagBeforeMerge = &rpcError{code: -39001}
|
||||||
|
|
||||||
|
// EthAPIBackend implements ethapi.Backend and tracers.Backend for full nodes.
|
||||||
type EthAPIBackend struct {
|
type EthAPIBackend struct {
|
||||||
extRPCEnabled bool
|
extRPCEnabled bool
|
||||||
allowUnprotectedTxs bool
|
allowUnprotectedTxs bool
|
||||||
|
|
@ -80,14 +104,14 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
|
||||||
if number == rpc.FinalizedBlockNumber {
|
if number == rpc.FinalizedBlockNumber {
|
||||||
block := b.eth.blockchain.CurrentFinalBlock()
|
block := b.eth.blockchain.CurrentFinalBlock()
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, errors.New("finalized block not found")
|
return nil, posTagBeforeMerge.With("finalized block not found")
|
||||||
}
|
}
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
if number == rpc.SafeBlockNumber {
|
if number == rpc.SafeBlockNumber {
|
||||||
block := b.eth.blockchain.CurrentSafeBlock()
|
block := b.eth.blockchain.CurrentSafeBlock()
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, errors.New("safe block not found")
|
return nil, posTagBeforeMerge.With("safe block not found")
|
||||||
}
|
}
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
@ -132,14 +156,14 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
|
||||||
if number == rpc.FinalizedBlockNumber {
|
if number == rpc.FinalizedBlockNumber {
|
||||||
header := b.eth.blockchain.CurrentFinalBlock()
|
header := b.eth.blockchain.CurrentFinalBlock()
|
||||||
if header == nil {
|
if header == nil {
|
||||||
return nil, errors.New("finalized block not found")
|
return nil, posTagBeforeMerge.With("finalized block not found")
|
||||||
}
|
}
|
||||||
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
|
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
|
||||||
}
|
}
|
||||||
if number == rpc.SafeBlockNumber {
|
if number == rpc.SafeBlockNumber {
|
||||||
header := b.eth.blockchain.CurrentSafeBlock()
|
header := b.eth.blockchain.CurrentSafeBlock()
|
||||||
if header == nil {
|
if header == nil {
|
||||||
return nil, errors.New("safe block not found")
|
return nil, posTagBeforeMerge.With("safe block not found1")
|
||||||
}
|
}
|
||||||
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
|
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue