diff --git a/stacks-common/src/types/mod.rs b/stacks-common/src/types/mod.rs index ca122b0aae..ce774b0090 100644 --- a/stacks-common/src/types/mod.rs +++ b/stacks-common/src/types/mod.rs @@ -1,5 +1,6 @@ use std::cmp::Ordering; use std::fmt; +use std::ops::{Deref, DerefMut, Index, IndexMut}; #[cfg(feature = "canonical")] pub mod sqlite; @@ -235,21 +236,6 @@ impl StacksEpochId { StacksEpochId::Epoch30 => cur_reward_cycle > first_epoch30_reward_cycle, } } - - /// Return the index for this epoch in the list of epochs - pub fn index(&self) -> usize { - match self { - StacksEpochId::Epoch10 => 0, - StacksEpochId::Epoch20 => 1, - StacksEpochId::Epoch2_05 => 2, - StacksEpochId::Epoch21 => 3, - StacksEpochId::Epoch22 => 4, - StacksEpochId::Epoch23 => 5, - StacksEpochId::Epoch24 => 6, - StacksEpochId::Epoch25 => 7, - StacksEpochId::Epoch30 => 8, - } - } } impl std::fmt::Display for StacksEpochId { @@ -475,3 +461,58 @@ impl Ord for StacksEpoch { self.epoch_id.cmp(&other.epoch_id) } } + +/// A wrapper for holding a list of Epochs, indexable by StacksEpochId +#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq)] +pub struct EpochList(Vec>); + +impl EpochList { + pub fn new(epochs: &[StacksEpoch]) -> EpochList { + EpochList(epochs.to_vec()) + } + + pub fn get(&self, index: StacksEpochId) -> Option<&StacksEpoch> { + self.0.get(StacksEpoch::find_epoch_by_id(&self.0, index)?) + } + + pub fn get_mut(&mut self, index: StacksEpochId) -> Option<&mut StacksEpoch> { + let index = StacksEpoch::find_epoch_by_id(&self.0, index)?; + self.0.get_mut(index) + } + + /// Truncates the list after the given epoch id + pub fn truncate_after(&mut self, epoch_id: StacksEpochId) { + if let Some(index) = StacksEpoch::find_epoch_by_id(&self.0, epoch_id) { + self.0.truncate(index + 1); + } + } +} + +impl Index for EpochList { + type Output = StacksEpoch; + fn index(&self, index: StacksEpochId) -> &StacksEpoch { + self.get(index) + .expect("Invalid StacksEpochId: could not find corresponding epoch") + } +} + +impl IndexMut for EpochList { + fn index_mut(&mut self, index: StacksEpochId) -> &mut StacksEpoch { + self.get_mut(index) + .expect("Invalid StacksEpochId: could not find corresponding epoch") + } +} + +impl Deref for EpochList { + type Target = [StacksEpoch]; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for EpochList { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} diff --git a/stackslib/src/burnchains/bitcoin/indexer.rs b/stackslib/src/burnchains/bitcoin/indexer.rs index 40cabd86d3..c67324cf97 100644 --- a/stackslib/src/burnchains/bitcoin/indexer.rs +++ b/stackslib/src/burnchains/bitcoin/indexer.rs @@ -45,7 +45,7 @@ use crate::burnchains::{ Burnchain, BurnchainBlockHeader, Error as burnchain_error, MagicBytes, BLOCKSTACK_MAGIC_MAINNET, }; use crate::core::{ - StacksEpoch, StacksEpochExtension, STACKS_EPOCHS_MAINNET, STACKS_EPOCHS_REGTEST, + EpochList, StacksEpoch, StacksEpochExtension, STACKS_EPOCHS_MAINNET, STACKS_EPOCHS_REGTEST, STACKS_EPOCHS_TESTNET, }; use crate::util_lib::db::Error as DBError; @@ -91,12 +91,12 @@ impl TryFrom for BitcoinNetworkType { /// Get the default epochs definitions for the given BitcoinNetworkType. /// Should *not* be used except by the BitcoinIndexer when no epochs vector /// was specified. -pub fn get_bitcoin_stacks_epochs(network_id: BitcoinNetworkType) -> Vec { - match network_id { - BitcoinNetworkType::Mainnet => STACKS_EPOCHS_MAINNET.to_vec(), - BitcoinNetworkType::Testnet => STACKS_EPOCHS_TESTNET.to_vec(), - BitcoinNetworkType::Regtest => STACKS_EPOCHS_REGTEST.to_vec(), - } +pub fn get_bitcoin_stacks_epochs(network_id: BitcoinNetworkType) -> EpochList { + EpochList::new(match network_id { + BitcoinNetworkType::Mainnet => &*STACKS_EPOCHS_MAINNET, + BitcoinNetworkType::Testnet => &*STACKS_EPOCHS_TESTNET, + BitcoinNetworkType::Regtest => &*STACKS_EPOCHS_REGTEST, + }) } #[derive(Debug, Clone, PartialEq)] @@ -112,7 +112,7 @@ pub struct BitcoinIndexerConfig { pub spv_headers_path: String, pub first_block: u64, pub magic_bytes: MagicBytes, - pub epochs: Option>, + pub epochs: Option, } #[derive(Debug)] @@ -1041,7 +1041,7 @@ impl BurnchainIndexer for BitcoinIndexer { /// 2) Use hard-coded static values, otherwise. /// /// It is an error (panic) to set custom epochs if running on `Mainnet`. - fn get_stacks_epochs(&self) -> Vec { + fn get_stacks_epochs(&self) -> EpochList { StacksEpoch::get_epochs(self.runtime.network_id, self.config.epochs.as_ref()) } diff --git a/stackslib/src/burnchains/burnchain.rs b/stackslib/src/burnchains/burnchain.rs index a5ecaa0458..705f16b3dc 100644 --- a/stackslib/src/burnchains/burnchain.rs +++ b/stackslib/src/burnchains/burnchain.rs @@ -29,6 +29,7 @@ use stacks_common::util::hash::to_hex; use stacks_common::util::vrf::VRFPublicKey; use stacks_common::util::{get_epoch_time_ms, get_epoch_time_secs, log, sleep_ms}; +use super::EpochList; use crate::burnchains::affirmation::update_pox_affirmation_maps; use crate::burnchains::bitcoin::address::{ to_c32_version_byte, BitcoinAddress, LegacyBitcoinAddressType, @@ -718,7 +719,7 @@ impl Burnchain { readwrite: bool, first_block_header_hash: BurnchainHeaderHash, first_block_header_timestamp: u64, - epochs: Vec, + epochs: EpochList, ) -> Result<(SortitionDB, BurnchainDB), burnchain_error> { Burnchain::setup_chainstate_dirs(&self.working_dir)?; diff --git a/stackslib/src/burnchains/indexer.rs b/stackslib/src/burnchains/indexer.rs index 5d8eef99a6..ebca4730df 100644 --- a/stackslib/src/burnchains/indexer.rs +++ b/stackslib/src/burnchains/indexer.rs @@ -62,7 +62,7 @@ pub trait BurnchainIndexer { fn get_first_block_height(&self) -> u64; fn get_first_block_header_hash(&self) -> Result; fn get_first_block_header_timestamp(&self) -> Result; - fn get_stacks_epochs(&self) -> Vec; + fn get_stacks_epochs(&self) -> EpochList; fn get_headers_path(&self) -> String; fn get_headers_height(&self) -> Result; diff --git a/stackslib/src/chainstate/burn/db/sortdb.rs b/stackslib/src/chainstate/burn/db/sortdb.rs index 53dc2d0547..66b1b02ea3 100644 --- a/stackslib/src/chainstate/burn/db/sortdb.rs +++ b/stackslib/src/chainstate/burn/db/sortdb.rs @@ -2969,9 +2969,9 @@ impl SortitionDB { db_tx: &Transaction, epochs: &[StacksEpoch], ) -> Result<(), db_error> { - let epochs = StacksEpoch::validate_epochs(epochs); + let epochs: &[StacksEpoch] = &StacksEpoch::validate_epochs(epochs); let existing_epochs = Self::get_stacks_epochs(db_tx)?; - if existing_epochs == epochs { + if &existing_epochs == epochs { return Ok(()); } @@ -3482,9 +3482,10 @@ impl SortitionDB { tx.commit()?; } else if version == expected_version { // this transaction is almost never needed - let validated_epochs = StacksEpoch::validate_epochs(epochs); + let validated_epochs: &[StacksEpoch] = + &StacksEpoch::validate_epochs(epochs); let existing_epochs = Self::get_stacks_epochs(self.conn())?; - if existing_epochs == validated_epochs { + if &existing_epochs == validated_epochs { return Ok(()); } diff --git a/stackslib/src/cli.rs b/stackslib/src/cli.rs index 9ff6e55644..1d8daeff84 100644 --- a/stackslib/src/cli.rs +++ b/stackslib/src/cli.rs @@ -53,7 +53,7 @@ pub struct StacksChainConfig { pub first_burn_header_hash: BurnchainHeaderHash, pub first_burn_header_timestamp: u64, pub pox_constants: PoxConstants, - pub epochs: Vec, + pub epochs: EpochList, } impl StacksChainConfig { @@ -65,7 +65,7 @@ impl StacksChainConfig { .unwrap(), first_burn_header_timestamp: BITCOIN_MAINNET_FIRST_BLOCK_TIMESTAMP.into(), pox_constants: PoxConstants::mainnet_default(), - epochs: STACKS_EPOCHS_MAINNET.to_vec(), + epochs: EpochList::new(&*STACKS_EPOCHS_MAINNET), } } } diff --git a/stackslib/src/core/mod.rs b/stackslib/src/core/mod.rs index ade8a82589..20e922865b 100644 --- a/stackslib/src/core/mod.rs +++ b/stackslib/src/core/mod.rs @@ -19,8 +19,8 @@ use std::collections::HashSet; use clarity::vm::costs::ExecutionCost; use lazy_static::lazy_static; use stacks_common::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, StacksBlockId}; -use stacks_common::types::StacksEpoch as GenericStacksEpoch; pub use stacks_common::types::StacksEpochId; +use stacks_common::types::{EpochList as GenericEpochList, StacksEpoch as GenericStacksEpoch}; use stacks_common::util::log; pub use self::mempool::MemPoolDB; @@ -35,6 +35,7 @@ pub mod tests; use std::cmp::Ordering; pub type StacksEpoch = GenericStacksEpoch; +pub type EpochList = GenericEpochList; // fork set identifier -- to be mixed with the consensus hash (encodes the version) pub const SYSTEM_FORK_SET_VERSION: [u8; 4] = [23u8, 0u8, 0u8, 0u8]; @@ -558,35 +559,35 @@ fn test_ord_for_stacks_epoch_id() { } pub trait StacksEpochExtension { #[cfg(test)] - fn unit_test(stacks_epoch_id: StacksEpochId, epoch_2_0_block_height: u64) -> Vec; + fn unit_test(stacks_epoch_id: StacksEpochId, epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_05(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_05(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_05_only(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_05_only(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_pre_2_05(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_pre_2_05(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_1(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_1(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_2(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_2(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_3(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_3(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_4(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_4(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_5(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_5(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_3_0(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_3_0(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_2_1_only(epoch_2_0_block_height: u64) -> Vec; + fn unit_test_2_1_only(epoch_2_0_block_height: u64) -> EpochList; #[cfg(test)] - fn unit_test_3_0_only(first_burnchain_height: u64) -> Vec; + fn unit_test_3_0_only(first_burnchain_height: u64) -> EpochList; fn all( epoch_2_0_block_height: u64, epoch_2_05_block_height: u64, epoch_2_1_block_height: u64, - ) -> Vec; - fn validate_epochs(epochs: &[StacksEpoch]) -> Vec; + ) -> EpochList; + fn validate_epochs(epochs: &[StacksEpoch]) -> EpochList; /// This method gets the epoch vector. /// /// Choose according to: @@ -597,15 +598,15 @@ pub trait StacksEpochExtension { /// fn get_epochs( bitcoin_network: BitcoinNetworkType, - configured_epochs: Option<&Vec>, - ) -> Vec; + configured_epochs: Option<&EpochList>, + ) -> EpochList; } impl StacksEpochExtension for StacksEpoch { fn get_epochs( bitcoin_network: BitcoinNetworkType, - configured_epochs: Option<&Vec>, - ) -> Vec { + configured_epochs: Option<&EpochList>, + ) -> EpochList { match configured_epochs { Some(epochs) => { assert!(bitcoin_network != BitcoinNetworkType::Mainnet); @@ -616,13 +617,13 @@ impl StacksEpochExtension for StacksEpoch { } #[cfg(test)] - fn unit_test_pre_2_05(first_burnchain_height: u64) -> Vec { + fn unit_test_pre_2_05(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -637,17 +638,17 @@ impl StacksEpochExtension for StacksEpoch { block_limit: ExecutionCost::max_value(), network_epoch: PEER_VERSION_EPOCH_2_0, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_05(first_burnchain_height: u64) -> Vec { + fn unit_test_2_05(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -675,17 +676,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_05, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_05_only(first_burnchain_height: u64) -> Vec { + fn unit_test_2_05_only(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -713,17 +714,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_05, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_1(first_burnchain_height: u64) -> Vec { + fn unit_test_2_1(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -764,17 +765,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_1, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_2(first_burnchain_height: u64) -> Vec { + fn unit_test_2_2(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -828,17 +829,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_2, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_3(first_burnchain_height: u64) -> Vec { + fn unit_test_2_3(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test_2_3 first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -905,17 +906,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_3, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_4(first_burnchain_height: u64) -> Vec { + fn unit_test_2_4(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test_2_4 first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -995,17 +996,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_4, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_5(first_burnchain_height: u64) -> Vec { + fn unit_test_2_5(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test_2_5 first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -1098,17 +1099,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_5, }, - ] + ]) } #[cfg(test)] - fn unit_test_3_0(first_burnchain_height: u64) -> Vec { + fn unit_test_3_0(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test_3_0 first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -1214,17 +1215,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_3_0, }, - ] + ]) } #[cfg(test)] - fn unit_test_2_1_only(first_burnchain_height: u64) -> Vec { + fn unit_test_2_1_only(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -1265,17 +1266,17 @@ impl StacksEpochExtension for StacksEpoch { }, network_epoch: PEER_VERSION_EPOCH_2_1, }, - ] + ]) } #[cfg(test)] - fn unit_test_3_0_only(first_burnchain_height: u64) -> Vec { + fn unit_test_3_0_only(first_burnchain_height: u64) -> EpochList { info!( "StacksEpoch unit_test first_burn_height = {}", first_burnchain_height ); - vec![ + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -1339,11 +1340,11 @@ impl StacksEpochExtension for StacksEpoch { block_limit: BLOCK_LIMIT_MAINNET_21, network_epoch: PEER_VERSION_EPOCH_3_0, }, - ] + ]) } #[cfg(test)] - fn unit_test(stacks_epoch_id: StacksEpochId, first_burnchain_height: u64) -> Vec { + fn unit_test(stacks_epoch_id: StacksEpochId, first_burnchain_height: u64) -> EpochList { match stacks_epoch_id { StacksEpochId::Epoch10 | StacksEpochId::Epoch20 => { StacksEpoch::unit_test_pre_2_05(first_burnchain_height) @@ -1362,8 +1363,8 @@ impl StacksEpochExtension for StacksEpoch { epoch_2_0_block_height: u64, epoch_2_05_block_height: u64, epoch_2_1_block_height: u64, - ) -> Vec { - vec![ + ) -> EpochList { + EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -1392,13 +1393,13 @@ impl StacksEpochExtension for StacksEpoch { block_limit: ExecutionCost::max_value(), network_epoch: PEER_VERSION_EPOCH_1_0, }, - ] + ]) } /// Verify that a list of epochs is well-formed, and if so, return the list of epochs. /// Epochs must proceed in order, and must represent contiguous block ranges. /// Panic if the list is not well-formed. - fn validate_epochs(epochs_ref: &[StacksEpoch]) -> Vec { + fn validate_epochs(epochs_ref: &[StacksEpoch]) -> EpochList { // sanity check -- epochs must all be contiguous, each epoch must be unique, // and the range of epochs should span the whole non-negative i64 space. let mut epochs = epochs_ref.to_vec(); @@ -1449,6 +1450,6 @@ impl StacksEpochExtension for StacksEpoch { } assert_eq!(epoch_end_height, STACKS_EPOCH_MAX); - epochs + EpochList::new(&epochs) } } diff --git a/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs b/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs index 82282926d3..f566d5cb50 100644 --- a/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs +++ b/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs @@ -48,7 +48,7 @@ use stacks::chainstate::burn::Opcodes; use stacks::chainstate::coordinator::comm::CoordinatorChannels; #[cfg(test)] use stacks::chainstate::stacks::address::PoxAddress; -use stacks::core::{StacksEpoch, StacksEpochId}; +use stacks::core::{EpochList, StacksEpochId}; use stacks::monitoring::{increment_btc_blocks_received_counter, increment_btc_ops_sent_counter}; use stacks::net::http::{HttpRequestContents, HttpResponsePayload}; use stacks::net::httpcore::{send_http_request, StacksHttpRequest}; @@ -2240,7 +2240,7 @@ impl BurnchainController for BitcoinRegtestController { Ok(()) } - fn get_stacks_epochs(&self) -> Vec { + fn get_stacks_epochs(&self) -> EpochList { self.indexer.get_stacks_epochs() } diff --git a/testnet/stacks-node/src/burnchains/mocknet_controller.rs b/testnet/stacks-node/src/burnchains/mocknet_controller.rs index d518f5bdea..235641f64a 100644 --- a/testnet/stacks-node/src/burnchains/mocknet_controller.rs +++ b/testnet/stacks-node/src/burnchains/mocknet_controller.rs @@ -14,7 +14,7 @@ use stacks::chainstate::burn::operations::{ }; use stacks::chainstate::burn::BlockSnapshot; use stacks::core::{ - StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, + EpochList, StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, STACKS_EPOCH_MAX, }; use stacks_common::types::chainstate::{BurnchainHeaderHash, PoxId}; @@ -99,10 +99,10 @@ impl BurnchainController for MocknetController { } } - fn get_stacks_epochs(&self) -> Vec { + fn get_stacks_epochs(&self) -> EpochList { match &self.config.burnchain.epochs { Some(epochs) => epochs.clone(), - None => vec![ + None => EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -124,7 +124,7 @@ impl BurnchainController for MocknetController { block_limit: ExecutionCost::max_value(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ], + ]), } } diff --git a/testnet/stacks-node/src/burnchains/mod.rs b/testnet/stacks-node/src/burnchains/mod.rs index 0c9446304d..82e2aff341 100644 --- a/testnet/stacks-node/src/burnchains/mod.rs +++ b/testnet/stacks-node/src/burnchains/mod.rs @@ -9,7 +9,7 @@ use stacks::burnchains::{BurnchainStateTransitionOps, Txid}; use stacks::chainstate::burn::db::sortdb::SortitionDB; use stacks::chainstate::burn::operations::BlockstackOperationType; use stacks::chainstate::burn::BlockSnapshot; -use stacks::core::{StacksEpoch, StacksEpochId}; +use stacks::core::{EpochList, StacksEpochId}; use stacks_common::codec::Error as CodecError; pub use self::bitcoin_regtest_controller::{make_bitcoin_indexer, BitcoinRegtestController}; @@ -69,7 +69,7 @@ pub trait BurnchainController { /// Invoke connect() on underlying burnchain and sortition databases, to perform any migration /// or instantiation before other callers may use open() fn connect_dbs(&mut self) -> Result<(), Error>; - fn get_stacks_epochs(&self) -> Vec; + fn get_stacks_epochs(&self) -> EpochList; #[cfg(test)] fn bootstrap_chain(&mut self, blocks_count: u64); diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index f1bcebcb3a..4131b995c1 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -52,6 +52,7 @@ use stacks::net::atlas::AtlasConfig; use stacks::net::connection::ConnectionOptions; use stacks::net::{Neighbor, NeighborKey}; use stacks::types::chainstate::BurnchainHeaderHash; +use stacks::types::EpochList; use stacks::util_lib::boot::boot_code_id; use stacks::util_lib::db::Error as DBError; use stacks_common::consts::SIGNER_SLOTS_PER_USER; @@ -432,10 +433,7 @@ impl Config { } if let Some(epochs) = &self.burnchain.epochs { - if let Some(epoch) = epochs - .iter() - .find(|epoch| epoch.epoch_id == StacksEpochId::Epoch10) - { + if let Some(epoch) = epochs.get(StacksEpochId::Epoch10) { // Epoch 1.0 start height can be equal to the first block height iff epoch 2.0 // start height is also equal to the first block height. assert!( @@ -444,20 +442,14 @@ impl Config { ); } - if let Some(epoch) = epochs - .iter() - .find(|epoch| epoch.epoch_id == StacksEpochId::Epoch20) - { + if let Some(epoch) = epochs.get(StacksEpochId::Epoch20) { assert_eq!( epoch.start_height, burnchain.first_block_height, "FATAL: Epoch 2.0 start height must match the first block height" ); } - if let Some(epoch) = epochs - .iter() - .find(|epoch| epoch.epoch_id == StacksEpochId::Epoch21) - { + if let Some(epoch) = epochs.get(StacksEpochId::Epoch21) { // Override v1_unlock_height to the start_height of epoch2.1 debug!( "Override v2_unlock_height from {} to {}", @@ -467,10 +459,7 @@ impl Config { burnchain.pox_constants.v1_unlock_height = epoch.start_height as u32 + 1; } - if let Some(epoch) = epochs - .iter() - .find(|epoch| epoch.epoch_id == StacksEpochId::Epoch22) - { + if let Some(epoch) = epochs.get(StacksEpochId::Epoch22) { // Override v2_unlock_height to the start_height of epoch2.2 debug!( "Override v2_unlock_height from {} to {}", @@ -480,10 +469,7 @@ impl Config { burnchain.pox_constants.v2_unlock_height = epoch.start_height as u32 + 1; } - if let Some(epoch) = epochs - .iter() - .find(|epoch| epoch.epoch_id == StacksEpochId::Epoch24) - { + if let Some(epoch) = epochs.get(StacksEpochId::Epoch24) { // Override pox_3_activation_height to the start_height of epoch2.4 debug!( "Override pox_3_activation_height from {} to {}", @@ -492,10 +478,7 @@ impl Config { burnchain.pox_constants.pox_3_activation_height = epoch.start_height as u32; } - if let Some(epoch) = epochs - .iter() - .find(|epoch| epoch.epoch_id == StacksEpochId::Epoch25) - { + if let Some(epoch) = epochs.get(StacksEpochId::Epoch25) { // Override pox_4_activation_height to the start_height of epoch2.5 debug!( "Override pox_4_activation_height from {} to {}", @@ -531,7 +514,7 @@ impl Config { self.burnchain.get_bitcoin_network().1, self.burnchain.epochs.as_ref(), ); - let Some(epoch_30) = epochs.get(StacksEpochId::Epoch30.index()) else { + let Some(epoch_30) = epochs.get(StacksEpochId::Epoch30) else { // no Epoch 3.0, so just return return; }; @@ -643,7 +626,7 @@ impl Config { burn_mode: &str, bitcoin_network: BitcoinNetworkType, pox_2_activation: Option, - ) -> Result, String> { + ) -> Result, String> { let default_epochs = match bitcoin_network { BitcoinNetworkType::Mainnet => { Err("Cannot configure epochs in mainnet mode".to_string()) @@ -711,7 +694,7 @@ impl Config { } // Stacks 1.0 must start at 0 - if matched_epochs[StacksEpochId::Epoch10.index()].1 != 0 { + if matched_epochs[0].1 != 0 { return Err("Stacks 1.0 must start at height = 0".into()); } @@ -726,8 +709,8 @@ impl Config { for (i, (epoch_id, start_height)) in matched_epochs.iter().enumerate() { if epoch_id != &out_epochs[i].epoch_id { return Err( - format!("Unmatched epochs in configuration and node implementation. Implemented = {}, Configured = {}", - epoch_id, &out_epochs[i].epoch_id)); + format!("Unmatched epochs in configuration and node implementation. Implemented = {}, Configured = {}", + epoch_id, &out_epochs[i].epoch_id)); } // end_height = next epoch's start height || i64::max if last epoch let end_height = if i + 1 < matched_epochs.len() { @@ -757,7 +740,7 @@ impl Config { } } - Ok(out_epochs) + Ok(EpochList::new(&out_epochs)) } pub fn from_config_file( @@ -1220,7 +1203,7 @@ pub struct BurnchainConfig { pub first_burn_block_hash: Option, /// Custom override for the definitions of the epochs. This will only be applied for testnet and /// regtest nodes. - pub epochs: Option>, + pub epochs: Option>, pub pox_2_activation: Option, pub pox_reward_length: Option, pub pox_prepare_length: Option, diff --git a/testnet/stacks-node/src/run_loop/boot_nakamoto.rs b/testnet/stacks-node/src/run_loop/boot_nakamoto.rs index a686c8eb26..41469b996f 100644 --- a/testnet/stacks-node/src/run_loop/boot_nakamoto.rs +++ b/testnet/stacks-node/src/run_loop/boot_nakamoto.rs @@ -238,7 +238,7 @@ impl BootRunLoop { config.burnchain.epochs.as_ref(), ); let epoch_3 = epochs - .get(StacksEpochId::Epoch30.index()) + .get(StacksEpochId::Epoch30) .ok_or("No Epoch-3.0 defined")?; Ok(u64::from(burn_height) >= epoch_3.start_height - 1) diff --git a/testnet/stacks-node/src/tests/epoch_205.rs b/testnet/stacks-node/src/tests/epoch_205.rs index 8425e4e336..ba9e918029 100644 --- a/testnet/stacks-node/src/tests/epoch_205.rs +++ b/testnet/stacks-node/src/tests/epoch_205.rs @@ -13,9 +13,8 @@ use stacks::chainstate::stacks::db::StacksChainState; use stacks::chainstate::stacks::{ StacksBlockHeader, StacksPrivateKey, StacksTransaction, TransactionPayload, }; -use stacks::core; use stacks::core::{ - StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, + self, EpochList, StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; use stacks_common::codec::StacksMessageCodec; @@ -56,9 +55,9 @@ fn test_exact_block_costs() { let transactions_to_broadcast = 25; let (mut conf, _miner_account) = neon_integration_test_conf(); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_205_transition_height; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_205_transition_height; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_205_transition_height; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_205_transition_height; conf.burnchain.epochs = Some(epochs); conf.node.mine_microblocks = true; @@ -304,9 +303,9 @@ fn test_dynamic_db_method_costs() { "; let (mut conf, _miner_account) = neon_integration_test_conf(); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_205_transition_height; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_205_transition_height; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_205_transition_height; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_205_transition_height; conf.burnchain.epochs = Some(epochs); @@ -507,9 +506,9 @@ fn transition_empty_blocks() { let (mut conf, miner_account) = neon_integration_test_conf(); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; conf.burnchain.epochs = Some(epochs); @@ -716,7 +715,7 @@ fn test_cost_limit_switch_version205() { let (mut conf, _) = neon_integration_test_conf(); // Create a schedule where we lower the read_count on Epoch2_05. - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -769,7 +768,7 @@ fn test_cost_limit_switch_version205() { }, network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); conf.initial_balances.push(InitialBalance { @@ -940,7 +939,7 @@ fn bigger_microblock_streams_in_2_05() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -980,7 +979,7 @@ fn bigger_microblock_streams_in_2_05() { }, network_epoch: PEER_VERSION_EPOCH_2_05, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); let txs: Vec> = spender_sks diff --git a/testnet/stacks-node/src/tests/epoch_21.rs b/testnet/stacks-node/src/tests/epoch_21.rs index 62ca7f271e..451c392758 100644 --- a/testnet/stacks-node/src/tests/epoch_21.rs +++ b/testnet/stacks-node/src/tests/epoch_21.rs @@ -23,8 +23,7 @@ use stacks::chainstate::stacks::miner::{ }; use stacks::chainstate::stacks::StacksBlockHeader; use stacks::clarity_cli::vm_execute as execute; -use stacks::core; -use stacks::core::BURNCHAIN_TX_SEARCH_WINDOW; +use stacks::core::{self, EpochList, BURNCHAIN_TX_SEARCH_WINDOW}; use stacks::util_lib::boot::boot_code_id; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksBlockId, VRFSeed, @@ -73,11 +72,11 @@ fn advance_to_2_1( conf.miner.block_reward_recipient = block_reward_recipient; test_observer::register_any(&mut conf); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; conf.burnchain.epochs = Some(epochs); @@ -576,11 +575,11 @@ fn transition_fixes_bitcoin_rigidity() { conf.initial_balances.append(&mut initial_balances); test_observer::register_any(&mut conf); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; conf.burnchain.epochs = Some(epochs); @@ -1496,11 +1495,11 @@ fn transition_removes_pox_sunset() { let epoch_21 = epoch_21_rc * reward_cycle_len + 1; - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 1; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 1; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_21; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_21; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 1; + epochs[StacksEpochId::Epoch2_05].start_height = 1; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_21; + epochs[StacksEpochId::Epoch21].start_height = epoch_21; conf.burnchain.epochs = Some(epochs); @@ -1769,11 +1768,11 @@ fn transition_empty_blocks() { let (mut conf, miner_account) = neon_integration_test_conf(); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; conf.node.mine_microblocks = false; conf.burnchain.max_rbf = 1000000; @@ -2050,11 +2049,11 @@ fn test_pox_reorgs_three_flaps() { conf_template.node.require_affirmed_anchor_blocks = false; // make epoch 2.1 start in the middle of boot-up - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 151; - epochs[StacksEpochId::Epoch21.index()].start_height = 151; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 151; + epochs[StacksEpochId::Epoch21].start_height = 151; conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) @@ -2592,11 +2591,11 @@ fn test_pox_reorg_one_flap() { conf_template.node.require_affirmed_anchor_blocks = false; // make epoch 2.1 start in the middle of boot-up - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 151; - epochs[StacksEpochId::Epoch21.index()].start_height = 151; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 151; + epochs[StacksEpochId::Epoch21].start_height = 151; conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) @@ -3018,11 +3017,11 @@ fn test_pox_reorg_flap_duel() { conf_template.node.require_affirmed_anchor_blocks = false; // make epoch 2.1 start in the middle of boot-up - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 151; - epochs[StacksEpochId::Epoch21.index()].start_height = 151; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 151; + epochs[StacksEpochId::Epoch21].start_height = 151; conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) @@ -3458,11 +3457,11 @@ fn test_pox_reorg_flap_reward_cycles() { conf_template.node.require_affirmed_anchor_blocks = false; // make epoch 2.1 start in the middle of boot-up - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 151; - epochs[StacksEpochId::Epoch21.index()].start_height = 151; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 151; + epochs[StacksEpochId::Epoch21].start_height = 151; conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) @@ -3890,11 +3889,11 @@ fn test_pox_missing_five_anchor_blocks() { conf_template.node.require_affirmed_anchor_blocks = false; // make epoch 2.1 start in the middle of boot-up - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 151; - epochs[StacksEpochId::Epoch21.index()].start_height = 151; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 151; + epochs[StacksEpochId::Epoch21].start_height = 151; conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) @@ -4290,11 +4289,11 @@ fn test_sortition_divergence_pre_21() { conf_template.node.always_use_affirmation_maps = false; // make epoch 2.1 start after we have created this error condition - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 241; - epochs[StacksEpochId::Epoch21.index()].start_height = 241; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 241; + epochs[StacksEpochId::Epoch21].start_height = 241; conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) @@ -4749,11 +4748,11 @@ fn trait_invocation_cross_epoch() { }]; conf.initial_balances.append(&mut initial_balances); test_observer::register_any(&mut conf); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); @@ -5023,11 +5022,11 @@ fn test_v1_unlock_height_with_current_stackers() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); @@ -5286,11 +5285,11 @@ fn test_v1_unlock_height_with_delay_and_current_stackers() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); diff --git a/testnet/stacks-node/src/tests/epoch_22.rs b/testnet/stacks-node/src/tests/epoch_22.rs index 83506b12c7..e8ae516313 100644 --- a/testnet/stacks-node/src/tests/epoch_22.rs +++ b/testnet/stacks-node/src/tests/epoch_22.rs @@ -8,8 +8,7 @@ use stacks::chainstate::stacks::address::PoxAddress; use stacks::chainstate::stacks::db::StacksChainState; use stacks::chainstate::stacks::miner::{signal_mining_blocked, signal_mining_ready}; use stacks::clarity_cli::vm_execute as execute; -use stacks::core; -use stacks::core::STACKS_EPOCH_MAX; +use stacks::core::{self, EpochList, STACKS_EPOCH_MAX}; use stacks::util_lib::boot::boot_code_id; use stacks_common::types::chainstate::{StacksAddress, StacksBlockId}; use stacks_common::types::PrivateKey; @@ -137,15 +136,15 @@ fn disable_pox() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch22.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch22); conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); @@ -676,15 +675,15 @@ fn pox_2_unlock_all() { }); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch22.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch22); conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); @@ -1292,15 +1291,15 @@ fn test_pox_reorg_one_flap() { conf_template.node.require_affirmed_anchor_blocks = false; // make epoch 2.1 and 2.2 start in the middle of boot-up - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].start_height = 101; - epochs[StacksEpochId::Epoch2_05.index()].end_height = 151; - epochs[StacksEpochId::Epoch21.index()].start_height = 151; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch22.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = 101; + epochs[StacksEpochId::Epoch2_05].start_height = 101; + epochs[StacksEpochId::Epoch2_05].end_height = 151; + epochs[StacksEpochId::Epoch21].start_height = 151; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch22); conf_template.burnchain.epochs = Some(epochs); let privks: Vec<_> = (0..5) diff --git a/testnet/stacks-node/src/tests/epoch_23.rs b/testnet/stacks-node/src/tests/epoch_23.rs index 5e7a5f2d1e..8c679907a2 100644 --- a/testnet/stacks-node/src/tests/epoch_23.rs +++ b/testnet/stacks-node/src/tests/epoch_23.rs @@ -18,8 +18,7 @@ use std::{env, thread}; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use stacks::burnchains::{Burnchain, PoxConstants}; -use stacks::core; -use stacks::core::STACKS_EPOCH_MAX; +use stacks::core::{self, EpochList, STACKS_EPOCH_MAX}; use stacks_common::util::sleep_ms; use crate::config::InitialBalance; @@ -103,17 +102,17 @@ fn trait_invocation_behavior() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].start_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch23.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].start_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch23); conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); diff --git a/testnet/stacks-node/src/tests/epoch_24.rs b/testnet/stacks-node/src/tests/epoch_24.rs index 304157fa45..0857495b52 100644 --- a/testnet/stacks-node/src/tests/epoch_24.rs +++ b/testnet/stacks-node/src/tests/epoch_24.rs @@ -26,7 +26,7 @@ use stacks::chainstate::stacks::boot::RawRewardSetEntry; use stacks::chainstate::stacks::db::StacksChainState; use stacks::chainstate::stacks::{Error, StacksTransaction, TransactionPayload}; use stacks::clarity_cli::vm_execute as execute; -use stacks::core::{self, StacksEpochId}; +use stacks::core::{self, EpochList, StacksEpochId}; use stacks_common::address::{AddressHashMode, C32_ADDRESS_VERSION_TESTNET_SINGLESIG}; use stacks_common::consts::STACKS_EPOCH_MAX; use stacks_common::types::chainstate::{StacksAddress, StacksBlockId, StacksPrivateKey}; @@ -155,19 +155,19 @@ fn fix_to_pox_contract() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].start_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].end_height = epoch_2_4; - epochs[StacksEpochId::Epoch24.index()].start_height = epoch_2_4; - epochs[StacksEpochId::Epoch24.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch24.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].start_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].end_height = epoch_2_4; + epochs[StacksEpochId::Epoch24].start_height = epoch_2_4; + epochs[StacksEpochId::Epoch24].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch24); conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); @@ -797,19 +797,19 @@ fn verify_auto_unlock_behavior() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].start_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].end_height = epoch_2_4; - epochs[StacksEpochId::Epoch24.index()].start_height = epoch_2_4; - epochs[StacksEpochId::Epoch24.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch24.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].start_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].end_height = epoch_2_4; + epochs[StacksEpochId::Epoch24].start_height = epoch_2_4; + epochs[StacksEpochId::Epoch24].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch24); conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); diff --git a/testnet/stacks-node/src/tests/epoch_25.rs b/testnet/stacks-node/src/tests/epoch_25.rs index 3312cb0a26..a2a89b6b9f 100644 --- a/testnet/stacks-node/src/tests/epoch_25.rs +++ b/testnet/stacks-node/src/tests/epoch_25.rs @@ -17,7 +17,7 @@ use std::{env, thread}; use clarity::vm::types::PrincipalData; use stacks::burnchains::{Burnchain, PoxConstants}; -use stacks::core::{self, StacksEpochId}; +use stacks::core::{self, EpochList, StacksEpochId}; use stacks_common::consts::STACKS_EPOCH_MAX; use stacks_common::types::chainstate::StacksPrivateKey; @@ -86,21 +86,21 @@ fn microblocks_disabled() { test_observer::register_any(&mut conf); conf.initial_balances.append(&mut initial_balances); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].end_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].start_height = epoch_2_05; - epochs[StacksEpochId::Epoch2_05.index()].end_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].start_height = epoch_2_1; - epochs[StacksEpochId::Epoch21.index()].end_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].start_height = epoch_2_2; - epochs[StacksEpochId::Epoch22.index()].end_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].start_height = epoch_2_3; - epochs[StacksEpochId::Epoch23.index()].end_height = epoch_2_4; - epochs[StacksEpochId::Epoch24.index()].start_height = epoch_2_4; - epochs[StacksEpochId::Epoch24.index()].end_height = epoch_2_5; - epochs[StacksEpochId::Epoch25.index()].start_height = epoch_2_5; - epochs[StacksEpochId::Epoch25.index()].end_height = STACKS_EPOCH_MAX; - epochs.truncate(StacksEpochId::Epoch25.index() + 1); + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].end_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].start_height = epoch_2_05; + epochs[StacksEpochId::Epoch2_05].end_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].start_height = epoch_2_1; + epochs[StacksEpochId::Epoch21].end_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].start_height = epoch_2_2; + epochs[StacksEpochId::Epoch22].end_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].start_height = epoch_2_3; + epochs[StacksEpochId::Epoch23].end_height = epoch_2_4; + epochs[StacksEpochId::Epoch24].start_height = epoch_2_4; + epochs[StacksEpochId::Epoch24].end_height = epoch_2_5; + epochs[StacksEpochId::Epoch25].start_height = epoch_2_5; + epochs[StacksEpochId::Epoch25].end_height = STACKS_EPOCH_MAX; + epochs.truncate_after(StacksEpochId::Epoch25); conf.burnchain.epochs = Some(epochs); let mut burnchain_config = Burnchain::regtest(&conf.get_burn_db_path()); diff --git a/testnet/stacks-node/src/tests/integrations.rs b/testnet/stacks-node/src/tests/integrations.rs index 236d76b000..bc7935f753 100644 --- a/testnet/stacks-node/src/tests/integrations.rs +++ b/testnet/stacks-node/src/tests/integrations.rs @@ -25,8 +25,8 @@ use stacks::clarity_vm::clarity::ClarityConnection; use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MAXIMUM_MEMPOOL_TX_CHAINING; use stacks::core::{ - StacksEpoch, StacksEpochId, CHAIN_ID_TESTNET, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, - PEER_VERSION_EPOCH_2_1, + EpochList, StacksEpoch, StacksEpochId, CHAIN_ID_TESTNET, PEER_VERSION_EPOCH_2_0, + PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; use stacks::net::api::callreadonly::CallReadOnlyRequestBody; use stacks::net::api::getaccount::AccountEntryResponse; @@ -2013,7 +2013,7 @@ fn make_keys(seed: &str, count: u64) -> Vec { fn block_limit_runtime_test() { let mut conf = super::new_test_conf(); - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -2074,7 +2074,7 @@ fn block_limit_runtime_test() { }, network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.commit_anchor_block_within = 5000; let contract_sk = StacksPrivateKey::from_hex(SK_1).unwrap(); diff --git a/testnet/stacks-node/src/tests/nakamoto_integrations.rs b/testnet/stacks-node/src/tests/nakamoto_integrations.rs index 4d26af746a..7fe79657cb 100644 --- a/testnet/stacks-node/src/tests/nakamoto_integrations.rs +++ b/testnet/stacks-node/src/tests/nakamoto_integrations.rs @@ -57,7 +57,7 @@ use stacks::chainstate::stacks::{ }; use stacks::core::mempool::MAXIMUM_MEMPOOL_TX_CHAINING; use stacks::core::{ - StacksEpoch, StacksEpochId, BLOCK_LIMIT_MAINNET_10, HELIUM_BLOCK_LIMIT_20, + EpochList, StacksEpoch, StacksEpochId, BLOCK_LIMIT_MAINNET_10, HELIUM_BLOCK_LIMIT_20, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, PEER_VERSION_EPOCH_2_2, PEER_VERSION_EPOCH_2_3, PEER_VERSION_EPOCH_2_4, PEER_VERSION_EPOCH_2_5, PEER_VERSION_EPOCH_3_0, PEER_VERSION_TESTNET, @@ -552,7 +552,7 @@ pub fn naka_neon_integration_conf(seed: Option<&[u8]>) -> (Config, StacksAddress conf.burnchain.mode = "nakamoto-neon".into(); // tests can override this, but these tests run with epoch 2.05 by default - conf.burnchain.epochs = Some(NAKAMOTO_INTEGRATION_EPOCHS.to_vec()); + conf.burnchain.epochs = Some(EpochList::new(&*NAKAMOTO_INTEGRATION_EPOCHS)); if let Some(seed) = seed { conf.node.seed = seed.to_vec(); @@ -806,7 +806,7 @@ pub fn boot_to_epoch_3( assert_eq!(stacker_sks.len(), signer_sks.len()); let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let current_height = btc_regtest_controller.get_headers_height(); info!( "Chain bootstrapped to bitcoin block {current_height:?}, starting Epoch 2x miner"; @@ -968,7 +968,7 @@ pub fn boot_to_pre_epoch_3_boundary( assert_eq!(stacker_sks.len(), signer_sks.len()); let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let current_height = btc_regtest_controller.get_headers_height(); info!( "Chain bootstrapped to bitcoin block {current_height:?}, starting Epoch 2x miner"; @@ -1206,7 +1206,7 @@ pub fn setup_epoch_3_reward_set( assert_eq!(stacker_sks.len(), signer_sks.len()); let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let reward_cycle_len = naka_conf.get_burnchain().pox_constants.reward_cycle_length as u64; let prepare_phase_len = naka_conf.get_burnchain().pox_constants.prepare_length as u64; @@ -1305,7 +1305,7 @@ pub fn boot_to_epoch_3_reward_set_calculation_boundary( ); let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let reward_cycle_len = naka_conf.get_burnchain().pox_constants.reward_cycle_length as u64; let prepare_phase_len = naka_conf.get_burnchain().pox_constants.prepare_length as u64; @@ -1340,7 +1340,7 @@ pub fn boot_to_epoch_25( btc_regtest_controller: &mut BitcoinRegtestController, ) { let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_25 = &epochs[StacksEpochId::Epoch25.index()]; + let epoch_25 = &epochs[StacksEpochId::Epoch25]; let reward_cycle_len = naka_conf.get_burnchain().pox_constants.reward_cycle_length as u64; let prepare_phase_len = naka_conf.get_burnchain().pox_constants.prepare_length as u64; @@ -1878,7 +1878,7 @@ fn flash_blocks_on_epoch_3() { // Get the Epoch 3.0 activation height (in terms of Bitcoin block height) let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let epoch_3_start_height = epoch_3.start_height; // Find the gap in burn blocks @@ -2387,10 +2387,10 @@ fn correct_burn_outs() { { let epochs = naka_conf.burnchain.epochs.as_mut().unwrap(); - epochs[StacksEpochId::Epoch24.index()].end_height = 208; - epochs[StacksEpochId::Epoch25.index()].start_height = 208; - epochs[StacksEpochId::Epoch25.index()].end_height = 225; - epochs[StacksEpochId::Epoch30.index()].start_height = 225; + epochs[StacksEpochId::Epoch24].end_height = 208; + epochs[StacksEpochId::Epoch25].start_height = 208; + epochs[StacksEpochId::Epoch25].end_height = 225; + epochs[StacksEpochId::Epoch30].start_height = 225; } naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1); @@ -2444,8 +2444,8 @@ fn correct_burn_outs() { wait_for_runloop(&blocks_processed); let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; - let epoch_25 = &epochs[StacksEpochId::Epoch25.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; + let epoch_25 = &epochs[StacksEpochId::Epoch25]; let current_height = btc_regtest_controller.get_headers_height(); info!( "Chain bootstrapped to bitcoin block {current_height:?}, starting Epoch 2x miner"; @@ -7501,7 +7501,7 @@ fn check_block_times() { blind_signer(&naka_conf, &signers, proposals_submitted); let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let epoch_3_start = epoch_3.start_height; let mut last_stacks_block_height = 0; let mut last_tenure_height = 0; diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs index 466d42354d..103dc246dd 100644 --- a/testnet/stacks-node/src/tests/neon_integrations.rs +++ b/testnet/stacks-node/src/tests/neon_integrations.rs @@ -43,7 +43,7 @@ use stacks::cli::{self, StacksChainConfig}; use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MemPoolWalkTxTypes; use stacks::core::{ - self, StacksEpoch, StacksEpochId, BLOCK_LIMIT_MAINNET_20, BLOCK_LIMIT_MAINNET_205, + self, EpochList, StacksEpoch, StacksEpochId, BLOCK_LIMIT_MAINNET_20, BLOCK_LIMIT_MAINNET_205, BLOCK_LIMIT_MAINNET_21, CHAIN_ID_TESTNET, HELIUM_BLOCK_LIMIT_20, PEER_VERSION_EPOCH_1_0, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, PEER_VERSION_EPOCH_2_2, PEER_VERSION_EPOCH_2_3, PEER_VERSION_EPOCH_2_4, PEER_VERSION_EPOCH_2_5, @@ -98,7 +98,7 @@ fn inner_neon_integration_test_conf(seed: Option>) -> (Config, StacksAdd let mut conf = super::new_test_conf(); // tests can override this, but these tests run with epoch 2.05 by default - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -127,7 +127,7 @@ fn inner_neon_integration_test_conf(seed: Option>) -> (Config, StacksAdd block_limit: HELIUM_BLOCK_LIMIT_20.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); let seed = seed.unwrap_or(conf.node.seed.clone()); conf.node.seed = seed; @@ -2137,7 +2137,7 @@ fn stx_delegate_btc_integration_test() { }); // update epoch info so that Epoch 2.1 takes effect - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -2159,7 +2159,7 @@ fn stx_delegate_btc_integration_test() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(3); test_observer::spawn(); @@ -2395,7 +2395,7 @@ fn stack_stx_burn_op_test() { }); // update epoch info so that Epoch 2.1 takes effect - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -2445,7 +2445,7 @@ fn stack_stx_burn_op_test() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_5, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(3); test_observer::spawn(); @@ -2798,7 +2798,7 @@ fn vote_for_aggregate_key_burn_op_test() { }); // update epoch info so that Epoch 2.1 takes effect - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -2848,7 +2848,7 @@ fn vote_for_aggregate_key_burn_op_test() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_5, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(3); test_observer::spawn(); @@ -5127,8 +5127,8 @@ fn size_overflow_unconfirmed_invalid_stream_microblocks_integration_test() { }) .collect(); - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].block_limit = core::BLOCK_LIMIT_MAINNET_20; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].block_limit = core::BLOCK_LIMIT_MAINNET_20; conf.burnchain.epochs = Some(epochs); conf.miner.first_attempt_time_ms = i64::MAX as u64; @@ -5277,8 +5277,8 @@ fn runtime_overflow_unconfirmed_microblocks_integration_test() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[StacksEpochId::Epoch20.index()].block_limit = core::BLOCK_LIMIT_MAINNET_20; + let mut epochs = EpochList::new(&*core::STACKS_EPOCHS_REGTEST); + epochs[StacksEpochId::Epoch20].block_limit = core::BLOCK_LIMIT_MAINNET_20; conf.burnchain.epochs = Some(epochs); let txs: Vec> = spender_sks @@ -6540,7 +6540,7 @@ fn microblock_limit_hit_integration_test() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -6575,7 +6575,7 @@ fn microblock_limit_hit_integration_test() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); // included in the first block @@ -9709,7 +9709,7 @@ fn test_problematic_txs_are_not_stored() { }); // force mainnet limits in 2.05 for this test - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -9731,7 +9731,7 @@ fn test_problematic_txs_are_not_stored() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); // take effect immediately @@ -9956,7 +9956,7 @@ fn test_problematic_blocks_are_not_mined() { }); // force mainnet limits in 2.05 for this test - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -9978,7 +9978,7 @@ fn test_problematic_blocks_are_not_mined() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); // AST precheck becomes default at burn height @@ -10311,7 +10311,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { }); // force mainnet limits in 2.05 for this test - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -10333,7 +10333,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); // AST precheck becomes default at burn height @@ -10702,7 +10702,7 @@ fn test_problematic_microblocks_are_not_mined() { }); // force mainnet limits in 2.05 for this test - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -10724,7 +10724,7 @@ fn test_problematic_microblocks_are_not_mined() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); // AST precheck becomes default at burn height @@ -11082,7 +11082,7 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { }); // force mainnet limits in 2.05 for this test - conf.burnchain.epochs = Some(vec![ + conf.burnchain.epochs = Some(EpochList::new(&[ StacksEpoch { epoch_id: StacksEpochId::Epoch20, start_height: 0, @@ -11104,7 +11104,7 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { block_limit: BLOCK_LIMIT_MAINNET_21.clone(), network_epoch: PEER_VERSION_EPOCH_2_1, }, - ]); + ])); conf.burnchain.pox_2_activation = Some(10_003); // AST precheck becomes default at burn height diff --git a/testnet/stacks-node/src/tests/signer/mod.rs b/testnet/stacks-node/src/tests/signer/mod.rs index 4738831beb..8306228837 100644 --- a/testnet/stacks-node/src/tests/signer/mod.rs +++ b/testnet/stacks-node/src/tests/signer/mod.rs @@ -42,7 +42,6 @@ use stacks::chainstate::coordinator::comm::CoordinatorChannels; use stacks::chainstate::nakamoto::signer_set::NakamotoSigners; use stacks::chainstate::stacks::boot::{NakamotoSignerEntry, SIGNERS_NAME}; use stacks::chainstate::stacks::StacksPrivateKey; -use stacks::core::StacksEpoch; use stacks::net::api::postblock_proposal::{ BlockValidateOk, BlockValidateReject, BlockValidateResponse, }; @@ -463,7 +462,7 @@ impl + Send + 'static, T: SignerEventTrait + 'static> SignerTest { let lock_period = 12; let epochs = self.running_nodes.conf.burnchain.epochs.clone().unwrap(); - let epoch_25 = &epochs[StacksEpochId::Epoch25.index()]; + let epoch_25 = &epochs[StacksEpochId::Epoch25]; let epoch_25_start_height = epoch_25.start_height; // stack enough to activate pox-4 let block_height = self @@ -806,7 +805,7 @@ fn reloads_signer_set_in() { let naka_conf = &signer_test.running_nodes.conf; let epochs = naka_conf.burnchain.epochs.clone().unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let reward_cycle_len = naka_conf.get_burnchain().pox_constants.reward_cycle_length as u64; let prepare_phase_len = naka_conf.get_burnchain().pox_constants.prepare_length as u64; @@ -2616,14 +2615,8 @@ fn mock_sign_epoch_25() { |node_config| { node_config.miner.pre_nakamoto_mock_signing = true; let epochs = node_config.burnchain.epochs.as_mut().unwrap(); - for epoch in epochs.iter_mut() { - if epoch.epoch_id == StacksEpochId::Epoch25 { - epoch.end_height = 251; - } - if epoch.epoch_id == StacksEpochId::Epoch30 { - epoch.start_height = 251; - } - } + epochs[StacksEpochId::Epoch25].end_height = 251; + epochs[StacksEpochId::Epoch30].start_height = 251; }, None, None, @@ -2636,7 +2629,7 @@ fn mock_sign_epoch_25() { .epochs .clone() .unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let epoch_3_boundary = epoch_3.start_height - 1; // We only advance to the boundary as epoch 2.5 miner gets torn down at the boundary signer_test.boot_to_epoch_25_reward_cycle(); @@ -2782,14 +2775,8 @@ fn multiple_miners_mock_sign_epoch_25() { config.miner.mining_key = Some(Secp256k1PrivateKey::from_seed(&[1])); config.miner.pre_nakamoto_mock_signing = true; let epochs = config.burnchain.epochs.as_mut().unwrap(); - for epoch in epochs.iter_mut() { - if epoch.epoch_id == StacksEpochId::Epoch25 { - epoch.end_height = 251; - } - if epoch.epoch_id == StacksEpochId::Epoch30 { - epoch.start_height = 251; - } - } + epochs[StacksEpochId::Epoch25].end_height = 251; + epochs[StacksEpochId::Epoch30].start_height = 251; config.events_observers.retain(|listener| { let Ok(addr) = std::net::SocketAddr::from_str(&listener.endpoint) else { warn!( @@ -2848,7 +2835,7 @@ fn multiple_miners_mock_sign_epoch_25() { .epochs .clone() .unwrap(); - let epoch_3 = &epochs[StacksEpochId::Epoch30.index()]; + let epoch_3 = &epochs[StacksEpochId::Epoch30]; let epoch_3_boundary = epoch_3.start_height - 1; // We only advance to the boundary as epoch 2.5 miner gets torn down at the boundary signer_test.boot_to_epoch_25_reward_cycle(); @@ -3790,10 +3777,10 @@ fn partial_tenure_fork() { // Move epoch 2.5 and 3.0 earlier, so we have more time for the // test before re-stacking is required. if let Some(epochs) = config.burnchain.epochs.as_mut() { - epochs[StacksEpochId::Epoch24.index()].end_height = 131; - epochs[StacksEpochId::Epoch25.index()].start_height = 131; - epochs[StacksEpochId::Epoch25.index()].end_height = 166; - epochs[StacksEpochId::Epoch30.index()].start_height = 166; + epochs[StacksEpochId::Epoch24].end_height = 131; + epochs[StacksEpochId::Epoch25].start_height = 131; + epochs[StacksEpochId::Epoch25].end_height = 166; + epochs[StacksEpochId::Epoch30].start_height = 166; } else { panic!("Expected epochs to be set"); }