Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move pos gain params to PosParams #2294

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Move the pos inflation gain parameters to the PosParams.
([\#2294](https://github.com/anoma/namada/pull/2294))
4 changes: 0 additions & 4 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions apps/src/lib/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
Expand Down
12 changes: 4 additions & 8 deletions apps/src/lib/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ pub struct ChainParams<T: TemplateValidation> {
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
Expand Down Expand Up @@ -307,8 +303,6 @@ impl ChainParams<Unvalidated> {
tx_whitelist,
implicit_vp,
epochs_per_year,
pos_gain_p,
pos_gain_d,
max_signatures_per_transaction,
max_block_gas,
fee_unshielding_gas_limit,
Expand Down Expand Up @@ -354,8 +348,6 @@ impl ChainParams<Unvalidated> {
tx_whitelist,
implicit_vp,
epochs_per_year,
pos_gain_p,
pos_gain_d,
max_signatures_per_transaction,
max_block_gas,
fee_unshielding_gas_limit,
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 3 additions & 6 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,19 +645,14 @@ where
let epochs_per_year: u64 = self
.read_storage_key(&params_storage::get_epochs_per_year_key())
.expect("Epochs per year should exist in storage");
let pos_p_gain_nom: Dec = self
.read_storage_key(&params_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(&params_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(&params_storage::get_staked_ratio_key())
.expect("PoS staked ratio should exist in storage");
let pos_last_inflation_amount: token::Amount = self
.read_storage_key(&params_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(
Expand All @@ -668,6 +663,8 @@ where
read_total_stake(&self.wl_storage, &params, 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 {
Expand Down
2 changes: 0 additions & 2 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions core/src/ledger/masp_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
54 changes: 0 additions & 54 deletions core/src/ledger/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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<S>(
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<S>(
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<S>(
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 0 additions & 22 deletions core/src/ledger/parameters/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
// ========================================
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions core/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions genesis/localnet/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions genesis/starter/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions proof_of_stake/src/parameters.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
}
}
}
Expand Down
Loading