applied all requested changes from review

This commit is contained in:
idky137 2024-03-19 12:49:49 +00:00
parent 64c6384d04
commit 31ea1358c9
No known key found for this signature in database
12 changed files with 38 additions and 33 deletions

View File

@ -382,7 +382,7 @@ impl Clone for NonEmptyHistoryTree {
let tree = match self.inner {
InnerHistoryTree::PreOrchard(_) => InnerHistoryTree::PreOrchard(
Tree::<PreOrchard>::new_from_cache(
&self.network.clone(),
&self.network,
self.network_upgrade,
self.size,
&self.peaks,

View File

@ -185,7 +185,7 @@ impl Address {
Self::Transparent(address) => Some(address.to_string()),
Self::Sapling { address, network } => {
let data = address.to_bytes();
let address = ZcashAddress::from_sapling((network).into(), data);
let address = ZcashAddress::from_sapling(network.into(), data);
Some(address.encode())
}
Self::Unified { .. } => None,

View File

@ -111,7 +111,7 @@ impl<V: Version> Tree<V> {
length: u32,
peaks: &BTreeMap<u32, Entry>,
extra: &BTreeMap<u32, Entry>,
) -> Result<Tree<V>, io::Error> {
) -> Result<Self, io::Error> {
let branch_id = network_upgrade
.branch_id()
.expect("unexpected pre-Overwinter MMR history tree");
@ -148,7 +148,7 @@ impl<V: Version> Tree<V> {
let height = block
.coinbase_height()
.expect("block must have coinbase height during contextual verification");
let network_upgrade = NetworkUpgrade::current(&network, height);
let network_upgrade = NetworkUpgrade::current(network, height);
let entry0 = Entry::new_leaf::<V>(block, network, sapling_root, orchard_root);
let mut peaks = BTreeMap::new();
peaks.insert(0u32, entry0);
@ -240,7 +240,7 @@ impl Version for zcash_history::V1 {
let height = block
.coinbase_height()
.expect("block must have coinbase height during contextual verification");
let network_upgrade = NetworkUpgrade::current(&network, height);
let network_upgrade = NetworkUpgrade::current(network, height);
let branch_id = network_upgrade
.branch_id()
.expect("must have branch ID for chain history network upgrades");

View File

@ -21,7 +21,7 @@ fn tree() -> Result<()> {
fn tree_for_network_upgrade(network: &Network, network_upgrade: NetworkUpgrade) -> Result<()> {
let (blocks, sapling_roots) = network.block_sapling_roots_map();
let height = network_upgrade.activation_height(&network).unwrap().0;
let height = network_upgrade.activation_height(network).unwrap().0;
// Load Block 0 (activation block of the given network upgrade)
let block0 = Arc::new(
@ -33,7 +33,7 @@ fn tree_for_network_upgrade(network: &Network, network_upgrade: NetworkUpgrade)
);
// Check its commitment
let commitment0 = block0.commitment(&network)?;
let commitment0 = block0.commitment(network)?;
if network_upgrade == NetworkUpgrade::Heartwood {
// Heartwood is the only upgrade that has a reserved value.
// (For other upgrades we could compare with the expected commitment,
@ -45,7 +45,7 @@ fn tree_for_network_upgrade(network: &Network, network_upgrade: NetworkUpgrade)
let sapling_root0 =
sapling::tree::Root::try_from(**sapling_roots.get(&height).expect("test vector exists"))?;
let (mut tree, _) =
Tree::<V1>::new_from_block(&network, block0, &sapling_root0, &Default::default())?;
Tree::<V1>::new_from_block(network, block0, &sapling_root0, &Default::default())?;
// Compute root hash of the MMR tree, which will be included in the next block
let hash0 = tree.hash();
@ -60,7 +60,7 @@ fn tree_for_network_upgrade(network: &Network, network_upgrade: NetworkUpgrade)
);
// Check its commitment
let commitment1 = block1.commitment(&network)?;
let commitment1 = block1.commitment(network)?;
assert_eq!(commitment1, Commitment::ChainHistoryRoot(hash0));
// Append Block to MMR tree

View File

@ -16,7 +16,7 @@ use crate::{
/// If passed a network/height without matching consensus branch ID (pre-Overwinter),
/// since `librustzcash` won't be able to parse it.
pub fn decrypts_successfully(transaction: &Transaction, network: &Network, height: Height) -> bool {
let network_upgrade = NetworkUpgrade::current(&network, height);
let network_upgrade = NetworkUpgrade::current(network, height);
let alt_tx = convert_tx_to_librustzcash(transaction, network_upgrade)
.expect("zcash_primitives and Zebra transaction formats must be compatible");

View File

@ -864,7 +864,7 @@ pub fn transaction_to_fake_v5(
) -> Transaction {
use Transaction::*;
let block_nu = NetworkUpgrade::current(&network, height);
let block_nu = NetworkUpgrade::current(network, height);
match trans {
V1 {

View File

@ -427,6 +427,6 @@ impl Output {
///
/// Returns None if the address type is not valid or unrecognized.
pub fn address(&self, network: &Network) -> Option<Address> {
zcash_primitives::transparent_output_address(self, &network)
zcash_primitives::transparent_output_address(self, network)
}
}

View File

@ -154,7 +154,7 @@ pub fn subsidy_is_valid(block: &Block, network: &Network) -> Result<(), BlockErr
};
let canopy_activation_height = NetworkUpgrade::Canopy
.activation_height(&network)
.activation_height(network)
.expect("Canopy activation height is known");
if height < SLOW_START_INTERVAL {
@ -295,7 +295,7 @@ pub fn merkle_root_validity(
) -> Result<(), BlockError> {
// TODO: deduplicate zebra-chain and zebra-consensus errors (#2908)
block
.check_transaction_network_upgrade_consistency(&network)
.check_transaction_network_upgrade_consistency(network)
.map_err(|_| BlockError::WrongTransactionConsensusBranchId)?;
let merkle_root = transaction_hashes.iter().cloned().collect();

View File

@ -25,7 +25,7 @@ pub fn funding_stream_values(
height: Height,
network: &Network,
) -> Result<HashMap<FundingStreamReceiver, Amount<NonNegative>>, Error> {
let canopy_height = Canopy.activation_height(&network).unwrap();
let canopy_height = Canopy.activation_height(network).unwrap();
let mut results = HashMap::new();
if height >= canopy_height {

View File

@ -8,16 +8,16 @@ use super::*;
#[test]
fn test_funding_stream_values() -> Result<(), Report> {
let _init_guard = zebra_test::init();
let network = Network::Mainnet;
let network = &Network::Mainnet;
// 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());
let canopy_height_minus1 = Canopy.activation_height(network).unwrap() - 1;
assert!(funding_stream_values(canopy_height_minus1.unwrap(), network)?.is_empty());
// funding stream is active
let canopy_height = Canopy.activation_height(&network);
let canopy_height_plus1 = Canopy.activation_height(&network).unwrap() + 1;
let canopy_height_plus2 = Canopy.activation_height(&network).unwrap() + 2;
let canopy_height = Canopy.activation_height(network);
let canopy_height_plus1 = Canopy.activation_height(network).unwrap() + 1;
let canopy_height_plus2 = Canopy.activation_height(network).unwrap() + 2;
let mut hash_map = HashMap::new();
hash_map.insert(FundingStreamReceiver::Ecc, Amount::try_from(21_875_000)?);
@ -31,28 +31,28 @@ 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
);
// funding stream period is ending
let range = FUNDING_STREAM_HEIGHT_RANGES.get(&network).unwrap();
let range = FUNDING_STREAM_HEIGHT_RANGES.get(network).unwrap();
let end = range.end;
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(())
}

View File

@ -66,7 +66,7 @@ pub fn halving_divisor(height: Height, network: &Network) -> Option<u64> {
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
pub fn block_subsidy(height: Height, network: &Network) -> Result<Amount<NonNegative>, Error> {
let blossom_height = Blossom
.activation_height(&network)
.activation_height(network)
.expect("blossom activation height should be available");
// If the halving divisor is larger than u64::MAX, the block subsidy is zero,
@ -130,7 +130,7 @@ mod test {
}
fn halving_for_network(network: &Network) -> Result<(), Report> {
let blossom_height = Blossom.activation_height(&network).unwrap();
let blossom_height = Blossom.activation_height(network).unwrap();
let first_halving_height = network.height_for_first_halving();
assert_eq!(
@ -256,7 +256,7 @@ mod test {
}
fn block_subsidy_for_network(network: &Network) -> Result<(), Report> {
let blossom_height = Blossom.activation_height(&network).unwrap();
let blossom_height = Blossom.activation_height(network).unwrap();
let first_halving_height = network.height_for_first_halving();
// After slow-start mining and before Blossom the block subsidy is 12.5 ZEC

View File

@ -240,9 +240,14 @@ where
// Make sure the state contains the known best chain checkpoints, in a separate thread.
let checkpoint_state_service = state_service.clone();
let checkpoint_sync = config.checkpoint_sync;
let network_clone = network.clone();
let (checkpoint_state_service, checkpoint_sync, network_clone) = {
let checkpoint_state_service = state_service.clone();
let checkpoint_sync = config.checkpoint_sync;
let network_clone = network.clone();
(checkpoint_state_service, checkpoint_sync, network_clone)
};
let state_checkpoint_verify_handle = tokio::task::spawn(
// TODO: move this into an async function?
async move {