converted zebra-consensus -- all crate tests pass

This commit is contained in:
idky137 2024-03-18 19:59:06 +00:00
parent 08ab2eac76
commit 04a93011bc
No known key found for this signature in database
19 changed files with 177 additions and 171 deletions

View File

@ -993,7 +993,7 @@ fn sapling_spend_v4_to_fake_v5(
/// Iterate over V4 transactions in the block test vectors for the specified `network`.
pub fn test_transactions(
network: Network,
network: &Network,
) -> impl DoubleEndedIterator<Item = (block::Height, Arc<Transaction>)> {
let blocks = network.block_iter();

View File

@ -108,9 +108,9 @@ where
V::Future: Send + 'static,
{
/// Creates a new SemanticBlockVerifier
pub fn new(network: Network, state_service: S, transaction_verifier: V) -> Self {
pub fn new(network: &Network, state_service: S, transaction_verifier: V) -> Self {
Self {
network,
network: network.clone(),
state_service,
transaction_verifier,
}
@ -139,7 +139,7 @@ where
fn call(&mut self, request: Request) -> Self::Future {
let mut state_service = self.state_service.clone();
let mut transaction_verifier = self.transaction_verifier.clone();
let network = self.network;
let network = self.network.clone();
let block = request.block();
@ -180,11 +180,11 @@ where
// > acceptance rules (excluding the check for a valid proof-of-work).
// <https://en.bitcoin.it/wiki/BIP_0023#Block_Proposal>
if request.is_proposal() {
check::difficulty_threshold_is_valid(&block.header, network, &height, &hash)?;
check::difficulty_threshold_is_valid(&block.header, &network, &height, &hash)?;
} else {
// Do the difficulty checks first, to raise the threshold for
// attacks that use any other fields.
check::difficulty_is_valid(&block.header, network, &height, &hash)?;
check::difficulty_is_valid(&block.header, &network, &height, &hash)?;
check::equihash_solution_is_valid(&block.header)?;
}
@ -195,7 +195,7 @@ where
let transaction_hashes: Arc<[_]> =
block.transactions.iter().map(|t| t.hash()).collect();
check::merkle_root_validity(network, &block, &transaction_hashes)?;
check::merkle_root_validity(&network, &block, &transaction_hashes)?;
// Since errors cause an early exit, try to do the
// quick checks first.
@ -205,12 +205,12 @@ where
check::time_is_valid_at(&block.header, now, &height, &hash)
.map_err(VerifyBlockError::Time)?;
let coinbase_tx = check::coinbase_is_first(&block)?;
check::subsidy_is_valid(&block, network)?;
check::subsidy_is_valid(&block, &network)?;
// Now do the slower checks
// Check compatibility with ZIP-212 shielded Sapling and Orchard coinbase output decryption
tx::check::coinbase_outputs_are_decryptable(&coinbase_tx, network, height)?;
tx::check::coinbase_outputs_are_decryptable(&coinbase_tx, &network, height)?;
// Send transactions to the transaction verifier to be checked
let mut async_checks = FuturesUnordered::new();
@ -277,7 +277,7 @@ where
hash,
source: amount_error,
})?;
check::miner_fees_are_valid(&block, network, block_miner_fees)?;
check::miner_fees_are_valid(&block, &network, block_miner_fees)?;
// Finally, submit the block for contextual verification.
let new_outputs = Arc::into_inner(known_utxos)

View File

@ -67,7 +67,7 @@ pub fn coinbase_is_first(block: &Block) -> Result<Arc<transaction::Transaction>,
/// If the header difficulty threshold is invalid, returns an error containing `height` and `hash`.
pub fn difficulty_threshold_is_valid(
header: &Header,
network: Network,
network: &Network,
height: &Height,
hash: &Hash,
) -> Result<ExpandedDifficulty, BlockError> {
@ -86,7 +86,7 @@ pub fn difficulty_threshold_is_valid(
*height,
*hash,
difficulty_threshold,
network,
network.clone(),
network.target_difficulty_limit(),
))?;
}
@ -102,7 +102,7 @@ pub fn difficulty_threshold_is_valid(
/// If the block is invalid, returns an error containing `height` and `hash`.
pub fn difficulty_is_valid(
header: &Header,
network: Network,
network: &Network,
height: &Height,
hash: &Hash,
) -> Result<(), BlockError> {
@ -123,7 +123,7 @@ pub fn difficulty_is_valid(
*height,
*hash,
difficulty_threshold,
network,
network.clone(),
))?;
}
@ -143,7 +143,7 @@ pub fn equihash_solution_is_valid(header: &Header) -> Result<(), equihash::Error
/// Returns `Ok(())` if the block subsidy in `block` is valid for `network`
///
/// [3.9]: https://zips.z.cash/protocol/protocol.pdf#subsidyconcepts
pub fn subsidy_is_valid(block: &Block, network: Network) -> Result<(), BlockError> {
pub fn subsidy_is_valid(block: &Block, network: &Network) -> Result<(), BlockError> {
let height = block.coinbase_height().ok_or(SubsidyError::NoCoinbase)?;
let coinbase = block.transactions.first().ok_or(SubsidyError::NoCoinbase)?;
@ -189,7 +189,7 @@ pub fn subsidy_is_valid(block: &Block, network: Network) -> Result<(), BlockErro
subsidy::funding_streams::funding_stream_address(height, network, receiver);
let has_expected_output =
subsidy::funding_streams::filter_outputs_by_address(coinbase, address)
subsidy::funding_streams::filter_outputs_by_address(coinbase, &address)
.iter()
.map(zebra_chain::transparent::Output::value)
.any(|value| value == expected_amount);
@ -210,7 +210,7 @@ pub fn subsidy_is_valid(block: &Block, network: Network) -> Result<(), BlockErro
/// [7.1.2]: https://zips.z.cash/protocol/protocol.pdf#txnconsensus
pub fn miner_fees_are_valid(
block: &Block,
network: Network,
network: &Network,
block_miner_fees: Amount<NonNegative>,
) -> Result<(), BlockError> {
let height = block.coinbase_height().ok_or(SubsidyError::NoCoinbase)?;
@ -289,7 +289,7 @@ pub fn time_is_valid_at(
/// [7.1]: https://zips.z.cash/protocol/nu5.pdf#txnencodingandconsensus
/// [7.6]: https://zips.z.cash/protocol/nu5.pdf#blockheader
pub fn merkle_root_validity(
network: Network,
network: &Network,
block: &Block,
transaction_hashes: &[transaction::Hash],
) -> Result<(), BlockError> {

View File

@ -23,7 +23,7 @@ mod tests;
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
pub fn funding_stream_values(
height: Height,
network: Network,
network: &Network,
) -> Result<HashMap<FundingStreamReceiver, Amount<NonNegative>>, Error> {
let canopy_height = Canopy.activation_height(&network).unwrap();
let mut results = HashMap::new();
@ -52,7 +52,7 @@ pub fn funding_stream_values(
/// as described in [protocol specification §7.10][7.10]
///
/// [7.10]: https://zips.z.cash/protocol/protocol.pdf#fundingstreams
fn funding_stream_address_period(height: Height, network: Network) -> u32 {
fn funding_stream_address_period(height: Height, network: &Network) -> u32 {
// Spec equation: `address_period = floor((height - (height_for_halving(1) - post_blossom_halving_interval))/funding_stream_address_change_interval)`,
// <https://zips.z.cash/protocol/protocol.pdf#fundingstreams>
//
@ -76,7 +76,7 @@ fn funding_stream_address_period(height: Height, network: Network) -> u32 {
/// as described in [protocol specification §7.10][7.10]
///
/// [7.10]: https://zips.z.cash/protocol/protocol.pdf#fundingstreams
fn funding_stream_address_index(height: Height, network: Network) -> usize {
fn funding_stream_address_index(height: Height, network: &Network) -> usize {
let num_addresses = network.num_funding_streams();
let index = 1u32
@ -100,7 +100,7 @@ fn funding_stream_address_index(height: Height, network: Network) -> usize {
/// only use transparent addresses,
pub fn funding_stream_address(
height: Height,
network: Network,
network: &Network,
receiver: FundingStreamReceiver,
) -> transparent::Address {
let index = funding_stream_address_index(height, network);
@ -127,7 +127,7 @@ pub fn funding_stream_recipient_info(
/// as the given lock_script as described in [protocol specification §7.10][7.10]
///
/// [7.10]: https://zips.z.cash/protocol/protocol.pdf#fundingstreams
pub fn check_script_form(lock_script: &Script, address: transparent::Address) -> bool {
pub fn check_script_form(lock_script: &Script, address: &transparent::Address) -> bool {
assert!(
address.is_script_hash(),
"incorrect funding stream address constant: {address} \
@ -141,7 +141,7 @@ pub fn check_script_form(lock_script: &Script, address: transparent::Address) ->
}
/// Returns a new funding stream coinbase output lock script, which pays to the P2SH `address`.
pub fn new_coinbase_script(address: transparent::Address) -> Script {
pub fn new_coinbase_script(address: &transparent::Address) -> Script {
assert!(
address.is_script_hash(),
"incorrect coinbase script address: {address} \
@ -158,7 +158,7 @@ pub fn new_coinbase_script(address: transparent::Address) -> Script {
/// Returns a list of outputs in `transaction`, which have a script address equal to `address`.
pub fn filter_outputs_by_address(
transaction: &Transaction,
address: transparent::Address,
address: &transparent::Address,
) -> Vec<transparent::Output> {
transaction
.outputs()

View File

@ -12,7 +12,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
// funding streams not active
let canopy_height_minus1 = Canopy.activation_height(&network).unwrap() - 1;
assert!(funding_stream_values(canopy_height_minus1.unwrap(), network)?.is_empty());
assert!(funding_stream_values(canopy_height_minus1.unwrap(), &network)?.is_empty());
// funding stream is active
let canopy_height = Canopy.activation_height(&network);
@ -31,15 +31,15 @@ fn test_funding_stream_values() -> Result<(), Report> {
);
assert_eq!(
funding_stream_values(canopy_height.unwrap(), network).unwrap(),
funding_stream_values(canopy_height.unwrap(), &network).unwrap(),
hash_map
);
assert_eq!(
funding_stream_values(canopy_height_plus1.unwrap(), network).unwrap(),
funding_stream_values(canopy_height_plus1.unwrap(), &network).unwrap(),
hash_map
);
assert_eq!(
funding_stream_values(canopy_height_plus2.unwrap(), network).unwrap(),
funding_stream_values(canopy_height_plus2.unwrap(), &network).unwrap(),
hash_map
);
@ -49,10 +49,10 @@ fn test_funding_stream_values() -> Result<(), Report> {
let last = end - 1;
assert_eq!(
funding_stream_values(last.unwrap(), network).unwrap(),
funding_stream_values(last.unwrap(), &network).unwrap(),
hash_map
);
assert!(funding_stream_values(end, network)?.is_empty());
assert!(funding_stream_values(end, &network)?.is_empty());
Ok(())
}
@ -74,7 +74,7 @@ fn test_funding_stream_addresses() -> Result<(), Report> {
);
// Asserts if address is not a P2SH address.
let _script = new_coinbase_script(address);
let _script = new_coinbase_script(&address);
}
}
}

View File

@ -20,7 +20,7 @@ use crate::{funding_stream_values, parameters::subsidy::*};
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
///
/// Returns `None` if the divisor would overflow a `u64`.
pub fn halving_divisor(height: Height, network: Network) -> Option<u64> {
pub fn halving_divisor(height: Height, network: &Network) -> Option<u64> {
let blossom_height = Blossom
.activation_height(&network)
.expect("blossom activation height should be available");
@ -64,7 +64,7 @@ pub fn halving_divisor(height: Height, network: Network) -> Option<u64> {
/// `BlockSubsidy(height)` as described in [protocol specification §7.8][7.8]
///
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
pub fn block_subsidy(height: Height, network: Network) -> Result<Amount<NonNegative>, Error> {
pub fn block_subsidy(height: Height, network: &Network) -> Result<Amount<NonNegative>, Error> {
let blossom_height = Blossom
.activation_height(&network)
.expect("blossom activation height should be available");
@ -97,7 +97,7 @@ pub fn block_subsidy(height: Height, network: Network) -> Result<Amount<NonNegat
/// `MinerSubsidy(height)` as described in [protocol specification §7.8][7.8]
///
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
pub fn miner_subsidy(height: Height, network: Network) -> Result<Amount<NonNegative>, Error> {
pub fn miner_subsidy(height: Height, network: &Network) -> Result<Amount<NonNegative>, Error> {
let total_funding_stream_amount: Result<Amount<NonNegative>, _> =
funding_stream_values(height, network)?.values().sum();
@ -123,13 +123,13 @@ mod test {
fn halving_test() -> Result<(), Report> {
let _init_guard = zebra_test::init();
halving_for_network(Network::Mainnet)?;
halving_for_network(Network::Testnet)?;
halving_for_network(&Network::Mainnet)?;
halving_for_network(&Network::Testnet)?;
Ok(())
}
fn halving_for_network(network: Network) -> Result<(), Report> {
fn halving_for_network(network: &Network) -> Result<(), Report> {
let blossom_height = Blossom.activation_height(&network).unwrap();
let first_halving_height = network.height_for_first_halving();
@ -249,13 +249,13 @@ mod test {
fn block_subsidy_test() -> Result<(), Report> {
let _init_guard = zebra_test::init();
block_subsidy_for_network(Network::Mainnet)?;
block_subsidy_for_network(Network::Testnet)?;
block_subsidy_for_network(&Network::Mainnet)?;
block_subsidy_for_network(&Network::Testnet)?;
Ok(())
}
fn block_subsidy_for_network(network: Network) -> Result<(), Report> {
fn block_subsidy_for_network(network: &Network) -> Result<(), Report> {
let blossom_height = Blossom.activation_height(&network).unwrap();
let first_halving_height = network.height_for_first_halving();

View File

@ -141,10 +141,10 @@ async fn check_transcripts() -> Result<(), Report> {
let network = Network::Mainnet;
let state_service = zebra_state::init_test(&network);
let transaction = transaction::Verifier::new(network, state_service.clone());
let transaction = transaction::Verifier::new(&network, state_service.clone());
let transaction = Buffer::new(BoxService::new(transaction), 1);
let block_verifier = Buffer::new(
SemanticBlockVerifier::new(network, state_service.clone(), transaction),
SemanticBlockVerifier::new(&network, state_service.clone(), transaction),
1,
);
@ -196,7 +196,7 @@ fn difficulty_is_valid_for_network(network: Network) -> Result<(), Report> {
.zcash_deserialize_into::<Block>()
.expect("block is structurally valid");
check::difficulty_is_valid(&block.header, network, &Height(height), &block.hash())
check::difficulty_is_valid(&block.header, &network, &Height(height), &block.hash())
.expect("the difficulty from a historical block should be valid");
}
@ -220,7 +220,7 @@ fn difficulty_validation_failure() -> Result<(), Report> {
// Validate the block
let result =
check::difficulty_is_valid(&block.header, Network::Mainnet, &height, &hash).unwrap_err();
check::difficulty_is_valid(&block.header, &Network::Mainnet, &height, &hash).unwrap_err();
let expected = BlockError::InvalidDifficulty(height, hash);
assert_eq!(expected, result);
@ -235,7 +235,7 @@ fn difficulty_validation_failure() -> Result<(), Report> {
// Validate the block as if it is a mainnet block
let result =
check::difficulty_is_valid(&block.header, Network::Mainnet, &height, &hash).unwrap_err();
check::difficulty_is_valid(&block.header, &Network::Mainnet, &height, &hash).unwrap_err();
let expected = BlockError::TargetDifficultyLimit(
height,
hash,
@ -255,7 +255,7 @@ fn difficulty_validation_failure() -> Result<(), Report> {
let difficulty_threshold = block.header.difficulty_threshold.to_expanded().unwrap();
// Validate the block
let result = check::difficulty_is_valid(&block.header, Network::Mainnet, &height, &bad_hash)
let result = check::difficulty_is_valid(&block.header, &Network::Mainnet, &height, &bad_hash)
.unwrap_err();
let expected =
BlockError::DifficultyFilter(height, bad_hash, difficulty_threshold, Network::Mainnet);
@ -306,7 +306,8 @@ fn subsidy_is_valid_for_network(network: Network) -> Result<(), Report> {
// TODO: first halving, second halving, third halving, and very large halvings
if block::Height(height) >= canopy_activation_height {
check::subsidy_is_valid(&block, network).expect("subsidies should pass for this block");
check::subsidy_is_valid(&block, &network)
.expect("subsidies should pass for this block");
}
}
@ -334,7 +335,7 @@ fn coinbase_validation_failure() -> Result<(), Report> {
assert_eq!(expected, result);
// Validate the block using subsidy_is_valid
let result = check::subsidy_is_valid(&block, network).unwrap_err();
let result = check::subsidy_is_valid(&block, &network).unwrap_err();
let expected = BlockError::Transaction(TransactionError::Subsidy(SubsidyError::NoCoinbase));
assert_eq!(expected, result);
@ -353,7 +354,7 @@ fn coinbase_validation_failure() -> Result<(), Report> {
assert_eq!(expected, result);
// Validate the block using subsidy_is_valid
let result = check::subsidy_is_valid(&block, network).unwrap_err();
let result = check::subsidy_is_valid(&block, &network).unwrap_err();
let expected = BlockError::Transaction(TransactionError::Subsidy(SubsidyError::NoCoinbase));
assert_eq!(expected, result);
@ -378,7 +379,7 @@ fn coinbase_validation_failure() -> Result<(), Report> {
assert_eq!(expected, result);
// Validate the block using subsidy_is_valid, which does not detect this error
check::subsidy_is_valid(&block, network)
check::subsidy_is_valid(&block, &network)
.expect("subsidy does not check for extra coinbase transactions");
Ok(())
@ -406,7 +407,7 @@ fn funding_stream_validation_for_network(network: Network) -> Result<(), Report>
let block = Block::zcash_deserialize(&block[..]).expect("block should deserialize");
// Validate
let result = check::subsidy_is_valid(&block, network);
let result = check::subsidy_is_valid(&block, &network);
assert!(result.is_ok());
}
}
@ -450,7 +451,7 @@ fn funding_stream_validation_failure() -> Result<(), Report> {
};
// Validate it
let result = check::subsidy_is_valid(&block, network);
let result = check::subsidy_is_valid(&block, &network);
let expected = Err(BlockError::Transaction(TransactionError::Subsidy(
SubsidyError::FundingStreamNotFound,
)));
@ -480,7 +481,7 @@ fn miner_fees_validation_for_network(network: Network) -> Result<(), Report> {
let miner_fees = Amount::try_from(MAX_MONEY / 2).unwrap();
// Validate
let result = check::miner_fees_are_valid(&block, network, miner_fees);
let result = check::miner_fees_are_valid(&block, &network, miner_fees);
assert!(result.is_ok());
}
}
@ -501,7 +502,7 @@ fn miner_fees_validation_failure() -> Result<(), Report> {
let miner_fees = Amount::zero();
// Validate
let result = check::miner_fees_are_valid(&block, network, miner_fees);
let result = check::miner_fees_are_valid(&block, &network, miner_fees);
let expected = Err(BlockError::Transaction(TransactionError::Subsidy(
SubsidyError::InvalidMinerFees,
@ -569,7 +570,7 @@ fn merkle_root_is_valid_for_network(network: Network) -> Result<(), Report> {
.map(|tx| tx.hash())
.collect::<Vec<_>>();
check::merkle_root_validity(network, &block, &transaction_hashes)
check::merkle_root_validity(&network, &block, &transaction_hashes)
.expect("merkle root should be valid for this block");
}
@ -616,7 +617,7 @@ fn merkle_root_fake_v5_for_network(network: Network) -> Result<(), Report> {
// but we also need to test against zcashd test vectors.
Arc::make_mut(&mut block.header).merkle_root = transaction_hashes.iter().cloned().collect();
check::merkle_root_validity(network, &block, &transaction_hashes)
check::merkle_root_validity(&network, &block, &transaction_hashes)
.expect("merkle root should be valid for this block");
}
@ -682,13 +683,13 @@ fn legacy_sigops_count_for_historic_blocks() {
fn transaction_expiration_height_validation() -> Result<(), Report> {
let _init_guard = zebra_test::init();
transaction_expiration_height_for_network(Network::Mainnet)?;
transaction_expiration_height_for_network(Network::Testnet)?;
transaction_expiration_height_for_network(&Network::Mainnet)?;
transaction_expiration_height_for_network(&Network::Testnet)?;
Ok(())
}
fn transaction_expiration_height_for_network(network: Network) -> Result<(), Report> {
fn transaction_expiration_height_for_network(network: &Network) -> Result<(), Report> {
let block_iter = network.block_iter();
for (&height, block) in block_iter {

View File

@ -203,7 +203,7 @@ where
/// `tower::Buffer` service.
#[allow(dead_code)]
pub fn new(
network: Network,
network: &Network,
initial_tip: Option<(block::Height, block::Hash)>,
state_service: S,
) -> Self {
@ -232,7 +232,7 @@ where
#[allow(dead_code)]
pub(crate) fn from_list(
list: impl IntoIterator<Item = (block::Height, block::Hash)>,
network: Network,
network: &Network,
initial_tip: Option<(block::Height, block::Hash)>,
state_service: S,
) -> Result<Self, VerifyCheckpointError> {
@ -253,7 +253,7 @@ where
/// hard-coded checkpoint lists. See that function for more details.
pub(crate) fn from_checkpoint_list(
checkpoint_list: CheckpointList,
network: Network,
network: &Network,
initial_tip: Option<(block::Height, block::Hash)>,
state_service: S,
) -> Self {
@ -273,7 +273,7 @@ where
let verifier = CheckpointVerifier {
checkpoint_list,
network,
network: network.clone(),
initial_tip_hash,
state_service,
queued: BTreeMap::new(),
@ -595,14 +595,14 @@ where
.ok_or(VerifyCheckpointError::CoinbaseHeight { hash })?;
self.check_height(height)?;
crate::block::check::difficulty_is_valid(&block.header, self.network, &height, &hash)?;
crate::block::check::difficulty_is_valid(&block.header, &self.network, &height, &hash)?;
crate::block::check::equihash_solution_is_valid(&block.header)?;
// don't do precalculation until the block passes basic difficulty checks
let block = CheckpointVerifiedBlock::with_hash(block, hash);
crate::block::check::merkle_root_validity(
self.network,
&self.network,
&block.block,
&block.transaction_hashes,
)?;

View File

@ -47,7 +47,7 @@ async fn single_item_checkpoint_list() -> Result<(), Report> {
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
CheckpointVerifier::from_list(genesis_checkpoint_list, &Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -126,7 +126,7 @@ async fn multi_item_checkpoint_list() -> Result<(), Report> {
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, Mainnet, None, state_service)
CheckpointVerifier::from_list(checkpoint_list, &Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -271,7 +271,7 @@ async fn continuous_blockchain(
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier = CheckpointVerifier::from_list(
checkpoint_list,
network,
&network,
initial_tip,
state_service.clone(),
)
@ -439,7 +439,7 @@ async fn block_higher_than_max_checkpoint_fail() -> Result<(), Report> {
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
CheckpointVerifier::from_list(genesis_checkpoint_list, &Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -513,7 +513,7 @@ async fn wrong_checkpoint_hash_fail() -> Result<(), Report> {
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(genesis_checkpoint_list, Mainnet, None, state_service)
CheckpointVerifier::from_list(genesis_checkpoint_list, &Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -686,7 +686,7 @@ async fn checkpoint_drop_cancel() -> Result<(), Report> {
let state_service = zebra_state::init_test(&Mainnet);
let mut checkpoint_verifier =
CheckpointVerifier::from_list(checkpoint_list, Mainnet, None, state_service)
CheckpointVerifier::from_list(checkpoint_list, &Mainnet, None, state_service)
.map_err(|e| eyre!(e))?;
assert_eq!(
@ -769,7 +769,7 @@ async fn hard_coded_mainnet() -> Result<(), Report> {
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);
let mut checkpoint_verifier = CheckpointVerifier::new(&Network::Mainnet, None, state_service);
assert_eq!(
checkpoint_verifier.previous_checkpoint_height(),

View File

@ -220,7 +220,7 @@ where
#[instrument(skip(state_service))]
pub async fn init<S>(
config: Config,
network: Network,
network: &Network,
mut state_service: S,
) -> (
Buffer<BoxService<Request, block::Hash, RouterError>, Request>,
@ -242,6 +242,7 @@ where
let checkpoint_state_service = state_service.clone();
let checkpoint_sync = config.checkpoint_sync;
let network_clone = network.clone();
let state_checkpoint_verify_handle = tokio::task::spawn(
// TODO: move this into an async function?
async move {
@ -263,7 +264,7 @@ where
// > activation block hashes given in § 3.12 Mainnet and Testnet on p. 20.
//
// <https://zips.z.cash/protocol/protocol.pdf#blockchain>
let full_checkpoints = network.checkpoint_list();
let full_checkpoints = network_clone.checkpoint_list();
let mut already_warned = false;
for (height, checkpoint_hash) in full_checkpoints.iter() {
@ -318,11 +319,11 @@ where
// transaction verification
let transaction = transaction::Verifier::new(network, state_service.clone());
let transaction = transaction::Verifier::new(&network, state_service.clone());
let transaction = Buffer::new(BoxService::new(transaction), VERIFIER_BUFFER_BOUND);
// block verification
let (list, max_checkpoint_height) = init_checkpoint_list(config, network);
let (list, max_checkpoint_height) = init_checkpoint_list(config, &network);
let tip = match state_service
.ready()
@ -341,8 +342,8 @@ where
"initializing block verifier router"
);
let block = SemanticBlockVerifier::new(network, state_service.clone(), transaction.clone());
let checkpoint = CheckpointVerifier::from_checkpoint_list(list, network, tip, state_service);
let block = SemanticBlockVerifier::new(&network, state_service.clone(), transaction.clone());
let checkpoint = CheckpointVerifier::from_checkpoint_list(list, &network, tip, state_service);
let router = BlockVerifierRouter {
checkpoint,
max_checkpoint_height,
@ -360,7 +361,7 @@ where
/// Parses the checkpoint list for `network` and `config`.
/// Returns the checkpoint list and maximum checkpoint height.
pub fn init_checkpoint_list(config: Config, network: Network) -> (CheckpointList, Height) {
pub fn init_checkpoint_list(config: Config, network: &Network) -> (CheckpointList, Height) {
// TODO: Zebra parses the checkpoint list three times at startup.
// Instead, cache the checkpoint list for each `network`.
let list = network.checkpoint_list();

View File

@ -71,7 +71,7 @@ async fn verifiers_from_network(
_transaction_verifier,
_groth16_download_handle,
_max_checkpoint_height,
) = crate::router::init(Config::default(), network, state_service.clone()).await;
) = crate::router::init(Config::default(), &network, state_service.clone()).await;
// We can drop the download task handle here, because:
// - if the download task fails, the tests will panic, and
@ -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

@ -73,9 +73,9 @@ where
ZS::Future: Send + 'static,
{
/// Create a new transaction verifier.
pub fn new(network: Network, state: ZS) -> Self {
pub fn new(network: &Network, state: ZS) -> Self {
Self {
network,
network: network.clone(),
state: Timeout::new(state, UTXO_LOOKUP_TIMEOUT),
script_verifier: script::Verifier,
}
@ -218,8 +218,8 @@ impl Request {
/// The network upgrade to consider for the verification.
///
/// This is based on the block height from the request, and the supplied `network`.
pub fn upgrade(&self, network: Network) -> NetworkUpgrade {
NetworkUpgrade::current(&network, self.height())
pub fn upgrade(&self, network: &Network) -> NetworkUpgrade {
NetworkUpgrade::current(network, self.height())
}
/// Returns true if the request is a mempool request.
@ -294,7 +294,7 @@ where
// TODO: break up each chunk into its own method
fn call(&mut self, req: Request) -> Self::Future {
let script_verifier = self.script_verifier;
let network = self.network;
let network = self.network.clone();
let state = self.state.clone();
let tx = req.transaction();
@ -321,7 +321,7 @@ where
// Validate `nExpiryHeight` consensus rules
if tx.is_coinbase() {
check::coinbase_expiry_height(&req.height(), &tx, network)?;
check::coinbase_expiry_height(&req.height(), &tx, &network)?;
} else {
check::non_coinbase_expiry_height(&req.height(), &tx)?;
}
@ -335,7 +335,7 @@ where
// [Canopy onward]: `vpub_old` MUST be zero.
// https://zips.z.cash/protocol/protocol.pdf#joinsplitdesc
check::disabled_add_to_sprout_pool(&tx, req.height(), network)?;
check::disabled_add_to_sprout_pool(&tx, req.height(), &network)?;
check::spend_conflicts(&tx)?;
@ -396,7 +396,7 @@ where
..
} => Self::verify_v4_transaction(
&req,
network,
&network,
script_verifier,
cached_ffi_transaction.clone(),
joinsplit_data,
@ -408,7 +408,7 @@ where
..
} => Self::verify_v5_transaction(
&req,
network,
&network,
script_verifier,
cached_ffi_transaction.clone(),
sapling_shielded_data,
@ -616,7 +616,7 @@ where
/// - the `sapling_shielded_data` in the transaction
fn verify_v4_transaction(
request: &Request,
network: Network,
network: &Network,
script_verifier: script::Verifier,
cached_ffi_transaction: Arc<CachedFfiTransaction>,
joinsplit_data: &Option<transaction::JoinSplitData<Groth16Proof>>,
@ -708,7 +708,7 @@ where
/// - the orchard shielded data of the transaction, if any
fn verify_v5_transaction(
request: &Request,
network: Network,
network: &Network,
script_verifier: script::Verifier,
cached_ffi_transaction: Arc<CachedFfiTransaction>,
sapling_shielded_data: &Option<sapling::ShieldedData<sapling::SharedAnchor>>,
@ -782,7 +782,7 @@ where
/// Returns script verification responses via the `utxo_sender`.
fn verify_transparent_inputs_and_outputs(
request: &Request,
network: Network,
network: &Network,
script_verifier: script::Verifier,
cached_ffi_transaction: Arc<CachedFfiTransaction>,
) -> Result<AsyncChecks, TransactionError> {

View File

@ -212,7 +212,7 @@ pub fn joinsplit_has_vpub_zero(tx: &Transaction) -> Result<(), TransactionError>
pub fn disabled_add_to_sprout_pool(
tx: &Transaction,
height: Height,
network: Network,
network: &Network,
) -> Result<(), TransactionError> {
let canopy_activation_height = NetworkUpgrade::Canopy
.activation_height(&network)
@ -325,7 +325,7 @@ where
/// <https://github.com/ZcashFoundation/zebra/issues/3027>
pub fn coinbase_outputs_are_decryptable(
transaction: &Transaction,
network: Network,
network: &Network,
height: Height,
) -> Result<(), TransactionError> {
// The consensus rule only applies to Heartwood onward.
@ -352,7 +352,7 @@ pub fn coinbase_outputs_are_decryptable(
pub fn coinbase_expiry_height(
block_height: &Height,
coinbase: &Transaction,
network: Network,
network: &Network,
) -> Result<(), TransactionError> {
let expiry_height = coinbase.expiry_height();

View File

@ -186,7 +186,7 @@ fn v5_transaction_with_no_inputs_fails_validation() {
#[tokio::test]
async fn mempool_request_with_missing_input_is_rejected() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let (height, tx) = transactions_from_blocks(zebra_test::vectors::MAINNET_BLOCKS.iter())
.find(|(_, tx)| !(tx.is_coinbase() || tx.inputs().is_empty()))
@ -235,7 +235,7 @@ async fn mempool_request_with_missing_input_is_rejected() {
#[tokio::test]
async fn mempool_request_with_present_input_is_accepted() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -302,7 +302,7 @@ async fn mempool_request_with_present_input_is_accepted() {
#[tokio::test]
async fn mempool_request_with_invalid_lock_time_is_rejected() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -381,7 +381,7 @@ async fn mempool_request_with_invalid_lock_time_is_rejected() {
#[tokio::test]
async fn mempool_request_with_unlocked_lock_time_is_accepted() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -448,7 +448,7 @@ async fn mempool_request_with_unlocked_lock_time_is_accepted() {
#[tokio::test]
async fn mempool_request_with_lock_time_max_sequence_number_is_accepted() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -518,7 +518,7 @@ async fn mempool_request_with_lock_time_max_sequence_number_is_accepted() {
#[tokio::test]
async fn mempool_request_with_past_lock_time_is_accepted() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -597,7 +597,7 @@ async fn mempool_request_with_immature_spend_is_rejected() {
let _init_guard = zebra_test::init();
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -700,7 +700,7 @@ async fn state_error_converted_correctly() {
use zebra_state::DuplicateNullifierError;
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -865,7 +865,7 @@ async fn v5_transaction_is_rejected_before_nu5_activation() {
for (network, blocks) in networks {
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let transaction = fake_v5_transactions_for_network(&network, blocks)
.next_back()
@ -912,7 +912,7 @@ fn v5_transaction_is_accepted_after_nu5_activation_for_network(network: Network)
let blocks = network.block_iter();
let state_service = service_fn(|_| async { unreachable!("Service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let mut transaction = fake_v5_transactions_for_network(&network, blocks)
.next_back()
@ -984,7 +984,7 @@ async fn v4_transaction_with_transparent_transfer_is_accepted() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1007,7 +1007,7 @@ async fn v4_transaction_with_transparent_transfer_is_accepted() {
async fn v4_transaction_with_last_valid_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Mainnet, state_service);
let verifier = Verifier::new(&Network::Mainnet, state_service);
let block_height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -1054,7 +1054,7 @@ async fn v4_transaction_with_last_valid_expiry_height() {
async fn v4_coinbase_transaction_with_low_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Mainnet, state_service);
let verifier = Verifier::new(&Network::Mainnet, state_service);
let block_height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -1095,7 +1095,7 @@ async fn v4_coinbase_transaction_with_low_expiry_height() {
async fn v4_transaction_with_too_low_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Mainnet, state_service);
let verifier = Verifier::new(&Network::Mainnet, state_service);
let block_height = NetworkUpgrade::Canopy
.activation_height(&Network::Mainnet)
@ -1147,7 +1147,7 @@ async fn v4_transaction_with_too_low_expiry_height() {
async fn v4_transaction_with_exceeding_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Mainnet, state_service);
let verifier = Verifier::new(&Network::Mainnet, state_service);
let block_height = block::Height::MAX;
@ -1198,7 +1198,7 @@ async fn v4_transaction_with_exceeding_expiry_height() {
async fn v4_coinbase_transaction_with_exceeding_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Mainnet, state_service);
let verifier = Verifier::new(&Network::Mainnet, state_service);
// Use an arbitrary pre-NU5 block height.
// It can't be NU5-onward because the expiry height limit is not enforced
@ -1274,7 +1274,7 @@ async fn v4_coinbase_transaction_is_accepted() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1329,7 +1329,7 @@ async fn v4_transaction_with_transparent_transfer_is_rejected_by_the_script() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1384,7 +1384,7 @@ async fn v4_transaction_with_conflicting_transparent_spend_is_rejected() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1450,7 +1450,7 @@ fn v4_transaction_with_conflicting_sprout_nullifier_inside_joinsplit_is_rejected
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1521,7 +1521,7 @@ fn v4_transaction_with_conflicting_sprout_nullifier_across_joinsplits_is_rejecte
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1580,7 +1580,7 @@ async fn v5_transaction_with_transparent_transfer_is_accepted() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1603,7 +1603,7 @@ async fn v5_transaction_with_transparent_transfer_is_accepted() {
async fn v5_transaction_with_last_valid_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Testnet, state_service);
let verifier = Verifier::new(&Network::Testnet, state_service);
let block_height = NetworkUpgrade::Nu5
.activation_height(&Network::Testnet)
@ -1648,7 +1648,7 @@ async fn v5_transaction_with_last_valid_expiry_height() {
async fn v5_coinbase_transaction_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Testnet, state_service);
let verifier = Verifier::new(&Network::Testnet, state_service);
let block_height = NetworkUpgrade::Nu5
.activation_height(&Network::Testnet)
@ -1763,7 +1763,7 @@ async fn v5_coinbase_transaction_expiry_height() {
async fn v5_transaction_with_too_low_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Testnet, state_service);
let verifier = Verifier::new(&Network::Testnet, state_service);
let block_height = NetworkUpgrade::Nu5
.activation_height(&Network::Testnet)
@ -1815,7 +1815,7 @@ async fn v5_transaction_with_too_low_expiry_height() {
async fn v5_transaction_with_exceeding_expiry_height() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(Network::Mainnet, state_service);
let verifier = Verifier::new(&Network::Mainnet, state_service);
let block_height = block::Height::MAX;
@ -1893,7 +1893,7 @@ async fn v5_coinbase_transaction_is_accepted() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -1950,7 +1950,7 @@ async fn v5_transaction_with_transparent_transfer_is_rejected_by_the_script() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -2007,7 +2007,7 @@ async fn v5_transaction_with_conflicting_transparent_spend_is_rejected() {
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
let result = verifier
.oneshot(Request::Block {
@ -2037,7 +2037,7 @@ fn v4_with_signed_sprout_transfer_is_accepted() {
zebra_test::MULTI_THREADED_RUNTIME.block_on(async {
let network = Network::Mainnet;
let (height, transaction) = test_transactions(network)
let (height, transaction) = test_transactions(&network)
.rev()
.filter(|(_, transaction)| {
!transaction.is_coinbase() && transaction.inputs().is_empty()
@ -2050,7 +2050,7 @@ fn v4_with_signed_sprout_transfer_is_accepted() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2109,7 +2109,7 @@ async fn v4_with_joinsplit_is_rejected_for_modification(
) {
let network = Network::Mainnet;
let (height, mut transaction) = test_transactions(network)
let (height, mut transaction) = test_transactions(&network)
.rev()
.filter(|(_, transaction)| !transaction.is_coinbase() && transaction.inputs().is_empty())
.find(|(_, transaction)| transaction.sprout_groth16_joinsplits().next().is_some())
@ -2130,7 +2130,7 @@ async fn v4_with_joinsplit_is_rejected_for_modification(
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called.") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier.
//
@ -2168,7 +2168,7 @@ fn v4_with_sapling_spends() {
zebra_test::MULTI_THREADED_RUNTIME.block_on(async {
let network = Network::Mainnet;
let (height, transaction) = test_transactions(network)
let (height, transaction) = test_transactions(&network)
.rev()
.filter(|(_, transaction)| {
!transaction.is_coinbase() && transaction.inputs().is_empty()
@ -2181,7 +2181,7 @@ fn v4_with_sapling_spends() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2208,7 +2208,7 @@ fn v4_with_duplicate_sapling_spends() {
zebra_test::MULTI_THREADED_RUNTIME.block_on(async {
let network = Network::Mainnet;
let (height, mut transaction) = test_transactions(network)
let (height, mut transaction) = test_transactions(&network)
.rev()
.filter(|(_, transaction)| {
!transaction.is_coinbase() && transaction.inputs().is_empty()
@ -2224,7 +2224,7 @@ fn v4_with_duplicate_sapling_spends() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2253,7 +2253,7 @@ fn v4_with_sapling_outputs_and_no_spends() {
zebra_test::MULTI_THREADED_RUNTIME.block_on(async {
let network = Network::Mainnet;
let (height, transaction) = test_transactions(network)
let (height, transaction) = test_transactions(&network)
.rev()
.filter(|(_, transaction)| {
!transaction.is_coinbase() && transaction.inputs().is_empty()
@ -2269,7 +2269,7 @@ fn v4_with_sapling_outputs_and_no_spends() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2318,7 +2318,7 @@ fn v5_with_sapling_spends() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2362,7 +2362,7 @@ fn v5_with_duplicate_sapling_spends() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2425,7 +2425,7 @@ fn v5_with_duplicate_orchard_action() {
// Initialize the verifier
let state_service =
service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = Verifier::new(network, state_service);
let verifier = Verifier::new(&network, state_service);
// Test the transaction verifier
let result = verifier
@ -2717,14 +2717,14 @@ fn add_to_sprout_pool_after_nu() {
// the coinbase transaction should pass the check.
assert_eq!(
check::disabled_add_to_sprout_pool(&block.transactions[0], block_height, network),
check::disabled_add_to_sprout_pool(&block.transactions[0], block_height, &network),
Ok(())
);
// the 2nd transaction has no joinsplits, should pass the check.
assert_eq!(block.transactions[1].joinsplit_count(), 0);
assert_eq!(
check::disabled_add_to_sprout_pool(&block.transactions[1], block_height, network),
check::disabled_add_to_sprout_pool(&block.transactions[1], block_height, &network),
Ok(())
);
@ -2737,7 +2737,7 @@ fn add_to_sprout_pool_after_nu() {
assert!(vpub_old > zero);
assert_eq!(
check::disabled_add_to_sprout_pool(&block.transactions[3], block_height, network),
check::disabled_add_to_sprout_pool(&block.transactions[3], block_height, &network),
Err(TransactionError::DisabledAddToSproutPool)
);
@ -2750,7 +2750,7 @@ fn add_to_sprout_pool_after_nu() {
assert_eq!(vpub_old, zero);
assert_eq!(
check::disabled_add_to_sprout_pool(&block.transactions[7], block_height, network),
check::disabled_add_to_sprout_pool(&block.transactions[7], block_height, &network),
Ok(())
);
}
@ -2796,7 +2796,7 @@ fn coinbase_outputs_are_decryptable_for_historical_blocks_for_network(
// and there are relevant outputs.
tested_coinbase_txs += 1;
}
check::coinbase_outputs_are_decryptable(coinbase_tx, network, height)
check::coinbase_outputs_are_decryptable(coinbase_tx, &network, height)
.expect("coinbase outputs must be decryptable with an all-zero key");
// For remaining transactions, check if existing outputs are NOT decryptable
@ -2805,11 +2805,11 @@ fn coinbase_outputs_are_decryptable_for_historical_blocks_for_network(
let has_outputs = tx.sapling_outputs().count() > 0 || tx.orchard_actions().count() > 0;
if has_outputs && heartwood_onward {
tested_non_coinbase_txs += 1;
check::coinbase_outputs_are_decryptable(tx, network, height).expect_err(
check::coinbase_outputs_are_decryptable(tx, &network, height).expect_err(
"decrypting a non-coinbase output with an all-zero key should fail",
);
} else {
check::coinbase_outputs_are_decryptable(tx, network, height)
check::coinbase_outputs_are_decryptable(tx, &network, height)
.expect("a transaction without outputs, or pre-Heartwood, must be considered 'decryptable'");
}
}
@ -2874,7 +2874,7 @@ fn coinbase_outputs_are_decryptable_for_fake_v5_blocks() {
assert_eq!(
check::coinbase_outputs_are_decryptable(
&transaction,
network,
&network,
NetworkUpgrade::Nu5.activation_height(&network).unwrap(),
),
Ok(())
@ -2916,7 +2916,7 @@ fn shielded_outputs_are_not_decryptable_for_fake_v5_blocks() {
assert_eq!(
check::coinbase_outputs_are_decryptable(
&transaction,
network,
&network,
NetworkUpgrade::Nu5.activation_height(&network).unwrap(),
),
Err(TransactionError::CoinbaseOutputsNotDecryptable)
@ -2927,7 +2927,7 @@ fn shielded_outputs_are_not_decryptable_for_fake_v5_blocks() {
#[tokio::test]
async fn mempool_zip317_error() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Nu5
.activation_height(&Network::Mainnet)
@ -2999,7 +2999,7 @@ async fn mempool_zip317_error() {
#[tokio::test]
async fn mempool_zip317_ok() {
let mut state: MockService<_, _, _, _> = MockService::build().for_prop_tests();
let verifier = Verifier::new(Network::Mainnet, state.clone());
let verifier = Verifier::new(&Network::Mainnet, state.clone());
let height = NetworkUpgrade::Nu5
.activation_height(&Network::Mainnet)

View File

@ -36,7 +36,7 @@ proptest! {
let zero_lock_time = LockTime::Height(block::Height(0));
let (transaction, known_utxos) = mock_transparent_transaction(
network,
&network,
block_height,
relative_source_fund_heights,
transaction_version,
@ -67,7 +67,7 @@ proptest! {
let _init_guard = zebra_test::init();
let (mut transaction, known_utxos) = mock_transparent_transaction(
network,
&network,
block_height,
relative_source_fund_heights,
transaction_version,
@ -105,7 +105,7 @@ proptest! {
let lock_time = LockTime::Height(unlock_height);
let (transaction, known_utxos) = mock_transparent_transaction(
network,
&network,
block_height,
relative_source_fund_heights,
transaction_version,
@ -138,7 +138,7 @@ proptest! {
};
let (transaction, known_utxos) = mock_transparent_transaction(
network,
&network,
block_height,
relative_source_fund_heights,
transaction_version,
@ -172,7 +172,7 @@ proptest! {
let lock_time = LockTime::Height(unlock_height);
let (transaction, known_utxos) = mock_transparent_transaction(
network,
&network,
block_height,
relative_source_fund_heights,
transaction_version,
@ -213,7 +213,7 @@ proptest! {
};
let (transaction, known_utxos) = mock_transparent_transaction(
network,
&network,
block_height,
relative_source_fund_heights,
transaction_version,
@ -251,7 +251,7 @@ fn sapling_onwards_strategy() -> impl Strategy<Value = (Network, block::Height)>
let end_height_value = block::Height::MAX_EXPIRY_HEIGHT.0;
(start_height_value..=end_height_value)
.prop_map(move |height_value| (network, block::Height(height_value)))
.prop_map(move |height_value| (network.clone(), block::Height(height_value)))
})
}
@ -281,7 +281,7 @@ fn sapling_onwards_strategy() -> impl Strategy<Value = (Network, block::Height)>
/// - if any item of `relative_source_heights` is not in the range `0.0..1.0` (see
/// [`scale_block_height`] for details)
fn mock_transparent_transaction(
network: Network,
network: &Network,
block_height: block::Height,
relative_source_heights: Vec<f64>,
transaction_version: u8,
@ -330,7 +330,7 @@ fn mock_transparent_transaction(
/// The `transaction_version` might be reduced if it is not supported by the network upgrade active
/// at the `block_height` of the specified `network`.
fn sanitize_transaction_version(
network: Network,
network: &Network,
transaction_version: u8,
block_height: block::Height,
) -> (u8, NetworkUpgrade) {
@ -450,7 +450,7 @@ fn validate(
// Initialize the verifier
let state_service =
tower::service_fn(|_| async { unreachable!("State service should not be called") });
let verifier = transaction::Verifier::new(network, state_service);
let verifier = transaction::Verifier::new(&network, state_service);
// Test the transaction verifier
verifier

View File

@ -86,7 +86,7 @@ pub async fn test_responses<State, ReadState>(
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(zebra_consensus::Config::default(), network, state.clone())
) = zebra_consensus::router::init(zebra_consensus::Config::default(), &network, state.clone())
.await;
let mut mock_sync_status = MockSyncStatus::default();

View File

@ -871,7 +871,7 @@ async fn rpc_getblockcount() {
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(zebra_consensus::Config::default(), Mainnet, state.clone())
) = zebra_consensus::router::init(zebra_consensus::Config::default(), &Mainnet, state.clone())
.await;
// Init RPC
@ -916,7 +916,7 @@ async fn rpc_getblockcount_empty_state() {
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(zebra_consensus::Config::default(), Mainnet, state.clone())
) = zebra_consensus::router::init(zebra_consensus::Config::default(), &Mainnet, state.clone())
.await;
// Init RPC
@ -963,7 +963,7 @@ async fn rpc_getpeerinfo() {
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(zebra_consensus::Config::default(), network, state.clone())
) = zebra_consensus::router::init(zebra_consensus::Config::default(), &network, state.clone())
.await;
let mock_peer_address = zebra_network::types::MetaAddr::new_initial_peer(
@ -1033,7 +1033,7 @@ async fn rpc_getblockhash() {
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(zebra_consensus::Config::default(), Mainnet, state.clone())
) = zebra_consensus::router::init(zebra_consensus::Config::default(), &Mainnet, state.clone())
.await;
// Init RPC
@ -1518,7 +1518,7 @@ async fn rpc_submitblock_errors() {
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(zebra_consensus::Config::default(), Mainnet, state.clone())
) = zebra_consensus::router::init(zebra_consensus::Config::default(), &Mainnet, state.clone())
.await;
// Init RPC

View File

@ -116,7 +116,7 @@ impl StartCmd {
info!("initializing node state");
let (_, max_checkpoint_height) = zebra_consensus::router::init_checkpoint_list(
config.consensus.clone(),
config.network.network,
&config.network.network,
);
info!("opening database, this may take a few minutes");
@ -168,7 +168,7 @@ impl StartCmd {
let (block_verifier_router, tx_verifier, consensus_task_handles, max_checkpoint_height) =
zebra_consensus::router::init(
config.consensus.clone(),
config.network.network,
&config.network.network,
state.clone(),
)
.await;

View File

@ -792,8 +792,12 @@ async fn caches_getaddr_response() {
_transaction_verifier,
_groth16_download_handle,
_max_checkpoint_height,
) = zebra_consensus::router::init(consensus_config.clone(), network, state_service.clone())
.await;
) = zebra_consensus::router::init(
consensus_config.clone(),
&network,
state_service.clone(),
)
.await;
let peer_set = MockService::build()
.with_max_request_delay(MAX_PEER_SET_REQUEST_DELAY)
@ -897,7 +901,7 @@ async fn setup(
// Download task panics and timeouts are propagated to the tests that use Groth16 verifiers.
let (block_verifier, _transaction_verifier, _groth16_download_handle, _max_checkpoint_height) =
zebra_consensus::router::init(consensus_config.clone(), network, state_service.clone())
zebra_consensus::router::init(consensus_config.clone(), &network, state_service.clone())
.await;
let mut peer_set = MockService::build()