Skip to content

Commit

Permalink
clear old enqueued slashes when processing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Oct 2, 2023
1 parent 7c7ee02 commit 85770be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions proof_of_stake/src/epoched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,9 @@ where
cur_slashes.push(updated_slash);
}

// Update the epochs of enqueued slashes in storage
enqueued_slashes_handle().update_data(storage, &params, current_epoch)?;

let mut deltas_for_update: HashMap<Address, Vec<(u64, token::Change)>> =
HashMap::new();

Expand Down
2 changes: 1 addition & 1 deletion proof_of_stake/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub type ValidatorSlashes = NestedMap<Address, Slashes>;
pub type EpochedSlashes = crate::epoched::NestedEpoched<
ValidatorSlashes,
crate::epoched::OffsetUnbondingLen,
crate::epoched::OffsetSlashProcessingLen,
crate::epoched::OffsetSlashProcessingLenPlus,
>;

/// Epoched validator's unbonds
Expand Down

0 comments on commit 85770be

Please sign in to comment.