Revert "correctly trim and download tips (#531)"
This reverts commit e102bd5e34.
This commit is contained in:
parent
e102bd5e34
commit
21bf913b48
|
|
@ -30,7 +30,7 @@ use zebra_chain::block::BlockHeaderHash;
|
||||||
mod sync;
|
mod sync;
|
||||||
|
|
||||||
// genesis
|
// genesis
|
||||||
const GENESIS: BlockHeaderHash = BlockHeaderHash([
|
static GENESIS: BlockHeaderHash = BlockHeaderHash([
|
||||||
8, 206, 61, 151, 49, 176, 0, 192, 131, 56, 69, 92, 138, 74, 107, 208, 93, 161, 110, 38, 177,
|
8, 206, 61, 151, 49, 176, 0, 192, 131, 56, 69, 92, 138, 74, 107, 208, 93, 161, 110, 38, 177,
|
||||||
29, 170, 27, 145, 113, 132, 236, 232, 15, 4, 0,
|
29, 170, 27, 145, 113, 132, 236, 232, 15, 4, 0,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -161,13 +161,11 @@ where
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
match res.map_err::<Report, _>(|e| eyre!(e)) {
|
match res.map_err::<Report, _>(|e| eyre!(e)) {
|
||||||
Ok(zn::Response::BlockHeaderHashes(mut hashes)) => {
|
Ok(zn::Response::BlockHeaderHashes(hashes)) => {
|
||||||
let new_tip = if let Some(tip) = hashes.pop() {
|
if hashes.is_empty() {
|
||||||
tip
|
|
||||||
} else {
|
|
||||||
tracing::debug!("skipping empty response");
|
tracing::debug!("skipping empty response");
|
||||||
continue;
|
continue;
|
||||||
};
|
}
|
||||||
|
|
||||||
// ExtendTips Step 3
|
// ExtendTips Step 3
|
||||||
//
|
//
|
||||||
|
|
@ -176,20 +174,22 @@ 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() {
|
if hashes[0] == super::GENESIS {
|
||||||
Some(&super::GENESIS) => {
|
tracing::debug!("skipping response that does not extend the tip");
|
||||||
tracing::debug!("skipping response that does not extend the tip");
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Some(_) | None => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtendTips Step 4
|
// ExtendTips Step 4
|
||||||
//
|
//
|
||||||
// Combine the last elements of the remaining responses into
|
// Combine the last elements of the remaining responses into
|
||||||
// a set, and add this set to the set of prospective tips.
|
// a set, and add this set to the set of prospective tips.
|
||||||
|
let new_tip = *hashes.last().expect("already checked is_empty");
|
||||||
let _ = self.prospective_tips.insert(new_tip);
|
let _ = self.prospective_tips.insert(new_tip);
|
||||||
|
|
||||||
|
// ExtendTips Step 5
|
||||||
|
//
|
||||||
|
// Combine all elements of the remaining responses into a
|
||||||
|
// set, and queue download and verification of those blocks
|
||||||
download_set.extend(hashes);
|
download_set.extend(hashes);
|
||||||
}
|
}
|
||||||
Ok(r) => tracing::error!("unexpected response {:?}", r),
|
Ok(r) => tracing::error!("unexpected response {:?}", r),
|
||||||
|
|
@ -198,20 +198,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.prospective_tips
|
self.request_blocks(download_set.into_iter().collect())
|
||||||
.retain(|tip| !download_set.contains(tip));
|
.await?;
|
||||||
|
|
||||||
// ExtendTips Step 5
|
|
||||||
//
|
|
||||||
// Combine all elements of the remaining responses into a
|
|
||||||
// set, and queue download and verification of those blocks
|
|
||||||
self.request_blocks(
|
|
||||||
download_set
|
|
||||||
.into_iter()
|
|
||||||
.chain(self.prospective_tips.iter().cloned())
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue