use penumbra_num::Amount;
use penumbra_proto::core::component::stake::v1 as pb;
use penumbra_proto::DomainType;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(try_from = "pb::StakeParameters", into = "pb::StakeParameters")]
pub struct StakeParameters {
pub unbonding_delay: u64,
pub active_validator_limit: u64,
pub slashing_penalty_misbehavior: u64,
pub slashing_penalty_downtime: u64,
pub signed_blocks_window_len: u64,
pub missed_blocks_maximum: u64,
pub min_validator_stake: Amount,
}
impl DomainType for StakeParameters {
type Proto = pb::StakeParameters;
}
impl TryFrom<pb::StakeParameters> for StakeParameters {
type Error = anyhow::Error;
fn try_from(msg: pb::StakeParameters) -> anyhow::Result<Self> {
Ok(StakeParameters {
active_validator_limit: msg.active_validator_limit,
slashing_penalty_downtime: msg.slashing_penalty_downtime,
slashing_penalty_misbehavior: msg.slashing_penalty_misbehavior,
missed_blocks_maximum: msg.missed_blocks_maximum,
signed_blocks_window_len: msg.signed_blocks_window_len,
min_validator_stake: msg
.min_validator_stake
.ok_or_else(|| anyhow::anyhow!("missing min_validator_stake"))?
.try_into()?,
unbonding_delay: msg.unbonding_delay,
})
}
}
impl From<StakeParameters> for pb::StakeParameters {
#[allow(deprecated)]
fn from(params: StakeParameters) -> Self {
pb::StakeParameters {
unbonding_epochs: 0,
active_validator_limit: params.active_validator_limit,
signed_blocks_window_len: params.signed_blocks_window_len,
missed_blocks_maximum: params.missed_blocks_maximum,
slashing_penalty_downtime: params.slashing_penalty_downtime,
slashing_penalty_misbehavior: params.slashing_penalty_misbehavior,
base_reward_rate: 0,
min_validator_stake: Some(params.min_validator_stake.into()),
unbonding_delay: params.unbonding_delay,
}
}
}
impl Default for StakeParameters {
fn default() -> Self {
Self {
unbonding_delay: 120960,
active_validator_limit: 80,
signed_blocks_window_len: 10000,
missed_blocks_maximum: 9500,
slashing_penalty_misbehavior: 1000_0000,
slashing_penalty_downtime: 1_0000,
min_validator_stake: 1_000_000u128.into(),
}
}
}