sync: try to ignore spurious inv messages.
Closes #697. per https://github.com/ZcashFoundation/zebra/issues/697#issuecomment-662742971 The response to a getblocks message is an inv message with the hashes of the following blocks. However, inv messages are also sent unsolicited to gossip new blocks across the network. Normally, this wouldn't be a problem, because for every other request we filter only for the messages that are relevant to us. But because the response to a getblocks message is an inv, the network layer doesn't (and can't) distinguish between the response inv and the unsolicited inv. But there is a mitigation we can do. In our sync algorithm we have two phases: (1) "ObtainTips" to get a set of tips to chase down, (2) repeatedly call "ExtendTips" to extend those as far as possible. The unsolicited inv messages have length 1, but when extending tips we expect to get more than one hash. So we could reject responses in ExtendTips that have length 1 in order to ignore these messages. This way we automatically ignore gossip messages during initial block sync (while we're extending a tip) but we don't ignore length-1 responses while trying to obtain tips (while querying the network for new tips).
This commit is contained in:
parent
90ec2982bf
commit
49aa41544d
|
@ -261,16 +261,20 @@ where
|
||||||
// It indicates that the remote peer does not have any blocks
|
// It indicates that the remote peer does not have any blocks
|
||||||
// following the prospective tip.
|
// following the prospective tip.
|
||||||
// TODO(jlusby): reject both main and test net genesis blocks
|
// TODO(jlusby): reject both main and test net genesis blocks
|
||||||
match hashes.first() {
|
match (hashes.first(), hashes.len()) {
|
||||||
Some(&super::GENESIS) => {
|
(_, 0) => {
|
||||||
tracing::debug!("skipping response, peer could not extend the tip");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
tracing::debug!("skipping empty response");
|
tracing::debug!("skipping empty response");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Some(_) => {}
|
(_, 1) => {
|
||||||
|
tracing::debug!("skipping length-1 response, in case it's an unsolicited inv message");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
(Some(&super::GENESIS), _) => {
|
||||||
|
tracing::debug!("skipping response, peer could not extend the tip");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_tip = hashes.pop().expect("expected: hashes must have len > 0");
|
let new_tip = hashes.pop().expect("expected: hashes must have len > 0");
|
||||||
|
|
Loading…
Reference in New Issue