From 7676a861cda650d8f72e947231c4f6f42768c4d4 Mon Sep 17 00:00:00 2001 From: brentstone Date: Fri, 15 Dec 2023 15:56:53 -0500 Subject: [PATCH 1/2] move pos gain params to PosParams --- apps/src/lib/config/genesis.rs | 4 -- apps/src/lib/config/genesis/chain.rs | 8 +-- apps/src/lib/config/genesis/templates.rs | 12 ++--- .../lib/node/ledger/shell/finalize_block.rs | 9 ++-- apps/src/lib/node/ledger/shell/mod.rs | 2 - apps/src/lib/node/ledger/storage/mod.rs | 2 - core/src/ledger/masp_conversions.rs | 2 - core/src/ledger/parameters/mod.rs | 54 ------------------- core/src/ledger/parameters/storage.rs | 22 -------- core/src/ledger/storage/mod.rs | 2 - genesis/localnet/parameters.toml | 8 +-- genesis/starter/parameters.toml | 8 +-- proof_of_stake/src/parameters.rs | 8 +++ 13 files changed, 27 insertions(+), 114 deletions(-) diff --git a/apps/src/lib/config/genesis.rs b/apps/src/lib/config/genesis.rs index f7da635257..4c9f013b4f 100644 --- a/apps/src/lib/config/genesis.rs +++ b/apps/src/lib/config/genesis.rs @@ -287,10 +287,6 @@ pub struct Parameters { pub epochs_per_year: u64, /// Maximum amount of signatures per transaction pub max_signatures_per_transaction: u8, - /// PoS gain p (read only) - pub pos_gain_p: Dec, - /// PoS gain d (read only) - pub pos_gain_d: Dec, /// PoS staked ratio (read + write for every epoch) pub staked_ratio: Dec, /// PoS inflation amount from the last epoch (read + write for every epoch) diff --git a/apps/src/lib/config/genesis/chain.rs b/apps/src/lib/config/genesis/chain.rs index d8e57f11f6..6f04281cdb 100644 --- a/apps/src/lib/config/genesis/chain.rs +++ b/apps/src/lib/config/genesis/chain.rs @@ -267,8 +267,6 @@ impl Finalized { tx_whitelist, implicit_vp, epochs_per_year, - pos_gain_p, - pos_gain_d, max_signatures_per_transaction, fee_unshielding_gas_limit, fee_unshielding_descriptions_limit, @@ -311,8 +309,6 @@ impl Finalized { tx_whitelist, implicit_vp_code_hash, epochs_per_year, - pos_gain_p, - pos_gain_d, staked_ratio, pos_inflation_amount: Amount::native_whole(pos_inflation_amount), max_proposal_bytes, @@ -350,6 +346,8 @@ impl Finalized { validator_stake_threshold, liveness_window_check, liveness_threshold, + rewards_gain_p, + rewards_gain_d, } = self.parameters.pos_params.clone(); namada::proof_of_stake::parameters::PosParams { @@ -368,6 +366,8 @@ impl Finalized { validator_stake_threshold, liveness_window_check, liveness_threshold, + rewards_gain_p, + rewards_gain_d, }, max_proposal_period: self.parameters.gov_params.max_proposal_period, } diff --git a/apps/src/lib/config/genesis/templates.rs b/apps/src/lib/config/genesis/templates.rs index 62209dd24d..e5d09da1e7 100644 --- a/apps/src/lib/config/genesis/templates.rs +++ b/apps/src/lib/config/genesis/templates.rs @@ -276,10 +276,6 @@ pub struct ChainParams { pub implicit_vp: String, /// Expected number of epochs per year pub epochs_per_year: u64, - /// PoS gain p - pub pos_gain_p: Dec, - /// PoS gain d - pub pos_gain_d: Dec, /// Maximum number of signature per transaction pub max_signatures_per_transaction: u8, /// Max gas for block @@ -307,8 +303,6 @@ impl ChainParams { tx_whitelist, implicit_vp, epochs_per_year, - pos_gain_p, - pos_gain_d, max_signatures_per_transaction, max_block_gas, fee_unshielding_gas_limit, @@ -354,8 +348,6 @@ impl ChainParams { tx_whitelist, implicit_vp, epochs_per_year, - pos_gain_p, - pos_gain_d, max_signatures_per_transaction, max_block_gas, fee_unshielding_gas_limit, @@ -410,6 +402,10 @@ pub struct PosParams { /// The minimum required activity of consensus validators, in percentage, /// over the `liveness_window_check` pub liveness_threshold: Dec, + /// PoS gain p (read only) + pub rewards_gain_p: Dec, + /// PoS gain d (read only) + pub rewards_gain_d: Dec, } #[derive( diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 239b7b35da..702262bf7d 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -645,12 +645,6 @@ where let epochs_per_year: u64 = self .read_storage_key(¶ms_storage::get_epochs_per_year_key()) .expect("Epochs per year should exist in storage"); - let pos_p_gain_nom: Dec = self - .read_storage_key(¶ms_storage::get_pos_gain_p_key()) - .expect("PoS P-gain factor should exist in storage"); - let pos_d_gain_nom: Dec = self - .read_storage_key(¶ms_storage::get_pos_gain_d_key()) - .expect("PoS D-gain factor should exist in storage"); let pos_last_staked_ratio: Dec = self .read_storage_key(¶ms_storage::get_staked_ratio_key()) @@ -658,6 +652,7 @@ where let pos_last_inflation_amount: token::Amount = self .read_storage_key(¶ms_storage::get_pos_inflation_amount_key()) .expect("PoS inflation amount should exist in storage"); + // Read from PoS storage let total_tokens: token::Amount = self .read_storage_key(&token::minted_balance_key( @@ -668,6 +663,8 @@ where read_total_stake(&self.wl_storage, ¶ms, last_epoch)?; let pos_locked_ratio_target = params.target_staked_ratio; let pos_max_inflation_rate = params.max_inflation_rate; + let pos_p_gain_nom = params.rewards_gain_p; + let pos_d_gain_nom = params.rewards_gain_d; // Run rewards PD controller let pos_controller = inflation::RewardsController { diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index 8e33bf87bb..00b70bedc3 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -2157,8 +2157,6 @@ mod test_utils { implicit_vp_code_hash: Default::default(), epochs_per_year: 365, max_signatures_per_transaction: 10, - pos_gain_p: Default::default(), - pos_gain_d: Default::default(), staked_ratio: Default::default(), pos_inflation_amount: Default::default(), fee_unshielding_gas_limit: 0, diff --git a/apps/src/lib/node/ledger/storage/mod.rs b/apps/src/lib/node/ledger/storage/mod.rs index 4a02b2bcf9..58ae90ce88 100644 --- a/apps/src/lib/node/ledger/storage/mod.rs +++ b/apps/src/lib/node/ledger/storage/mod.rs @@ -162,8 +162,6 @@ mod tests { implicit_vp_code_hash: Default::default(), epochs_per_year: 365, max_signatures_per_transaction: 10, - pos_gain_p: Default::default(), - pos_gain_d: Default::default(), staked_ratio: Default::default(), pos_inflation_amount: Default::default(), fee_unshielding_gas_limit: 0, diff --git a/core/src/ledger/masp_conversions.rs b/core/src/ledger/masp_conversions.rs index ab915c22e2..f7b7c2568a 100644 --- a/core/src/ledger/masp_conversions.rs +++ b/core/src/ledger/masp_conversions.rs @@ -550,8 +550,6 @@ mod tests { implicit_vp_code_hash: Default::default(), epochs_per_year: 365, max_signatures_per_transaction: 10, - pos_gain_p: Default::default(), - pos_gain_d: Default::default(), staked_ratio: Default::default(), pos_inflation_amount: Default::default(), fee_unshielding_gas_limit: 0, diff --git a/core/src/ledger/parameters/mod.rs b/core/src/ledger/parameters/mod.rs index f8f33d9768..9b768f6d69 100644 --- a/core/src/ledger/parameters/mod.rs +++ b/core/src/ledger/parameters/mod.rs @@ -55,10 +55,6 @@ pub struct Parameters { pub epochs_per_year: u64, /// Maximum number of signature per transaction pub max_signatures_per_transaction: u8, - /// PoS gain p (read only) - pub pos_gain_p: Dec, - /// PoS gain d (read only) - pub pos_gain_d: Dec, /// PoS staked ratio (read + write for every epoch) pub staked_ratio: Dec, /// PoS inflation amount from the last epoch (read + write for every epoch) @@ -129,8 +125,6 @@ impl Parameters { implicit_vp_code_hash, epochs_per_year, max_signatures_per_transaction, - pos_gain_p, - pos_gain_d, staked_ratio, pos_inflation_amount, minimum_gas_price, @@ -208,12 +202,6 @@ impl Parameters { max_signatures_per_transaction, )?; - let pos_gain_p_key = storage::get_pos_gain_p_key(); - storage.write(&pos_gain_p_key, pos_gain_p)?; - - let pos_gain_d_key = storage::get_pos_gain_d_key(); - storage.write(&pos_gain_d_key, pos_gain_d)?; - let staked_ratio_key = storage::get_staked_ratio_key(); storage.write(&staked_ratio_key, staked_ratio)?; @@ -315,32 +303,6 @@ where storage.write(&key, value) } -/// Update the PoS P-gain parameter in storage. Returns the parameters and gas -/// cost. -pub fn update_pos_gain_p_parameter( - storage: &mut S, - value: &Dec, -) -> storage_api::Result<()> -where - S: StorageRead + StorageWrite, -{ - let key = storage::get_pos_gain_p_key(); - storage.write(&key, value) -} - -/// Update the PoS D-gain parameter in storage. Returns the parameters and gas -/// cost. -pub fn update_pos_gain_d_parameter( - storage: &mut S, - value: &Dec, -) -> storage_api::Result<()> -where - S: StorageRead + StorageWrite, -{ - let key = storage::get_pos_gain_d_key(); - storage.write(&key, value) -} - /// Update the PoS staked ratio parameter in storage. Returns the parameters and /// gas cost. pub fn update_staked_ratio_parameter( @@ -514,20 +476,6 @@ where .ok_or(ReadError::ParametersMissing) .into_storage_result()?; - // read PoS gain P - let pos_gain_p_key = storage::get_pos_gain_p_key(); - let value = storage.read(&pos_gain_p_key)?; - let pos_gain_p = value - .ok_or(ReadError::ParametersMissing) - .into_storage_result()?; - - // read PoS gain D - let pos_gain_d_key = storage::get_pos_gain_d_key(); - let value = storage.read(&pos_gain_d_key)?; - let pos_gain_d = value - .ok_or(ReadError::ParametersMissing) - .into_storage_result()?; - // read staked ratio let staked_ratio_key = storage::get_staked_ratio_key(); let value = storage.read(&staked_ratio_key)?; @@ -567,8 +515,6 @@ where implicit_vp_code_hash, epochs_per_year, max_signatures_per_transaction, - pos_gain_p, - pos_gain_d, staked_ratio, pos_inflation_amount, minimum_gas_price, diff --git a/core/src/ledger/parameters/storage.rs b/core/src/ledger/parameters/storage.rs index fd7f4fabad..c8c72ed8c9 100644 --- a/core/src/ledger/parameters/storage.rs +++ b/core/src/ledger/parameters/storage.rs @@ -26,8 +26,6 @@ struct Keys { // ======================================== // PoS parameters // ======================================== - pos_gain_d: &'static str, - pos_gain_p: &'static str, pos_inflation_amount: &'static str, staked_ratio: &'static str, // ======================================== @@ -96,16 +94,6 @@ pub fn is_epochs_per_year_key(key: &Key) -> bool { is_epochs_per_year_key_at_addr(key, &ADDRESS) } -/// Returns if the key is the pos_gain_p key. -pub fn is_pos_gain_p_key(key: &Key) -> bool { - is_pos_gain_p_key_at_addr(key, &ADDRESS) -} - -/// Returns if the key is the pos_gain_d key. -pub fn is_pos_gain_d_key(key: &Key) -> bool { - is_pos_gain_d_key_at_addr(key, &ADDRESS) -} - /// Returns if the key is the staked ratio key. pub fn is_staked_ratio_key(key: &Key) -> bool { is_staked_ratio_key_at_addr(key, &ADDRESS) @@ -166,16 +154,6 @@ pub fn get_epochs_per_year_key() -> Key { get_epochs_per_year_key_at_addr(ADDRESS) } -/// Storage key used for pos_gain_p parameter. -pub fn get_pos_gain_p_key() -> Key { - get_pos_gain_p_key_at_addr(ADDRESS) -} - -/// Storage key used for pos_gain_d parameter. -pub fn get_pos_gain_d_key() -> Key { - get_pos_gain_d_key_at_addr(ADDRESS) -} - /// Storage key used for staked ratio parameter. pub fn get_staked_ratio_key() -> Key { get_staked_ratio_key_at_addr(ADDRESS) diff --git a/core/src/ledger/storage/mod.rs b/core/src/ledger/storage/mod.rs index 6a51b207a8..a89496c396 100644 --- a/core/src/ledger/storage/mod.rs +++ b/core/src/ledger/storage/mod.rs @@ -1460,8 +1460,6 @@ mod tests { implicit_vp_code_hash: Hash::zero(), epochs_per_year: 100, max_signatures_per_transaction: 15, - pos_gain_p: Dec::new(1,1).expect("Cannot fail"), - pos_gain_d: Dec::new(1,1).expect("Cannot fail"), staked_ratio: Dec::new(1,1).expect("Cannot fail"), pos_inflation_amount: token::Amount::zero(), fee_unshielding_gas_limit: 20_000, diff --git a/genesis/localnet/parameters.toml b/genesis/localnet/parameters.toml index 266fe803fa..7a99fa34b5 100644 --- a/genesis/localnet/parameters.toml +++ b/genesis/localnet/parameters.toml @@ -17,10 +17,6 @@ tx_whitelist = [] implicit_vp = "vp_implicit" # Expected number of epochs per year (also sets the min duration of an epoch in seconds) epochs_per_year = 31_536_000 -# The P gain factor in the Proof of Stake rewards controller -pos_gain_p = "0.1" -# The D gain factor in the Proof of Stake rewards controller -pos_gain_d = "0.1" # Maximum number of signature per transaction max_signatures_per_transaction = 15 # Max gas for block @@ -72,6 +68,10 @@ liveness_window_check = 100 # The minimum required activity of consensus validators, in percentage, over # the `liveness_window_check` liveness_threshold = "0.9" +# The P gain factor in the Proof of Stake rewards controller +rewards_gain_p = "0.25" +# The D gain factor in the Proof of Stake rewards controller +rewards_gain_d = "0.25" # Governance parameters. [gov_params] diff --git a/genesis/starter/parameters.toml b/genesis/starter/parameters.toml index 543f7dbc13..926e564755 100644 --- a/genesis/starter/parameters.toml +++ b/genesis/starter/parameters.toml @@ -17,10 +17,6 @@ tx_whitelist = [] implicit_vp = "vp_implicit" # Expected number of epochs per year (also sets the min duration of an epoch in seconds) epochs_per_year = 31_536_000 -# The P gain factor in the Proof of Stake rewards controller -pos_gain_p = "0.1" -# The D gain factor in the Proof of Stake rewards controller -pos_gain_d = "0.1" # Maximum number of signature per transaction max_signatures_per_transaction = 15 # Max gas for block @@ -72,6 +68,10 @@ liveness_window_check = 10_000 # The minimum required activity of consensus validators, in percentage, over # the `liveness_window_check` liveness_threshold = "0.9" +# The P gain factor in the Proof of Stake rewards controller +rewards_gain_p = "0.25" +# The D gain factor in the Proof of Stake rewards controller +rewards_gain_d = "0.25" # Governance parameters. [gov_params] diff --git a/proof_of_stake/src/parameters.rs b/proof_of_stake/src/parameters.rs index ecacdde206..cb963d9e36 100644 --- a/proof_of_stake/src/parameters.rs +++ b/proof_of_stake/src/parameters.rs @@ -1,5 +1,7 @@ //! Proof-of-Stake system parameters +use std::str::FromStr; + use borsh::{BorshDeserialize, BorshSerialize}; use namada_core::ledger::governance::parameters::GovernanceParameters; use namada_core::types::dec::Dec; @@ -64,6 +66,10 @@ pub struct OwnedPosParams { /// The minimum required activity of consesus validators, in percentage, /// over the `liveness_window_check` pub liveness_threshold: Dec, + /// PoS gain p (read only) + pub rewards_gain_p: Dec, + /// PoS gain d (read only) + pub rewards_gain_d: Dec, } impl Default for PosParams { @@ -101,6 +107,8 @@ impl Default for OwnedPosParams { validator_stake_threshold: token::Amount::native_whole(1_u64), liveness_window_check: 10_000, liveness_threshold: Dec::new(9, 1).expect("Test failed"), + rewards_gain_p: Dec::from_str("0.25").expect("Test failed"), + rewards_gain_d: Dec::from_str("0.25").expect("Test failed"), } } } From 8f57cc70ea540c17b7f8fb1da9482b0f9bab8777 Mon Sep 17 00:00:00 2001 From: brentstone Date: Sat, 16 Dec 2023 18:38:05 -0500 Subject: [PATCH 2/2] changelog: add #2294 --- .../unreleased/improvements/2294-move-gain-params-to-pos.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/2294-move-gain-params-to-pos.md diff --git a/.changelog/unreleased/improvements/2294-move-gain-params-to-pos.md b/.changelog/unreleased/improvements/2294-move-gain-params-to-pos.md new file mode 100644 index 0000000000..54203f8ab4 --- /dev/null +++ b/.changelog/unreleased/improvements/2294-move-gain-params-to-pos.md @@ -0,0 +1,2 @@ +- Move the pos inflation gain parameters to the PosParams. + ([\#2294](https://github.com/anoma/namada/pull/2294)) \ No newline at end of file