Address review comments

This commit is contained in:
Zahary Karadjov 2020-11-20 16:42:04 +02:00 committed by zah
parent d232f16b40
commit 316a19af5f
4 changed files with 38 additions and 17 deletions

View File

@ -200,8 +200,8 @@ func addBlock(eth1Chain: var Eth1Chain, newBlock: Eth1Block) =
eth1Chain.blocks.addLast newBlock eth1Chain.blocks.addLast newBlock
eth1Chain.blocksByHash[newBlock.voteData.block_hash.asBlockHash] = newBlock eth1Chain.blocksByHash[newBlock.voteData.block_hash.asBlockHash] = newBlock
template hash*(x: Eth1Data): Hash = func hash*(x: Eth1Data): Hash =
hash(x.block_hash.data) hashData(unsafeAddr x, sizeof(x))
template hash*(x: Eth1Block): Hash = template hash*(x: Eth1Block): Hash =
hash(x.voteData) hash(x.voteData)

View File

@ -1,9 +1,9 @@
import import
std/[sequtils, deques], std/sequtils,
json_rpc/[rpcserver, jsonmarshal], json_rpc/[rpcserver, jsonmarshal],
chronicles, chronicles,
../version, ../beacon_node_common, ../eth2_json_rpc_serialization, ../version, ../beacon_node_common, ../eth2_json_rpc_serialization,
../eth1_monitor, ../validator_duties, ../eth2_network, ../peer_pool, ../eth2_network, ../peer_pool,
../spec/[datatypes, digest, presets], ../spec/[datatypes, digest, presets],
./rpc_utils ./rpc_utils
@ -11,7 +11,6 @@ logScope: topics = "debugapi"
type type
RpcServer = RpcHttpServer RpcServer = RpcHttpServer
Eth1Block = eth1_monitor.Eth1Block
proc installDebugApiHandlers*(rpcServer: RpcServer, node: BeaconNode) = proc installDebugApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
rpcServer.rpc("get_v1_debug_beacon_states_stateId") do ( 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]]: stateId: string) -> seq[tuple[root: Eth2Digest, slot: Slot]]:
return node.chainDag.heads.mapIt((it.root, it.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)

View File

@ -5,19 +5,22 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
std/strutils, std/[deques, sequtils, strutils],
chronos, chronos,
stew/shims/macros, stew/shims/macros,
stew/byteutils, stew/byteutils,
json_rpc/[rpcserver, jsonmarshal], json_rpc/[rpcserver, jsonmarshal],
rpc_utils,
../beacon_node_common, ../nimbus_binary_common, ../eth2_network, ../beacon_node_common, ../nimbus_binary_common, ../eth2_network,
../eth1_monitor, ../validator_duties,
../spec/[digest, datatypes, presets] ../spec/[digest, datatypes, presets]
logScope: topics = "nimbusapi" logScope: topics = "nimbusapi"
type type
RpcServer = RpcHttpServer RpcServer = RpcHttpServer
Eth1Block = eth1_monitor.Eth1Block
when defined(chronosFutureTracking): when defined(chronosFutureTracking):
type type
@ -99,6 +102,20 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
updateLogLevel(level) updateLogLevel(level)
return true 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): when defined(chronosFutureTracking):
rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]: rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]:
var res: seq[FutureInfo] var res: seq[FutureInfo]

View File

@ -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 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 ### getChronosFutures
Get the current list of live async futures in the process - compile with `-d:chronosFutureTracking` to enable. Get the current list of live async futures in the process - compile with `-d:chronosFutureTracking` to enable.