diff --git a/zebrad/src/components/sync.rs b/zebrad/src/components/sync.rs index f08940c2c7e..ad0a0021a20 100644 --- a/zebrad/src/components/sync.rs +++ b/zebrad/src/components/sync.rs @@ -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; } @@ -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], diff --git a/zebrad/src/components/sync/tests/vectors.rs b/zebrad/src/components/sync/tests/vectors.rs index 355caf7170a..800fbcc2be3 100644 --- a/zebrad/src/components/sync/tests/vectors.rs +++ b/zebrad/src/components/sync/tests/vectors.rs @@ -70,9 +70,6 @@ async fn sync_blocks_ok() -> Result<(), crate::BoxError> { let block4: Arc = zebra_test::vectors::BLOCK_MAINNET_4_BYTES.zcash_deserialize_into()?; let block4_hash = block4.hash(); - let block5: Arc = 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); @@ -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) @@ -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 @@ -312,9 +307,6 @@ async fn sync_blocks_duplicate_hashes_ok() -> Result<(), crate::BoxError> { let block4: Arc = zebra_test::vectors::BLOCK_MAINNET_4_BYTES.zcash_deserialize_into()?; let block4_hash = block4.hash(); - let block5: Arc = 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); @@ -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) @@ -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 @@ -607,9 +597,6 @@ async fn sync_block_too_high_obtain_tips() -> Result<(), crate::BoxError> { let block2: Arc = zebra_test::vectors::BLOCK_MAINNET_2_BYTES.zcash_deserialize_into()?; let block2_hash = block2.hash(); - let block3: Arc = 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 = zebra_test::vectors::BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into()?; @@ -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) @@ -780,9 +766,6 @@ async fn sync_block_too_high_extend_tips() -> Result<(), crate::BoxError> { let block4: Arc = zebra_test::vectors::BLOCK_MAINNET_4_BYTES.zcash_deserialize_into()?; let block4_hash = block4.hash(); - let block5: Arc = 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 = zebra_test::vectors::BLOCK_MAINNET_982681_BYTES.zcash_deserialize_into()?; @@ -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) @@ -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