Skip to content

Commit 316a19a

Browse files
committed
Address review comments
1 parent d232f16 commit 316a19a

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

beacon_chain/eth1_monitor.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ func addBlock(eth1Chain: var Eth1Chain, newBlock: Eth1Block) =
200200
eth1Chain.blocks.addLast newBlock
201201
eth1Chain.blocksByHash[newBlock.voteData.block_hash.asBlockHash] = newBlock
202202

203-
template hash*(x: Eth1Data): Hash =
204-
hash(x.block_hash.data)
203+
func hash*(x: Eth1Data): Hash =
204+
hashData(unsafeAddr x, sizeof(x))
205205

206206
template hash*(x: Eth1Block): Hash =
207207
hash(x.voteData)

beacon_chain/rpc/debug_api.nim

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import
2-
std/[sequtils, deques],
2+
std/sequtils,
33
json_rpc/[rpcserver, jsonmarshal],
44
chronicles,
55
../version, ../beacon_node_common, ../eth2_json_rpc_serialization,
6-
../eth1_monitor, ../validator_duties, ../eth2_network, ../peer_pool,
6+
../eth2_network, ../peer_pool,
77
../spec/[datatypes, digest, presets],
88
./rpc_utils
99

1010
logScope: topics = "debugapi"
1111

1212
type
1313
RpcServer = RpcHttpServer
14-
Eth1Block = eth1_monitor.Eth1Block
1514

1615
proc installDebugApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
1716
rpcServer.rpc("get_v1_debug_beacon_states_stateId") do (
@@ -23,14 +22,3 @@ proc installDebugApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
2322
stateId: string) -> seq[tuple[root: Eth2Digest, slot: Slot]]:
2423
return node.chainDag.heads.mapIt((it.root, it.slot))
2524

26-
rpcServer.rpc("get_v1_debug_eth1_chain") do () -> seq[Eth1Block]:
27-
return mapIt(node.eth1Monitor.blocks, it)
28-
29-
rpcServer.rpc("get_v1_debug_eth1_proposal_data") do () -> BlockProposalEth1Data:
30-
let
31-
wallSlot = node.beaconClock.now.slotOrZero
32-
head = node.doChecksAndGetCurrentHead(wallSlot)
33-
34-
node.chainDag.withState(node.chainDag.tmpState, head.atSlot(wallSlot)):
35-
return node.getBlockProposalEth1Data(state)
36-

beacon_chain/rpc/nimbus_api.nim

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
# at your option. This file may not be copied, modified, or distributed except according to those terms.
66

77
import
8-
std/strutils,
8+
std/[deques, sequtils, strutils],
99
chronos,
1010
stew/shims/macros,
1111
stew/byteutils,
1212
json_rpc/[rpcserver, jsonmarshal],
1313

14+
rpc_utils,
1415
../beacon_node_common, ../nimbus_binary_common, ../eth2_network,
16+
../eth1_monitor, ../validator_duties,
1517
../spec/[digest, datatypes, presets]
1618

1719
logScope: topics = "nimbusapi"
1820

1921
type
2022
RpcServer = RpcHttpServer
23+
Eth1Block = eth1_monitor.Eth1Block
2124

2225
when defined(chronosFutureTracking):
2326
type
@@ -99,6 +102,20 @@ proc installNimbusApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
99102
updateLogLevel(level)
100103
return true
101104

105+
rpcServer.rpc("getEth1Chain") do () -> seq[Eth1Block]:
106+
result = if node.eth1Monitor != nil:
107+
mapIt(node.eth1Monitor.blocks, it)
108+
else:
109+
@[]
110+
111+
rpcServer.rpc("getEth1ProposalData") do () -> BlockProposalEth1Data:
112+
let
113+
wallSlot = node.beaconClock.now.slotOrZero
114+
head = node.doChecksAndGetCurrentHead(wallSlot)
115+
116+
node.chainDag.withState(node.chainDag.tmpState, head.atSlot(wallSlot)):
117+
return node.getBlockProposalEth1Data(state)
118+
102119
when defined(chronosFutureTracking):
103120
rpcServer.rpc("getChronosFutures") do () -> seq[FutureInfo]:
104121
var res: seq[FutureInfo]

docs/the_nimbus_book/src/api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ Set the current logging level dynamically: TRACE, DEBUG, INFO, NOTICE, WARN, ERR
184184
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
185185
```
186186

187+
### getEth1Chain
188+
189+
Get the list of Eth1 blocks that the beacon node is currently storing in memory.
190+
191+
```
192+
curl -d '{"jsonrpc":"2.0","id":"id","method":"getEth1Chain","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result'
193+
```
194+
195+
### getEth1ProposalData
196+
197+
Inspect the eth1 data that the beacon node would produce if it was tasked to produce a block for the current slot.
198+
199+
```
200+
curl -d '{"jsonrpc":"2.0","id":"id","method":"getEth1ProposalData","params":[] }' -H 'Content-Type: application/json' localhost:9190 -s | jq '.result'
201+
```
202+
187203
### getChronosFutures
188204

189205
Get the current list of live async futures in the process - compile with `-d:chronosFutureTracking` to enable.

0 commit comments

Comments
 (0)