From 316a19af5fffb3161235509e405773c631f7f269 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 20 Nov 2020 16:42:04 +0200 Subject: [PATCH] Address review comments --- beacon_chain/eth1_monitor.nim | 4 ++-- beacon_chain/rpc/debug_api.nim | 16 ++-------------- beacon_chain/rpc/nimbus_api.nim | 19 ++++++++++++++++++- docs/the_nimbus_book/src/api.md | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/beacon_chain/eth1_monitor.nim b/beacon_chain/eth1_monitor.nim index 791e3102e..992a32fcd 100644 --- a/beacon_chain/eth1_monitor.nim +++ b/beacon_chain/eth1_monitor.nim @@ -200,8 +200,8 @@ func addBlock(eth1Chain: var Eth1Chain, newBlock: Eth1Block) = eth1Chain.blocks.addLast newBlock eth1Chain.blocksByHash[newBlock.voteData.block_hash.asBlockHash] = newBlock -template hash*(x: Eth1Data): Hash = - hash(x.block_hash.data) +func hash*(x: Eth1Data): Hash = + hashData(unsafeAddr x, sizeof(x)) template hash*(x: Eth1Block): Hash = hash(x.voteData) diff --git a/beacon_chain/rpc/debug_api.nim b/beacon_chain/rpc/debug_api.nim index 6e010257b..3279ba219 100644 --- a/beacon_chain/rpc/debug_api.nim +++ b/beacon_chain/rpc/debug_api.nim @@ -1,9 +1,9 @@ import - std/[sequtils, deques], + std/sequtils, json_rpc/[rpcserver, jsonmarshal], chronicles, ../version, ../beacon_node_common, ../eth2_json_rpc_serialization, - ../eth1_monitor, ../validator_duties, ../eth2_network, ../peer_pool, + ../eth2_network, ../peer_pool, ../spec/[datatypes, digest, presets], ./rpc_utils @@ -11,7 +11,6 @@ logScope: topics = "debugapi" type RpcServer = RpcHttpServer - Eth1Block = eth1_monitor.Eth1Block proc installDebugApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = rpcServer.rpc("get_v1_debug_beacon_states_stateId") do ( @@ -23,14 +22,3 @@ proc installDebugApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = stateId: string) -> seq[tuple[root: Eth2Digest, slot: Slot]]: return node.chainDag.heads.mapIt((it.root, it.slot)) - rpcServer.rpc("get_v1_debug_eth1_chain") do () -> seq[Eth1Block]: - return mapIt(node.eth1Monitor.blocks, it) - - rpcServer.rpc("get_v1_debug_eth1_proposal_data") do () -> BlockProposalEth1Data: - let - wallSlot = node.beaconClock.now.slotOrZero - head = node.doChecksAndGetCurrentHead(wallSlot) - - node.chainDag.withState(node.chainDag.tmpState, head.atSlot(wallSlot)): - return node.getBlockProposalEth1Data(state) - diff --git a/beacon_chain/rpc/nimbus_api.nim b/beacon_chain/rpc/nimbus_api.nim index a0f823193..01fb37717 100644 --- a/beacon_chain/rpc/nimbus_api.nim +++ b/beacon_chain/rpc/nimbus_api.nim @@ -5,19 +5,22 @@ # at your option. This file may not be copied, modified, or distributed except according to those terms. import - std/strutils, + std/[deques, sequtils, strutils], chronos, stew/shims/macros, stew/byteutils, json_rpc/[rpcserver, jsonmarshal], + rpc_utils, ../beacon_node_common, ../nimbus_binary_common, ../eth2_network, + ../eth1_monitor, ../validator_duties, ../spec/[digest, datatypes, presets] logScope: topics = "nimbusapi" type RpcServer = RpcHttpServer + Eth1Block = eth1_monitor.Eth1Block when defined(chronosFutureTracking): type @@ -99,6 +102,20 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = updateLogLevel(level) return true + rpcServer.rpc("getEth1Chain") do () -> seq[Eth1Block]: + result = if node.eth1Monitor != nil: + mapIt(node.eth1Monitor.blocks, it) + else: + @[] + + rpcServer.rpc("getEth1ProposalData") do () -> BlockProposalEth1Data: + let + wallSlot = node.beaconClock.now.slotOrZero + head = node.doChecksAndGetCurrentHead(wallSlot) + + node.chainDag.withState(node.chainDag.tmpState, head.atSlot(wallSlot)): + return node.getBlockProposalEth1Data(state) + when defined(chronosFutureTracking): rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]: var res: seq[FutureInfo] diff --git a/docs/the_nimbus_book/src/api.md b/docs/the_nimbus_book/src/api.md index 3a00f4a27..fbf20b340 100644 --- a/docs/the_nimbus_book/src/api.md +++ b/docs/the_nimbus_book/src/api.md @@ -184,6 +184,22 @@ Set the current logging level dynamically: TRACE, DEBUG, INFO, NOTICE, WARN, ERR curl -d '{"jsonrpc":"2.0","id":"id","method":"setLogLevel","params":["DEBUG; TRACE:discv5,libp2p; REQUIRED:none; DISABLED:none"] }' -H 'Content-Type: application/json' localhost:9190 -s | jq ``` +### getEth1Chain + +Get the list of Eth1 blocks that the beacon node is currently storing in memory. + +``` +curl -d '{"jsonrpc":"2.0","id":"id","method":"getEth1Chain","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result' +``` + +### getEth1ProposalData + +Inspect the eth1 data that the beacon node would produce if it was tasked to produce a block for the current slot. + +``` +curl -d '{"jsonrpc":"2.0","id":"id","method":"getEth1ProposalData","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result' +``` + ### getChronosFutures Get the current list of live async futures in the process - compile with `-d:chronosFutureTracking` to enable.