Skip to content

Commit 984e752

Browse files
authored
eth: return error from eth_chainID during sync before EIP-155 activates (#21686)
This changes the chainID RPC method to return an error when EIP-155 is not yet active at the current block height. It used to simply return zero in this case, but that's confusing.
1 parent 39b3b8f commit 984e752

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎eth/api.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 {
6767
}
6868

6969
// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
70-
func (api *PublicEthereumAPI) ChainId() hexutil.Uint64 {
71-
chainID := new(big.Int)
70+
func (api *PublicEthereumAPI) ChainId() (hexutil.Uint64, error) {
71+
// if current block is at or past the EIP-155 replay-protection fork block, return chainID from config
7272
if config := api.e.blockchain.Config(); config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
73-
chainID = config.ChainID
73+
return (hexutil.Uint64)(config.ChainID.Uint64()), nil
7474
}
75-
return (hexutil.Uint64)(chainID.Uint64())
75+
return hexutil.Uint64(0), fmt.Errorf("chain not synced beyond EIP-155 replay-protection fork block")
7676
}
7777

7878
// PublicMinerAPI provides an API to control the miner.

0 commit comments

Comments
 (0)