Last active
February 16, 2024 23:05
-
-
Save gmega/35aef177a37d21cb0524723d8dfbd3b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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