From 9c949b60cbd063ec900564ea2d688b47000663c6 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 1 Dec 2021 19:03:47 -0500 Subject: [PATCH 01/16] fix genesis chain_specs so round inflation is set based on default blocks per round configured --- node/service/src/chain_spec/moonbase.rs | 26 ++++++++++-------------- node/service/src/chain_spec/moonbeam.rs | 24 +++++++++------------- node/service/src/chain_spec/moonriver.rs | 24 +++++++++------------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index c2a503f6b2..8d5fff4110 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -28,8 +28,8 @@ use moonbase_runtime::{ CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, PolkadotXcmConfig, - Precompiles, Range, SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, - WASM_BINARY, + Precompiles, Range, Runtime, SchedulerConfig, SudoConfig, SystemConfig, + TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -161,24 +161,20 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - InflationInfo { - expect: Range { - min: 100_000 * UNIT, - ideal: 200_000 * UNIT, - max: 500_000 * UNIT, - }, - annual: Range { + InflationInfo::new::( + // annual inflation + Range { min: Perbill::from_percent(4), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5), }, - // 8766 rounds (hours) in a year - round: Range { - min: Perbill::from_parts(Perbill::from_percent(4).deconstruct() / 8766), - ideal: Perbill::from_parts(Perbill::from_percent(5).deconstruct() / 8766), - max: Perbill::from_parts(Perbill::from_percent(5).deconstruct() / 8766), + // staking expectations + Range { + min: 100_000 * MOVR, + ideal: 200_000 * MOVR, + max: 500_000 * MOVR, }, - } + ) } pub fn testnet_genesis( diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index e1207b996d..bc95a52cd0 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -28,7 +28,7 @@ use moonbeam_runtime::{ CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, - SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, + Runtime, SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -144,24 +144,20 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - InflationInfo { - expect: Range { - min: 100_000 * GLMR, - ideal: 200_000 * GLMR, - max: 500_000 * GLMR, - }, - annual: Range { + InflationInfo::new::( + // annual inflation + Range { min: Perbill::from_percent(4), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5), }, - // 8766 rounds (hours) in a year - round: Range { - min: Perbill::from_parts(Perbill::from_percent(4).deconstruct() / 8766), - ideal: Perbill::from_parts(Perbill::from_percent(5).deconstruct() / 8766), - max: Perbill::from_parts(Perbill::from_percent(5).deconstruct() / 8766), + // staking expectations + Range { + min: 100_000 * MOVR, + ideal: 200_000 * MOVR, + max: 500_000 * MOVR, }, - } + ) } pub fn testnet_genesis( diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index 748b8bc13e..e3602df4ad 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -28,7 +28,7 @@ use moonriver_runtime::{ CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, - SchedulerConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, + Runtime, SchedulerConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -140,24 +140,20 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - InflationInfo { - expect: Range { - min: 100_000 * MOVR, - ideal: 200_000 * MOVR, - max: 500_000 * MOVR, - }, - annual: Range { + InflationInfo::new::( + // annual inflation + Range { min: Perbill::from_percent(4), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5), }, - // 8766 rounds (hours) in a year - round: Range { - min: Perbill::from_parts(Perbill::from_percent(4).deconstruct() / 8766), - ideal: Perbill::from_parts(Perbill::from_percent(5).deconstruct() / 8766), - max: Perbill::from_parts(Perbill::from_percent(5).deconstruct() / 8766), + // staking expectations + Range { + min: 100_000 * MOVR, + ideal: 200_000 * MOVR, + max: 500_000 * MOVR, }, - } + ) } pub fn testnet_genesis( From d03c2c56e3c8fb8e542d897a5493ec967b5b6ae6 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 1 Dec 2021 19:21:47 -0500 Subject: [PATCH 02/16] fix build --- node/service/src/chain_spec/moonbase.rs | 6 +++--- node/service/src/chain_spec/moonbeam.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 8d5fff4110..1688820a6b 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -170,9 +170,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { }, // staking expectations Range { - min: 100_000 * MOVR, - ideal: 200_000 * MOVR, - max: 500_000 * MOVR, + min: 100_000 * UNIT, + ideal: 200_000 * UNIT, + max: 500_000 * UNIT, }, ) } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index bc95a52cd0..e79ca5b811 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -153,9 +153,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { }, // staking expectations Range { - min: 100_000 * MOVR, - ideal: 200_000 * MOVR, - max: 500_000 * MOVR, + min: 100_000 * GLMR, + ideal: 200_000 * GLMR, + max: 500_000 * GLMR, }, ) } From d56a379cd933d26158f916e1b81880e2806298df Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 08:59:17 -0500 Subject: [PATCH 03/16] use gorka suggestion to use associated type instead of storage item --- node/service/src/chain_spec/moonbase.rs | 27 +++++++++++++++++------- node/service/src/chain_spec/moonbeam.rs | 27 +++++++++++++++++------- node/service/src/chain_spec/moonriver.rs | 27 +++++++++++++++++------- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 1688820a6b..90662b5599 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -161,20 +161,31 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - InflationInfo::new::( + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * UNIT, + ideal: 200_000 * UNIT, + max: 500_000 * UNIT, + }, // annual inflation - Range { + annual: Range { min: Perbill::from_percent(4), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5), }, - // staking expectations - Range { - min: 100_000 * UNIT, - ideal: 200_000 * UNIT, - max: 500_000 * UNIT, + round: Range { + min: Perbill::from_parts( + Perbill::from_percent(4).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), + ideal: Perbill::from_parts( + Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), + max: Perbill::from_parts( + Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), }, - ) + } } pub fn testnet_genesis( diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index e79ca5b811..1ee928c259 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -144,20 +144,31 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - InflationInfo::new::( + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * UNIT, + ideal: 200_000 * UNIT, + max: 500_000 * UNIT, + }, // annual inflation - Range { + annual: Range { min: Perbill::from_percent(4), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5), }, - // staking expectations - Range { - min: 100_000 * GLMR, - ideal: 200_000 * GLMR, - max: 500_000 * GLMR, + round: Range { + min: Perbill::from_parts( + Perbill::from_percent(4).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), + ideal: Perbill::from_parts( + Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), + max: Perbill::from_parts( + Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), }, - ) + } } pub fn testnet_genesis( diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index e3602df4ad..048c5d9442 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -140,20 +140,31 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - InflationInfo::new::( + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * UNIT, + ideal: 200_000 * UNIT, + max: 500_000 * UNIT, + }, // annual inflation - Range { + annual: Range { min: Perbill::from_percent(4), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5), }, - // staking expectations - Range { - min: 100_000 * MOVR, - ideal: 200_000 * MOVR, - max: 500_000 * MOVR, + round: Range { + min: Perbill::from_parts( + Perbill::from_percent(4).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), + ideal: Perbill::from_parts( + Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), + max: Perbill::from_parts( + Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + ), }, - ) + } } pub fn testnet_genesis( From 26f8809f10e31fb6a67f1b0b4d65ef5b430de1d8 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 09:21:56 -0500 Subject: [PATCH 04/16] fix units --- node/service/src/chain_spec/moonbeam.rs | 6 +++--- node/service/src/chain_spec/moonriver.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 1ee928c259..ba6ccb17e7 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -147,9 +147,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { InflationInfo { // staking expectations expect: Range { - min: 100_000 * UNIT, - ideal: 200_000 * UNIT, - max: 500_000 * UNIT, + min: 100_000 * GLMR, + ideal: 200_000 * GLMR, + max: 500_000 * GLMR, }, // annual inflation annual: Range { diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index 048c5d9442..3e6c08affd 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -143,9 +143,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { InflationInfo { // staking expectations expect: Range { - min: 100_000 * UNIT, - ideal: 200_000 * UNIT, - max: 500_000 * UNIT, + min: 100_000 * MOVR, + ideal: 200_000 * MOVR, + max: 500_000 * MOVR, }, // annual inflation annual: Range { From 0fefea6d025aca7b86201c06f014a99366332d47 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 10:00:29 -0500 Subject: [PATCH 05/16] export ParachainStakingConfigTrait from runtime to use in chainspecs --- node/service/src/chain_spec/moonbase.rs | 15 +++++++++------ node/service/src/chain_spec/moonbeam.rs | 14 +++++++++----- node/service/src/chain_spec/moonriver.rs | 14 +++++++++----- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/src/lib.rs | 2 +- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 90662b5599..262525cdef 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -27,9 +27,9 @@ use moonbase_runtime::{ currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, - MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, PolkadotXcmConfig, - Precompiles, Range, Runtime, SchedulerConfig, SudoConfig, SystemConfig, - TechCommitteeCollectiveConfig, WASM_BINARY, + MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, + ParachainStakingConfigTrait, PolkadotXcmConfig, Precompiles, Range, Runtime, SchedulerConfig, + SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -176,13 +176,16 @@ pub fn moonbeam_inflation_config() -> InflationInfo { }, round: Range { min: Perbill::from_parts( - Perbill::from_percent(4).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(4).deconstruct() + / ::DefaultBlocksPerRound::get(), ), ideal: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(5).deconstruct() + / ::DefaultBlocksPerRound::get(), ), max: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(5).deconstruct() + / ::DefaultBlocksPerRound::get(), ), }, } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index ba6ccb17e7..db6ee1c1ea 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -27,8 +27,9 @@ use moonbeam_runtime::{ currency::GLMR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, - MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, - Runtime, SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, + MaintenanceModeConfig, ParachainBondConfigTrait, ParachainInfoConfig, ParachainStakingConfig, + Precompiles, Range, Runtime, SchedulerConfig, SudoConfig, SystemConfig, + TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -159,13 +160,16 @@ pub fn moonbeam_inflation_config() -> InflationInfo { }, round: Range { min: Perbill::from_parts( - Perbill::from_percent(4).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(4).deconstruct() + / ::DefaultBlocksPerRound::get(), ), ideal: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(5).deconstruct() + / ::DefaultBlocksPerRound::get(), ), max: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(5).deconstruct() + / ::DefaultBlocksPerRound::get(), ), }, } diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index 3e6c08affd..c1f908bd24 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -27,8 +27,9 @@ use moonriver_runtime::{ currency::MOVR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, - MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, - Runtime, SchedulerConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, + MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, + ParachainStakingConfigTrait, Precompiles, Range, Runtime, SchedulerConfig, SystemConfig, + TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -155,13 +156,16 @@ pub fn moonbeam_inflation_config() -> InflationInfo { }, round: Range { min: Perbill::from_parts( - Perbill::from_percent(4).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(4).deconstruct() + / ::DefaultBlocksPerRound::get(), ), ideal: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(5).deconstruct() + / ::DefaultBlocksPerRound::get(), ), max: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() / Runtime::DefaultBlocksPerRound::get(), + Perbill::from_percent(5).deconstruct() + / ::DefaultBlocksPerRound::get(), ), }, } diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 261ebe4bd6..c1b5fcb3f4 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -76,7 +76,7 @@ use pallet_evm::{ Runner, }; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -pub use parachain_staking::{InflationInfo, Range}; +pub use parachain_staking::{Config as ParachainStakingConfigTrait, InflationInfo, Range}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 9a85626710..377f946b59 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -56,7 +56,7 @@ use pallet_evm::{ Runner, }; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -pub use parachain_staking::{InflationInfo, Range}; +pub use parachain_staking::{Config as ParachainStakingConfigTrait, InflationInfo, Range}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 9541e88c10..5e64e3ac9f 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -56,7 +56,7 @@ use pallet_evm::{ Runner, }; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -pub use parachain_staking::{InflationInfo, Range}; +pub use parachain_staking::{Config as ParachainStakingConfigTrait, InflationInfo, Range}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; From 9ab44c5a505a53889ff701a0cfdaceeaf94c7ae5 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 10:14:20 -0500 Subject: [PATCH 06/16] fix --- node/service/src/chain_spec/moonbeam.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index db6ee1c1ea..105ffc66df 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -27,9 +27,8 @@ use moonbeam_runtime::{ currency::GLMR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, - MaintenanceModeConfig, ParachainBondConfigTrait, ParachainInfoConfig, ParachainStakingConfig, - Precompiles, Range, Runtime, SchedulerConfig, SudoConfig, SystemConfig, - TechCommitteeCollectiveConfig, WASM_BINARY, + MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, + Runtime, SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; From 4be3630f3288448dbb1368696ead82bdc6fe8e75 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 10:19:37 -0500 Subject: [PATCH 07/16] revert export use direct const getter --- node/service/src/chain_spec/moonbase.rs | 12 ++++++------ node/service/src/chain_spec/moonbeam.rs | 6 +++--- node/service/src/chain_spec/moonriver.rs | 11 +++++------ runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/src/lib.rs | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 262525cdef..aacc5fb20b 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -27,9 +27,9 @@ use moonbase_runtime::{ currency::UNIT, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, - MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, - ParachainStakingConfigTrait, PolkadotXcmConfig, Precompiles, Range, Runtime, SchedulerConfig, - SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, + MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, PolkadotXcmConfig, + Precompiles, Range, SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, + WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -177,15 +177,15 @@ pub fn moonbeam_inflation_config() -> InflationInfo { round: Range { min: Perbill::from_parts( Perbill::from_percent(4).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonbase_runtime::DefaultBlocksPerRound::get(), ), ideal: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonbase_runtime::DefaultBlocksPerRound::get(), ), max: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonbase_runtime::DefaultBlocksPerRound::get(), ), }, } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 105ffc66df..f4920a75fe 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -160,15 +160,15 @@ pub fn moonbeam_inflation_config() -> InflationInfo { round: Range { min: Perbill::from_parts( Perbill::from_percent(4).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonbeam_runtime::DefaultBlocksPerRound::get(), ), ideal: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonbeam_runtime::DefaultBlocksPerRound::get(), ), max: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonbeam_runtime::DefaultBlocksPerRound::get(), ), }, } diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index c1f908bd24..6f775c517a 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -27,9 +27,8 @@ use moonriver_runtime::{ currency::MOVR, AccountId, AuthorFilterConfig, AuthorMappingConfig, Balance, BalancesConfig, CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, - MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, - ParachainStakingConfigTrait, Precompiles, Range, Runtime, SchedulerConfig, SystemConfig, - TechCommitteeCollectiveConfig, WASM_BINARY, + MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, + SchedulerConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; @@ -157,15 +156,15 @@ pub fn moonbeam_inflation_config() -> InflationInfo { round: Range { min: Perbill::from_parts( Perbill::from_percent(4).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonriver_runtime::DefaultBlocksPerRound::get(), ), ideal: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonriver_runtime::DefaultBlocksPerRound::get(), ), max: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / ::DefaultBlocksPerRound::get(), + / moonriver_runtime::DefaultBlocksPerRound::get(), ), }, } diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index c1b5fcb3f4..261ebe4bd6 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -76,7 +76,7 @@ use pallet_evm::{ Runner, }; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -pub use parachain_staking::{Config as ParachainStakingConfigTrait, InflationInfo, Range}; +pub use parachain_staking::{InflationInfo, Range}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 377f946b59..9a85626710 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -56,7 +56,7 @@ use pallet_evm::{ Runner, }; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -pub use parachain_staking::{Config as ParachainStakingConfigTrait, InflationInfo, Range}; +pub use parachain_staking::{InflationInfo, Range}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 5e64e3ac9f..9541e88c10 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -56,7 +56,7 @@ use pallet_evm::{ Runner, }; use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; -pub use parachain_staking::{Config as ParachainStakingConfigTrait, InflationInfo, Range}; +pub use parachain_staking::{InflationInfo, Range}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; From e61bfd84dda06ce548f2eb418ffcc371f31a95bb Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 10:36:28 -0500 Subject: [PATCH 08/16] unused import --- node/service/src/chain_spec/moonbeam.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index f4920a75fe..5d51ff98a3 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -28,7 +28,7 @@ use moonbeam_runtime::{ CouncilCollectiveConfig, CrowdloanRewardsConfig, DemocracyConfig, EVMConfig, EthereumChainIdConfig, EthereumConfig, GenesisAccount, GenesisConfig, InflationInfo, MaintenanceModeConfig, ParachainInfoConfig, ParachainStakingConfig, Precompiles, Range, - Runtime, SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, + SchedulerConfig, SudoConfig, SystemConfig, TechCommitteeCollectiveConfig, WASM_BINARY, }; use nimbus_primitives::NimbusId; use sc_service::ChainType; From 6dce348fb880db4d7dbbf5b5775f08e8a83b65f3 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 11:17:16 -0500 Subject: [PATCH 09/16] try TS inflation genesis config --- tests/tests/test-staking.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/tests/test-staking.ts b/tests/tests/test-staking.ts index c0dc333950..e75a56e592 100644 --- a/tests/tests/test-staking.ts +++ b/tests/tests/test-staking.ts @@ -56,11 +56,12 @@ describeDevMoonbeam("Staking - Genesis", (context) => { expect(inflationInfo.toHuman()["annual"]["ideal"]).to.eq("5.00%"); expect(inflationInfo.toHuman()["annual"]["max"]).to.eq("5.00%"); expect(inflationInfo.toHuman()["round"]["min"]).to.eq("0.00%"); - expect(Number(inflationInfo["round"]["min"])).to.eq(4563); // 4% / 8766 * 10^9 + // what is new blocks per + expect(Number(inflationInfo["round"]["min"])).to.eq(66666); // 4% / blocks per year * 10^9 expect(inflationInfo.toHuman()["round"]["ideal"]).to.eq("0.00%"); - expect(Number(inflationInfo["round"]["ideal"])).to.eq(5703); // 5% / 8766 * 10^9 + expect(Number(inflationInfo["round"]["ideal"])).to.eq(83332); // 5% / blocks per year * 10^9 expect(inflationInfo.toHuman()["round"]["max"]).to.eq("0.00%"); - expect(Number(inflationInfo["round"]["max"])).to.eq(5703); // 5% / 8766 * 10^9 + expect(Number(inflationInfo["round"]["max"])).to.eq(83332); // 5% / blocks per year * 10^9 }); }); From 8fd339421a9ed76cb388eaf563e6c5125c026023 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 11:33:56 -0500 Subject: [PATCH 10/16] fix arithmetic --- node/service/src/chain_spec/moonbase.rs | 9 ++++++--- node/service/src/chain_spec/moonbeam.rs | 9 ++++++--- node/service/src/chain_spec/moonriver.rs | 9 ++++++--- tests/tests/test-staking.ts | 1 - 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index aacc5fb20b..7e1fc0caa5 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -161,6 +161,9 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { + const SECONDS_PER_YEAR: u32 = 31557600; + const SECONDS_PER_BLOCK: u32 = 12; + const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; InflationInfo { // staking expectations expect: Range { @@ -177,15 +180,15 @@ pub fn moonbeam_inflation_config() -> InflationInfo { round: Range { min: Perbill::from_parts( Perbill::from_percent(4).deconstruct() - / moonbase_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get()), ), ideal: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / moonbase_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get()), ), max: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / moonbase_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get()), ), }, } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 5d51ff98a3..05660fc9e6 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -144,6 +144,9 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { + const SECONDS_PER_YEAR: u32 = 31557600; + const SECONDS_PER_BLOCK: u32 = 12; + const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; InflationInfo { // staking expectations expect: Range { @@ -160,15 +163,15 @@ pub fn moonbeam_inflation_config() -> InflationInfo { round: Range { min: Perbill::from_parts( Perbill::from_percent(4).deconstruct() - / moonbeam_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get()), ), ideal: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / moonbeam_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get()), ), max: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / moonbeam_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get()), ), }, } diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index 6f775c517a..a1086087fc 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -140,6 +140,9 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { + const SECONDS_PER_YEAR: u32 = 31557600; + const SECONDS_PER_BLOCK: u32 = 12; + const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; InflationInfo { // staking expectations expect: Range { @@ -156,15 +159,15 @@ pub fn moonbeam_inflation_config() -> InflationInfo { round: Range { min: Perbill::from_parts( Perbill::from_percent(4).deconstruct() - / moonriver_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get()), ), ideal: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / moonriver_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get()), ), max: Perbill::from_parts( Perbill::from_percent(5).deconstruct() - / moonriver_runtime::DefaultBlocksPerRound::get(), + / (BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get()), ), }, } diff --git a/tests/tests/test-staking.ts b/tests/tests/test-staking.ts index e75a56e592..9a4a4d6ee0 100644 --- a/tests/tests/test-staking.ts +++ b/tests/tests/test-staking.ts @@ -56,7 +56,6 @@ describeDevMoonbeam("Staking - Genesis", (context) => { expect(inflationInfo.toHuman()["annual"]["ideal"]).to.eq("5.00%"); expect(inflationInfo.toHuman()["annual"]["max"]).to.eq("5.00%"); expect(inflationInfo.toHuman()["round"]["min"]).to.eq("0.00%"); - // what is new blocks per expect(Number(inflationInfo["round"]["min"])).to.eq(66666); // 4% / blocks per year * 10^9 expect(inflationInfo.toHuman()["round"]["ideal"]).to.eq("0.00%"); expect(Number(inflationInfo["round"]["ideal"])).to.eq(83332); // 5% / blocks per year * 10^9 From 73c5f690d883aa14a45f9986814fd94209405896 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 11:54:36 -0500 Subject: [PATCH 11/16] fix annual to round inflation in genesis --- Cargo.lock | 1 + node/service/Cargo.toml | 1 + node/service/src/chain_spec/moonbase.rs | 26 +++++++++------------- node/service/src/chain_spec/moonbeam.rs | 26 +++++++++------------- node/service/src/chain_spec/moonriver.rs | 26 +++++++++------------- pallets/parachain-staking/src/inflation.rs | 7 ++++-- 6 files changed, 40 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31d4418019..ee316c4cc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5516,6 +5516,7 @@ dependencies = [ "pallet-sudo", "pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc-runtime-api", + "parachain-staking", "parity-scale-codec", "parking_lot 0.9.0", "polkadot-cli", diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index a2db03a187..290cffbb35 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -41,6 +41,7 @@ moonbeam-rpc-txpool = { path = "../../client/rpc/txpool" } moonbase-runtime = { path = "../../runtime/moonbase", optional = true } moonbeam-runtime = { path = "../../runtime/moonbeam", optional = true } moonriver-runtime = { path = "../../runtime/moonriver", optional = true } +parachain-staking = { path = "../../pallets/parachain-staking", optional = true } # Substrate frame-system-rpc-runtime-api = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.12" } diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 7e1fc0caa5..6476df16a6 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -161,9 +161,14 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - const SECONDS_PER_YEAR: u32 = 31557600; - const SECONDS_PER_BLOCK: u32 = 12; - const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; + fn to_round_inflation(annual: Perbill) -> Perbill { + use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get(), + ) + } InflationInfo { // staking expectations expect: Range { @@ -178,18 +183,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { max: Perbill::from_percent(5), }, round: Range { - min: Perbill::from_parts( - Perbill::from_percent(4).deconstruct() - / (BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get()), - ), - ideal: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() - / (BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get()), - ), - max: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() - / (BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get()), - ), + min: to_round_inflation(Perbill::from_percent(4)), + ideal: to_round_inflation(Perbill::from_percent(5)), + max: to_round_inflation(Perbill::from_percent(5)), }, } } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 05660fc9e6..a2991540a8 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -144,9 +144,14 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - const SECONDS_PER_YEAR: u32 = 31557600; - const SECONDS_PER_BLOCK: u32 = 12; - const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; + fn to_round_inflation(annual: Perbill) -> Perbill { + use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get(), + ) + } InflationInfo { // staking expectations expect: Range { @@ -161,18 +166,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { max: Perbill::from_percent(5), }, round: Range { - min: Perbill::from_parts( - Perbill::from_percent(4).deconstruct() - / (BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get()), - ), - ideal: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() - / (BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get()), - ), - max: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() - / (BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get()), - ), + min: to_round_inflation(Perbill::from_percent(4)), + ideal: to_round_inflation(Perbill::from_percent(5)), + max: to_round_inflation(Perbill::from_percent(5)), }, } } diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index a1086087fc..e1a0225c84 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -140,9 +140,14 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - const SECONDS_PER_YEAR: u32 = 31557600; - const SECONDS_PER_BLOCK: u32 = 12; - const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; + fn to_round_inflation(annual: Perbill) -> Perbill { + use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get(), + ) + } InflationInfo { // staking expectations expect: Range { @@ -157,18 +162,9 @@ pub fn moonbeam_inflation_config() -> InflationInfo { max: Perbill::from_percent(5), }, round: Range { - min: Perbill::from_parts( - Perbill::from_percent(4).deconstruct() - / (BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get()), - ), - ideal: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() - / (BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get()), - ), - max: Perbill::from_parts( - Perbill::from_percent(5).deconstruct() - / (BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get()), - ), + min: to_round_inflation(Perbill::from_percent(4)), + ideal: to_round_inflation(Perbill::from_percent(5)), + max: to_round_inflation(Perbill::from_percent(5)), }, } } diff --git a/pallets/parachain-staking/src/inflation.rs b/pallets/parachain-staking/src/inflation.rs index af3e7dcb94..0d1bcca8eb 100644 --- a/pallets/parachain-staking/src/inflation.rs +++ b/pallets/parachain-staking/src/inflation.rs @@ -28,7 +28,7 @@ use substrate_fixed::types::{I32F32, I64F64}; const SECONDS_PER_YEAR: u32 = 31557600; const SECONDS_PER_BLOCK: u32 = 12; -const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; +pub const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; fn rounds_per_year() -> u32 { let blocks_per_round = >::round().length; @@ -60,7 +60,10 @@ impl From for Range { } /// Convert an annual inflation to a round inflation /// round = 1 - (1+annual)^(1/rounds_per_year) -fn perbill_annual_to_perbill_round(annual: Range, rounds_per_year: u32) -> Range { +pub fn perbill_annual_to_perbill_round( + annual: Range, + rounds_per_year: u32, +) -> Range { let exponent = I32F32::from_num(1) / I32F32::from_num(rounds_per_year); let annual_to_round = |annual: Perbill| -> Perbill { let x = I32F32::from_num(annual.deconstruct()) / I32F32::from_num(Perbill::ACCURACY); From 6df6d287b20e2d4501ff4e21ee35a8cfc6903c17 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 11:56:02 -0500 Subject: [PATCH 12/16] fix --- node/service/src/chain_spec/moonbeam.rs | 2 +- node/service/src/chain_spec/moonriver.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index a2991540a8..3319364a7d 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -149,7 +149,7 @@ pub fn moonbeam_inflation_config() -> InflationInfo { perbill_annual_to_perbill_round( annual, // rounds per year - BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get(), + BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get(), ) } InflationInfo { diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index e1a0225c84..aead65824c 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -145,7 +145,7 @@ pub fn moonbeam_inflation_config() -> InflationInfo { perbill_annual_to_perbill_round( annual, // rounds per year - BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get(), + BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get(), ) } InflationInfo { From aae47f0122250d041693fb2b0a16e72b5cfc92ab Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 12:10:19 -0500 Subject: [PATCH 13/16] fix --- node/service/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 290cffbb35..e4ed8da644 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -36,12 +36,12 @@ moonbeam-rpc-primitives-debug = { path = "../../primitives/rpc/debug" } moonbeam-rpc-primitives-txpool = { path = "../../primitives/rpc/txpool" } moonbeam-rpc-trace = { path = "../../client/rpc/trace" } moonbeam-rpc-txpool = { path = "../../client/rpc/txpool" } +parachain-staking = { path = "../../pallets/parachain-staking" } # Moonbeam runtimes moonbase-runtime = { path = "../../runtime/moonbase", optional = true } moonbeam-runtime = { path = "../../runtime/moonbeam", optional = true } moonriver-runtime = { path = "../../runtime/moonriver", optional = true } -parachain-staking = { path = "../../pallets/parachain-staking", optional = true } # Substrate frame-system-rpc-runtime-api = { git = "https://github.com/purestake/substrate", branch = "moonbeam-polkadot-v0.9.12" } From e0038efc74c0485548b0940ad9608b480f2c9823 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 12:16:24 -0500 Subject: [PATCH 14/16] pub mod inflation --- pallets/parachain-staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index 413a9bceb1..a1883dad79 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -47,7 +47,7 @@ #[cfg(any(test, feature = "runtime-benchmarks"))] mod benchmarks; -mod inflation; +pub mod inflation; pub mod migrations; #[cfg(test)] mod mock; From c4b89244744e8d394420ddd2e33a47e2f72b4187 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 12:40:21 -0500 Subject: [PATCH 15/16] compiles still TS tests off --- node/service/src/chain_spec/moonbase.rs | 19 ++++++++----------- node/service/src/chain_spec/moonbeam.rs | 19 ++++++++----------- node/service/src/chain_spec/moonriver.rs | 19 ++++++++----------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/node/service/src/chain_spec/moonbase.rs b/node/service/src/chain_spec/moonbase.rs index 6476df16a6..fef53efa41 100644 --- a/node/service/src/chain_spec/moonbase.rs +++ b/node/service/src/chain_spec/moonbase.rs @@ -161,7 +161,7 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - fn to_round_inflation(annual: Perbill) -> Perbill { + fn to_round_inflation(annual: Range) -> Range { use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; perbill_annual_to_perbill_round( annual, @@ -169,6 +169,11 @@ pub fn moonbeam_inflation_config() -> InflationInfo { BLOCKS_PER_YEAR / moonbase_runtime::DefaultBlocksPerRound::get(), ) } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; InflationInfo { // staking expectations expect: Range { @@ -177,16 +182,8 @@ pub fn moonbeam_inflation_config() -> InflationInfo { max: 500_000 * UNIT, }, // annual inflation - annual: Range { - min: Perbill::from_percent(4), - ideal: Perbill::from_percent(5), - max: Perbill::from_percent(5), - }, - round: Range { - min: to_round_inflation(Perbill::from_percent(4)), - ideal: to_round_inflation(Perbill::from_percent(5)), - max: to_round_inflation(Perbill::from_percent(5)), - }, + annual, + round: to_round_inflation(annual), } } diff --git a/node/service/src/chain_spec/moonbeam.rs b/node/service/src/chain_spec/moonbeam.rs index 3319364a7d..4a47cfd7f0 100644 --- a/node/service/src/chain_spec/moonbeam.rs +++ b/node/service/src/chain_spec/moonbeam.rs @@ -144,7 +144,7 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - fn to_round_inflation(annual: Perbill) -> Perbill { + fn to_round_inflation(annual: Range) -> Range { use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; perbill_annual_to_perbill_round( annual, @@ -152,6 +152,11 @@ pub fn moonbeam_inflation_config() -> InflationInfo { BLOCKS_PER_YEAR / moonbeam_runtime::DefaultBlocksPerRound::get(), ) } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; InflationInfo { // staking expectations expect: Range { @@ -160,16 +165,8 @@ pub fn moonbeam_inflation_config() -> InflationInfo { max: 500_000 * GLMR, }, // annual inflation - annual: Range { - min: Perbill::from_percent(4), - ideal: Perbill::from_percent(5), - max: Perbill::from_percent(5), - }, - round: Range { - min: to_round_inflation(Perbill::from_percent(4)), - ideal: to_round_inflation(Perbill::from_percent(5)), - max: to_round_inflation(Perbill::from_percent(5)), - }, + annual, + round: to_round_inflation(annual), } } diff --git a/node/service/src/chain_spec/moonriver.rs b/node/service/src/chain_spec/moonriver.rs index aead65824c..8ce76f7686 100644 --- a/node/service/src/chain_spec/moonriver.rs +++ b/node/service/src/chain_spec/moonriver.rs @@ -140,7 +140,7 @@ pub fn get_chain_spec(para_id: ParaId) -> ChainSpec { } pub fn moonbeam_inflation_config() -> InflationInfo { - fn to_round_inflation(annual: Perbill) -> Perbill { + fn to_round_inflation(annual: Range) -> Range { use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; perbill_annual_to_perbill_round( annual, @@ -148,6 +148,11 @@ pub fn moonbeam_inflation_config() -> InflationInfo { BLOCKS_PER_YEAR / moonriver_runtime::DefaultBlocksPerRound::get(), ) } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; InflationInfo { // staking expectations expect: Range { @@ -156,16 +161,8 @@ pub fn moonbeam_inflation_config() -> InflationInfo { max: 500_000 * MOVR, }, // annual inflation - annual: Range { - min: Perbill::from_percent(4), - ideal: Perbill::from_percent(5), - max: Perbill::from_percent(5), - }, - round: Range { - min: to_round_inflation(Perbill::from_percent(4)), - ideal: to_round_inflation(Perbill::from_percent(5)), - max: to_round_inflation(Perbill::from_percent(5)), - }, + annual, + round: to_round_inflation(annual), } } From cf4e2f1cb6e43bf9e04ddb4c7b59c2734604ab25 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 2 Dec 2021 13:37:04 -0500 Subject: [PATCH 16/16] fix ts --- tests/tests/test-staking.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/tests/test-staking.ts b/tests/tests/test-staking.ts index 9a4a4d6ee0..221da8cf39 100644 --- a/tests/tests/test-staking.ts +++ b/tests/tests/test-staking.ts @@ -56,11 +56,11 @@ describeDevMoonbeam("Staking - Genesis", (context) => { expect(inflationInfo.toHuman()["annual"]["ideal"]).to.eq("5.00%"); expect(inflationInfo.toHuman()["annual"]["max"]).to.eq("5.00%"); expect(inflationInfo.toHuman()["round"]["min"]).to.eq("0.00%"); - expect(Number(inflationInfo["round"]["min"])).to.eq(66666); // 4% / blocks per year * 10^9 + expect(Number(inflationInfo["round"]["min"])).to.eq(8949); // 4% / blocks per year * 10^9 expect(inflationInfo.toHuman()["round"]["ideal"]).to.eq("0.00%"); - expect(Number(inflationInfo["round"]["ideal"])).to.eq(83332); // 5% / blocks per year * 10^9 + expect(Number(inflationInfo["round"]["ideal"])).to.eq(11132); // 5% / blocks per year * 10^9 expect(inflationInfo.toHuman()["round"]["max"]).to.eq("0.00%"); - expect(Number(inflationInfo["round"]["max"])).to.eq(83332); // 5% / blocks per year * 10^9 + expect(Number(inflationInfo["round"]["max"])).to.eq(11132); // 5% / blocks per year * 10^9 }); });