Use block requests to check if block responses are correct (#7653)

* Use block requests to check if block responses are correct

Before this pr sync relied on recently announced blocks to check if a
given peer response is correct. However this could lead to situations
where we requested a block from a peer and it gave us the requested, but
we rejected the response because this peer never send us an announcement
for the given block. See the added tests for a reproduction of the
problem.
With this pr, we now take the block request to check if a given response
matches the request. A node should not send us a block response
without a request anyway.

Essentially there is still a bug, because as you see in the test, we are
requesting block 2, while we already have this block imported. It even
happens that we request a block from the network that we have authored.
However a fix for this would require some more refactoring of the sync code.

* Revert change

* Give the test a proper name

* Add moar logging

* Move cheaper checks

* Move checks to common place
This commit is contained in:
Bastian Köcher
2020-12-03 15:49:23 +01:00
committed by GitHub
parent 56c97ce604
commit 2877c038cf
3 changed files with 278 additions and 72 deletions
@@ -549,7 +549,6 @@ mod tests {
best_hash: Hash::random(),
best_number: g.gen(),
state: ArbitraryPeerSyncState::arbitrary(g).0,
recently_announced: Default::default()
};
ArbitraryPeerSync(ps)
}