Skip to content

Instantly share code, notes, and snippets.

@gmega
Last active February 16, 2024 23:05
Show Gist options
  • Save gmega/35aef177a37d21cb0524723d8dfbd3b4 to your computer and use it in GitHub Desktop.
Save gmega/35aef177a37d21cb0524723d8dfbd3b4 to your computer and use it in GitHub Desktop.
test "Should actively cancel want-haves if block received from elsewhere":
let
# Peer wanting to download blocks
downloader = nodes[4]
# Bystander peer - gets block request but can't satisfy them
bystander = nodes[3]
# Holder of actual blocks
blockHolder = nodes[1]
await connectNodes(@[downloader, bystander])
let downloaderId = downloader.switch.peerInfo.peerId
let aBlock = blocks[0]
let blockRequest = downloader.engine.requestBlock(aBlock.cid)
# Bystander knows that downloader wants the block.
check eventually(
bystander
.engine
.peers
.get(downloaderId)
.peerWants
.filterIt( it.address == aBlock.address )
.len == 1
)
(await blockHolder.engine.localStore.putBlock(aBlock)).tryGet()
await connectNodes(@[downloader, blockHolder])
check (await blockRequest).cid == aBlock.cid
# Downloader should have the block
check (await downloader.engine.localStore.hasBlock(aBlock.cid)).tryGet()
# Downloader should have actively cancelled the want-have at the bystander
check eventually(
bystander
.engine
.peers
.get(downloaderId)
.peerWants
.filterIt( it.address == aBlock.address )
.len == 0
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment