Skip to content

Commit 14e13e2

Browse files
Automatically create StacksEpochId::ALL from varients to prevent manual update
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 74e94fc commit 14e13e2

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

stacks-common/src/types/mod.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,23 @@ pub const MINING_COMMITMENT_WINDOW: u8 = 6;
9595
// Only relevant for Nakamoto (epoch 3.x)
9696
pub const MINING_COMMITMENT_FREQUENCY_NAKAMOTO: u8 = 3;
9797

98-
#[repr(u32)]
99-
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash, Copy, Serialize, Deserialize)]
100-
pub enum StacksEpochId {
98+
macro_rules! define_stacks_epochs {
99+
($($variant:ident = $value:expr),* $(,)?) => {
100+
#[repr(u32)]
101+
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
102+
pub enum StacksEpochId {
103+
$($variant = $value),*
104+
}
105+
106+
impl StacksEpochId {
107+
pub const ALL: &'static [StacksEpochId] = &[
108+
$(StacksEpochId::$variant),*
109+
];
110+
}
111+
};
112+
}
113+
114+
define_stacks_epochs! {
101115
Epoch10 = 0x01000,
102116
Epoch20 = 0x02000,
103117
Epoch2_05 = 0x02005,
@@ -447,20 +461,6 @@ impl StacksEpochId {
447461
StacksEpochId::Epoch33
448462
}
449463

450-
pub const ALL_GTE_20: &'static [StacksEpochId] = &[
451-
StacksEpochId::Epoch20,
452-
StacksEpochId::Epoch2_05,
453-
StacksEpochId::Epoch21,
454-
StacksEpochId::Epoch22,
455-
StacksEpochId::Epoch23,
456-
StacksEpochId::Epoch24,
457-
StacksEpochId::Epoch25,
458-
StacksEpochId::Epoch30,
459-
StacksEpochId::Epoch31,
460-
StacksEpochId::Epoch32,
461-
StacksEpochId::Epoch33,
462-
];
463-
464464
/// In this epoch, how should the mempool perform garbage collection?
465465
pub fn mempool_garbage_behavior(&self) -> MempoolCollectionBehavior {
466466
match self {

stackslib/src/chainstate/tests/consensus.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ macro_rules! contract_call_consensus_test {
443443
#[test]
444444
fn $name() {
445445
// Handle deploy_epochs parameter (default to all epochs >= 2.0 if not provided)
446-
let deploy_epochs = StacksEpochId::ALL_GTE_20;
446+
let deploy_epochs = &StacksEpochId::ALL[1..];
447447
$(let deploy_epochs = $deploy_epochs;)?
448448

449449
// Handle call_epochs parameter (default to EPOCHS_TO_TEST if not provided)
@@ -912,25 +912,10 @@ impl ConsensusTest<'_> {
912912
info!("StacksEpoch calculate_epochs first_burn_height = {first_burnchain_height}");
913913
let reward_cycle_length = pox_constants.reward_cycle_length as u64;
914914
let prepare_length = pox_constants.prepare_length as u64;
915-
// Define all epochs in order
916-
let epoch_ids = [
917-
StacksEpochId::Epoch10,
918-
StacksEpochId::Epoch20,
919-
StacksEpochId::Epoch2_05,
920-
StacksEpochId::Epoch21,
921-
StacksEpochId::Epoch22,
922-
StacksEpochId::Epoch23,
923-
StacksEpochId::Epoch24,
924-
StacksEpochId::Epoch25,
925-
StacksEpochId::Epoch30,
926-
StacksEpochId::Epoch31,
927-
StacksEpochId::Epoch32,
928-
StacksEpochId::Epoch33,
929-
];
930915
// Initialize heights
931916
let mut epochs = vec![];
932917
let mut current_height = 0;
933-
for epoch_id in epoch_ids.iter() {
918+
for epoch_id in StacksEpochId::ALL.iter() {
934919
let start_height = current_height;
935920
let end_height = match *epoch_id {
936921
StacksEpochId::Epoch10 => first_burnchain_height,

0 commit comments

Comments
 (0)