Skip to content

Commit b274b29

Browse files
committed
fix: fix testdiscovery so it works with stricter block protocol
1 parent 572b448 commit b274b29

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

codex/blockexchange/engine/engine.nim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,10 @@ proc validateBlockDelivery(self: BlockExcEngine, bd: BlockDelivery): ?!void =
555555
return success()
556556

557557
proc blocksDeliveryHandler*(
558-
self: BlockExcEngine, peer: PeerId, blocksDelivery: seq[BlockDelivery]
558+
self: BlockExcEngine,
559+
peer: PeerId,
560+
blocksDelivery: seq[BlockDelivery],
561+
allowSpurious: bool = false,
559562
) {.async: (raises: []).} =
560563
trace "Received blocks from peer", peer, blocks = (blocksDelivery.mapIt(it.address))
561564

@@ -569,7 +572,7 @@ proc blocksDeliveryHandler*(
569572

570573
try:
571574
# Unknown peers and unrequested blocks are dropped with a warning.
572-
if peerCtx == nil or not peerCtx.blockReceived(bd.address):
575+
if not allowSpurious and (peerCtx == nil or not peerCtx.blockReceived(bd.address)):
573576
warn "Dropping unrequested or duplicate block received from peer"
574577
codex_block_exchange_spurious_blocks_received.inc()
575578
continue

tests/codex/blockexchange/discovery/testdiscovery.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
216216
test "E2E - Should advertise and discover blocks":
217217
# Distribute the manifests and trees amongst 1..3
218218
# Ask 0 to download everything without connecting him beforehand
219-
220219
var advertised: Table[Cid, SignedPeerRecord]
221220

222221
MockDiscovery(blockexc[1].engine.discovery.discovery).publishBlockProvideHandler = proc(
@@ -242,6 +241,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
242241
blk: mBlocks[0], address: BlockAddress(leaf: false, cid: mBlocks[0].cid)
243242
)
244243
],
244+
allowSpurious = true,
245245
)
246246

247247
discard blockexc[2].engine.pendingBlocks.getWantHandle(mBlocks[1].cid)
@@ -252,6 +252,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
252252
blk: mBlocks[1], address: BlockAddress(leaf: false, cid: mBlocks[1].cid)
253253
)
254254
],
255+
allowSpurious = true,
255256
)
256257

257258
discard blockexc[3].engine.pendingBlocks.getWantHandle(mBlocks[2].cid)
@@ -262,6 +263,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
262263
blk: mBlocks[2], address: BlockAddress(leaf: false, cid: mBlocks[2].cid)
263264
)
264265
],
266+
allowSpurious = true,
265267
)
266268

267269
MockDiscovery(blockexc[0].engine.discovery.discovery).findBlockProvidersHandler = proc(
@@ -311,6 +313,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
311313
blk: mBlocks[0], address: BlockAddress(leaf: false, cid: mBlocks[0].cid)
312314
)
313315
],
316+
allowSpurious = true,
314317
)
315318

316319
discard blockexc[2].engine.pendingBlocks.getWantHandle(mBlocks[1].cid)
@@ -321,6 +324,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
321324
blk: mBlocks[1], address: BlockAddress(leaf: false, cid: mBlocks[1].cid)
322325
)
323326
],
327+
allowSpurious = true,
324328
)
325329

326330
discard blockexc[3].engine.pendingBlocks.getWantHandle(mBlocks[2].cid)
@@ -331,6 +335,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
331335
blk: mBlocks[2], address: BlockAddress(leaf: false, cid: mBlocks[2].cid)
332336
)
333337
],
338+
allowSpurious = true,
334339
)
335340

336341
MockDiscovery(blockexc[0].engine.discovery.discovery).findBlockProvidersHandler = proc(

0 commit comments

Comments
 (0)