From 8bb1145b4398a0136917e2b30ef0fe6278702423 Mon Sep 17 00:00:00 2001 From: Agnish Ghosh Date: Sun, 18 Aug 2024 21:42:10 +0530 Subject: [PATCH] populate dataColumnSidecarByRange with remote custody columns --- beacon_chain/spec/eip7594_helpers.nim | 28 ++++++++++++++++++++++++++- beacon_chain/sync/sync_manager.nim | 14 +++++++++++++- beacon_chain/sync/sync_queue.nim | 1 - 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/beacon_chain/spec/eip7594_helpers.nim b/beacon_chain/spec/eip7594_helpers.nim index 7613e7f3c..fba404163 100644 --- a/beacon_chain/spec/eip7594_helpers.nim +++ b/beacon_chain/spec/eip7594_helpers.nim @@ -31,10 +31,25 @@ proc sortedColumnIndices*(columnsPerSubnet: ColumnIndex, subnetIds: HashSet[uint for i in 0 ..< columnsPerSubnet: for subnetId in subnetIds: let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId - result.add(ColumnIndex(index)) + res.add(ColumnIndex(index)) res.sort() res +proc sortedColumnIndexList*(columnsPerSubnet: ColumnIndex, + subnetIds: HashSet[uint64]): + List[ColumnIndex, NUMBER_OF_COLUMNS] = + var + res: seq[ColumnIndex] + list: List[ColumnIndex, NUMBER_OF_COLUMNS] + for i in 0 ..< columnsPerSubnet: + for subnetId in subnetIds: + let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId + res.add(ColumnIndex(index)) + res.sort() + for elem in res: + discard list.add(ColumnIndex(elem)) + list + proc get_custody_column_subnet*(node_id: NodeId, custody_subnet_count: uint64): Result[HashSet[uint64], cstring] = @@ -81,6 +96,17 @@ proc get_custody_columns*(node_id: NodeId, ok(sortedColumnIndices(ColumnIndex(columns_per_subnet), subnet_ids)) +proc get_custody_column_list*(node_id: NodeId, + custody_subnet_count: uint64): + Result[List[ColumnIndex, NUMBER_OF_COLUMNS], cstring] = + + let subnet_ids = get_custody_column_subnet(node_id, custody_subnet_count).get + + # columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT + let columns_per_subnet = NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT + + ok(sortedColumnIndexList(ColumnIndex(columns_per_subnet), subnet_ids)) + # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/_features/eip7594/das-core.md#compute_extended_matrix proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[seq[MatrixEntry], cstring] = # This helper demonstrates the relationship between blobs and the `MatrixEntries` diff --git a/beacon_chain/sync/sync_manager.nim b/beacon_chain/sync/sync_manager.nim index dc2febfc3..1f684d333 100644 --- a/beacon_chain/sync/sync_manager.nim +++ b/beacon_chain/sync/sync_manager.nim @@ -280,9 +280,21 @@ proc getDataColumnSidecars[A, B](man: SyncManager[A, B], peer: A, direction = man.direction topics = "syncman" + let + remoteCustodySubnetCount = + if man.supernode: + DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64 + else: + CUSTODY_REQUIREMENT.uint64 + + let + remoteNodeId = getNodeIdFromPeer(peer) + remoteCustodyColumns = + remoteNodeId.get_custody_column_list(remoteCustodySubnetCount).get + doAssert(not(req.isEmpty()), "Request must not be empty!") debug "Requesting data column sidecars from peer", request = req - dataColumnSidecarsByRange(peer, req.slot, req.count, req.columns) + dataColumnSidecarsByRange(peer, req.slot, req.count, remoteCustodyColumns) func groupDataColumns*[T](req: SyncRequest[T], blocks: seq[ref ForkedSignedBeaconBlock], diff --git a/beacon_chain/sync/sync_queue.nim b/beacon_chain/sync/sync_queue.nim index a49255746..7c288f5c1 100644 --- a/beacon_chain/sync/sync_queue.nim +++ b/beacon_chain/sync/sync_queue.nim @@ -38,7 +38,6 @@ type index*: uint64 slot*: Slot count*: uint64 - columns*: List[ColumnIndex, NUMBER_OF_COLUMNS] item*: T SyncResult*[T] = object