Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions zebrad/src/components/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,33 +805,7 @@ where
Ok(zn::Response::BlockHashes(hashes)) => {
trace!(?hashes);

// zcashd sometimes appends an unrelated hash at the start
// or end of its response.
//
// We can't discard the first hash, because it might be a
// block we want to download. So we just accept any
// out-of-order first hashes.

// We use the last hash for the tip, and we want to avoid bad
// tips from zcashd's quirk of appending an unrelated hash.
// So we discard the last hash on mainnet/testnet.
// (We don't need to worry about missed downloads, because we
// will pick them up again in ExtendTips.)
//
// In regtest we only connect to Zebra nodes, not zcashd,
// so we trust all hashes in the response and keep them all.
// This is necessary when there are only a small number of
// blocks to sync (e.g. 2 new blocks), where stripping the
// last hash leaves only 1 unknown hash and rchunks_exact(2)
// would discard the entire response.
let hashes = if self.is_regtest {
hashes.as_slice()
} else {
match hashes.as_slice() {
[] => continue,
[rest @ .., _last] => rest,
}
};
let hashes = hashes.as_slice();
if hashes.is_empty() {
continue;
}
Expand Down Expand Up @@ -995,15 +969,6 @@ where
}
};

// We use the last hash for the tip, and we want to avoid
// bad tips. So we discard the last hash. (We don't need
// to worry about missed downloads, because we will pick
// them up again in the next ExtendTips.)
let unknown_hashes = match unknown_hashes {
[] => continue,
[rest @ .., _last] => rest,
};

let new_tip = if let Some(end) = unknown_hashes.rchunks_exact(2).next() {
CheckedTip {
tip: end[0],
Expand Down
19 changes: 0 additions & 19 deletions zebrad/src/components/sync/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ async fn sync_blocks_ok() -> Result<(), crate::BoxError> {
let block4: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_4_BYTES.zcash_deserialize_into()?;
let block4_hash = block4.hash();

let block5: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_5_BYTES.zcash_deserialize_into()?;
let block5_hash = block5.hash();

// Start the syncer
let chain_sync_task_handle = tokio::spawn(chain_sync_future);

Expand Down Expand Up @@ -127,7 +124,6 @@ async fn sync_blocks_ok() -> Result<(), crate::BoxError> {
.respond(zn::Response::BlockHashes(vec![
block1_hash, // tip
block2_hash, // expected_next
block3_hash, // (discarded - last hash, possibly incorrect)
]));

// State is checked for the first unknown block (block 1)
Expand Down Expand Up @@ -213,7 +209,6 @@ async fn sync_blocks_ok() -> Result<(), crate::BoxError> {
block2_hash, // tip (discarded - already fetched)
block3_hash, // expected_next
block4_hash,
block5_hash, // (discarded - last hash, possibly incorrect)
]));

// Clear remaining block locator requests
Expand Down Expand Up @@ -312,9 +307,6 @@ async fn sync_blocks_duplicate_hashes_ok() -> Result<(), crate::BoxError> {
let block4: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_4_BYTES.zcash_deserialize_into()?;
let block4_hash = block4.hash();

let block5: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_5_BYTES.zcash_deserialize_into()?;
let block5_hash = block5.hash();

// Start the syncer
let chain_sync_task_handle = tokio::spawn(chain_sync_future);

Expand Down Expand Up @@ -371,7 +363,6 @@ async fn sync_blocks_duplicate_hashes_ok() -> Result<(), crate::BoxError> {
block1_hash,
block1_hash, // tip
block2_hash, // expected_next
block3_hash, // (discarded - last hash, possibly incorrect)
]));

// State is checked for the first unknown block (block 1)
Expand Down Expand Up @@ -459,7 +450,6 @@ async fn sync_blocks_duplicate_hashes_ok() -> Result<(), crate::BoxError> {
block4_hash,
block3_hash,
block4_hash,
block5_hash, // (discarded - last hash, possibly incorrect)
]));

// Clear remaining block locator requests
Expand Down Expand Up @@ -607,9 +597,6 @@ async fn sync_block_too_high_obtain_tips() -> Result<(), crate::BoxError> {
let block2: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_2_BYTES.zcash_deserialize_into()?;
let block2_hash = block2.hash();

let block3: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_3_BYTES.zcash_deserialize_into()?;
let block3_hash = block3.hash();

// Also get a block that is a long way away from genesis
let block982k: Arc<Block> =
zebra_test::vectors::BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into()?;
Expand Down Expand Up @@ -670,7 +657,6 @@ async fn sync_block_too_high_obtain_tips() -> Result<(), crate::BoxError> {
block982k_hash,
block1_hash, // tip
block2_hash, // expected_next
block3_hash, // (discarded - last hash, possibly incorrect)
]));

// State is checked for the first unknown block (block 982k)
Expand Down Expand Up @@ -780,9 +766,6 @@ async fn sync_block_too_high_extend_tips() -> Result<(), crate::BoxError> {
let block4: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_4_BYTES.zcash_deserialize_into()?;
let block4_hash = block4.hash();

let block5: Arc<Block> = zebra_test::vectors::BLOCK_MAINNET_5_BYTES.zcash_deserialize_into()?;
let block5_hash = block5.hash();

// Also get a block that is a long way away from genesis
let block982k: Arc<Block> =
zebra_test::vectors::BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into()?;
Expand Down Expand Up @@ -842,7 +825,6 @@ async fn sync_block_too_high_extend_tips() -> Result<(), crate::BoxError> {
.respond(zn::Response::BlockHashes(vec![
block1_hash, // tip
block2_hash, // expected_next
block3_hash, // (discarded - last hash, possibly incorrect)
]));

// State is checked for the first unknown block (block 1)
Expand Down Expand Up @@ -929,7 +911,6 @@ async fn sync_block_too_high_extend_tips() -> Result<(), crate::BoxError> {
block3_hash, // expected_next
block4_hash,
block982k_hash,
block5_hash, // (discarded - last hash, possibly incorrect)
]));

// Clear remaining block locator requests
Expand Down
Loading