mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
replace is_mainnet() with !is_testnet() (#2125)
* replace is_mainnet() with !is_testnet() makes testing "mainnet" code significantly easier (its the default) * fix next_target_adjustment test based on tromp analysis * rustfmt * cleanup wallet db files and add to gitignore * fix
This commit is contained in:
parent
ed9c1acec1
commit
305b36dcce
4 changed files with 37 additions and 21 deletions
|
@ -62,29 +62,31 @@ pub const COINBASE_MATURITY: u64 = DAY_HEIGHT;
|
||||||
/// function of block height (time). Starts at 90% losing a percent
|
/// function of block height (time). Starts at 90% losing a percent
|
||||||
/// approximately every week. Represented as an integer between 0 and 100.
|
/// approximately every week. Represented as an integer between 0 and 100.
|
||||||
pub fn secondary_pow_ratio(height: u64) -> u64 {
|
pub fn secondary_pow_ratio(height: u64) -> u64 {
|
||||||
if global::is_mainnet() {
|
if global::is_testnet() {
|
||||||
90u64.saturating_sub(height / (2 * YEAR_HEIGHT / 90))
|
|
||||||
} else {
|
|
||||||
if height < T4_CUCKAROO_HARDFORK {
|
if height < T4_CUCKAROO_HARDFORK {
|
||||||
// Maintaining pre hardfork testnet4 behavior
|
// Maintaining pre hardfork testnet4 behavior
|
||||||
90u64.saturating_sub(height / WEEK_HEIGHT)
|
90u64.saturating_sub(height / WEEK_HEIGHT)
|
||||||
} else {
|
} else {
|
||||||
90u64.saturating_sub(height / (2 * YEAR_HEIGHT / 90))
|
90u64.saturating_sub(height / (2 * YEAR_HEIGHT / 90))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Mainnet (or testing mainnet code).
|
||||||
|
90u64.saturating_sub(height / (2 * YEAR_HEIGHT / 90))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The AR scale damping factor to use. Dependent on block height
|
/// The AR scale damping factor to use. Dependent on block height
|
||||||
/// to account for pre HF behavior on testnet4.
|
/// to account for pre HF behavior on testnet4.
|
||||||
fn ar_scale_damp_factor(height: u64) -> u64 {
|
fn ar_scale_damp_factor(height: u64) -> u64 {
|
||||||
if global::is_mainnet() {
|
if global::is_testnet() {
|
||||||
AR_SCALE_DAMP_FACTOR
|
|
||||||
} else {
|
|
||||||
if height < T4_CUCKAROO_HARDFORK {
|
if height < T4_CUCKAROO_HARDFORK {
|
||||||
DIFFICULTY_DAMP_FACTOR
|
DIFFICULTY_DAMP_FACTOR
|
||||||
} else {
|
} else {
|
||||||
AR_SCALE_DAMP_FACTOR
|
AR_SCALE_DAMP_FACTOR
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Mainnet (or testing mainnet code).
|
||||||
|
AR_SCALE_DAMP_FACTOR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +334,8 @@ where
|
||||||
/// the hardfork.
|
/// the hardfork.
|
||||||
fn ar_count(height: u64, diff_data: &[HeaderInfo]) -> u64 {
|
fn ar_count(height: u64, diff_data: &[HeaderInfo]) -> u64 {
|
||||||
let mut to_skip = 1;
|
let mut to_skip = 1;
|
||||||
if !global::is_mainnet() && height < T4_CUCKAROO_HARDFORK {
|
if global::is_testnet() && height < T4_CUCKAROO_HARDFORK {
|
||||||
|
// Maintain behavior of testnet4 pre-HF.
|
||||||
to_skip = 0;
|
to_skip = 0;
|
||||||
}
|
}
|
||||||
100 * diff_data
|
100 * diff_data
|
||||||
|
|
|
@ -1295,14 +1295,14 @@ pub fn kernel_sig_msg(
|
||||||
lock_height: u64,
|
lock_height: u64,
|
||||||
features: KernelFeatures,
|
features: KernelFeatures,
|
||||||
) -> Result<secp::Message, Error> {
|
) -> Result<secp::Message, Error> {
|
||||||
let msg = if global::is_mainnet() {
|
let msg = if global::is_testnet() {
|
||||||
let hash = (fee, lock_height, features).hash();
|
|
||||||
secp::Message::from_slice(&hash.as_bytes())?
|
|
||||||
} else {
|
|
||||||
let mut bytes = [0; 32];
|
let mut bytes = [0; 32];
|
||||||
BigEndian::write_u64(&mut bytes[16..24], fee);
|
BigEndian::write_u64(&mut bytes[16..24], fee);
|
||||||
BigEndian::write_u64(&mut bytes[24..], lock_height);
|
BigEndian::write_u64(&mut bytes[24..], lock_height);
|
||||||
secp::Message::from_slice(&bytes)?
|
secp::Message::from_slice(&bytes)?
|
||||||
|
} else {
|
||||||
|
let hash = (fee, lock_height, features).hash();
|
||||||
|
secp::Message::from_slice(&hash.as_bytes())?
|
||||||
};
|
};
|
||||||
Ok(msg)
|
Ok(msg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,7 +284,8 @@ pub fn is_user_testing_mode() -> bool {
|
||||||
ChainTypes::UserTesting == *param_ref
|
ChainTypes::UserTesting == *param_ref
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Are we in production mode (a live public network)?
|
/// Are we in production mode?
|
||||||
|
/// Production defined as a live public network, testnet[n] or mainnet.
|
||||||
pub fn is_production_mode() -> bool {
|
pub fn is_production_mode() -> bool {
|
||||||
let param_ref = CHAIN_TYPE.read();
|
let param_ref = CHAIN_TYPE.read();
|
||||||
ChainTypes::Testnet1 == *param_ref
|
ChainTypes::Testnet1 == *param_ref
|
||||||
|
@ -294,10 +295,13 @@ pub fn is_production_mode() -> bool {
|
||||||
|| ChainTypes::Mainnet == *param_ref
|
|| ChainTypes::Mainnet == *param_ref
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Are we in mainnet?
|
/// Are we in one of our (many) testnets?
|
||||||
pub fn is_mainnet() -> bool {
|
pub fn is_testnet() -> bool {
|
||||||
let param_ref = CHAIN_TYPE.read();
|
let param_ref = CHAIN_TYPE.read();
|
||||||
ChainTypes::Mainnet == *param_ref
|
ChainTypes::Testnet1 == *param_ref
|
||||||
|
|| ChainTypes::Testnet2 == *param_ref
|
||||||
|
|| ChainTypes::Testnet3 == *param_ref
|
||||||
|
|| ChainTypes::Testnet4 == *param_ref
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to get a nonce known to create a valid POW on
|
/// Helper function to get a nonce known to create a valid POW on
|
||||||
|
|
|
@ -384,9 +384,18 @@ fn next_target_adjustment() {
|
||||||
let diff_min = Difficulty::min();
|
let diff_min = Difficulty::min();
|
||||||
|
|
||||||
// Check we don't get stuck on difficulty <= MIN_DIFFICULTY (at 4x faster blocks at least)
|
// Check we don't get stuck on difficulty <= MIN_DIFFICULTY (at 4x faster blocks at least)
|
||||||
let mut hi = HeaderInfo::from_diff_scaling(diff_min, MIN_DIFFICULTY as u32);
|
let mut hi = HeaderInfo::from_diff_scaling(diff_min, AR_SCALE_DAMP_FACTOR as u32);
|
||||||
hi.is_secondary = false;
|
hi.is_secondary = false;
|
||||||
let hinext = next_difficulty(1, repeat(15, hi.clone(), DIFFICULTY_ADJUST_WINDOW, None));
|
let hinext = next_difficulty(
|
||||||
|
1,
|
||||||
|
repeat(
|
||||||
|
BLOCK_TIME_SEC / 4,
|
||||||
|
hi.clone(),
|
||||||
|
DIFFICULTY_ADJUST_WINDOW,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
assert_ne!(hinext.difficulty, diff_min);
|
assert_ne!(hinext.difficulty, diff_min);
|
||||||
|
|
||||||
// Check we don't get stuck on scale MIN_DIFFICULTY, when primary frequency is too high
|
// Check we don't get stuck on scale MIN_DIFFICULTY, when primary frequency is too high
|
||||||
|
@ -476,7 +485,7 @@ fn test_secondary_pow_ratio() {
|
||||||
// Tests for mainnet chain type.
|
// Tests for mainnet chain type.
|
||||||
{
|
{
|
||||||
global::set_mining_mode(global::ChainTypes::Mainnet);
|
global::set_mining_mode(global::ChainTypes::Mainnet);
|
||||||
assert_eq!(global::is_mainnet(), true);
|
assert_eq!(global::is_testnet(), false);
|
||||||
|
|
||||||
assert_eq!(secondary_pow_ratio(1), 90);
|
assert_eq!(secondary_pow_ratio(1), 90);
|
||||||
assert_eq!(secondary_pow_ratio(89), 90);
|
assert_eq!(secondary_pow_ratio(89), 90);
|
||||||
|
@ -518,7 +527,7 @@ fn test_secondary_pow_ratio() {
|
||||||
// Tests for testnet4 chain type (covers pre and post hardfork).
|
// Tests for testnet4 chain type (covers pre and post hardfork).
|
||||||
{
|
{
|
||||||
global::set_mining_mode(global::ChainTypes::Testnet4);
|
global::set_mining_mode(global::ChainTypes::Testnet4);
|
||||||
assert_eq!(global::is_mainnet(), false);
|
assert_eq!(global::is_testnet(), true);
|
||||||
|
|
||||||
assert_eq!(secondary_pow_ratio(1), 90);
|
assert_eq!(secondary_pow_ratio(1), 90);
|
||||||
assert_eq!(secondary_pow_ratio(89), 90);
|
assert_eq!(secondary_pow_ratio(89), 90);
|
||||||
|
@ -566,7 +575,7 @@ fn test_secondary_pow_scale() {
|
||||||
// testnet4 testing
|
// testnet4 testing
|
||||||
{
|
{
|
||||||
global::set_mining_mode(global::ChainTypes::Testnet4);
|
global::set_mining_mode(global::ChainTypes::Testnet4);
|
||||||
assert_eq!(global::is_mainnet(), false);
|
assert_eq!(global::is_testnet(), true);
|
||||||
|
|
||||||
// all primary, factor should increase so it becomes easier to find a high
|
// all primary, factor should increase so it becomes easier to find a high
|
||||||
// difficulty block
|
// difficulty block
|
||||||
|
@ -640,7 +649,7 @@ fn test_secondary_pow_scale() {
|
||||||
// mainnet testing
|
// mainnet testing
|
||||||
{
|
{
|
||||||
global::set_mining_mode(global::ChainTypes::Mainnet);
|
global::set_mining_mode(global::ChainTypes::Mainnet);
|
||||||
assert_eq!(global::is_mainnet(), true);
|
assert_eq!(global::is_testnet(), false);
|
||||||
|
|
||||||
// all primary, factor should increase so it becomes easier to find a high
|
// all primary, factor should increase so it becomes easier to find a high
|
||||||
// difficulty block
|
// difficulty block
|
||||||
|
|
Loading…
Reference in a new issue