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

feat: update faucets #6024

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
257 changes: 101 additions & 156 deletions base_layer/core/src/blocks/faucets/esmeralda_faucet.json

Large diffs are not rendered by default.

1,302 changes: 101 additions & 1,201 deletions base_layer/core/src/blocks/faucets/igor_faucet.json

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions base_layer/core/src/blocks/faucets/nextnet_faucet.json

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions base_layer/core/src/blocks/faucets/stagenet_faucet.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn get_stagenet_genesis_block() -> ChainBlock {
let mut block = get_stagenet_genesis_block_raw();

// Add faucet utxos - enable/disable as required
let add_faucet_utxos = false;
let add_faucet_utxos = true;
if add_faucet_utxos {
// NB! Update 'consensus_constants.rs/pub fn igor()/ConsensusConstants {faucet_value: ?}' with total value
// NB: `stagenet_genesis_sanity_check` must pass
Expand All @@ -119,9 +119,9 @@ pub fn get_stagenet_genesis_block() -> ChainBlock {

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("b3569982f737771e11008c97050640d12a94ce42231ac69fb955dbf66c9d19b8").unwrap();
FixedHash::from_hex("3f4011ec1e8ddfbd66fb7331c5623b38f529a66e81233d924df85f2070b2aacb").unwrap();
block.header.output_mr =
FixedHash::from_hex("95f849715638f24c62f6673693efad50523da0841fb77b6b6e068b95c85fe890").unwrap();
FixedHash::from_hex("3e40efda288a57d3319c63388dd47ffe4b682baaf6a3b58622ec94d77ad712a2").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand All @@ -140,7 +140,7 @@ pub fn get_stagenet_genesis_block() -> ChainBlock {

fn get_stagenet_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("07 Nov 2023 08:00:00 +0200").expect("parse may not fail");
let genesis_timestamp = DateTime::parse_from_rfc2822("07 Nov 2024 08:00:00 +0200").expect("parse may not fail");
let not_before_proof = b"i am the stagenet genesis block, watch out, here i come \
\
The New York Times , 2000/01/01 \
Expand All @@ -159,7 +159,7 @@ pub fn get_nextnet_genesis_block() -> ChainBlock {
let mut block = get_nextnet_genesis_block_raw();

// Add faucet utxos - enable/disable as required
let add_faucet_utxos = false;
let add_faucet_utxos = true;
if add_faucet_utxos {
// NB! Update 'consensus_constants.rs/pub fn igor()/ConsensusConstants {faucet_value: ?}' with total value
// NB: `nextnet_genesis_sanity_check` must pass
Expand All @@ -171,9 +171,9 @@ pub fn get_nextnet_genesis_block() -> ChainBlock {

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("b3569982f737771e11008c97050640d12a94ce42231ac69fb955dbf66c9d19b8").unwrap();
FixedHash::from_hex("3f4011ec1e8ddfbd66fb7331c5623b38f529a66e81233d924df85f2070b2aacb").unwrap();
block.header.output_mr =
FixedHash::from_hex("95f849715638f24c62f6673693efad50523da0841fb77b6b6e068b95c85fe890").unwrap();
FixedHash::from_hex("3e40efda288a57d3319c63388dd47ffe4b682baaf6a3b58622ec94d77ad712a2").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand Down Expand Up @@ -229,9 +229,9 @@ pub fn get_igor_genesis_block() -> ChainBlock {

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("5057ce1672184c5875bc707119a506fdb44bbc7b8eb33420aee642e1064ace3a").unwrap();
FixedHash::from_hex("bc5d677b0b8349adc9d7e4a18ace7406986fc7017866f4fd351ecb0f35d6da5e").unwrap();
block.header.output_mr =
FixedHash::from_hex("162adb813d717bd7eea0b3ba447af30c00f5e4b7959e69658fc4f356fa7bbf9f").unwrap();
FixedHash::from_hex("d227ba7b215eab4dae9e0d5a678b84ffbed1d7d3cebdeafae4704e504bd2e5f3").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand All @@ -250,7 +250,7 @@ pub fn get_igor_genesis_block() -> ChainBlock {

fn get_igor_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("07 Nov 2023 08:20:00 +0200").expect("parse may not fail");
let genesis_timestamp = DateTime::parse_from_rfc2822("12 Dec 2023 08:20:00 +0200").expect("parse may not fail");
// Let us add a "not before" proof to the genesis block
let not_before_proof = b"but igor is the best, it is whispered in the wind \
\
Expand Down Expand Up @@ -283,9 +283,9 @@ pub fn get_esmeralda_genesis_block() -> ChainBlock {

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("9166f00ee1d2b86ba15ec2f1e388a9527ef190b06af645ebed3ef81e397fd1b2").unwrap();
FixedHash::from_hex("3f4011ec1e8ddfbd66fb7331c5623b38f529a66e81233d924df85f2070b2aacb").unwrap();
block.header.output_mr =
FixedHash::from_hex("db15c3dfcd164190452fdfe2820b095bd8c0ef295f762441157a164328aba5c4").unwrap();
FixedHash::from_hex("3e40efda288a57d3319c63388dd47ffe4b682baaf6a3b58622ec94d77ad712a2").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand All @@ -304,7 +304,7 @@ pub fn get_esmeralda_genesis_block() -> ChainBlock {

fn get_esmeralda_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("01 Dec 2023 08:01:00 +0200").expect("parse may not fail");
let genesis_timestamp = DateTime::parse_from_rfc2822("12 Dec 2023 08:01:00 +0200").expect("parse may not fail");
// Let us add a "not before" proof to the genesis block
let not_before_proof =
b"as I sip my drink, thoughts of esmeralda consume my mind, like a refreshing nourishing draught \
Expand Down Expand Up @@ -387,23 +387,23 @@ mod test {
// Note: Generate new data for `pub fn get_stagenet_genesis_block()` and `fn get_stagenet_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
let block = get_stagenet_genesis_block();
check_block(Network::StageNet, &block, 0, 0);
check_block(Network::StageNet, &block, 100, 1);
}

#[test]
fn nextnet_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_nextnet_genesis_block()` and `fn get_stagenet_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
let block = get_nextnet_genesis_block();
check_block(Network::NextNet, &block, 0, 0);
check_block(Network::NextNet, &block, 100, 1);
}

#[test]
fn esmeralda_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_esmeralda_genesis_block()` and `fn get_esmeralda_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
let block = get_esmeralda_genesis_block();
check_block(Network::Esmeralda, &block, 155, 1);
check_block(Network::Esmeralda, &block, 100, 1);
}

#[test]
Expand Down
89 changes: 65 additions & 24 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ pub struct PowAlgorithmConstants {
pub target_time: u64,
}

const ESMERALDA_FAUCET_VALUE: u64 = 6_050_258_300_519_067;
const FAUCET_VALUE: u64 = 6_030_157_777_181_012;
const ESMERALDA_FAUCET_VALUE: u64 = FAUCET_VALUE;
// const IGOR_FAUCET_VALUE: u64 = 1_897_859_637_874_722;

// The target time used by the difficulty adjustment algorithms, their target time is the target block interval * PoW
// algorithm count
Expand Down Expand Up @@ -443,7 +445,7 @@ impl ConsensusConstants {
max_randomx_seed_height: u64::MAX,
max_extra_field_size: 200,
proof_of_work: algos,
faucet_value: 0.into(), // 1_195_651_566_094_148.into(),
faucet_value: 0.into(), // IGOR_FAUCET_VALUE.into(),
transaction_weight: TransactionWeight::v1(),
max_script_byte_size: 2048,
input_version_range,
Expand All @@ -468,7 +470,7 @@ impl ConsensusConstants {
/// *
/// Esmeralda testnet has the following characteristics:
/// * 2 min blocks on average (5 min SHA-3, 3 min MM)
/// * 21 billion tXTR with a 3-year half-life
/// * 21 billion tXTR with a 2.76-year half-life
/// * 800 T tail emission (± 1% inflation after initial 21 billion has been mined)
/// * Coinbase lock height - 12 hours = 360 blocks
pub fn esmeralda() -> Vec<Self> {
Expand All @@ -493,7 +495,7 @@ impl ConsensusConstants {
difficulty_block_window: 90,
max_block_transaction_weight: 127_795,
median_timestamp_count: 11,
emission_initial: 18_462_816_327 * uT,
emission_initial: 13_952_877_857 * uT,
emission_decay: &ESMERALDA_DECAY_PARAMS,
emission_tail: 800 * T,
max_randomx_seed_height: 3000,
Expand Down Expand Up @@ -554,8 +556,7 @@ impl ConsensusConstants {
max_randomx_seed_height: 3000,
max_extra_field_size: 200,
proof_of_work: algos,
faucet_value: 0.into(), /* ESMERALDA_FAUCET_VALUE.into(), // The esmeralda genesis block is re-used for
* stagenet */
faucet_value: FAUCET_VALUE.into(),
transaction_weight: TransactionWeight::v1(),
max_script_byte_size: 2048,
input_version_range,
Expand Down Expand Up @@ -604,8 +605,7 @@ impl ConsensusConstants {
max_randomx_seed_height: 3000,
max_extra_field_size: 200,
proof_of_work: algos,
faucet_value: 0.into(), /* ESMERALDA_FAUCET_VALUE.into(), // The esmeralda genesis block is re-used for
* stagenet */
faucet_value: FAUCET_VALUE.into(),
transaction_weight: TransactionWeight::v1(),
max_script_byte_size: 2048,
input_version_range,
Expand Down Expand Up @@ -771,8 +771,8 @@ fn assert_hybrid_pow_constants(
}
}

static EMISSION_DECAY: [u64; 6] = [21u64, 22, 23, 25, 26, 37];
const ESMERALDA_DECAY_PARAMS: [u64; 6] = [21u64, 22, 23, 25, 26, 37]; // less significant values don't matter
const EMISSION_DECAY: [u64; 6] = [21u64, 22, 23, 25, 26, 37];
const ESMERALDA_DECAY_PARAMS: [u64; 6] = EMISSION_DECAY; // less significant values don't matter

/// Class to create custom consensus constants
pub struct ConsensusConstantsBuilder {
Expand Down Expand Up @@ -889,6 +889,49 @@ mod test {
ConsensusConstants::mainnet();
}

// Comment out the feature flag to run this test
#[test]
#[cfg(feature = "schedule_get_constants")]
fn esmeralda_schedule_get_constants() {
let mut esmeralda = ConsensusConstants::esmeralda();
loop {
let schedule = EmissionSchedule::new(
esmeralda[0].emission_initial,
esmeralda[0].emission_decay,
esmeralda[0].emission_tail,
);
// No genesis block coinbase
assert_eq!(schedule.block_reward(0), MicroMinotari(0));
// Coinbases starts at block 1
let coinbase_offset = 1;
let first_reward = schedule.block_reward(coinbase_offset);
assert_eq!(first_reward, esmeralda[0].emission_initial * uT);
assert_eq!(schedule.supply_at_block(coinbase_offset), first_reward);
// Tail emission starts after block 3,255,552 + coinbase_offset
let mut rewards = schedule
.iter()
.skip(3_255_552 + usize::try_from(coinbase_offset).unwrap());
let supply = loop {
let (block_num, reward, supply) = rewards.next().unwrap();
let total_supply = supply + esmeralda[0].faucet_value;
println!(
"Initial: {}, Block: {}, Reward: {}, Supply: {}, Total supply: {}",
esmeralda[0].emission_initial, block_num, reward, supply, total_supply
);
if reward == esmeralda[0].emission_tail {
break supply;
}
};
let total_supply_up_to_tail_emission = supply + esmeralda[0].faucet_value;
if total_supply_up_to_tail_emission >= 21_000_000_800_000_000 * uT {
println!("Total supply up to tail emission: {}", total_supply_up_to_tail_emission);
break;
}
esmeralda[0].emission_initial = esmeralda[0].emission_initial + MicroMinotari(1);
}
panic!("\n\nThis test may not pass in CI\n\n");
}

#[test]
fn esmeralda_schedule() {
let esmeralda = ConsensusConstants::esmeralda();
Expand All @@ -904,19 +947,22 @@ mod test {
let first_reward = schedule.block_reward(coinbase_offset);
assert_eq!(first_reward, esmeralda[0].emission_initial * uT);
assert_eq!(schedule.supply_at_block(coinbase_offset), first_reward);
let three_years = 365 * 24 * 30 * 3;
// 'half_life_block' at approximately '(total supply - faucet value) / 2'
#[allow(clippy::cast_possible_truncation)]
let half_life_block = (365.0 * 24.0 * 30.0 * 2.76) as u64;
assert_eq!(
schedule.supply_at_block(three_years + coinbase_offset),
10_500_682_498_903_652 * uT
); // Around 10.5 billion
// Tail emission starts after block 3,574,175
schedule.supply_at_block(half_life_block + coinbase_offset),
7_483_280_506_356_578 * uT
);
// Tail emission starts after block 3,255,552 + coinbase_offset
let mut rewards = schedule
.iter()
.skip(3_574_174 + usize::try_from(coinbase_offset).unwrap());
.skip(3255552 + usize::try_from(coinbase_offset).unwrap());
let (block_num, reward, supply) = rewards.next().unwrap();
assert_eq!(block_num, 3_574_175 + coinbase_offset);
assert_eq!(reward, 800_000_598 * uT);
assert_eq!(supply, 20_100_525_123_936_707 * uT); // Still 900 mil tokens to go when tail emission kicks in
assert_eq!(block_num, 3255553 + coinbase_offset);
assert_eq!(reward, 800_000_415 * uT);
let total_supply_up_to_tail_emission = supply + esmeralda[0].faucet_value;
assert_eq!(total_supply_up_to_tail_emission, 20_999_999_999_819_869 * uT);
let (_, reward, _) = rewards.next().unwrap();
assert_eq!(reward, esmeralda[0].emission_tail);
}
Expand All @@ -932,11 +978,6 @@ mod test {
let first_reward = schedule.block_reward(coinbase_offset);
assert_eq!(first_reward, igor[0].emission_initial * uT);
assert_eq!(schedule.supply_at_block(coinbase_offset), first_reward);
let three_years = 365 * 24 * 30 * 3;
assert_eq!(
schedule.supply_at_block(three_years + coinbase_offset),
3_150_642_608_358_864 * uT
);
// Tail emission starts after block 11_084_819
let rewards = schedule.iter().skip(11_084_819 - 25);
let mut previous_reward = MicroMinotari(0);
Expand Down
4 changes: 2 additions & 2 deletions base_layer/tari_mining_helper_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ mod tests {

#[test]
fn detect_change_in_consensus_encoding() {
const NONCE: u64 = 7161662395197423680;
let difficulty = Difficulty::from_u64(1007).expect("Failed to create difficulty");
const NONCE: u64 = 12357147376603363070;
let difficulty = Difficulty::from_u64(4196).expect("Failed to create difficulty");
unsafe {
let mut error = -1;
let error_ptr = &mut error as *mut c_int;
Expand Down
Loading