fix: fix testdiscovery so it works with stricter block protocol

This commit is contained in:
gmega 2025-07-03 12:06:02 -03:00 committed by Chrysostomos Nanakos
parent 544ec123c7
commit 908d527dc9
No known key found for this signature in database
2 changed files with 11 additions and 3 deletions

View File

@ -561,7 +561,10 @@ proc validateBlockDelivery(self: BlockExcEngine, bd: BlockDelivery): ?!void =
return success()
proc blocksDeliveryHandler*(
self: BlockExcEngine, peer: PeerId, blocksDelivery: seq[BlockDelivery]
self: BlockExcEngine,
peer: PeerId,
blocksDelivery: seq[BlockDelivery],
allowSpurious: bool = false,
) {.async: (raises: []).} =
trace "Received blocks from peer", peer, blocks = (blocksDelivery.mapIt(it.address))
@ -575,7 +578,7 @@ proc blocksDeliveryHandler*(
try:
# Unknown peers and unrequested blocks are dropped with a warning.
if peerCtx == nil or not peerCtx.blockReceived(bd.address):
if not allowSpurious and (peerCtx == nil or not peerCtx.blockReceived(bd.address)):
warn "Dropping unrequested or duplicate block received from peer"
codex_block_exchange_spurious_blocks_received.inc()
continue

View File

@ -216,7 +216,6 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
test "E2E - Should advertise and discover blocks":
# Distribute the manifests and trees amongst 1..3
# Ask 0 to download everything without connecting him beforehand
var advertised: Table[Cid, SignedPeerRecord]
MockDiscovery(blockexc[1].engine.discovery.discovery).publishBlockProvideHandler = proc(
@ -242,6 +241,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
blk: mBlocks[0], address: BlockAddress(leaf: false, cid: mBlocks[0].cid)
)
],
allowSpurious = true,
)
discard blockexc[2].engine.pendingBlocks.getWantHandle(mBlocks[1].cid)
@ -252,6 +252,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
blk: mBlocks[1], address: BlockAddress(leaf: false, cid: mBlocks[1].cid)
)
],
allowSpurious = true,
)
discard blockexc[3].engine.pendingBlocks.getWantHandle(mBlocks[2].cid)
@ -262,6 +263,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
blk: mBlocks[2], address: BlockAddress(leaf: false, cid: mBlocks[2].cid)
)
],
allowSpurious = true,
)
MockDiscovery(blockexc[0].engine.discovery.discovery).findBlockProvidersHandler = proc(
@ -311,6 +313,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
blk: mBlocks[0], address: BlockAddress(leaf: false, cid: mBlocks[0].cid)
)
],
allowSpurious = true,
)
discard blockexc[2].engine.pendingBlocks.getWantHandle(mBlocks[1].cid)
@ -321,6 +324,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
blk: mBlocks[1], address: BlockAddress(leaf: false, cid: mBlocks[1].cid)
)
],
allowSpurious = true,
)
discard blockexc[3].engine.pendingBlocks.getWantHandle(mBlocks[2].cid)
@ -331,6 +335,7 @@ asyncchecksuite "E2E - Multiple Nodes Discovery":
blk: mBlocks[2], address: BlockAddress(leaf: false, cid: mBlocks[2].cid)
)
],
allowSpurious = true,
)
MockDiscovery(blockexc[0].engine.discovery.discovery).findBlockProvidersHandler = proc(