Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
internal/ethapi: always return chain id (geth #25166)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTrustyDev committed Nov 10, 2022
1 parent 0739ad7 commit d9e17a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 4 additions & 14 deletions rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit d9e17a7

Please sign in to comment.