Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(chain): Remove Copy trait impl from Network #8354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
78d799d
removed derive copy from network, address and ledgerstate
idky137 Mar 15, 2024
abe86ad
changed is_max_block_time_enforced to accept ref
idky137 Mar 11, 2024
2586f10
changed NetworkUpgrade::Current to accept ref
idky137 Mar 11, 2024
b088c07
changed NetworkUpgrade::Next to accept ref
idky137 Mar 11, 2024
d555f5b
changed NetworkUpgrade::IsActivationHeight to accept ref
idky137 Mar 11, 2024
9d507bd
changed NetworkUpgrade::TargetSpacingForHeight to accept ref
idky137 Mar 11, 2024
d6a03ae
changed NetworkUpgrade::TargetSpacings to accept ref
idky137 Mar 11, 2024
8eb42ff
changed NetworkUpgrade::MinimumDifficultySpacing_forHeight to accept ref
idky137 Mar 11, 2024
c04c94f
changed NetworkUpgrade::IsTestnetMinDifficultyBlock to accept ref
idky137 Mar 11, 2024
bdf80c1
changed NetworkUpgrade::AveragingWindowTimespanForHeight to accept ref
idky137 Mar 11, 2024
30c4cbe
changed NetworkUpgrade::ActivationHeight to accept ref
idky137 Mar 11, 2024
0e23b5d
changed sapling_activation_height to accept ref
idky137 Mar 11, 2024
05c2a88
fixed lifetime for target_spacings
idky137 Mar 11, 2024
984d106
fixed sapling_activation_height
idky137 Mar 11, 2024
3d63f83
changed transaction_to_fake_v5 and fake_v5_transactions_for_network t…
idky137 Mar 12, 2024
6af7425
changed Input::vec_strategy to accept ref to network
idky137 Mar 12, 2024
f3ce942
changed functions in zebra-chain/src/primitives/zcash_history.rs to a…
idky137 Mar 12, 2024
d985e87
changed functions in zebra-chain/src/history_tree.rs to accept ref to…
idky137 Mar 13, 2024
4ba2241
changed functions in zebra-chain/src/history_tree.rs to accept ref to…
idky137 Mar 13, 2024
c656b2b
changed functions in zebra-chain/src/primitives/address.rs to accept …
idky137 Mar 13, 2024
42de8e2
changed functions in zebra-chain/src/primitives/viewing_key* to accep…
idky137 Mar 13, 2024
44a49a6
changed functions in zebra-chain/src/transparent/address.rs to accept…
idky137 Mar 13, 2024
eccc589
changed functions in zebra-chain/src/primitives/zcash_primitives.rs t…
idky137 Mar 13, 2024
59fb9e6
changed functions in zebra-chain/src/primitives/zcash_note_encryption…
idky137 Mar 13, 2024
e42c6fa
changed functions in zebra-chain/src/primitives/history_tree* to acce…
idky137 Mar 13, 2024
fdf8b1c
changed functions in zebra-chain/src/block* to accept ref to network
idky137 Mar 13, 2024
322fbf9
fixed errors in zebra-chain::parameters::network
idky137 Mar 13, 2024
51f8c51
fixed errors in zebra-chain::parameters::network
idky137 Mar 13, 2024
b865166
fixed errors in zebra-chain
idky137 Mar 13, 2024
d61639d
changed NonEmptyHistoryTree and InnerHistoryTree to hold value instea…
idky137 Mar 13, 2024
72540ec
changed NonEmptyHistoryTree and InnerHistoryTree to hold value instea…
idky137 Mar 13, 2024
5be0d86
fixed errors in zebra-chain/src/block/arbitrary.rs
idky137 Mar 13, 2024
6906634
finished fixing errors in zebra-chain - all crate tests pass
idky137 Mar 13, 2024
313598b
changed functions in zebra-state::service::finalized_state to accept …
idky137 Mar 15, 2024
7c1ab87
changed functions in zebra-state::service::non_finalized_state to acc…
idky137 Mar 18, 2024
a24612e
zebra-state tests run but fail with overflow error
idky137 Mar 18, 2024
7e539ae
zebra-state tests all pass
idky137 Mar 18, 2024
08ed2f3
converted zebra-network -- all crate tests pass
idky137 Mar 18, 2024
08ab2ea
applied all requested changes from review
idky137 Mar 18, 2024
04a9301
converted zebra-consensus -- all crate tests pass
idky137 Mar 18, 2024
fed20b2
converted zebra-scan -- all crate tests pass
idky137 Mar 18, 2024
676b3ad
converted zebra-rpc -- all crate tests pass
idky137 Mar 18, 2024
3063bca
converted zebra-grpc -- all crate tests pass
idky137 Mar 18, 2024
64c6384
converted zebrad -- all crate tests pass
idky137 Mar 18, 2024
31ea135
applied all requested changes from review
idky137 Mar 19, 2024
17ea497
fixed all clippy errors
idky137 Mar 19, 2024
06ad700
Merge remote-tracking branch 'ecc/main' into remove_derive_copy_from_…
idky137 Mar 19, 2024
b09707c
fixed build error in zebrad/src/components/mempool/crawler.rs
idky137 Mar 19, 2024
4e81cad
Merge remote-tracking branch 'ecc/main' into remove_derive_copy_from_…
idky137 Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Block {
///
/// Returns an error if this block does not have a block height,
/// or if the commitment value is structurally invalid.
pub fn commitment(&self, network: Network) -> Result<Commitment, CommitmentError> {
pub fn commitment(&self, network: &Network) -> Result<Commitment, CommitmentError> {
match self.coinbase_height() {
None => Err(CommitmentError::MissingBlockHeight {
block_hash: self.hash(),
Expand All @@ -121,7 +121,7 @@ impl Block {
#[allow(clippy::unwrap_in_result)]
pub fn check_transaction_network_upgrade_consistency(
&self,
network: Network,
network: &Network,
) -> Result<(), error::BlockError> {
let block_nu =
NetworkUpgrade::current(network, self.coinbase_height().expect("a valid height"));
Expand Down
36 changes: 19 additions & 17 deletions zebra-chain/src/block/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Randomised property testing for [`Block`]s.

use std::{collections::HashMap, sync::Arc};

Check warning on line 3 in zebra-chain/src/block/arbitrary.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

the item `HashMap` is imported redundantly

Check warning on line 3 in zebra-chain/src/block/arbitrary.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

the item `Arc` is imported redundantly

use proptest::{
arbitrary::{any, Arbitrary},

Check warning on line 6 in zebra-chain/src/block/arbitrary.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

the item `any` is imported redundantly

Check warning on line 6 in zebra-chain/src/block/arbitrary.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

the item `Arbitrary` is imported redundantly
prelude::*,
};

Expand All @@ -13,8 +13,8 @@
fmt::{HexDebug, SummaryDebug},
history_tree::HistoryTree,
parameters::{
Network,

Check warning on line 16 in zebra-chain/src/block/arbitrary.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

the item `Network` is imported redundantly
NetworkUpgrade::{self, *},

Check warning on line 17 in zebra-chain/src/block/arbitrary.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

the item `NetworkUpgrade` is imported redundantly
GENESIS_PREVIOUS_BLOCK_HASH,
},
serialization,
Expand Down Expand Up @@ -69,7 +69,7 @@
type Strategy = BoxedStrategy<Self>;
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
#[non_exhaustive]
/// The configuration data for proptest when generating arbitrary chains
pub struct LedgerState {
Expand Down Expand Up @@ -245,7 +245,7 @@
if let Some(network_upgrade_override) = self.network_upgrade_override {
network_upgrade_override
} else {
NetworkUpgrade::current(self.network, self.height)
NetworkUpgrade::current(&self.network, self.height)
}
}

Expand All @@ -268,9 +268,9 @@
let default_network = Network::default();
let default_override = LedgerStateOverride::default();

let most_recent_nu = NetworkUpgrade::current(default_network, Height::MAX);
let most_recent_nu = NetworkUpgrade::current(&default_network, Height::MAX);
let most_recent_activation_height =
most_recent_nu.activation_height(default_network).unwrap();
most_recent_nu.activation_height(&default_network).unwrap();

LedgerState {
height: most_recent_activation_height,
Expand All @@ -290,7 +290,7 @@
let default_network = Network::default();

// TODO: dynamically select any future network upgrade (#1974)
let nu5_activation_height = Nu5.activation_height(default_network);
let nu5_activation_height = Nu5.activation_height(&default_network);
let nu5_override = if nu5_activation_height.is_some() {
None
} else {
Expand Down Expand Up @@ -348,12 +348,14 @@
type Parameters = LedgerState;

fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
let transactions_strategy =
let transactions_strategy = {
let ledger_state = ledger_state.clone();
// Generate a random number transactions. A coinbase tx is always generated, so if
// `transaction_count` is zero, the block will contain only the coinbase tx.
(0..MAX_ARBITRARY_ITEMS).prop_flat_map(move |transaction_count| {
Transaction::vec_strategy(ledger_state, transaction_count)
});
Transaction::vec_strategy(ledger_state.clone(), transaction_count)
})
};

// TODO: if needed, fixup:
// - history and authorizing data commitments
Expand Down Expand Up @@ -411,7 +413,7 @@

// generate block strategies with the correct heights
for _ in 0..count {
vec.push((Just(current.height), Block::arbitrary_with(current)));
vec.push((Just(current.height), Block::arbitrary_with(current.clone())));
current.height.0 += 1;
}

Expand Down Expand Up @@ -473,9 +475,9 @@
if generate_valid_commitments {
let current_height = block.coinbase_height().unwrap();
let heartwood_height = NetworkUpgrade::Heartwood
.activation_height(current.network)
.activation_height(&current.network)
.unwrap();
let nu5_height = NetworkUpgrade::Nu5.activation_height(current.network);
let nu5_height = NetworkUpgrade::Nu5.activation_height(&current.network);

match current_height.cmp(&heartwood_height) {
std::cmp::Ordering::Less => {
Expand Down Expand Up @@ -520,16 +522,16 @@
if let Some(history_tree) = history_tree.as_mut() {
history_tree
.push(
current.network,
&current.network,
Arc::new(block.clone()),
sapling_tree.root(),
orchard_tree.root(),
&sapling_tree.root(),
&orchard_tree.root(),
)
.unwrap();
} else {
history_tree = Some(
HistoryTree::from_block(
current.network,
&current.network,
Arc::new(block.clone()),
&sapling_tree.root(),
&orchard_tree.root(),
Expand Down Expand Up @@ -703,10 +705,10 @@
fn arbitrary_with(_args: ()) -> Self::Strategy {
(any::<[u8; 32]>(), any::<Network>(), any::<Height>())
.prop_map(|(commitment_bytes, network, block_height)| {
if block_height == Heartwood.activation_height(network).unwrap() {
if block_height == Heartwood.activation_height(&network).unwrap() {
Commitment::ChainHistoryActivationReserved
} else {
Commitment::from_bytes(commitment_bytes, network, block_height)
Commitment::from_bytes(commitment_bytes, &network, block_height)
.expect("unexpected failure in from_bytes parsing")
}
})
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/block/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Commitment {
// TODO: rename as from_bytes_in_serialized_order()
pub(super) fn from_bytes(
bytes: [u8; 32],
network: Network,
network: &Network,
height: block::Height,
) -> Result<Commitment, CommitmentError> {
use Commitment::*;
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/block/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ proptest! {

// just skip the test if the bytes don't parse, because there's nothing
// to compare with
if let Ok(commitment) = Commitment::from_bytes(bytes, network, block_height) {
if let Ok(commitment) = Commitment::from_bytes(bytes, &network, block_height) {
let other_bytes = commitment.to_bytes();

prop_assert_eq![bytes, other_bytes];
Expand All @@ -104,7 +104,7 @@ proptest! {
let bytes = block.zcash_serialize_to_vec()?;

// Check the block commitment
let commitment = block.commitment(network);
let commitment = block.commitment(&network);
if let Ok(commitment) = commitment {
let commitment_bytes = commitment.to_bytes();
prop_assert_eq![block.header.commitment_bytes.0, commitment_bytes];
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/block/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn block_test_vectors_height(network: Network) {

if height
>= Sapling
.activation_height(network)
.activation_height(&network)
.expect("sapling activation height is set")
.0
{
Expand Down Expand Up @@ -260,7 +260,7 @@ fn block_commitment(network: Network) {
.zcash_deserialize_into::<Block>()
.expect("block is structurally valid");

let commitment = block.commitment(network).unwrap_or_else(|_| {
let commitment = block.commitment(&network).unwrap_or_else(|_| {
panic!("unexpected structurally invalid block commitment at {network} {height}")
});

Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/chain_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub trait ChainTip {
/// and the height of the best tip.
fn estimate_network_chain_tip_height(
&self,
network: Network,
network: &Network,
now: DateTime<Utc>,
) -> Option<block::Height> {
let (current_height, current_block_time) = self.best_tip_height_and_block_time()?;
Expand All @@ -110,7 +110,7 @@ pub trait ChainTip {
/// Returns `None` if the state is empty.
fn estimate_distance_to_network_chain_tip(
&self,
network: Network,
network: &Network,
) -> Option<(block::HeightDiff, block::Height)> {
let (current_height, current_block_time) = self.best_tip_height_and_block_time()?;

Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/chain_tip/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl ChainTip for MockChainTip {

fn estimate_distance_to_network_chain_tip(
&self,
_network: Network,
_network: &Network,
) -> Option<(block::HeightDiff, block::Height)> {
self.estimated_distance_to_network_chain_tip
.borrow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl NetworkChainTipHeightEstimator {
pub fn new(
current_block_time: DateTime<Utc>,
current_height: block::Height,
network: Network,
network: &Network,
) -> Self {
let mut target_spacings = NetworkUpgrade::target_spacings(network);
let (_genesis_height, initial_target_spacing) =
Expand Down
6 changes: 3 additions & 3 deletions zebra-chain/src/chain_tip/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ proptest! {
) {
let (chain_tip, mock_chain_tip_sender) = MockChainTip::new();
let blossom_activation_height = NetworkUpgrade::Blossom
.activation_height(network)
.activation_height(&network)
.expect("Blossom activation height is missing");

block_heights.sort();
Expand All @@ -50,13 +50,13 @@ proptest! {

let time_displacement = calculate_time_displacement(
time_displacement_factor,
NetworkUpgrade::current(network, network_height),
NetworkUpgrade::current(&network, network_height),
);

let mock_local_time = current_block_time + estimated_time_difference + time_displacement;

assert_eq!(
chain_tip.estimate_network_chain_tip_height(network, mock_local_time),
chain_tip.estimate_network_chain_tip_height(&network, mock_local_time),
Some(network_height)
);
}
Expand Down
40 changes: 20 additions & 20 deletions zebra-chain/src/history_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl NonEmptyHistoryTree {
/// The parameters must come from the values of [`NonEmptyHistoryTree::size`],
/// [`NonEmptyHistoryTree::peaks`] and [`NonEmptyHistoryTree::current_height`] of a HistoryTree.
pub fn from_cache(
network: Network,
network: &Network,
size: u32,
peaks: BTreeMap<u32, Entry>,
current_height: Height,
Expand Down Expand Up @@ -114,7 +114,7 @@ impl NonEmptyHistoryTree {
}
};
Ok(Self {
network,
network: network.clone(),
network_upgrade,
inner,
size,
Expand All @@ -130,7 +130,7 @@ impl NonEmptyHistoryTree {
/// (ignored for pre-Orchard blocks).
#[allow(clippy::unwrap_in_result)]
pub fn from_block(
network: Network,
network: &Network,
block: Arc<Block>,
sapling_root: &sapling::tree::Root,
orchard_root: &orchard::tree::Root,
Expand Down Expand Up @@ -169,7 +169,7 @@ impl NonEmptyHistoryTree {
let mut peaks = BTreeMap::new();
peaks.insert(0u32, entry);
Ok(NonEmptyHistoryTree {
network,
network: network.clone(),
network_upgrade,
inner: tree,
size: 1,
Expand Down Expand Up @@ -208,11 +208,11 @@ impl NonEmptyHistoryTree {
self.current_height
);

let network_upgrade = NetworkUpgrade::current(self.network, height);
let network_upgrade = NetworkUpgrade::current(&self.network, height);
if network_upgrade != self.network_upgrade {
// This is the activation block of a network upgrade.
// Create a new tree.
let new_tree = Self::from_block(self.network, block, sapling_root, orchard_root)?;
let new_tree = Self::from_block(&self.network, block, sapling_root, orchard_root)?;
// Replaces self with the new tree
*self = new_tree;
assert_eq!(self.network_upgrade, network_upgrade);
Expand Down Expand Up @@ -328,7 +328,7 @@ impl NonEmptyHistoryTree {
self.inner = match self.inner {
InnerHistoryTree::PreOrchard(_) => {
InnerHistoryTree::PreOrchard(Tree::<PreOrchard>::new_from_cache(
self.network,
&self.network,
self.network_upgrade,
self.size,
&self.peaks,
Expand All @@ -337,7 +337,7 @@ impl NonEmptyHistoryTree {
}
InnerHistoryTree::OrchardOnward(_) => {
InnerHistoryTree::OrchardOnward(Tree::<OrchardOnward>::new_from_cache(
self.network,
&self.network,
self.network_upgrade,
self.size,
&self.peaks,
Expand Down Expand Up @@ -373,7 +373,7 @@ impl NonEmptyHistoryTree {

/// Return the network where this tree is used.
pub fn network(&self) -> Network {
self.network
self.network.clone()
}
}

Expand All @@ -382,7 +382,7 @@ impl Clone for NonEmptyHistoryTree {
let tree = match self.inner {
InnerHistoryTree::PreOrchard(_) => InnerHistoryTree::PreOrchard(
Tree::<PreOrchard>::new_from_cache(
self.network,
&self.network,
self.network_upgrade,
self.size,
&self.peaks,
Expand All @@ -392,7 +392,7 @@ impl Clone for NonEmptyHistoryTree {
),
InnerHistoryTree::OrchardOnward(_) => InnerHistoryTree::OrchardOnward(
Tree::<OrchardOnward>::new_from_cache(
self.network,
&self.network,
self.network_upgrade,
self.size,
&self.peaks,
Expand All @@ -402,7 +402,7 @@ impl Clone for NonEmptyHistoryTree {
),
};
NonEmptyHistoryTree {
network: self.network,
network: self.network.clone(),
network_upgrade: self.network_upgrade,
inner: tree,
size: self.size,
Expand All @@ -423,7 +423,7 @@ impl HistoryTree {
/// If the block is pre-Heartwood, it returns an empty history tree.
#[allow(clippy::unwrap_in_result)]
pub fn from_block(
network: Network,
network: &Network,
block: Arc<Block>,
sapling_root: &sapling::tree::Root,
orchard_root: &orchard::tree::Root,
Expand All @@ -450,10 +450,10 @@ impl HistoryTree {
#[allow(clippy::unwrap_in_result)]
pub fn push(
&mut self,
network: Network,
network: &Network,
block: Arc<Block>,
sapling_root: sapling::tree::Root,
orchard_root: orchard::tree::Root,
sapling_root: &sapling::tree::Root,
orchard_root: &orchard::tree::Root,
) -> Result<(), HistoryTreeError> {
let heartwood_height = NetworkUpgrade::Heartwood
.activation_height(network)
Expand All @@ -472,9 +472,9 @@ impl HistoryTree {
std::cmp::Ordering::Equal => {
let tree = Some(NonEmptyHistoryTree::from_block(
network,
block.clone(),
&sapling_root,
&orchard_root,
block,
arya2 marked this conversation as resolved.
Show resolved Hide resolved
sapling_root,
orchard_root,
)?);
// Replace the current object with the new tree
*self = HistoryTree(tree);
Expand All @@ -483,7 +483,7 @@ impl HistoryTree {
self.0
.as_mut()
.expect("history tree must exist Heartwood-onward")
.push(block.clone(), &sapling_root, &orchard_root)?;
.push(block.clone(), sapling_root, orchard_root)?;
}
};
Ok(())
Expand Down
Loading
Loading