Skip to content

Commit b913e23

Browse files
authored
Tidying up wire protocol handler and add limit (#3116)
Unfortunately, because of rlp encoding, the rate limiter like in nimbus-eth2 cannot be applied to nimbus-eth1 wire protocol handler immediately. So we stick with what the spec says. In nimbus-eth2 or consensus layer in general, the wire protocol is encoded in SSZ. So it is possible to send the message in chunk relatively easy. While execution client is using RLP encoding. Even before sending the wire message, the full payload length prefix must be calculated, therefore a special RLP encoder is needed. And because the full payload must be held in memory, benefits of incremental read from database cannot be applied.
1 parent fbb8f15 commit b913e23

File tree

27 files changed

+308
-750
lines changed

27 files changed

+308
-750
lines changed

execution_chain/core/chain/forked_chain.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ func txFrame*(c: ForkedChainRef, blockHash: Hash32): CoreDbTxRef =
575575

576576
c.baseTxFrame
577577

578+
func baseTxFrame*(c: ForkedChainRef): CoreDbTxRef =
579+
c.baseTxFrame
580+
578581
func txFrame*(c: ForkedChainRef, header: Header): CoreDbTxRef =
579582
c.txFrame(header.blockHash())
580583

execution_chain/networking/p2p.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export
2121
logScope:
2222
topics = "eth p2p"
2323

24-
2524
proc addCapability*(node: EthereumNode,
2625
p: ProtocolInfo,
2726
networkState: RootRef = nil) =

execution_chain/nimbus_desc.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type
4343
ethNode*: EthereumNode
4444
state*: NimbusState
4545
ctx*: EthContext
46-
chainRef*: ForkedChainRef
46+
fc*: ForkedChainRef
4747
txPool*: TxPoolRef
4848
networkLoop*: Future[void]
4949
peerManager*: PeerManagerRef

execution_chain/nimbus_execution_client.nim

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import
2727
./core/eip4844,
2828
./db/core_db/persistent,
2929
./db/storage_types,
30-
./sync/handlers,
30+
./sync/wire_protocol,
3131
./common/chain_config_hash
3232

3333
from beacon_chain/nimbus_binary_common import setupFileLimits
@@ -43,12 +43,12 @@ when defined(evmc_enabled):
4343
proc basicServices(nimbus: NimbusNode,
4444
conf: NimbusConf,
4545
com: CommonRef) =
46-
nimbus.chainRef = ForkedChainRef.init(com)
46+
nimbus.fc = ForkedChainRef.init(com)
4747

4848
# txPool must be informed of active head
4949
# so it can know the latest account state
5050
# e.g. sender nonce, etc
51-
nimbus.txPool = TxPoolRef.new(nimbus.chainRef)
51+
nimbus.txPool = TxPoolRef.new(nimbus.fc)
5252
nimbus.beaconEngine = BeaconEngineRef.new(nimbus.txPool)
5353

5454
proc manageAccounts(nimbus: NimbusNode, conf: NimbusConf) =
@@ -107,12 +107,11 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
107107
rng = nimbus.ctx.rng)
108108

109109
# Add protocol capabilities
110-
nimbus.ethNode.addEthHandlerCapability(
111-
nimbus.ethNode.peerPool, nimbus.chainRef, nimbus.txPool)
110+
nimbus.ethNode.addEthHandlerCapability(nimbus.txPool)
112111

113112
# Always initialise beacon syncer
114113
nimbus.beaconSyncRef = BeaconSyncRef.init(
115-
nimbus.ethNode, nimbus.chainRef, conf.maxPeers, conf.beaconBlocksQueueHwm)
114+
nimbus.ethNode, nimbus.fc, conf.maxPeers, conf.beaconBlocksQueueHwm)
116115

117116
# Connect directly to the static nodes
118117
let staticPeers = conf.getStaticPeers()

execution_chain/sync/beacon.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import
1616
../core/chain,
1717
../networking/p2p,
1818
./beacon/[worker, worker_desc, worker/db],
19-
"."/[sync_desc, sync_sched, protocol]
19+
"."/[sync_desc, sync_sched, wire_protocol]
2020

2121
logScope:
2222
topics = "beacon sync"

execution_chain/sync/beacon/worker/blocks_staged/bodies.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import
1515
pkg/[chronicles, chronos, results],
1616
pkg/eth/common,
1717
pkg/stew/interval_set,
18-
../../../protocol,
18+
../../../wire_protocol,
1919
../../worker_desc,
2020
../../../../networking/p2p
2121

execution_chain/sync/beacon/worker/headers_staged/headers.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import
1515
pkg/[chronicles, chronos, results],
1616
pkg/eth/common,
1717
pkg/stew/interval_set,
18-
../../../protocol,
19-
../../../protocol/eth/eth_types,
2018
../../worker_desc,
19+
../../../wire_protocol,
2120
../../../../networking/p2p
2221

2322
# ------------------------------------------------------------------------------

execution_chain/sync/beacon/worker/start_stop.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import
1414
pkg/eth/common,
1515
../../../core/chain,
1616
../../../networking/p2p,
17-
../../protocol,
17+
../../wire_protocol,
1818
../worker_desc,
1919
./blocks_staged/staged_queue,
2020
./headers_staged/staged_queue,
@@ -119,7 +119,7 @@ proc startBuddy*(buddy: BeaconBuddyRef): bool =
119119
let
120120
ctx = buddy.ctx
121121
peer = buddy.peer
122-
if peer.supports(protocol.eth) and peer.state(protocol.eth).initialized:
122+
if peer.supports(wire_protocol.eth) and peer.state(wire_protocol.eth).initialized:
123123
ctx.pool.nBuddies.inc
124124
return true
125125

execution_chain/sync/handlers.nim

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)