Restore cidOrTreeCid
This commit is contained in:
parent
512a736c79
commit
3e706b3eea
|
@ -56,19 +56,10 @@ type
|
|||
discoveryLoopSleep: Duration # Discovery loop sleep
|
||||
inFlightDiscReqs*: Table[Cid, Future[seq[SignedPeerRecord]]] # Inflight discovery requests
|
||||
|
||||
proc getCid(address: BlockAddress): Cid =
|
||||
# We advertise and discover only the CID part of a block address.
|
||||
# Indices are ignored. This means that multiple blocks of the same tree will
|
||||
# have a single DHT entry.
|
||||
if address.leaf:
|
||||
address.treeCid
|
||||
else:
|
||||
address.cid
|
||||
|
||||
proc discoveryQueueLoop(b: DiscoveryEngine) {.async: (raises: []).} =
|
||||
while b.discEngineRunning:
|
||||
for address in toSeq(b.pendingBlocks.wantList):
|
||||
let cid = address.getCid()
|
||||
let cid = address.cidOrTreeCid
|
||||
try:
|
||||
await b.discoveryQueue.put(cid)
|
||||
except CancelledError:
|
||||
|
@ -134,15 +125,17 @@ proc discoveryTaskLoop(b: DiscoveryEngine) {.async: (raises: []).} =
|
|||
|
||||
info "Exiting discovery task runner"
|
||||
|
||||
proc queueFindBlocksReq*(b: DiscoveryEngine, addresses: seq[BlockAddress]) {.inline.} =
|
||||
for address in addresses:
|
||||
let cid = address.getCid()
|
||||
proc queueFindBlocksReq*(b: DiscoveryEngine, cids: seq[Cid]) {.inline.} =
|
||||
for cid in cids:
|
||||
if cid notin b.discoveryQueue:
|
||||
try:
|
||||
b.discoveryQueue.putNoWait(cid)
|
||||
except CatchableError as exc:
|
||||
warn "Exception queueing discovery request", exc = exc.msg
|
||||
|
||||
proc queueFindBlocksReq*(b: DiscoveryEngine, addresses: seq[BlockAddress]) {.inline.} =
|
||||
b.queueFindBlocksReq(addresses.mapIt(it.cidOrTreeCid))
|
||||
|
||||
proc start*(b: DiscoveryEngine) {.async.} =
|
||||
## Start the discengine task
|
||||
##
|
||||
|
|
|
@ -65,12 +65,7 @@ func peersHave*(self: PeerCtxStore, address: BlockAddress): seq[BlockExcPeerCtx]
|
|||
toSeq(self.peers.values).filterIt( it.peerHave.anyIt( it == address ) )
|
||||
|
||||
func countPeersWhoHave*(self: PeerCtxStore, cid: Cid): int =
|
||||
proc getCid(address: BlockAddress): Cid =
|
||||
if address.leaf:
|
||||
address.treeCid
|
||||
else:
|
||||
address.cid
|
||||
self.peers.values.countIt(it.peerHave.anyIt( it.getCid() == cid ) )
|
||||
self.peers.values.countIt(it.peerHave.anyIt( it.cidOrTreeCid == cid ) )
|
||||
|
||||
func peersWant*(self: PeerCtxStore, address: BlockAddress): seq[BlockExcPeerCtx] =
|
||||
toSeq(self.peers.values).filterIt( it.peerWants.anyIt( it == address ) )
|
||||
|
|
|
@ -66,6 +66,12 @@ proc `$`*(a: BlockAddress): string =
|
|||
else:
|
||||
"cid: " & $a.cid
|
||||
|
||||
proc cidOrTreeCid*(a: BlockAddress): Cid =
|
||||
if a.leaf:
|
||||
a.treeCid
|
||||
else:
|
||||
a.cid
|
||||
|
||||
proc address*(b: Block): BlockAddress =
|
||||
BlockAddress(leaf: false, cid: b.cid)
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ checksuite "Pending Blocks":
|
|||
discard blks.mapIt( pendingBlocks.getWantHandle( it.cid ) )
|
||||
|
||||
check:
|
||||
blks.mapIt( $it.cid ).sorted(cmp[string]) ==
|
||||
toSeq(pendingBlocks.wantListBlockCids).mapIt( $it ).sorted(cmp[string])
|
||||
blks.mapIt( $BlockAddress.init(it.cid) ).sorted(cmp[string]) ==
|
||||
toSeq(pendingBlocks.wantList).mapIt( $it ).sorted(cmp[string])
|
||||
|
||||
test "Should get want handles list":
|
||||
let
|
||||
|
|
Loading…
Reference in New Issue