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

Override global one times. #3737

Merged
merged 8 commits into from
Oct 7, 2022
3 changes: 2 additions & 1 deletion core/src/core/pmmr/readonly_pmmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ where
Some(p) => p,
None => self.size,
};
let mut pmmr_index = pmmr_index1 - 1;
let mut pmmr_index = pmmr_index1.saturating_sub(1);

while return_vec.len() < max_count as usize && pmmr_index < size {
if let Some(t) = self.get_data(pmmr_index) {
return_vec.push(t);
Expand Down
20 changes: 20 additions & 0 deletions core/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ pub fn init_global_chain_type(new_type: ChainTypes) {
GLOBAL_CHAIN_TYPE.init(new_type)
}

/// Set the global chain_type using an override
pub fn set_global_chain_type(new_type: ChainTypes) {
GLOBAL_CHAIN_TYPE.set(new_type, true);
}

/// Set the chain type on a per-thread basis via thread_local storage.
pub fn set_local_chain_type(new_type: ChainTypes) {
CHAIN_TYPE.with(|chain_type| chain_type.set(Some(new_type)))
Expand All @@ -207,12 +212,22 @@ pub fn init_global_future_time_limit(new_ftl: u64) {
GLOBAL_FUTURE_TIME_LIMIT.init(new_ftl)
}

/// The global future time limit may be reset again using the override
pub fn set_global_future_time_limit(new_ftl: u64) {
GLOBAL_FUTURE_TIME_LIMIT.set(new_ftl, true)
}

/// One time initialization of the global accept fee base
/// Will panic if we attempt to re-initialize this (via OneTime).
pub fn init_global_accept_fee_base(new_base: u64) {
GLOBAL_ACCEPT_FEE_BASE.init(new_base)
}

/// The global accept fee base may be reset using override.
pub fn set_global_accept_fee_base(new_base: u64) {
GLOBAL_ACCEPT_FEE_BASE.set(new_base, true)
}

/// Set the accept fee base on a per-thread basis via thread_local storage.
pub fn set_local_accept_fee_base(new_base: u64) {
ACCEPT_FEE_BASE.with(|base| base.set(Some(new_base)))
Expand Down Expand Up @@ -265,6 +280,11 @@ pub fn init_global_nrd_enabled(enabled: bool) {
GLOBAL_NRD_FEATURE_ENABLED.init(enabled)
}

/// Set the global NRD feature flag using override.
pub fn set_global_nrd_enabled(enabled: bool) {
GLOBAL_NRD_FEATURE_ENABLED.set(enabled, true)
}

/// Explicitly enable the local NRD feature flag.
pub fn set_local_nrd_enabled(enabled: bool) {
NRD_FEATURE_ENABLED.with(|flag| flag.set(Some(enabled)))
Expand Down
5 changes: 3 additions & 2 deletions servers/src/grin/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ pub const MAINNET_DNS_SEEDS: &[&str] = &[
];
/// DNS Seeds with contact email associated - Testnet
pub const TESTNET_DNS_SEEDS: &[&str] = &[
"floonet.seed.grin.icu", // [email protected]
"floonet.seed.713.mw", // [email protected]
"floonet.seed.grin.lesceller.com", // [email protected]
"floonet.seed.grin.prokapi.com", // [email protected]
"grintestseed.revcore.net", // [email protected]
"testnet.grin.punksec.de", // [email protected]
"testnet.grinnode.30-r.com", // [email protected]
];

pub fn connect_and_monitor(
Expand Down
9 changes: 8 additions & 1 deletion util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ where
/// Initializes the OneTime, should only be called once after construction.
/// Will panic (via assert) if called more than once.
pub fn init(&self, value: T) {
self.set(value, false);
}

/// Allows the one time to be set again with an override.
pub fn set(&self, value: T, is_override: bool) {
let mut inner = self.inner.write();
assert!(inner.is_none());
if !is_override {
assert!(inner.is_none());
}
*inner = Some(value);
}

Expand Down