From 5ffc155cd2243cad7d404c91061775287428efcf Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Wed, 6 Dec 2023 09:58:31 -0800 Subject: [PATCH] Remove Penalty::default method This was a source of confusion about the representation. --- crates/core/component/stake/src/component.rs | 6 +++--- crates/core/component/stake/src/penalty.rs | 2 +- crates/core/component/stake/src/undelegate_claim/proof.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/core/component/stake/src/component.rs b/crates/core/component/stake/src/component.rs index 3ba46e98d2..a06136a732 100644 --- a/crates/core/component/stake/src/component.rs +++ b/crates/core/component/stake/src/component.rs @@ -411,7 +411,7 @@ pub(crate) trait StakingImpl: StateWriteExt { let penalty = self .penalty_in_epoch(&validator.identity_key, epoch_to_end.index) .await? - .unwrap_or_default(); + .unwrap_or(Penalty::from_percent(0)); let prev_validator_rate_with_penalty = prev_validator_rate.slash(penalty); // Then compute the next validator rate, accounting for funding streams and validator state. @@ -1099,7 +1099,7 @@ pub trait StateReadExt: StateRead { let start_key = state_key::penalty_in_epoch(id, start); let end_key = state_key::penalty_in_epoch(id, end); - let mut compounded = Penalty::default(); + let mut compounded = Penalty::from_percent(0); for (_key, penalty) in all_penalties.range(start_key..end_key) { compounded = compounded.compound(*penalty); } @@ -1413,7 +1413,7 @@ pub trait StateWriteExt: StateWrite { let current_penalty = self .penalty_in_epoch(identity_key, current_epoch_index) .await? - .unwrap_or_default(); + .unwrap_or(Penalty::from_percent(0)); let new_penalty = current_penalty.compound(slashing_penalty); diff --git a/crates/core/component/stake/src/penalty.rs b/crates/core/component/stake/src/penalty.rs index f31687753f..3925dc17db 100644 --- a/crates/core/component/stake/src/penalty.rs +++ b/crates/core/component/stake/src/penalty.rs @@ -18,7 +18,7 @@ use penumbra_num::{ /// Tracks slashing penalties applied to a validator in some epoch. /// /// The penalty is represented as a fixed-point integer in bps^2 (denominator 10^8). -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[serde(try_from = "pbs::Penalty", into = "pbs::Penalty")] pub struct Penalty(U128x128); diff --git a/crates/core/component/stake/src/undelegate_claim/proof.rs b/crates/core/component/stake/src/undelegate_claim/proof.rs index 4064d2f031..fd5bf52e29 100644 --- a/crates/core/component/stake/src/undelegate_claim/proof.rs +++ b/crates/core/component/stake/src/undelegate_claim/proof.rs @@ -72,7 +72,7 @@ impl ConstraintSynthesizer for UndelegateClaimCircuit { impl DummyWitness for UndelegateClaimCircuit { fn with_dummy_witness() -> Self { - let penalty = Penalty::default(); + let penalty = Penalty::from_percent(0); let balance_blinding = Fr::from(1); let unbonding_amount = Amount::from(1u64); let unbonding_id = *STAKING_TOKEN_ASSET_ID;