don't pass entire blocks to list blocks calback
This commit is contained in:
parent
92662dea62
commit
104d5d095e
|
@ -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
|
||||
|
||||
|
|
|
@ -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*(
|
||||
|
|
|
@ -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 =
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue