If the first ExtendTips hash is bad, discard it and re-check (#992)

This commit is contained in:
teor 2020-09-04 08:08:19 +10:00 committed by GitHub
parent 8a4245daab
commit c770daa51f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 5 deletions

View File

@ -284,14 +284,41 @@ where
match res.map_err::<Report, _>(|e| eyre!(e)) { match res.map_err::<Report, _>(|e| eyre!(e)) {
Ok(zn::Response::BlockHashes(hashes)) => { Ok(zn::Response::BlockHashes(hashes)) => {
tracing::debug!(first = ?hashes.first(), len = ?hashes.len()); tracing::debug!(first = ?hashes.first(), len = ?hashes.len());
tracing::trace!(?hashes);
let unknown_hashes = match hashes.split_first() { // zcashd sometimes appends an unrelated hash at the
None => continue, // start or end of its response. Check the first hash
Some((expected_hash, rest)) if expected_hash == &tip.expected_next => { // against the previous response, and discard mismatches.
let unknown_hashes = match hashes.as_slice() {
[expected_hash, rest @ ..] if expected_hash == &tip.expected_next => {
rest rest
} }
Some((other_hash, _rest)) => { // If the first hash doesn't match, retry with the second.
tracing::debug!(?other_hash, ?tip.expected_next, "discarding response with unexpected next hash"); [first_hash, expected_hash, rest @ ..]
if expected_hash == &tip.expected_next =>
{
tracing::debug!(?first_hash,
?tip.expected_next,
?tip.tip,
"unexpected first hash, but the second matches: using the hashes after the match");
rest
}
// We ignore these responses
[] => continue,
[single_hash] => {
tracing::debug!(?single_hash,
?tip.expected_next,
?tip.tip,
"discarding response containing a single unexpected hash");
continue;
}
[first_hash, second_hash, rest @ ..] => {
tracing::debug!(?first_hash,
?second_hash,
rest_len = ?rest.len(),
?tip.expected_next,
?tip.tip,
"discarding response that starts with two unexpected hashes");
continue; continue;
} }
}; };