From fb81937708197d0bde93556a70f721c344c3d012 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Wed, 5 Apr 2023 16:14:42 +0200 Subject: [PATCH] Add a version to fluffy and add web3_clientVersion JSON-RPC (#1531) --- fluffy/fluffy.nim | 4 +++- fluffy/rpc/eth_rpc_client.nim | 1 + fluffy/rpc/rpc_calls/rpc_web3_calls.nim | 1 + fluffy/rpc/rpc_web3_api.nim | 20 ++++++++++++++++ fluffy/version.nim | 32 +++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 fluffy/rpc/rpc_calls/rpc_web3_calls.nim create mode 100644 fluffy/rpc/rpc_web3_api.nim create mode 100644 fluffy/version.nim diff --git a/fluffy/fluffy.nim b/fluffy/fluffy.nim index cb2b887d3..dc28f37f1 100644 --- a/fluffy/fluffy.nim +++ b/fluffy/fluffy.nim @@ -19,7 +19,8 @@ import beacon_chain/spec/datatypes/altair, beacon_chain/gossip_processing/light_client_processor, ./conf, ./network_metadata, ./common/common_utils, - ./rpc/[rpc_eth_api, rpc_discovery_api, rpc_portal_api, rpc_portal_debug_api], + ./rpc/[rpc_web3_api, rpc_eth_api, rpc_discovery_api, rpc_portal_api, + rpc_portal_debug_api], ./network/state/[state_network, state_content], ./network/history/[history_network, history_content], ./network/beacon_light_client/[ @@ -246,6 +247,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = let ta = initTAddress(config.rpcAddress, config.rpcPort) var rpcHttpServerWithProxy = RpcProxy.new([ta], config.proxyUri) rpcHttpServerWithProxy.installDiscoveryApiHandlers(d) + rpcHttpServerWithProxy.installWeb3ApiHandlers() if stateNetwork.isSome(): rpcHttpServerWithProxy.installPortalApiHandlers( stateNetwork.get().portalProtocol, "state") diff --git a/fluffy/rpc/eth_rpc_client.nim b/fluffy/rpc/eth_rpc_client.nim index 6cd36adfa..75a067101 100644 --- a/fluffy/rpc/eth_rpc_client.nim +++ b/fluffy/rpc/eth_rpc_client.nim @@ -15,3 +15,4 @@ import export rpcclient, rpc_types, hexstrings, errors createRpcSigs(RpcClient, currentSourcePath.parentDir / "rpc_calls" / "rpc_eth_calls.nim") +createRpcSigs(RpcClient, currentSourcePath.parentDir / "rpc_calls" / "rpc_web3_calls.nim") diff --git a/fluffy/rpc/rpc_calls/rpc_web3_calls.nim b/fluffy/rpc/rpc_calls/rpc_web3_calls.nim new file mode 100644 index 000000000..04f5a0e0c --- /dev/null +++ b/fluffy/rpc/rpc_calls/rpc_web3_calls.nim @@ -0,0 +1 @@ +proc web3_clientVersion(): string diff --git a/fluffy/rpc/rpc_web3_api.nim b/fluffy/rpc/rpc_web3_api.nim new file mode 100644 index 000000000..70e9e8061 --- /dev/null +++ b/fluffy/rpc/rpc_web3_api.nim @@ -0,0 +1,20 @@ +# Nimbus fluffy +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +{.push raises: [].} + +import + json_rpc/[rpcproxy, rpcserver], + ../version + +export rpcserver + +proc installWeb3ApiHandlers*(rpcServer: RpcServer|RpcProxy) + {.raises: [CatchableError].} = + + rpcServer.rpc("web3_clientVersion") do() -> string: + return clientVersion diff --git a/fluffy/version.nim b/fluffy/version.nim new file mode 100644 index 000000000..e4a37987a --- /dev/null +++ b/fluffy/version.nim @@ -0,0 +1,32 @@ +# Nimbus fluffy +# Copyright (c) 2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +{.push raises: [].} + +import strutils + +const + versionMajor* = 0 + versionMinor* = 1 + versionBuild* = 0 + + gitRevision* = strip(staticExec("git rev-parse --short HEAD"))[0..5] + + versionAsStr* = + $versionMajor & "." & $versionMinor & "." & $versionBuild + + fullVersionStr* = "v" & versionAsStr & "-" & gitRevision + + clientName* = "fluffy" + + nimVersion* = staticExec("nim --version | grep -oP '[0-9]+\\.[0-9]+\\.[0-9]+'") + + # The web3_clientVersion + clientVersion* = clientName & "/" & + fullVersionStr & "/" & + hostOS & "-" & hostCPU & "/" & + "Nim" & nimVersion