Skip to content

Commit

Permalink
Use identity_key consistently instead of validator_identity, record s…
Browse files Browse the repository at this point in the history
…lashing penalty events
  • Loading branch information
zbuc committed Jun 6, 2024
1 parent bb0611d commit 5ebad1b
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 37 deletions.
7 changes: 7 additions & 0 deletions crates/core/component/stake/src/component/stake.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod address;

use crate::event::slashing_penalty_applied;
use crate::params::StakeParameters;
use crate::rate::BaseRateData;
use crate::validator::{self, Validator};
Expand Down Expand Up @@ -473,6 +474,12 @@ pub(crate) trait RateDataWrite: StateWrite {

let new_penalty = current_penalty.compound(slashing_penalty);

// Emit an event indicating the validator had a slashing penalty applied.
self.record_proto(slashing_penalty_applied(
*identity_key,
current_epoch_index,
new_penalty,
));
self.put(
state_key::penalty::for_id_in_epoch(identity_key, current_epoch_index),
new_penalty,
Expand Down
18 changes: 15 additions & 3 deletions crates/core/component/stake/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
rate,
validator::{BondingState, State, Validator},
Delegate, IdentityKey, Undelegate,
Delegate, IdentityKey, Penalty, Undelegate,
};
use penumbra_num::Amount;
use penumbra_proto::core::component::stake::v1 as pb;
Expand Down Expand Up @@ -61,14 +61,14 @@ pub fn validator_missed_block(identity_key: IdentityKey) -> pb::EventValidatorMi

pub fn delegate(delegate: &Delegate) -> pb::EventDelegate {
pb::EventDelegate {
validator_identity: Some(delegate.validator_identity.into()),
identity_key: Some(delegate.validator_identity.into()),
amount: Some(delegate.unbonded_amount.into()),
}
}

pub fn undelegate(undelegate: &Undelegate) -> pb::EventUndelegate {
pb::EventUndelegate {
validator_identity: Some(undelegate.validator_identity.into()),
identity_key: Some(undelegate.validator_identity.into()),
amount: Some(undelegate.unbonded_amount.into()),
}
}
Expand All @@ -86,3 +86,15 @@ pub fn tombstone_validator(
voting_power: evidence.validator.power.value(),
}
}

pub fn slashing_penalty_applied(
identity_key: IdentityKey,
epoch_index: u64,
new_penalty: Penalty,
) -> pb::EventSlashingPenaltyApplied {
pb::EventSlashingPenaltyApplied {
identity_key: Some(identity_key.into()),
epoch_index,
new_penalty: Some(new_penalty.into()),
}
}
29 changes: 23 additions & 6 deletions crates/proto/src/gen/penumbra.core.component.stake.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,7 @@ impl ::prost::Name for EventValidatorMissedBlock {
pub struct EventDelegate {
/// The validator's identity key.
#[prost(message, optional, tag = "1")]
pub validator_identity: ::core::option::Option<
super::super::super::keys::v1::IdentityKey,
>,
pub identity_key: ::core::option::Option<super::super::super::keys::v1::IdentityKey>,
/// The amount of stake delegated, in the staking token.
#[prost(message, optional, tag = "3")]
pub amount: ::core::option::Option<super::super::super::num::v1::Amount>,
Expand All @@ -963,9 +961,7 @@ impl ::prost::Name for EventDelegate {
pub struct EventUndelegate {
/// The validator's identity key.
#[prost(message, optional, tag = "1")]
pub validator_identity: ::core::option::Option<
super::super::super::keys::v1::IdentityKey,
>,
pub identity_key: ::core::option::Option<super::super::super::keys::v1::IdentityKey>,
/// The amount of stake undelegated, in the staking token.
#[prost(message, optional, tag = "3")]
pub amount: ::core::option::Option<super::super::super::num::v1::Amount>,
Expand All @@ -977,6 +973,27 @@ impl ::prost::Name for EventUndelegate {
::prost::alloc::format!("penumbra.core.component.stake.v1.{}", Self::NAME)
}
}
/// Indicates a slashing penalty was applied to a validator's reward rates.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EventSlashingPenaltyApplied {
/// The validator's identity key.
#[prost(message, optional, tag = "1")]
pub identity_key: ::core::option::Option<super::super::super::keys::v1::IdentityKey>,
/// The epoch in which the penalty was applied.
#[prost(uint64, tag = "2")]
pub epoch_index: u64,
/// The penalty amount after slashing.
#[prost(message, optional, tag = "3")]
pub new_penalty: ::core::option::Option<Penalty>,
}
impl ::prost::Name for EventSlashingPenaltyApplied {
const NAME: &'static str = "EventSlashingPenaltyApplied";
const PACKAGE: &'static str = "penumbra.core.component.stake.v1";
fn full_name() -> ::prost::alloc::string::String {
::prost::alloc::format!("penumbra.core.component.stake.v1.{}", Self::NAME)
}
}
/// Generated client implementations.
#[cfg(feature = "rpc")]
pub mod query_service_client {
Expand Down
Loading

0 comments on commit 5ebad1b

Please sign in to comment.