diff --git a/rusk/src/lib/node.rs b/rusk/src/lib/node.rs index df4daeba3d..4800d3b74a 100644 --- a/rusk/src/lib/node.rs +++ b/rusk/src/lib/node.rs @@ -237,8 +237,8 @@ const fn coinbase_value( /// The emission schedule works as follows: /// - the emission follows a Bitcoin-like halving function -/// - a total 499_782_528 Dusk will be emitted over 36 years divided in 9 -/// periods of 4 years each +/// - a total 500.000.000,256000 Dusk will be emitted over 36 years divided in +/// 9 periods of 4 years each /// /// Considering the target block rate of 10 seconds, we assume a production of /// 8640 blocks per day, which corresponds to 12_614_400 blocks per period. @@ -248,19 +248,28 @@ const BLOCKS_PER_DAY: u64 = 8640; // Target block production per 4-year period const BLOCKS_PER_PERIOD: u64 = BLOCKS_PER_DAY * 365 * 4; // Block emission for each period, following the halving function -const BLOCK_EMISSIONS: [f64; 9] = - [19.86, 9.93, 4.96, 2.48, 1.24, 0.62, 0.31, 0.15, 0.07]; +const BLOCK_EMISSIONS: [u64; 9] = [ + dusk(19.8574), + dusk(9.9287), + dusk(4.96435), + dusk(2.48218), + dusk(1.24109), + dusk(0.62054), + dusk(0.31027), + dusk(0.15514), + dusk(0.07757), +]; // Returns the block emission for a certain height pub const fn emission_amount(block_height: u64) -> Dusk { if block_height == 0 { - return dusk(0.0); + return 0; } let period = (block_height - 1) / BLOCKS_PER_PERIOD; match period { - 0..=8 => dusk(BLOCK_EMISSIONS[period as usize]), - _ => dusk(0.0), + 0..=8 => BLOCK_EMISSIONS[period as usize], + _ => 0, } } @@ -281,16 +290,17 @@ mod tests { // Block range and expected emission for each period let test_cases = vec![ - (1, 12_614_400, dusk(19.86)), // Period 1 - (12_614_401, 25_228_800, dusk(9.93)), // Period 2 - (25_228_801, 37_843_200, dusk(4.96)), // Period 3 - (37_843_201, 50_457_600, dusk(2.48)), // Period 4 - (50_457_601, 63_072_000, dusk(1.24)), // Period 5 - (63_072_001, 75_686_400, dusk(0.62)), // Period 6 - (75_686_401, 88_300_800, dusk(0.31)), // Period 7 - (88_300_801, 100_915_200, dusk(0.15)), // Period 8 - (100_915_201, 113_529_600, dusk(0.07)), // Period 9 - (113_529_601, u64::MAX, dusk(0.0)), // Beyond period 9 + (0, 0, dusk(0.0)), // Genesis + (1, 12_614_400, dusk(19.8574)), // Period 1 + (12_614_401, 25_228_800, dusk(9.9287)), // Period 2 + (25_228_801, 37_843_200, dusk(4.96435)), // Period 3 + (37_843_201, 50_457_600, dusk(2.48218)), // Period 4 + (50_457_601, 63_072_000, dusk(1.24109)), // Period 5 + (63_072_001, 75_686_400, dusk(0.62054)), // Period 6 + (75_686_401, 88_300_800, dusk(0.31027)), // Period 7 + (88_300_801, 100_915_200, dusk(0.15514)), // Period 8 + (100_915_201, 113_529_600, dusk(0.07757)), // Period 9 + (113_529_601, u64::MAX, dusk(0.0)), // Beyond period 9 ]; // Test emission periods @@ -314,15 +324,15 @@ mod tests { } const EXPECTED_PERIOD_EMISSIONS: [u64; 9] = [ - 250_521_984, // Period 1 - 125_260_992, // Period 2 - 62_567_424, // Period 3 - 31_283_712, // Period 4 - 15_641_856, // Period 5 - 7_820_928, // Period 6 - 3_910_464, // Period 7 - 1_892_160, // Period 8 - 883_008, // Period 9 + dusk(250_489_186.56), // Period 1 + dusk(125_244_593.28), // Period 2 + dusk(62_622_296.64), // Period 3 + dusk(31_311_211.392), // Period 4 + dusk(15_655_605.696), // Period 5 + dusk(7_827_739.776), // Period 6 + dusk(3_913_869.888), // Period 7 + dusk(1_956_998.016), // Period 8 + dusk(978_499.008), // Period 9 ]; #[test] @@ -330,8 +340,7 @@ mod tests { // Check each period emission corresponds to the expected value for (i, &expected) in EXPECTED_PERIOD_EMISSIONS.iter().enumerate() { let block_emission = BLOCK_EMISSIONS[i]; - let period_emission = - (block_emission * BLOCKS_PER_PERIOD as f64) as u64; + let period_emission = block_emission * BLOCKS_PER_PERIOD; assert_eq!( period_emission, expected, @@ -346,12 +355,12 @@ mod tests { #[test] fn test_total_emission() { // Expected total emission based on the schedule - let expected_total = 499_782_528u64; + let expected_total = dusk(500_000_000.256); // Loop through each block emission and calculate the total emission let mut total_emission = 0u64; for &be in BLOCK_EMISSIONS.iter() { - total_emission += (be * BLOCKS_PER_PERIOD as f64) as u64; + total_emission += be * BLOCKS_PER_PERIOD; } // Ensure the calculated total matches the expected total