don't pass entire blocks to list blocks calback

This commit is contained in:
Dmitriy Ryajov 2022-04-19 20:44:25 -06:00
parent 92662dea62
commit 104d5d095e
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
6 changed files with 9 additions and 12 deletions

View File

@ -105,9 +105,9 @@ proc discoveryLoopRunner(b: BlockExcEngine) {.async.} =
await sleepAsync(30.seconds)
proc advertiseLoopRunner*(b: BlockExcEngine) {.async.} =
proc onBlock(blk: bt.Block) {.async.} =
proc onBlock(cid: Cid) {.async.} =
try:
await b.advertiseQueue.put(blk.cid)
await b.advertiseQueue.put(cid)
except CatchableError as exc:
trace "Exception listing blocks", exc = exc.msg

View File

@ -20,7 +20,7 @@ import ../blocktype
export blocktype, libp2p
type
OnBlock* = proc(blk: Block): Future[void] {.upraises: [], gcsafe.}
OnBlock* = proc(cid: Cid): Future[void] {.upraises: [], gcsafe.}
BlockStore* = ref object of RootObj
method getBlock*(

View File

@ -70,10 +70,7 @@ method hasBlock*(self: CacheStore, cid: Cid): bool =
method listBlocks*(s: CacheStore, onBlock: OnBlock) {.async.} =
for cid in toSeq(s.cache.keys):
without blk =? (await s.getBlock(cid)):
trace "Couldn't get block", cid = $cid
await onBlock(blk)
await onBlock(cid)
func putBlockSync(self: CacheStore, blk: Block): bool =

View File

@ -143,7 +143,7 @@ method listBlocks*(self: FSStore, onBlock: OnBlock) {.async.} =
# getting a weird `Error: unhandled exception: index 1 not in 0 .. 0 [IndexError]`
# compilation error if using different syntax/construct bellow
try:
await onBlock((await self.getBlock(cid.tryGet())).tryGet())
await onBlock(cid.get())
except CatchableError as exc:
trace "Couldn't get block", cid = $(cid.get())

View File

@ -112,8 +112,8 @@ suite "Cache Store tests":
var listed = false
await store.listBlocks(
proc(blk: Block) {.gcsafe, async.} =
check blk.cid in store
proc(cid: Cid) {.gcsafe, async.} =
check cid in store
listed = true
)

View File

@ -57,8 +57,8 @@ suite "FS Store":
writeFile(store.blockPath(newBlock.cid), newBlock.data)
await store.listBlocks(
proc(blk: Block) {.gcsafe, async.} =
check blk.cid == newBlock.cid)
proc(cid: Cid) {.gcsafe, async.} =
check cid == newBlock.cid)
test "fail hasBlock":
check not store.hasBlock(newBlock.cid)