change lookupcsc logic

This commit is contained in:
Agnish Ghosh 2024-09-19 15:02:41 +05:30
parent e8b64d8dd2
commit 2608c19a13
1 changed files with 26 additions and 26 deletions

View File

@ -2439,39 +2439,39 @@ func announcedENR*(node: Eth2Node): enr.Record =
node.discovery.localNode.record node.discovery.localNode.record
proc lookupCscFromPeer*(peer: Peer): uint64 = proc lookupCscFromPeer*(peer: Peer): uint64 =
# Fetches the custody column count from a remote peer ## Fetches the custody column count from a remote peer
# if the peer advertises their custody column count ## if the peer advertises their custody column count
# via the `csc` ENR field. If the peer does NOT, then ## via the `csc` ENR field. If the peer does NOT, then
# the default value is assume, i.e, CUSTODY_REQUIREMENT ## the default value is assume, i.e, CUSTODY_REQUIREMENT
let metadata = peer.metadata
let enrOpt = peer.enr if metadata.isErr:
if enrOpt.isNone: debug "Could not get csc from metadata, trying from ENR",
debug "Could not get ENR from peer, trying to fetch csc from metadata",
peer_id = peer.peerId peer_id = peer.peerId
let metadata = peer.metadata let enrOpt = peer.enr
if not metadata.isOk: if not enrOpt.isNone:
return(CUSTODY_REQUIREMENT.uint64) let
else: enr = enrOpt.get
return(metadata.get.custody_subnet_count) enrFieldOpt =
else:
let
enr = enrOpt.get
enrFieldOpt =
enr.get(enrCustodySubnetCountField, seq[byte]) enr.get(enrCustodySubnetCountField, seq[byte])
if enrFieldOpt.isOk:
if enrFieldOpt.isOk:
try: try:
let csc = SSZ.decode(enrFieldOpt.get(), uint8) let csc =
SSZ.decode(enrFieldOpt.get, uint8)
debug "LookupCscFromPeer: csc value", debug "LookupCscFromPeer: csc value",
csc = csc csc = csc
return csc return csc
except SszError as e: except SszError as e:
debug "Could not decide the csc field in the ENR" return CUSTODY_REQUIREMENT.uint64
return CUSTODY_REQUIREMENT except SerializationError as e:
except SerializationError: return CUSTODY_REQUIREMENT.uint64
debug "Error in serializing the value" else:
return CUSTODY_REQUIREMENT return CUSTODY_REQUIREMENT.uint64
elif metadata.isOk:
debug "LookupCscFromPeer: csc value from metadata",
csc = metadata.get.custody_subnet_count
return metadata.get.custody_subnet_count
else:
return CUSTODY_REQUIREMENT.uint64
func shortForm*(id: NetKeyPair): string = func shortForm*(id: NetKeyPair): string =
$PeerId.init(id.pubkey) $PeerId.init(id.pubkey)