-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix syncer download order and add sync tests (#3168)
* Refactor so that RetryLimit::Future is std::marker::Sync * Make the syncer future std::marker::Send by spawning tips futures * Download synced blocks in chain order, not HashSet order * Improve MockService failure messages * Add closure-based responses to the MockService API * Move MockChainTip to zebra-chain * Add a MockChainTipSender type alias * Support MockChainTip in ChainSync and its downloader * Add syncer tests for obtain tips, extend tips, and wrong block hashes * Add block too high tests for obtain tips and extend tips * Add syncer tests for duplicate FindBlocks response hashes * Allow longer request delays for mocked services in syncer tests
- Loading branch information
Showing
13 changed files
with
1,293 additions
and
129 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Mock [`ChainTip`]s for use in tests. | ||
use std::sync::Arc; | ||
|
||
use tokio::sync::watch; | ||
|
||
use crate::{block, chain_tip::ChainTip, transaction}; | ||
|
||
/// A sender that sets the `best_tip_height` of a [`MockChainTip`].] | ||
pub type MockChainTipSender = watch::Sender<Option<block::Height>>; | ||
|
||
/// A mock [`ChainTip`] implementation that allows setting the `best_tip_height` externally. | ||
#[derive(Clone, Debug)] | ||
pub struct MockChainTip { | ||
best_tip_height: watch::Receiver<Option<block::Height>>, | ||
} | ||
|
||
impl MockChainTip { | ||
/// Create a new [`MockChainTip`]. | ||
/// | ||
/// Returns the [`MockChainTip`] instance and the endpoint to modiy the current best tip | ||
/// height. | ||
/// | ||
/// Initially, the best tip height is [`None`]. | ||
pub fn new() -> (Self, MockChainTipSender) { | ||
let (sender, receiver) = watch::channel(None); | ||
|
||
let mock_chain_tip = MockChainTip { | ||
best_tip_height: receiver, | ||
}; | ||
|
||
(mock_chain_tip, sender) | ||
} | ||
} | ||
|
||
impl ChainTip for MockChainTip { | ||
fn best_tip_height(&self) -> Option<block::Height> { | ||
*self.best_tip_height.borrow() | ||
} | ||
|
||
fn best_tip_hash(&self) -> Option<block::Hash> { | ||
unreachable!("Method not used in tests"); | ||
} | ||
|
||
fn best_tip_mined_transaction_ids(&self) -> Arc<[transaction::Hash]> { | ||
unreachable!("Method not used in tests"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.