RPC: Calculate `eth_protocolVersion` from live protocol

In RPC `eth_protocolVersion`, look at the live `EthereumNode` to find which
version of `eth/NN` protocol is active, instead of trusting a compile-time
constant.  It's better to check dynamically.  GraphQL already does this.

As a result, the RPC code doesn't depend on `eth_protocol` any more.

To make sure there are no more accidental users of the old constant,
`protocolVersion` is no longer exported from `protocol_eth65`.

(The simplest way to support `eth/65` was to make `eth_protocolVersion` use
`protocol_eth65.protocolVersion`, to get 65.  But that's silly.  More
seriously, when we add another version (`eth/66`) running alongside `eth/65`,
that expression would still compile ok yet return the wrong value, while still
passing the RPC test suite.)

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-07-23 17:31:35 +01:00
parent bb282a5348
commit 5ddfd7dd05
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
1 changed files with 5 additions and 3 deletions

View File

@ -11,7 +11,6 @@ import
strutils, times, options, tables,
json_rpc/rpcserver, hexstrings, stint, stew/byteutils,
eth/[common, keys, rlp, p2p], nimcrypto,
../sync/protocol_eth65,
../transaction, ../config, ../vm_state, ../constants,
../utils, ../db/[db_chain, state_db],
rpc_types, rpc_utils,
@ -37,14 +36,17 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB , server: RpcServer) =
proc accountDbFromTag(tag: string, readOnly = true): ReadOnlyStateDB =
result = getAccountDb(chain.headerFromTag(tag))
server.rpc("eth_protocolVersion") do() -> string:
server.rpc("eth_protocolVersion") do() -> Option[string]:
# Old Ethereum wiki documents this as returning a decimal string.
# Infura documents this as returning 0x-prefixed hex string.
# Geth 1.10.0 has removed this call "as it makes no sense".
# - https://eth.wiki/json-rpc/API#eth_protocolversion
# - https://infura.io/docs/ethereum/json-rpc/eth-protocolVersion
# - https://blog.ethereum.org/2021/03/03/geth-v1-10-0/#compatibility
result = $protocol_eth65.protocolVersion
for n in node.capabilities:
if n.name == "eth":
return some($n.version)
return none(string)
server.rpc("eth_syncing") do() -> JsonNode:
## Returns SyncObject or false when not syncing.