From 7df75d77fad35b87f2e7307c95a221c0c92f42a5 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 17 Apr 2023 19:18:54 +0200 Subject: [PATCH] move spec constants to spec (#4825) * move spec constants to spec quite funny, this removes >_1000_ transitive imports when building `nimbus_validator_client`. `genDepend`: ```sh [arnetheduck@praeceps beacon_chain]$ diff -u nimbus_validator_client.dot.pre nimbus_validator_client.dot | wc 1167 3507 103822 ``` * imports * better constants * oops * too many blobs * reorder spec constants in fork order * cleanup --- .../spec/eth2_apis/rest_light_client_calls.nim | 2 +- beacon_chain/spec/network.nim | 9 +++++++++ beacon_chain/sync/light_client_manager.nim | 1 + beacon_chain/sync/sync_manager.nim | 2 +- beacon_chain/sync/sync_protocol.nim | 13 ++++--------- beacon_chain/trusted_node_sync.nim | 3 ++- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/beacon_chain/spec/eth2_apis/rest_light_client_calls.nim b/beacon_chain/spec/eth2_apis/rest_light_client_calls.nim index b26d2fece..d18c10003 100644 --- a/beacon_chain/spec/eth2_apis/rest_light_client_calls.nim +++ b/beacon_chain/spec/eth2_apis/rest_light_client_calls.nim @@ -195,7 +195,7 @@ proc getLightClientBootstrap*( contentType: resp.contentType, data: data)) -from ../../networking/eth2_network import MAX_REQUEST_LIGHT_CLIENT_UPDATES +from ../../spec/network import MAX_REQUEST_LIGHT_CLIENT_UPDATES export MAX_REQUEST_LIGHT_CLIENT_UPDATES proc getLightClientUpdatesByRangePlain( diff --git a/beacon_chain/spec/network.nim b/beacon_chain/spec/network.nim index 998a4fd56..eb27b0286 100644 --- a/beacon_chain/spec/network.nim +++ b/beacon_chain/spec/network.nim @@ -25,12 +25,21 @@ const topicBlsToExecutionChangeSuffix* = "bls_to_execution_change/ssz_snappy" # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/p2p-interface.md#configuration + MAX_REQUEST_BLOCKS* = 1024 RESP_TIMEOUT* = 10.seconds + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/light-client/p2p-interface.md#configuration + MAX_REQUEST_LIGHT_CLIENT_UPDATES* = 128 + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/p2p-interface.md#configuration GOSSIP_MAX_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/p2p-interface.md#configuration + MAX_REQUEST_BLOCKS_DENEB* = 128 # TODO Make use of in request code + MAX_REQUEST_BLOB_SIDECARS* = MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK + # TODO MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS + defaultEth2TcpPort* = 9000 defaultEth2TcpPortDesc* = $defaultEth2TcpPort diff --git a/beacon_chain/sync/light_client_manager.nim b/beacon_chain/sync/light_client_manager.nim index eaa3b04d5..c26c055ea 100644 --- a/beacon_chain/sync/light_client_manager.nim +++ b/beacon_chain/sync/light_client_manager.nim @@ -10,6 +10,7 @@ import chronos, chronicles, stew/base10 import eth/p2p/discoveryv5/random2, + ../spec/network, ../networking/eth2_network, ../beacon_clock, "."/sync_protocol, "."/sync_manager diff --git a/beacon_chain/sync/sync_manager.nim b/beacon_chain/sync/sync_manager.nim index 6a9b538d4..a56cae0dc 100644 --- a/beacon_chain/sync/sync_manager.nim +++ b/beacon_chain/sync/sync_manager.nim @@ -78,7 +78,7 @@ type slots*: uint64 BeaconBlocksRes = NetRes[List[ref ForkedSignedBeaconBlock, MAX_REQUEST_BLOCKS]] - BlobSidecarsRes = NetRes[List[ref BlobSidecar, Limit(MAX_REQUEST_BLOBS_SIDECARS * MAX_BLOBS_PER_BLOCK)]] + BlobSidecarsRes = NetRes[List[ref BlobSidecar, Limit(MAX_REQUEST_BLOB_SIDECARS)]] proc now*(sm: typedesc[SyncMoment], slots: uint64): SyncMoment {.inline.} = SyncMoment(stamp: now(chronos.Moment), slots: slots) diff --git a/beacon_chain/sync/sync_protocol.nim b/beacon_chain/sync/sync_protocol.nim index f4401d718..ecf80d6e4 100644 --- a/beacon_chain/sync/sync_protocol.nim +++ b/beacon_chain/sync/sync_protocol.nim @@ -22,13 +22,8 @@ logScope: topics = "sync" const - MAX_REQUEST_BLOCKS* = 1024 - MAX_REQUEST_BLOBS_SIDECARS* = 128 - blockResponseCost = allowedOpsPerSecondCost(64) # Allow syncing ~64 blocks/sec (minus request costs) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/light-client/p2p-interface.md#configuration - MAX_REQUEST_LIGHT_CLIENT_UPDATES* = 128 lightClientBootstrapResponseCost = allowedOpsPerSecondCost(1) ## Only one bootstrap per peer should ever be needed - no need to allow more lightClientUpdateResponseCost = allowedOpsPerSecondCost(1000) @@ -71,7 +66,7 @@ type slot: Slot BlockRootsList* = List[Eth2Digest, Limit MAX_REQUEST_BLOCKS] - BlobIdentifierList* = List[BlobIdentifier, Limit (MAX_REQUEST_BLOBS_SIDECARS * MAX_BLOBS_PER_BLOCK)] + BlobIdentifierList* = List[BlobIdentifier, Limit (MAX_REQUEST_BLOB_SIDECARS)] template readChunkPayload*( conn: Connection, peer: Peer, MsgType: type ForkySignedBeaconBlock): @@ -434,7 +429,7 @@ p2pProtocol BeaconSync(version = 1, peer: Peer, blobIds: BlobIdentifierList, response: MultipleChunksResponse[ - ref BlobSidecar, Limit(MAX_REQUEST_BLOBS_SIDECARS * MAX_BLOBS_PER_BLOCK)]) + ref BlobSidecar, Limit(MAX_REQUEST_BLOB_SIDECARS)]) {.async, libp2pProtocol("blob_sidecars_by_root", 1).} = # TODO Semantically, this request should return a non-ref, but doing so # runs into extreme inefficiency due to the compiler introducing @@ -486,7 +481,7 @@ p2pProtocol BeaconSync(version = 1, peer: Peer, startSlot: Slot, reqCount: uint64, - response: MultipleChunksResponse[ref BlobSidecar, Limit(MAX_REQUEST_BLOBS_SIDECARS * MAX_BLOBS_PER_BLOCK)]) + response: MultipleChunksResponse[ref BlobSidecar, Limit(MAX_REQUEST_BLOB_SIDECARS)]) {.async, libp2pProtocol("blob_sidecars_by_range", 1).} = # TODO This code is more complicated than it needs to be, since the type # of the multiple chunks response is not actually used in this server @@ -512,7 +507,7 @@ p2pProtocol BeaconSync(version = 1, if startSlot.epoch < epochBoundary: raise newException(ResourceUnavailableError, BlobsOutOfRange) - var blockIds: array[MAX_REQUEST_BLOBS_SIDECARS, BlockId] + var blockIds: array[int(MAX_REQUEST_BLOB_SIDECARS), BlockId] let count = int min(reqCount, blockIds.lenu64) endIndex = count - 1 diff --git a/beacon_chain/trusted_node_sync.nim b/beacon_chain/trusted_node_sync.nim index 916afd7b1..18d48adf4 100644 --- a/beacon_chain/trusted_node_sync.nim +++ b/beacon_chain/trusted_node_sync.nim @@ -12,7 +12,8 @@ import ./sync/sync_manager, ./consensus_object_pools/[block_clearance, blockchain_dag], ./spec/eth2_apis/rest_beacon_client, - ./spec/[beaconstate, eth2_merkleization, forks, light_client_sync, presets, + ./spec/[beaconstate, eth2_merkleization, forks, light_client_sync, + network, presets, state_transition, deposit_snapshots], "."/[beacon_clock, beacon_chain_db, era_db]