Skip to content

Commit

Permalink
chore(nns): add feature flag for stable index
Browse files Browse the repository at this point in the history
  • Loading branch information
max-dfinity committed Nov 6, 2024
1 parent a05b99a commit f14f3ef
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions rs/nns/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ use std::{
time::{Duration, SystemTime},
};

#[cfg(test)]
#[cfg(any(test, feature = "canbench-rs"))]
pub mod test_utils;

mod account_id_index;
Expand Down Expand Up @@ -203,19 +203,23 @@ thread_local! {

static ARE_SET_VISIBILITY_PROPOSALS_ENABLED: Cell<bool> = const { Cell::new(true) };

static ACTIVE_NEURONS_IN_STABLE_MEMORY_ENABLED: Cell<bool> = const { Cell::new(false) };
static ACTIVE_NEURONS_IN_STABLE_MEMORY_ENABLED: Cell<bool> = const { Cell::new(cfg!(feature = "test")) };

static USE_STABLE_MEMORY_FOLLOWING_INDEX: Cell<bool> = const { Cell::new(cfg!(feature = "test")) };
}

pub fn is_voting_power_adjustment_enabled() -> bool {
IS_VOTING_POWER_ADJUSTMENT_ENABLED.with(|ok| ok.get())
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_enable_voting_power_adjustment() -> Temporary {
Temporary::new(&IS_VOTING_POWER_ADJUSTMENT_ENABLED, true)
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_disable_voting_power_adjustment() -> Temporary {
Temporary::new(&IS_VOTING_POWER_ADJUSTMENT_ENABLED, false)
}
Expand All @@ -225,11 +229,13 @@ pub fn is_private_neuron_enforcement_enabled() -> bool {
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_enable_private_neuron_enforcement() -> Temporary {
Temporary::new(&IS_PRIVATE_NEURON_ENFORCEMENT_ENABLED, true)
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_disable_private_neuron_enforcement() -> Temporary {
Temporary::new(&IS_PRIVATE_NEURON_ENFORCEMENT_ENABLED, false)
}
Expand All @@ -239,11 +245,13 @@ pub fn are_set_visibility_proposals_enabled() -> bool {
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_enable_set_visibility_proposals() -> Temporary {
Temporary::new(&ARE_SET_VISIBILITY_PROPOSALS_ENABLED, true)
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_disable_set_visibility_proposals() -> Temporary {
Temporary::new(&ARE_SET_VISIBILITY_PROPOSALS_ENABLED, false)
}
Expand All @@ -253,15 +261,33 @@ pub fn is_active_neurons_in_stable_memory_enabled() -> bool {
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_enable_active_neurons_in_stable_memory() -> Temporary {
Temporary::new(&ACTIVE_NEURONS_IN_STABLE_MEMORY_ENABLED, true)
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_disable_active_neurons_in_stable_memory() -> Temporary {
Temporary::new(&ACTIVE_NEURONS_IN_STABLE_MEMORY_ENABLED, false)
}

pub fn use_stable_memory_following_index() -> bool {
USE_STABLE_MEMORY_FOLLOWING_INDEX.with(|ok| ok.get())
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_enable_stable_memory_following_index() -> Temporary {
Temporary::new(&USE_STABLE_MEMORY_FOLLOWING_INDEX, true)
}

/// Only integration tests should use this.
#[cfg(any(test, feature = "canbench-rs", feature = "test"))]
pub fn temporarily_disable_stable_memory_following_index() -> Temporary {
Temporary::new(&USE_STABLE_MEMORY_FOLLOWING_INDEX, false)
}

pub fn decoder_config() -> DecoderConfig {
let mut config = DecoderConfig::new();
config.set_skipping_quota(DEFAULT_SKIPPING_QUOTA);
Expand Down

0 comments on commit f14f3ef

Please sign in to comment.