Skip to content

Commit

Permalink
Adds full_activation_list() method and uses it in `getblockchaininf…
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 authored Jul 20, 2024
1 parent bbb710f commit 6b9b994
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
25 changes: 25 additions & 0 deletions zebra-chain/src/parameters/network/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,28 @@ fn check_network_name() {
"network must be displayed as configured network name"
);
}

#[test]
fn check_full_activation_list() {
let network = testnet::Parameters::build()
.with_activation_heights(ConfiguredActivationHeights {
nu5: Some(1),
..Default::default()
})
.to_network();

// We expect the first 8 network upgrades to be included, up to NU5
let expected_network_upgrades = &NETWORK_UPGRADES_IN_ORDER[..8];
let full_activation_list_network_upgrades: Vec<_> = network
.full_activation_list()
.into_iter()
.map(|(_, nu)| nu)
.collect();

for expected_network_upgrade in expected_network_upgrades {
assert!(
full_activation_list_network_upgrades.contains(expected_network_upgrade),
"full activation list should contain expected network upgrade"
);
}
}
12 changes: 12 additions & 0 deletions zebra-chain/src/parameters/network_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ impl Network {
/// When the environment variable TEST_FAKE_ACTIVATION_HEIGHTS is set
/// and it's a test build, this returns a list of fake activation heights
/// used by some tests.
///
/// Note: This skips implicit network upgrade activations, use [`Network::full_activation_list`]
/// to get an explicit list of all network upgrade activations.
pub fn activation_list(&self) -> BTreeMap<block::Height, NetworkUpgrade> {
match self {
// To prevent accidentally setting this somehow, only check the env var
Expand All @@ -283,6 +286,15 @@ impl Network {
Testnet(params) => params.activation_heights().clone(),
}
}

/// Returns a vector of all implicit and explicit network upgrades for `network`,
/// in ascending height order.
pub fn full_activation_list(&self) -> Vec<(block::Height, NetworkUpgrade)> {
NETWORK_UPGRADES_IN_ORDER
.into_iter()
.map_while(|nu| Some((NetworkUpgrade::activation_height(&nu, self)?, nu)))
.collect()
}
}

impl NetworkUpgrade {
Expand Down
2 changes: 1 addition & 1 deletion zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ where
//
// Get the network upgrades in height order, like `zcashd`.
let mut upgrades = IndexMap::new();
for (activation_height, network_upgrade) in network.activation_list() {
for (activation_height, network_upgrade) in network.full_activation_list() {
// Zebra defines network upgrades based on incompatible consensus rule changes,
// but zcashd defines them based on ZIPs.
//
Expand Down

0 comments on commit 6b9b994

Please sign in to comment.