From 85770beec8bd02d7fb0686611b926192e3c55c81 Mon Sep 17 00:00:00 2001 From: brentstone Date: Mon, 2 Oct 2023 14:05:29 -0600 Subject: [PATCH] clear old enqueued slashes when processing slashes --- proof_of_stake/src/epoched.rs | 25 +++++++++++++++++++++++++ proof_of_stake/src/lib.rs | 3 +++ proof_of_stake/src/types.rs | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/proof_of_stake/src/epoched.rs b/proof_of_stake/src/epoched.rs index 8b86f4dbd4..0f66a36d84 100644 --- a/proof_of_stake/src/epoched.rs +++ b/proof_of_stake/src/epoched.rs @@ -877,6 +877,29 @@ impl EpochOffset for OffsetSlashProcessingLen { } } +/// Offset at the slash processing delay plus the default num past epochs. +#[derive( + Debug, + Clone, + BorshDeserialize, + BorshSerialize, + BorshSchema, + PartialEq, + Eq, + PartialOrd, + Ord, +)] +pub struct OffsetSlashProcessingLenPlus; +impl EpochOffset for OffsetSlashProcessingLenPlus { + fn value(params: &PosParams) -> u64 { + params.slash_processing_epoch_offset() + DEFAULT_NUM_PAST_EPOCHS + } + + fn dyn_offset() -> DynEpochOffset { + DynEpochOffset::SlashProcessingLenPlus + } +} + /// Maximum offset. #[derive( Debug, @@ -1018,6 +1041,8 @@ pub enum DynEpochOffset { /// Offset at slash processing delay (unbonding + /// cubic_slashing_window + 1). SlashProcessingLen, + /// Offset at slash processing delay plus the defaul num past epochs + SlashProcessingLenPlus, /// Offset at the max proposal period MaxProposalPeriod, /// Offset at the max proposal period plus the default num past epochs diff --git a/proof_of_stake/src/lib.rs b/proof_of_stake/src/lib.rs index 6f39fc6527..223abdc1fe 100644 --- a/proof_of_stake/src/lib.rs +++ b/proof_of_stake/src/lib.rs @@ -3689,6 +3689,9 @@ where cur_slashes.push(updated_slash); } + // Update the epochs of enqueued slashes in storage + enqueued_slashes_handle().update_data(storage, ¶ms, current_epoch)?; + let mut deltas_for_update: HashMap> = HashMap::new(); diff --git a/proof_of_stake/src/types.rs b/proof_of_stake/src/types.rs index c7d666bdd3..68a89c86cb 100644 --- a/proof_of_stake/src/types.rs +++ b/proof_of_stake/src/types.rs @@ -140,7 +140,7 @@ pub type ValidatorSlashes = NestedMap; pub type EpochedSlashes = crate::epoched::NestedEpoched< ValidatorSlashes, crate::epoched::OffsetUnbondingLen, - crate::epoched::OffsetSlashProcessingLen, + crate::epoched::OffsetSlashProcessingLenPlus, >; /// Epoched validator's unbonds