Skip to content

Commit 706683e

Browse files
piersyfjl
andauthored
internal/ethapi: fix eth_chainId method (ethereum#22243)
This removes the duplicated definition of eth_chainID in package eth and updates the definition in internal/ethapi to treat chain ID as a bigint. Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent c79fc20 commit 706683e

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

eth/api.go

-9
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ func (api *PublicEthereumAPI) Coinbase() (common.Address, error) {
6161
return api.Etherbase()
6262
}
6363

64-
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
65-
func (api *PublicEthereumAPI) ChainId() (hexutil.Uint64, error) {
66-
// if current block is at or past the EIP-155 replay-protection fork block, return chainID from config
67-
if config := api.e.blockchain.Config(); config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
68-
return (hexutil.Uint64)(config.ChainID.Uint64()), nil
69-
}
70-
return hexutil.Uint64(0), fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block")
71-
}
72-
7364
// PublicMinerAPI provides an API to control the miner.
7465
// It offers only methods that operate on data that pose no security risk when it is publicly accessible.
7566
type PublicMinerAPI struct {

internal/ethapi/api.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,13 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI {
529529
return &PublicBlockChainAPI{b}
530530
}
531531

532-
// ChainId returns the chainID value for transaction replay protection.
533-
func (s *PublicBlockChainAPI) ChainId() *hexutil.Big {
534-
return (*hexutil.Big)(s.b.ChainConfig().ChainID)
532+
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
533+
func (api *PublicBlockChainAPI) ChainId() (*hexutil.Big, error) {
534+
// if current block is at or past the EIP-155 replay-protection fork block, return chainID from config
535+
if config := api.b.ChainConfig(); config.IsEIP155(api.b.CurrentBlock().Number()) {
536+
return (*hexutil.Big)(config.ChainID), nil
537+
}
538+
return nil, fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block")
535539
}
536540

537541
// BlockNumber returns the block number of the chain head.

0 commit comments

Comments
 (0)