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

Minimum validator commission rate param #3831

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ pub async fn query_protocol_parameters(
liveness_threshold,
rewards_gain_p,
rewards_gain_d,
min_commission_rate,
},
max_proposal_period: _,
} = query_pos_parameters(context.client()).await;
Expand Down Expand Up @@ -929,6 +930,12 @@ pub async fn query_protocol_parameters(
"",
tm_votes_per_token
);
display_line!(
context.io(),
"{:4}Minimum allowable validator commission rate: {}",
"",
min_commission_rate
);
}

pub async fn query_bond<C: Client + Sync>(
Expand Down
2 changes: 2 additions & 0 deletions crates/apps_lib/src/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ impl Finalized {
liveness_threshold,
rewards_gain_p,
rewards_gain_d,
min_commission_rate,
} = self.parameters.pos_params.clone();

namada_sdk::proof_of_stake::parameters::PosParams {
Expand All @@ -429,6 +430,7 @@ impl Finalized {
liveness_threshold,
rewards_gain_p,
rewards_gain_d,
min_commission_rate,
},
max_proposal_period: self.parameters.gov_params.max_proposal_period,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/apps_lib/src/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ pub struct PosParams {
pub rewards_gain_p: Dec,
/// PoS gain d (read only)
pub rewards_gain_d: Dec,
/// Minimum validator commission rate
pub min_commission_rate: Dec,
}

#[derive(
Expand Down
5 changes: 5 additions & 0 deletions crates/proof_of_stake/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ pub enum CommissionRateChangeError {
LargerThanOne(Dec, Address),
#[error("Rate change of {0} is too large for validator {1}")]
RateChangeTooLarge(Dec, Address),
#[error(
"Invalid commission rate of {0}; the minimum allowed by the protocol \
is {1}"
)]
RateBelowMin(Dec, Dec),
#[error(
"There is no maximum rate change written in storage for validator {0}"
)]
Expand Down
12 changes: 11 additions & 1 deletion crates/proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,14 +1667,14 @@ where
S: StorageRead + StorageWrite,
Gov: governance::Read<S>,
{
// Check that the rate is a number between 0.0 and 1.0
if new_rate.is_negative() {
return Err(CommissionRateChangeError::NegativeRate(
new_rate,
validator.clone(),
)
.into());
}

if new_rate > Dec::one() {
return Err(CommissionRateChangeError::LargerThanOne(
new_rate,
Expand All @@ -1690,6 +1690,16 @@ where
})?;

let params = read_pos_params::<S, Gov>(storage)?;

// Check that the new rate is allowed by the min commission rate
if new_rate < params.min_commission_rate {
return Err(CommissionRateChangeError::RateBelowMin(
new_rate,
params.min_commission_rate,
)
.into());
}

let commission_handle = validator_commission_rate_handle(validator);
let pipeline_epoch = checked!(current_epoch + params.pipeline_len)?;

Expand Down
3 changes: 3 additions & 0 deletions crates/proof_of_stake/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct OwnedPosParams {
pub rewards_gain_p: Dec,
/// PoS gain d (read only)
pub rewards_gain_d: Dec,
/// Minimum validator commission rate
pub min_commission_rate: Dec,
}

impl Default for OwnedPosParams {
Expand Down Expand Up @@ -108,6 +110,7 @@ impl Default for OwnedPosParams {
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"),
min_commission_rate: Dec::from_str("0.05").expect("Test failed"),
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,18 @@ pub async fn build_validator_commission_change(
*rate,
)));
}
if *rate < params.min_commission_rate {
edisplay_line!(
context.io(),
"New rate is below the minimum allowed by the protocol: {}",
params.min_commission_rate
);
if !tx_args.force {
return Err(Error::from(TxSubmitError::InvalidCommissionRate(
*rate,
)));
}
}

let pipeline_epoch_minus_one =
epoch.unchecked_add(params.pipeline_len - 1);
Expand Down Expand Up @@ -873,6 +885,19 @@ pub async fn build_validator_metadata_change(
)));
}
}
if *rate < params.min_commission_rate {
edisplay_line!(
context.io(),
"New rate is below the minimum allowed by the protocol: {}",
params.min_commission_rate
);
if !tx_args.force {
return Err(Error::from(TxSubmitError::InvalidCommissionRate(
*rate,
)));
}
}

let pipeline_epoch_minus_one =
epoch.unchecked_add(params.pipeline_len - 1);

Expand Down
2 changes: 2 additions & 0 deletions genesis/hardware/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ liveness_threshold = "0.9"
rewards_gain_p = "0.25"
# The D gain factor in the Proof of Stake rewards controller
rewards_gain_d = "0.25"
# Minimum allowable validator commission rate
min_commission_rate = "0.05"

# Governance parameters.
[gov_params]
Expand Down
2 changes: 2 additions & 0 deletions genesis/localnet/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ liveness_threshold = "0.9"
rewards_gain_p = "0.25"
# The D gain factor in the Proof of Stake rewards controller
rewards_gain_d = "0.25"
# Minimum allowable validator commission rate
min_commission_rate = "0.05"

# Governance parameters.
[gov_params]
Expand Down
2 changes: 2 additions & 0 deletions genesis/starter/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ liveness_threshold = "0.9"
rewards_gain_p = "0.25"
# The D gain factor in the Proof of Stake rewards controller
rewards_gain_d = "0.25"
# Minimum allowable validator commission rate
min_commission_rate = "0.05"

# Governance parameters.
[gov_params]
Expand Down
Loading