rework filtering for root request

This commit is contained in:
Agnish Ghosh 2024-09-23 00:03:37 +05:30
parent 916ac0eb58
commit d08044f584

View File

@ -269,26 +269,28 @@ proc fetchBlobsFromNetwork(self: RequestManager,
if not(isNil(peer)): if not(isNil(peer)):
self.network.peerPool.release(peer) self.network.peerPool.release(peer)
proc constructValidCustodyPeers(rman: RequestManager, proc checkPeerCustody*(rman: RequestManager,
peers: openArray[Peer]): peer: Peer):
seq[Peer] = bool =
let localCustodySubnetCount = ## Returns true if the peer custodies atleast
## ONE of the common custody columns, straight
## away returns true if the peer is a supernode.
if rman.supernode: if rman.supernode:
DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64 if peer.lookupCscFromPeer() == DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64:
return true
else: else:
CUSTODY_REQUIREMENT if peer.lookupCscFromPeer() == DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64:
return true
# Fetching the local cusotrdy columns elif peer.lookupCscFromPeer() == CUSTODY_REQUIREMENT.uint64:
let # Fetch local custody column
localNodeId = rman.network.nodeId let localNodeId = rman.network.nodeId
localCustodyColumns = let localCustodyColumns =
localNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64, localNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64,
localCustodySubnetCount)) CUSTODY_REQUIREMENT.uint64))
var validPeers: seq[Peer] # Fetch the remote custody count
for peer in peers:
# Get the custody subnet count of the remote peer
let remoteCustodySubnetCount = let remoteCustodySubnetCount =
peer.lookupCscFromPeer() peer.lookupCscFromPeer()
@ -300,24 +302,14 @@ proc constructValidCustodyPeers(rman: RequestManager,
remoteNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64, remoteNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64,
remoteCustodySubnetCount)) remoteCustodySubnetCount))
# If the remote peer custodies less columns than for local_column in localCustodyColumns:
# our local node if local_column in remoteCustodyColumns:
# We skip it return true
if remoteCustodyColumns.len < localCustodyColumns.len: else:
continue return false
# If the remote peer custodies all the possible columns else:
if remoteCustodyColumns.len == NUMBER_OF_COLUMNS: return false
validPeers.add(peer)
# Filtering out the inval;id peers
for column in localCustodyColumns:
if column notin remoteCustodyColumns:
continue
# Otherwise add the peer to the set of valid peers
validPeers.add(peer)
validPeers
proc fetchDataColumnsFromNetwork(rman: RequestManager, proc fetchDataColumnsFromNetwork(rman: RequestManager,
colIdList: seq[DataColumnIdentifier]) colIdList: seq[DataColumnIdentifier])
@ -327,11 +319,7 @@ proc fetchDataColumnsFromNetwork(rman: RequestManager,
try: try:
peer = await rman.network.peerPool.acquire() peer = await rman.network.peerPool.acquire()
# Create a peer list, which shall be later trimmed off as to which if rman.checkPeerCustody(peer):
# of the peers have the valid custody columns
peers.add(peer)
let validPeers = rman.constructValidCustodyPeers(peers)
if peer in validPeers:
debug "Requesting data columns by root", peer = peer, columns = shortLog(colIdList), debug "Requesting data columns by root", peer = peer, columns = shortLog(colIdList),
peer_score = peer.getScore() peer_score = peer.getScore()
let columns = await dataColumnSidecarsByRoot(peer, DataColumnIdentifierList colIdList) let columns = await dataColumnSidecarsByRoot(peer, DataColumnIdentifierList colIdList)
@ -355,7 +343,7 @@ proc fetchDataColumnsFromNetwork(rman: RequestManager,
let col = o.unsafeGet() let col = o.unsafeGet()
discard await rman.blockVerifier(col, false) discard await rman.blockVerifier(col, false)
else: else:
debug "Data columns by root request failed", debug "Data columns by root request not done, peer doesn't have custody column",
peer = peer, columns = shortLog(colIdList), err = columns.error() peer = peer, columns = shortLog(colIdList), err = columns.error()
# peer.updateScore(PeerScoreNoValues) # peer.updateScore(PeerScoreNoValues)