From d9e17a7b1702060f1bd65416dbe9095fe20f245b Mon Sep 17 00:00:00 2001 From: VictorTrustyDev Date: Fri, 11 Nov 2022 01:37:16 +0700 Subject: [PATCH] internal/ethapi: always return chain id (geth #25166) --- rpc/backend/backend.go | 2 +- rpc/backend/chain_info.go | 18 ++++-------------- rpc/backend/tx_info.go | 5 +---- rpc/namespaces/ethereum/eth/api.go | 4 ++-- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/rpc/backend/backend.go b/rpc/backend/backend.go index edc891ad34..33f1cf7e9d 100644 --- a/rpc/backend/backend.go +++ b/rpc/backend/backend.go @@ -91,7 +91,7 @@ type EVMBackend interface { GetTransactionCount(address common.Address, blockNum rpctypes.BlockNumber) (*hexutil.Uint64, error) // Chain Info - ChainID() (*hexutil.Big, error) + ChainID() *hexutil.Big ChainConfig() *params.ChainConfig GlobalMinGasPrice() (sdk.Dec, error) BaseFee(blockRes *tmrpctypes.ResultBlockResults) (*big.Int, error) diff --git a/rpc/backend/chain_info.go b/rpc/backend/chain_info.go index 33954aa23a..3dff44d610 100644 --- a/rpc/backend/chain_info.go +++ b/rpc/backend/chain_info.go @@ -18,23 +18,13 @@ import ( ) // ChainID is the EIP-155 replay-protection chain id for the current ethereum chain config. -func (b *Backend) ChainID() (*hexutil.Big, error) { +func (b *Backend) ChainID() *hexutil.Big { eip155ChainID, err := ethermint.ParseChainID(b.clientCtx.ChainID) if err != nil { panic(err) } - // if current block is at or past the EIP-155 replay-protection fork block, return chainID from config - bn, err := b.BlockNumber() - if err != nil { - b.logger.Debug("failed to fetch latest block number", "error", err.Error()) - return (*hexutil.Big)(eip155ChainID), nil - } - - if config := b.ChainConfig(); config.IsEIP155(new(big.Int).SetUint64(uint64(bn))) { - return (*hexutil.Big)(config.ChainID), nil - } - return nil, fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block") + return (*hexutil.Big)(eip155ChainID) } // ChainConfig returns the latest ethereum chain configuration @@ -141,8 +131,8 @@ func (b *Backend) GetCoinbase() (sdk.AccAddress, error) { // FeeHistory returns data relevant for fee estimation based on the specified range of blocks. func (b *Backend) FeeHistory( userBlockCount rpc.DecimalOrHex, // number blocks to fetch, maximum is 100 - lastBlock rpc.BlockNumber, // the block to start search , to oldest - rewardPercentiles []float64, // percentiles to fetch reward + lastBlock rpc.BlockNumber, // the block to start search , to oldest + rewardPercentiles []float64, // percentiles to fetch reward ) (*rpctypes.FeeHistoryResult, error) { blockEnd := int64(lastBlock) diff --git a/rpc/backend/tx_info.go b/rpc/backend/tx_info.go index 08f3af7b5b..f488f89195 100644 --- a/rpc/backend/tx_info.go +++ b/rpc/backend/tx_info.go @@ -161,10 +161,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{ status = hexutil.Uint(ethtypes.ReceiptStatusSuccessful) } - chainID, err := b.ChainID() - if err != nil { - return nil, err - } + chainID := b.ChainID() from, err := ethMsg.GetSender(chainID.ToInt()) if err != nil { diff --git a/rpc/namespaces/ethereum/eth/api.go b/rpc/namespaces/ethereum/eth/api.go index c58a3357e8..9f0b000128 100644 --- a/rpc/namespaces/ethereum/eth/api.go +++ b/rpc/namespaces/ethereum/eth/api.go @@ -79,7 +79,7 @@ type EthereumAPI interface { EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error) FeeHistory(blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*rpctypes.FeeHistoryResult, error) MaxPriorityFeePerGas() (*hexutil.Big, error) - ChainId() (*hexutil.Big, error) + ChainId() *hexutil.Big // Getting Uncles // @@ -328,7 +328,7 @@ func (e *PublicAPI) MaxPriorityFeePerGas() (*hexutil.Big, error) { } // ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config. -func (e *PublicAPI) ChainId() (*hexutil.Big, error) { //nolint +func (e *PublicAPI) ChainId() *hexutil.Big { //nolint e.logger.Debug("eth_chainId") return e.backend.ChainID() }