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,55 +269,47 @@ 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
if rman.supernode: ## ONE of the common custody columns, straight
DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64 ## away returns true if the peer is a supernode.
if rman.supernode:
if peer.lookupCscFromPeer() == DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64:
return true
else:
if peer.lookupCscFromPeer() == DATA_COLUMN_SIDECAR_SUBNET_COUNT.uint64:
return true
elif peer.lookupCscFromPeer() == CUSTODY_REQUIREMENT.uint64:
# Fetch local custody column
let localNodeId = rman.network.nodeId
let localCustodyColumns =
localNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64,
CUSTODY_REQUIREMENT.uint64))
# Fetch the remote custody count
let remoteCustodySubnetCount =
peer.lookupCscFromPeer()
# Extract remote peer's nodeID from peerID
# Fetch custody columns from remote peer
let
remoteNodeId = getNodeIdFromPeer(peer)
remoteCustodyColumns =
remoteNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64,
remoteCustodySubnetCount))
for local_column in localCustodyColumns:
if local_column in remoteCustodyColumns:
return true
else:
return false
else: else:
CUSTODY_REQUIREMENT return false
# Fetching the local cusotrdy columns
let
localNodeId = rman.network.nodeId
localCustodyColumns =
localNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64,
localCustodySubnetCount))
var validPeers: seq[Peer]
for peer in peers:
# Get the custody subnet count of the remote peer
let remoteCustodySubnetCount =
peer.lookupCscFromPeer()
# Extract remote peer's nodeID from peerID
# Fetch custody columns from remote peer
let
remoteNodeId = getNodeIdFromPeer(peer)
remoteCustodyColumns =
remoteNodeId.get_custody_columns(max(SAMPLES_PER_SLOT.uint64,
remoteCustodySubnetCount))
# If the remote peer custodies less columns than
# our local node
# We skip it
if remoteCustodyColumns.len < localCustodyColumns.len:
continue
# If the remote peer custodies all the possible columns
if remoteCustodyColumns.len == NUMBER_OF_COLUMNS:
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)