From 94c44345e351ccd0ff4c75dd920c3e2268509b1e Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 7 Oct 2024 15:54:55 +0100 Subject: [PATCH 1/9] Fixed inflation rate Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 42 +++++++++++++++------------------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 7431585f0d..89e7d8f784 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -704,35 +704,25 @@ impl pallet_parameters::Config for Runtime { pub struct EraPayout; impl pallet_staking::EraPayout for EraPayout { fn era_payout( - total_staked: Balance, + _total_staked: Balance, _total_issuance: Balance, era_duration_millis: u64, ) -> (Balance, Balance) { - const MILLISECONDS_PER_YEAR: u64 = 1000 * 3600 * 24 * 36525 / 100; - - let params = relay_common::EraPayoutParams { - total_staked, - total_stakable: Balances::total_issuance(), - ideal_stake: dynamic_params::inflation::IdealStake::get(), - max_annual_inflation: dynamic_params::inflation::MaxInflation::get(), - min_annual_inflation: dynamic_params::inflation::MinInflation::get(), - falloff: dynamic_params::inflation::Falloff::get(), - period_fraction: Perquintill::from_rational(era_duration_millis, MILLISECONDS_PER_YEAR), - legacy_auction_proportion: if dynamic_params::inflation::UseAuctionSlots::get() { - let auctioned_slots = parachains_paras::Parachains::::get() - .into_iter() - // all active para-ids that do not belong to a system chain is the number of - // parachains that we should take into account for inflation. - .filter(|i| *i >= LOWEST_PUBLIC_ID) - .count() as u64; - Some(Perquintill::from_rational(auctioned_slots.min(60), 300u64)) - } else { - None - }, - }; - - log::debug!(target: LOG_TARGET, "params: {:?}", params); - relay_common::relay_era_payout(params) + const MILLISECONDS_PER_YEAR: u64 = (1000 * 3600 * 24 * 36525) / 100; + // A normal-sized era will have 1 / 356 here: + let relative_era_len = Perquintill::from_rational(era_duration_millis, MILLISECONDS_PER_YEAR); + + // TI at the time of execution of [Referendum 1139](https://polkadot.subsquare.io/referenda/1139), block hash: `0x39422610299a75ef69860417f4d0e1d94e77699f45005645ffc5e8e619950f9f`. + let fixed_total_issuance = 15_011_657_390_566_252_333; + let yearly_inflation_rate = Perquintill::from_percent(8); + let yearly_emission = fixed_total_issuance * fixed_inflation_rate; + + let era_emission = yearly_emission * relative_era_len; + // 15% to treasury, as per ref 1139. + let to_treasury = era_emission * Perquintill::from_percent(15); + let to_stakers = era_emission - to_treasury; + + (to_stakers, to_treasury) } } From 7698b450c49e464ab22c82d815dcd0c050555047 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 7 Oct 2024 17:09:36 +0100 Subject: [PATCH 2/9] tests Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 16 ++++++-- Cargo.toml | 1 + relay/polkadot/Cargo.toml | 1 + relay/polkadot/src/lib.rs | 85 +++++++++++++++++++++++++++++++++------ 4 files changed, 87 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f4d467771..5d83f61bbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7420,6 +7420,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-format" version = "0.4.4" @@ -15088,12 +15094,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.30" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "num-conv", "powerfmt", "serde", "time-core", @@ -15108,10 +15115,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] diff --git a/Cargo.toml b/Cargo.toml index 13199f41e3..e96581a7b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ license = "GPL-3.0-only" # TODO ; } + /// Defines how much should the inflation be for an era given its duration. pub struct EraPayout; impl pallet_staking::EraPayout for EraPayout { @@ -709,20 +710,21 @@ impl pallet_staking::EraPayout for EraPayout { era_duration_millis: u64, ) -> (Balance, Balance) { const MILLISECONDS_PER_YEAR: u64 = (1000 * 3600 * 24 * 36525) / 100; - // A normal-sized era will have 1 / 356 here: - let relative_era_len = Perquintill::from_rational(era_duration_millis, MILLISECONDS_PER_YEAR); - + // A normal-sized era will have 1 / 356.25 here: + let relative_era_len = + FixedU128::from_rational(era_duration_millis.into(), MILLISECONDS_PER_YEAR.into()); + // TI at the time of execution of [Referendum 1139](https://polkadot.subsquare.io/referenda/1139), block hash: `0x39422610299a75ef69860417f4d0e1d94e77699f45005645ffc5e8e619950f9f`. - let fixed_total_issuance = 15_011_657_390_566_252_333; - let yearly_inflation_rate = Perquintill::from_percent(8); - let yearly_emission = fixed_total_issuance * fixed_inflation_rate; - - let era_emission = yearly_emission * relative_era_len; + let fixed_total_issuance: i128 = 15_011_657_390_566_252_333; + let yearly_inflation_rate = FixedU128::from_rational(8, 100); + let yearly_emission = yearly_inflation_rate.saturating_mul_int(fixed_total_issuance); + + let era_emission = relative_era_len.saturating_mul_int(yearly_emission); // 15% to treasury, as per ref 1139. - let to_treasury = era_emission * Perquintill::from_percent(15); - let to_stakers = era_emission - to_treasury; - - (to_stakers, to_treasury) + let to_treasury = FixedU128::from_rational(15, 100).saturating_mul_int(era_emission); + let to_stakers = era_emission.saturating_sub(to_treasury); + + (to_stakers.saturated_into(), to_treasury.saturated_into()) } } @@ -3367,6 +3369,7 @@ mod multiplier_tests { dispatch::DispatchInfo, traits::{OnFinalize, PalletInfoAccess}, }; + use pallet_staking::EraPayout; use polkadot_runtime_common::{MinimumMultiplier, TargetBlockFullness}; use separator::Separatable; use sp_runtime::traits::Convert; @@ -3398,6 +3401,64 @@ mod multiplier_tests { }) } + use approx::assert_relative_eq; + const MILLISECONDS_PER_DAY: u64 = 24 * 60 * 60 * 1000; + + #[test] + fn staking_inflation_correct() { + let (to_stakers, to_treasury) = super::EraPayout::era_payout( + 123, // ignored + 456, // ignored + MILLISECONDS_PER_DAY, + ); + + // Values are within 0.1% + assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64, max_relative = 0.1); + assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64, max_relative = 0.1); + } + + #[test] + fn staking_inflation_correct_longer_era() { + // Twice the era duration means twice the emission: + let (to_stakers, to_treasury) = super::EraPayout::era_payout( + 123, // ignored + 456, // ignored + 2 * MILLISECONDS_PER_DAY, + ); + assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64 * 2.0, max_relative = 0.1); + assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64 * 2.0, max_relative = 0.1); + } + + #[test] + fn staking_inflation_correct_whole_year() { + let (to_stakers, to_treasury) = super::EraPayout::era_payout( + 123, // ignored + 456, // ignored + (35625 * MILLISECONDS_PER_DAY) / 100, // 1 year + ); + + // 8% of the fixed total issuance: 120M Dot per year + let yearly_emission = 120_093_259 * UNITS; + + assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.1); + assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.1); + } + + // 10 years into the future, our values do not overflow. + #[test] + fn staking_inflation_correct_not_overflow() { + let (to_stakers, to_treasury) = super::EraPayout::era_payout( + 123, // ignored + 456, // ignored + (35625 * MILLISECONDS_PER_DAY) / 10, // 10 years + ); + let initial_ti: i128 = 15_011_657_390_566_252_333; + let projected_total_issuance = (to_stakers as i128 + to_treasury as i128) + initial_ti; + + // In 2034, there will be about 26.7 billion DOTs in existence. + assert_eq!(projected_total_issuance, 26_725_065_621_398_235_666); + } + #[test] fn fast_unstake_estimate() { use pallet_fast_unstake::WeightInfo; From 1cfdf1769b614c94ce4aab47f8b58e29a87cd6a6 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 7 Oct 2024 17:26:47 +0100 Subject: [PATCH 3/9] more tests Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index b1da1d13c0..d2389cf16e 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -3459,6 +3459,27 @@ mod multiplier_tests { assert_eq!(projected_total_issuance, 26_725_065_621_398_235_666); } + // Print percent per year, just as convenience. + #[test] + fn staking_inflation_correct_print_percent() { + let (to_stakers, to_treasury) = super::EraPayout::era_payout( + 123, // ignored + 456, // ignored + (35625 * MILLISECONDS_PER_DAY) / 100, // 1 year + ); + let yearly_emission = to_stakers + to_treasury; + let mut ti: i128 = 15_011_657_390_566_252_333; + + for y in 0..10 { + let new_ti = ti + yearly_emission as i128; + let inflation = 100.0 * (new_ti - ti) as f64 / ti as f64; + println!("Year {y} inflation: {inflation}%"); + ti = new_ti; + + assert!(inflation <= 8.0 && inflation > 2.0, "sanity check"); + } + } + #[test] fn fast_unstake_estimate() { use pallet_fast_unstake::WeightInfo; From f624eab6da308c1ec9a8536c19a4c3455dd5cdf7 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 8 Oct 2024 14:06:29 +0100 Subject: [PATCH 4/9] formatting Signed-off-by: Oliver Tale-Yazdi --- Cargo.lock | 1 + relay/polkadot/src/lib.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d83f61bbe..ef1c6afbbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10069,6 +10069,7 @@ dependencies = [ name = "polkadot-runtime" version = "1.0.0" dependencies = [ + "approx", "binary-merkle-tree", "frame-benchmarking", "frame-election-provider-support", diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index d2389cf16e..57e423adf1 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -3432,8 +3432,8 @@ mod multiplier_tests { #[test] fn staking_inflation_correct_whole_year() { let (to_stakers, to_treasury) = super::EraPayout::era_payout( - 123, // ignored - 456, // ignored + 123, // ignored + 456, // ignored (35625 * MILLISECONDS_PER_DAY) / 100, // 1 year ); @@ -3448,8 +3448,8 @@ mod multiplier_tests { #[test] fn staking_inflation_correct_not_overflow() { let (to_stakers, to_treasury) = super::EraPayout::era_payout( - 123, // ignored - 456, // ignored + 123, // ignored + 456, // ignored (35625 * MILLISECONDS_PER_DAY) / 10, // 10 years ); let initial_ti: i128 = 15_011_657_390_566_252_333; @@ -3463,8 +3463,8 @@ mod multiplier_tests { #[test] fn staking_inflation_correct_print_percent() { let (to_stakers, to_treasury) = super::EraPayout::era_payout( - 123, // ignored - 456, // ignored + 123, // ignored + 456, // ignored (35625 * MILLISECONDS_PER_DAY) / 100, // 1 year ); let yearly_emission = to_stakers + to_treasury; From f078b689706243409a782e19d8f4cf171f035576 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 8 Oct 2024 18:16:31 +0100 Subject: [PATCH 5/9] fix tests and typos Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 57e423adf1..36b03679ad 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -710,7 +710,7 @@ impl pallet_staking::EraPayout for EraPayout { era_duration_millis: u64, ) -> (Balance, Balance) { const MILLISECONDS_PER_YEAR: u64 = (1000 * 3600 * 24 * 36525) / 100; - // A normal-sized era will have 1 / 356.25 here: + // A normal-sized era will have 1 / 365.25 here: let relative_era_len = FixedU128::from_rational(era_duration_millis.into(), MILLISECONDS_PER_YEAR.into()); @@ -3434,7 +3434,7 @@ mod multiplier_tests { let (to_stakers, to_treasury) = super::EraPayout::era_payout( 123, // ignored 456, // ignored - (35625 * MILLISECONDS_PER_DAY) / 100, // 1 year + (36525 * MILLISECONDS_PER_DAY) / 100, // 1 year ); // 8% of the fixed total issuance: 120M Dot per year @@ -3444,19 +3444,36 @@ mod multiplier_tests { assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.1); } + #[test] + fn staking_inflation_while_year_exact() { + let (to_stakers, to_treasury) = super::EraPayout::era_payout( + 123, // ignored + 456, // ignored + (365625 * MILLISECONDS_PER_DAY) / 100, // 1 year + ); + + // 8% of the fixed total issuance is about 120M Dot per year + let yearly_emission = 120_093_259 * UNITS; + // But also check it exactly: + assert_eq!(to_stakers + to_treasury, 1200932590000000000); + + assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.1); + assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.1); + } + // 10 years into the future, our values do not overflow. #[test] fn staking_inflation_correct_not_overflow() { let (to_stakers, to_treasury) = super::EraPayout::era_payout( 123, // ignored 456, // ignored - (35625 * MILLISECONDS_PER_DAY) / 10, // 10 years + (365625 * MILLISECONDS_PER_DAY) / 10, // 10 years ); let initial_ti: i128 = 15_011_657_390_566_252_333; let projected_total_issuance = (to_stakers as i128 + to_treasury as i128) + initial_ti; - // In 2034, there will be about 26.7 billion DOTs in existence. - assert_eq!(projected_total_issuance, 26_725_065_621_398_235_666); + // In 2034, there will be about 2.7 billion DOT in existence. + assert_relative_eq!(projected_total_issuance as f64, (2_700_000_0000 * UNITS) as f64, max_relative = 0.1); } // Print percent per year, just as convenience. @@ -3465,7 +3482,7 @@ mod multiplier_tests { let (to_stakers, to_treasury) = super::EraPayout::era_payout( 123, // ignored 456, // ignored - (35625 * MILLISECONDS_PER_DAY) / 100, // 1 year + (365625 * MILLISECONDS_PER_DAY) / 100, // 1 year ); let yearly_emission = to_stakers + to_treasury; let mut ti: i128 = 15_011_657_390_566_252_333; From daf083cb8974fa57a3a1dbab63e3b61b391dfbb5 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 8 Oct 2024 18:41:46 +0100 Subject: [PATCH 6/9] test fixes Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 57 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 36b03679ad..ee2ababa76 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -716,8 +716,8 @@ impl pallet_staking::EraPayout for EraPayout { // TI at the time of execution of [Referendum 1139](https://polkadot.subsquare.io/referenda/1139), block hash: `0x39422610299a75ef69860417f4d0e1d94e77699f45005645ffc5e8e619950f9f`. let fixed_total_issuance: i128 = 15_011_657_390_566_252_333; - let yearly_inflation_rate = FixedU128::from_rational(8, 100); - let yearly_emission = yearly_inflation_rate.saturating_mul_int(fixed_total_issuance); + let fixed_inflation_rate = FixedU128::from_rational(8, 100); + let yearly_emission = fixed_inflation_rate.saturating_mul_int(fixed_total_issuance); let era_emission = relative_era_len.saturating_mul_int(yearly_emission); // 15% to treasury, as per ref 1139. @@ -3405,7 +3405,7 @@ mod multiplier_tests { const MILLISECONDS_PER_DAY: u64 = 24 * 60 * 60 * 1000; #[test] - fn staking_inflation_correct() { + fn staking_inflation_correct_single_era() { let (to_stakers, to_treasury) = super::EraPayout::era_payout( 123, // ignored 456, // ignored @@ -3413,8 +3413,14 @@ mod multiplier_tests { ); // Values are within 0.1% - assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64, max_relative = 0.1); - assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64, max_relative = 0.1); + assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64, max_relative = 0.01); + assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64, max_relative = 0.01); + // Total per day is ~328,797 DOT + assert_relative_eq!( + (to_stakers as f64 + to_treasury as f64), + (328_797 * UNITS) as f64, + max_relative = 0.01 + ); } #[test] @@ -3425,8 +3431,9 @@ mod multiplier_tests { 456, // ignored 2 * MILLISECONDS_PER_DAY, ); - assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64 * 2.0, max_relative = 0.1); - assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64 * 2.0, max_relative = 0.1); + + assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64 * 2.0, max_relative = 0.01); + assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64 * 2.0, max_relative = 0.01); } #[test] @@ -3437,28 +3444,16 @@ mod multiplier_tests { (36525 * MILLISECONDS_PER_DAY) / 100, // 1 year ); - // 8% of the fixed total issuance: 120M Dot per year + // Our yearly emissions is about 120M DOT: let yearly_emission = 120_093_259 * UNITS; - - assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.1); - assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.1); - } - - #[test] - fn staking_inflation_while_year_exact() { - let (to_stakers, to_treasury) = super::EraPayout::era_payout( - 123, // ignored - 456, // ignored - (365625 * MILLISECONDS_PER_DAY) / 100, // 1 year + assert_relative_eq!( + to_stakers as f64 + to_treasury as f64, + yearly_emission as f64, + max_relative = 0.01 ); - // 8% of the fixed total issuance is about 120M Dot per year - let yearly_emission = 120_093_259 * UNITS; - // But also check it exactly: - assert_eq!(to_stakers + to_treasury, 1200932590000000000); - - assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.1); - assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.1); + assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.01); + assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.01); } // 10 years into the future, our values do not overflow. @@ -3467,13 +3462,17 @@ mod multiplier_tests { let (to_stakers, to_treasury) = super::EraPayout::era_payout( 123, // ignored 456, // ignored - (365625 * MILLISECONDS_PER_DAY) / 10, // 10 years + (36525 * MILLISECONDS_PER_DAY) / 10, // 10 years ); let initial_ti: i128 = 15_011_657_390_566_252_333; let projected_total_issuance = (to_stakers as i128 + to_treasury as i128) + initial_ti; // In 2034, there will be about 2.7 billion DOT in existence. - assert_relative_eq!(projected_total_issuance as f64, (2_700_000_0000 * UNITS) as f64, max_relative = 0.1); + assert_relative_eq!( + projected_total_issuance as f64, + (2_700_000_000 * UNITS) as f64, + max_relative = 0.01 + ); } // Print percent per year, just as convenience. @@ -3482,7 +3481,7 @@ mod multiplier_tests { let (to_stakers, to_treasury) = super::EraPayout::era_payout( 123, // ignored 456, // ignored - (365625 * MILLISECONDS_PER_DAY) / 100, // 1 year + (36525 * MILLISECONDS_PER_DAY) / 100, // 1 year ); let yearly_emission = to_stakers + to_treasury; let mut ti: i128 = 15_011_657_390_566_252_333; From 73098e9dab3b914446640fc0b0869c11cfbdb1de Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 8 Oct 2024 18:41:52 +0100 Subject: [PATCH 7/9] CHANGELOG Signed-off-by: Oliver Tale-Yazdi --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 263d11c1dd..4d9cbc5dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ Changelog for the runtimes governed by the Polkadot Fellowship. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] + +### Changed + +Change Polkadot inflation to 120M DOT per year ([polkadot-fellows/runtimes#471](https://github.com/polkadot-fellows/runtimes/pull/471)) + ## [1.3.3] 01.10.2024 ### Changed From 364030dee8b39c99614508460de7381dec3e1f0a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 8 Oct 2024 18:44:07 +0100 Subject: [PATCH 8/9] run tests with 0.1% precision Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index ee2ababa76..927322a472 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -3413,13 +3413,13 @@ mod multiplier_tests { ); // Values are within 0.1% - assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64, max_relative = 0.01); - assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64, max_relative = 0.01); + assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64, max_relative = 0.001); + assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64, max_relative = 0.001); // Total per day is ~328,797 DOT assert_relative_eq!( (to_stakers as f64 + to_treasury as f64), (328_797 * UNITS) as f64, - max_relative = 0.01 + max_relative = 0.001 ); } @@ -3432,8 +3432,8 @@ mod multiplier_tests { 2 * MILLISECONDS_PER_DAY, ); - assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64 * 2.0, max_relative = 0.01); - assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64 * 2.0, max_relative = 0.01); + assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64 * 2.0, max_relative = 0.001); + assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64 * 2.0, max_relative = 0.001); } #[test] @@ -3449,11 +3449,11 @@ mod multiplier_tests { assert_relative_eq!( to_stakers as f64 + to_treasury as f64, yearly_emission as f64, - max_relative = 0.01 + max_relative = 0.001 ); - assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.01); - assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.01); + assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.001); + assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.001); } // 10 years into the future, our values do not overflow. @@ -3471,7 +3471,7 @@ mod multiplier_tests { assert_relative_eq!( projected_total_issuance as f64, (2_700_000_000 * UNITS) as f64, - max_relative = 0.01 + max_relative = 0.001 ); } From a010bdc416b9f184738abbe7522bcf1d88127815 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 8 Oct 2024 18:50:53 +0100 Subject: [PATCH 9/9] fmt Signed-off-by: Oliver Tale-Yazdi --- relay/polkadot/src/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 927322a472..2ee7fdd5c7 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -3432,8 +3432,16 @@ mod multiplier_tests { 2 * MILLISECONDS_PER_DAY, ); - assert_relative_eq!(to_stakers as f64, (279_477 * UNITS) as f64 * 2.0, max_relative = 0.001); - assert_relative_eq!(to_treasury as f64, (49_320 * UNITS) as f64 * 2.0, max_relative = 0.001); + assert_relative_eq!( + to_stakers as f64, + (279_477 * UNITS) as f64 * 2.0, + max_relative = 0.001 + ); + assert_relative_eq!( + to_treasury as f64, + (49_320 * UNITS) as f64 * 2.0, + max_relative = 0.001 + ); } #[test] @@ -3453,7 +3461,11 @@ mod multiplier_tests { ); assert_relative_eq!(to_stakers as f64, yearly_emission as f64 * 0.85, max_relative = 0.001); - assert_relative_eq!(to_treasury as f64, yearly_emission as f64 * 0.15, max_relative = 0.001); + assert_relative_eq!( + to_treasury as f64, + yearly_emission as f64 * 0.15, + max_relative = 0.001 + ); } // 10 years into the future, our values do not overflow.