From 104d5d095e3c749a49c24bebb85db179e4cdc508 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 19 Apr 2022 20:44:25 -0600 Subject: [PATCH] don't pass entire blocks to list blocks calback --- dagger/blockexchange/engine.nim | 4 ++-- dagger/stores/blockstore.nim | 2 +- dagger/stores/cachestore.nim | 5 +---- dagger/stores/fsstore.nim | 2 +- tests/dagger/stores/testcachestore.nim | 4 ++-- tests/dagger/stores/testfsstore.nim | 4 ++-- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/dagger/blockexchange/engine.nim b/dagger/blockexchange/engine.nim index fdca9955..c8c8ad6b 100644 --- a/dagger/blockexchange/engine.nim +++ b/dagger/blockexchange/engine.nim @@ -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 diff --git a/dagger/stores/blockstore.nim b/dagger/stores/blockstore.nim index 7288a454..ddcbc550 100644 --- a/dagger/stores/blockstore.nim +++ b/dagger/stores/blockstore.nim @@ -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*( diff --git a/dagger/stores/cachestore.nim b/dagger/stores/cachestore.nim index abe642df..50cfaf9d 100644 --- a/dagger/stores/cachestore.nim +++ b/dagger/stores/cachestore.nim @@ -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 = diff --git a/dagger/stores/fsstore.nim b/dagger/stores/fsstore.nim index 735fc65a..b561250d 100644 --- a/dagger/stores/fsstore.nim +++ b/dagger/stores/fsstore.nim @@ -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()) diff --git a/tests/dagger/stores/testcachestore.nim b/tests/dagger/stores/testcachestore.nim index ea88ea22..3bd128dd 100644 --- a/tests/dagger/stores/testcachestore.nim +++ b/tests/dagger/stores/testcachestore.nim @@ -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 ) diff --git a/tests/dagger/stores/testfsstore.nim b/tests/dagger/stores/testfsstore.nim index 86dd0411..628cf42d 100644 --- a/tests/dagger/stores/testfsstore.nim +++ b/tests/dagger/stores/testfsstore.nim @@ -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)