changed functions in zebra-state::service::non_finalized_state to accept &Network

This commit is contained in:
idky137 2024-03-18 12:35:04 +00:00
parent 313598b4b7
commit 7c1ab87fd4
No known key found for this signature in database
17 changed files with 53 additions and 53 deletions

View File

@ -139,7 +139,7 @@ async fn check_transcripts() -> Result<(), Report> {
let _init_guard = zebra_test::init();
let network = Network::Mainnet;
let state_service = zebra_state::init_test(network);
let state_service = zebra_state::init_test(&network);
let transaction = transaction::Verifier::new(network, state_service.clone());
let transaction = Buffer::new(BoxService::new(transaction), 1);

View File

@ -45,7 +45,7 @@ async fn single_item_checkpoint_list() -> Result<(), Report> {
.cloned()
.collect();
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
@ -124,7 +124,7 @@ async fn multi_item_checkpoint_list() -> Result<(), Report> {
.map(|(_block, height, hash)| (*height, *hash))
.collect();
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
@ -268,7 +268,7 @@ async fn continuous_blockchain(
let initial_tip = restart_height.map(|block::Height(height)| {
(blockchain[height as usize].1, blockchain[height as usize].2)
});
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier = CheckpointVerifier::from_list(
checkpoint_list,
network,
@ -437,7 +437,7 @@ async fn block_higher_than_max_checkpoint_fail() -> Result<(), Report> {
.cloned()
.collect();
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
@ -511,7 +511,7 @@ async fn wrong_checkpoint_hash_fail() -> Result<(), Report> {
.cloned()
.collect();
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
@ -684,7 +684,7 @@ async fn checkpoint_drop_cancel() -> Result<(), Report> {
.map(|(_block, height, hash)| (*height, *hash))
.collect();
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
@ -767,7 +767,7 @@ async fn hard_coded_mainnet() -> Result<(), Report> {
Arc::<Block>::zcash_deserialize(&zebra_test::vectors::BLOCK_MAINNET_GENESIS_BYTES[..])?;
let hash0 = block0.hash();
let state_service = zebra_state::init_test(Mainnet);
let state_service = zebra_state::init_test(&Mainnet);
// Use the hard-coded checkpoint list
let mut checkpoint_verifier = CheckpointVerifier::new(Network::Mainnet, None, state_service);

View File

@ -65,7 +65,7 @@ async fn verifiers_from_network(
+ Clone
+ 'static,
) {
let state_service = zs::init_test(network);
let state_service = zs::init_test(&network);
let (
block_verifier_router,
_transaction_verifier,
@ -172,7 +172,7 @@ async fn verify_checkpoint(config: Config) -> Result<(), Report> {
_transaction_verifier,
_groth16_download_handle,
_max_checkpoint_height,
) = super::init(config.clone(), network, zs::init_test(network)).await;
) = super::init(config.clone(), network, zs::init_test(&network)).await;
// Add a timeout layer
let block_verifier_router =

View File

@ -909,7 +909,7 @@ async fn rpc_getblockcount_empty_state() {
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
// Create an empty state
let (state, read_state, latest_chain_tip, _chain_tip_change) =
zebra_state::init_test_services(Mainnet);
zebra_state::init_test_services(&Mainnet);
let (
block_verifier_router,
@ -956,7 +956,7 @@ async fn rpc_getpeerinfo() {
let mut mempool: MockService<_, _, _, BoxError> = MockService::build().for_unit_tests();
// Create an empty state
let (state, read_state, latest_chain_tip, _chain_tip_change) =
zebra_state::init_test_services(Mainnet);
zebra_state::init_test_services(&Mainnet);
let (
block_verifier_router,

View File

@ -353,7 +353,7 @@ impl StateService {
let non_finalized_state = NonFinalizedState::new(network);
let (non_finalized_state_sender, non_finalized_state_receiver) =
watch::channel(NonFinalizedState::new(finalized_state.network()));
watch::channel(NonFinalizedState::new(&finalized_state.network()));
// Security: The number of blocks in these channels is limited by
// the syncer and inbound lookahead limits.
@ -399,7 +399,7 @@ impl StateService {
let finalized_block_write_last_sent_hash = finalized_state.db.finalized_tip_hash();
let state = Self {
network,
network: network.clone(),
full_verifier_utxo_lookahead,
non_finalized_state_queued_blocks,
finalized_state_queued_blocks: HashMap::new(),
@ -1935,7 +1935,7 @@ pub fn spawn_init(
///
/// This can be used to create a state service for testing. See also [`init`].
#[cfg(any(test, feature = "proptest-impl"))]
pub fn init_test(network: Network) -> Buffer<BoxService<Request, Response, BoxError>, Request> {
pub fn init_test(network: &Network) -> Buffer<BoxService<Request, Response, BoxError>, Request> {
// TODO: pass max_checkpoint_height and checkpoint_verify_concurrency limit
// if we ever need to test final checkpoint sent UTXO queries
let (state_service, _, _, _) =
@ -1950,7 +1950,7 @@ pub fn init_test(network: Network) -> Buffer<BoxService<Request, Response, BoxEr
/// This can be used to create a state service for testing. See also [`init`].
#[cfg(any(test, feature = "proptest-impl"))]
pub fn init_test_services(
network: Network,
network: &Network,
) -> (
Buffer<BoxService<Request, Response, BoxError>, Request>,
ReadStateService,

View File

@ -147,7 +147,7 @@ impl ChainTipSender {
#[instrument(skip(initial_tip), fields(new_height, new_hash))]
pub fn new(
initial_tip: impl Into<Option<ChainTipBlock>>,
network: Network,
network: &Network,
) -> (Self, LatestChainTip, ChainTipChange) {
let initial_tip = initial_tip.into();
Self::record_new_tip(&initial_tip);
@ -584,11 +584,11 @@ impl ChainTipChange {
}
/// Create a new [`ChainTipChange`] from a [`LatestChainTip`] receiver and [`Network`].
fn new(latest_chain_tip: LatestChainTip, network: Network) -> Self {
fn new(latest_chain_tip: LatestChainTip, network: &Network) -> Self {
Self {
latest_chain_tip,
last_change_hash: None,
network,
network: network.clone(),
}
}

View File

@ -38,7 +38,7 @@ proptest! {
tip_updates in any::<SummaryDebug<Vec<(BlockUpdate, BlockConnection, TipChangeCheck)>>>(),
network in any::<Network>(),
) {
let (mut chain_tip_sender, latest_chain_tip, mut chain_tip_change) = ChainTipSender::new(None, network);
let (mut chain_tip_sender, latest_chain_tip, mut chain_tip_change) = ChainTipSender::new(None, &network);
let mut latest_finalized_tip = None;
let mut latest_non_finalized_tip = None;

View File

@ -12,7 +12,7 @@ use super::super::ChainTipSender;
#[test]
fn current_best_tip_is_initially_empty() {
let (_chain_tip_sender, latest_chain_tip, _chain_tip_change) =
ChainTipSender::new(None, Mainnet);
ChainTipSender::new(None, &Mainnet);
assert_eq!(latest_chain_tip.best_tip_height(), None);
assert_eq!(latest_chain_tip.best_tip_hash(), None);
@ -37,7 +37,7 @@ fn empty_latest_chain_tip_is_empty() {
#[test]
fn chain_tip_change_is_initially_not_ready() {
let (_chain_tip_sender, _latest_chain_tip, mut chain_tip_change) =
ChainTipSender::new(None, Mainnet);
ChainTipSender::new(None, &Mainnet);
// TODO: use `tokio::task::unconstrained` to avoid spurious waits from tokio's cooperative multitasking
// (needs a recent tokio version)

View File

@ -91,7 +91,7 @@ impl Clone for NonFinalizedState {
fn clone(&self) -> Self {
Self {
chain_set: self.chain_set.clone(),
network: self.network,
network: self.network.clone(),
#[cfg(feature = "getblocktemplate-rpcs")]
should_count_metrics: self.should_count_metrics,
@ -108,10 +108,10 @@ impl Clone for NonFinalizedState {
impl NonFinalizedState {
/// Returns a new non-finalized state for `network`.
pub fn new(network: Network) -> NonFinalizedState {
pub fn new(network: &Network) -> NonFinalizedState {
NonFinalizedState {
chain_set: Default::default(),
network,
network: network.clone(),
#[cfg(feature = "getblocktemplate-rpcs")]
should_count_metrics: true,
#[cfg(feature = "progress-bar")]

View File

@ -477,7 +477,7 @@ fn rejection_restores_internal_state_genesis() -> Result<()> {
)
}
))| {
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(&Config::ephemeral(), &network, #[cfg(feature = "elasticsearch")] None);
let fake_value_pool = ValueBalance::<NonNegative>::fake_populated_pool();

View File

@ -151,10 +151,10 @@ fn best_chain_wins_for_network(network: Network) -> Result<()> {
let expected_hash = block2.hash();
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -187,10 +187,10 @@ fn finalize_pops_from_best_chain_for_network(network: Network) -> Result<()> {
let block2 = block1.make_fake_child().set_work(10);
let child = block1.make_fake_child().set_work(1);
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -237,10 +237,10 @@ fn commit_block_extending_best_chain_doesnt_drop_worst_chains_for_network(
let child1 = block1.make_fake_child().set_work(1);
let child2 = block2.make_fake_child().set_work(1);
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -282,10 +282,10 @@ fn shorter_chain_can_be_best_chain_for_network(network: Network) -> Result<()> {
let short_chain_block = block1.make_fake_child().set_work(3);
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -327,10 +327,10 @@ fn longer_chain_with_more_work_wins_for_network(network: Network) -> Result<()>
let short_chain_block = block1.make_fake_child().set_work(3);
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -370,10 +370,10 @@ fn equal_length_goes_to_more_work_for_network(network: Network) -> Result<()> {
let more_work_child = block1.make_fake_child().set_work(3);
let expected_hash = more_work_child.hash();
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -417,10 +417,10 @@ fn history_tree_is_updated_for_network_upgrade(
.expect("block is structurally valid"),
);
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);
@ -515,10 +515,10 @@ fn commitment_is_validated_for_network_upgrade(network: Network, network_upgrade
.expect("block is structurally valid"),
);
let mut state = NonFinalizedState::new(network);
let mut state = NonFinalizedState::new(&network);
let finalized_state = FinalizedState::new(
&Config::ephemeral(),
network,
&network,
#[cfg(feature = "elasticsearch")]
None,
);

View File

@ -37,7 +37,7 @@ async fn empty_read_state_still_responds_to_requests() -> Result<()> {
let transcript = Transcript::from(empty_state_test_cases());
let network = Mainnet;
let (_state, read_state, _latest_chain_tip, _chain_tip_change) = init_test_services(network);
let (_state, read_state, _latest_chain_tip, _chain_tip_change) = init_test_services(&network);
transcript.check(read_state).await?;

View File

@ -253,7 +253,7 @@ async fn empty_state_still_responds_to_requests() -> Result<()> {
let transcript = Transcript::from(iter);
let network = Network::Mainnet;
let state = init_test(network);
let state = init_test(&network);
transcript.check(state).await?;
@ -401,7 +401,7 @@ proptest! {
let _init_guard = zebra_test::init();
// We're waiting to verify each block here, so we don't need the maximum checkpoint height.
let (mut state_service, _, _, _) = StateService::new(Config::ephemeral(), network, Height::MAX, 0);
let (mut state_service, _, _, _) = StateService::new(Config::ephemeral(), &network, Height::MAX, 0);
prop_assert_eq!(state_service.read_service.db.finalized_value_pool(), ValueBalance::zero());
prop_assert_eq!(
@ -493,7 +493,7 @@ proptest! {
let _init_guard = zebra_test::init();
// We're waiting to verify each block here, so we don't need the maximum checkpoint height.
let (mut state_service, _read_only_state_service, latest_chain_tip, mut chain_tip_change) = StateService::new(Config::ephemeral(), network, Height::MAX, 0);
let (mut state_service, _read_only_state_service, latest_chain_tip, mut chain_tip_change) = StateService::new(Config::ephemeral(), &network, Height::MAX, 0);
prop_assert_eq!(latest_chain_tip.best_tip_height(), None);
prop_assert_eq!(chain_tip_change.last_tip_change(), None);

View File

@ -104,7 +104,7 @@ pub(crate) fn new_state_with_mainnet_genesis(
None,
false,
);
let non_finalized_state = NonFinalizedState::new(network);
let non_finalized_state = NonFinalizedState::new(&network);
assert_eq!(
None,

View File

@ -237,7 +237,7 @@ fn setup_crawler() -> (
// the network should be irrelevant here
let (chain_tip_sender, _latest_chain_tip, chain_tip_change) =
ChainTipSender::new(None, Network::Mainnet);
ChainTipSender::new(None, &Network::Mainnet);
Crawler::spawn(
&Config::default(),

View File

@ -65,7 +65,7 @@ proptest! {
_tx_verifier,
mut recent_syncs,
mut chain_tip_sender,
) = setup(network);
) = setup(&network);
time::pause();
@ -115,7 +115,7 @@ proptest! {
_tx_verifier,
mut recent_syncs,
mut chain_tip_sender,
) = setup(network);
) = setup(&network);
time::pause();
@ -196,7 +196,7 @@ proptest! {
mut tx_verifier,
mut recent_syncs,
mut chain_tip_sender,
) = setup(network);
) = setup(&network);
time::pause();
@ -254,7 +254,7 @@ fn block1_chain_tip() -> Option<ChainTipBlock> {
/// Create a new [`Mempool`] instance using mocked services.
fn setup(
network: Network,
network: &Network,
) -> (
Mempool,
MockPeerSet,

View File

@ -149,7 +149,7 @@ fn request_genesis_is_rate_limited() {
});
// create an empty latest chain tip
let (_sender, latest_chain_tip, _change) = ChainTipSender::new(None, Network::Mainnet);
let (_sender, latest_chain_tip, _change) = ChainTipSender::new(None, &network::Mainnet);
// create a verifier service that will always panic as it will never be called
let verifier_service =