Skip to content

Commit

Permalink
WIP debugging SM v1 failure
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Sep 29, 2023
1 parent cca37af commit d0f994f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
23 changes: 16 additions & 7 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4417,9 +4417,10 @@ where
compute_cubic_slash_rate(storage, &params, infraction_epoch)?;

// Collect the enqueued slashes and update their rates
let mut eager_validator_slashes: HashMap<Address, Vec<Slash>> =
HashMap::new(); // TODO: will need to update this in storage later
let mut eager_validator_slash_rates: HashMap<Address, Dec> = HashMap::new();
let mut eager_validator_slashes: BTreeMap<Address, Vec<Slash>> =
BTreeMap::new(); // TODO: will need to update this in storage later
let mut eager_validator_slash_rates: BTreeMap<Address, Dec> =
BTreeMap::new();

// `slashPerValidator` and `slashesMap` while also updating in storage
for enqueued_slash in enqueued_slashes.iter(storage)? {
Expand Down Expand Up @@ -4609,6 +4610,11 @@ where
.or_default();

// `slashValidatorRedelegation`
tracing::debug!(
"Slashing {} redelegation to {}",
validator,
&dest_validator
);
slash_validator_redelegation(
storage,
params,
Expand Down Expand Up @@ -4664,7 +4670,7 @@ fn slash_validator_redelegation<S>(
where
S: StorageRead,
{
tracing::debug!("\nSLASHING VAL REDELEGATIONS\n");
// tracing::debug!("\nSLASHING VAL REDELEGATIONS\n");
let infraction_epoch =
current_epoch - params.slash_processing_epoch_offset();

Expand Down Expand Up @@ -4821,9 +4827,12 @@ where
);

init_tot_unbonded = updated_total_unbonded;
let map_value = slashed_amounts.entry(epoch).or_default();
// dbg!(&map_value);
*map_value += cmp::min(slashed, slashable_stake).change();
let to_slash = cmp::min(slashed, slashable_stake).change();
if !to_slash.is_zero() {
let map_value = slashed_amounts.entry(epoch).or_default();
// dbg!(&map_value);
*map_value += to_slash;
}
}
// dbg!(&slashed_amounts);

Expand Down
8 changes: 7 additions & 1 deletion proof_of_stake/src/tests/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4331,6 +4331,12 @@ impl AbstractPosState {
let to_modify =
val_slash_amounts.entry(dest_val.clone()).or_default();

tracing::debug!(
"Slashing {} redelegation to {}",
validator,
&dest_val
);

// `slashValidatorRedelegation`
self.slash_validator_redelegation(
validator, &dest_val, slash_rate, to_modify,
Expand Down Expand Up @@ -4893,7 +4899,7 @@ impl AbstractPosState {
slash_rate: Dec,
slash_amounts: &mut BTreeMap<Epoch, token::Change>,
) {
tracing::debug!("\nSLASHING VAL REDELEGATIONS\n");
// tracing::debug!("\nSLASHING VAL REDELEGATIONS\n");

let infraction_epoch =
self.epoch - self.params.slash_processing_epoch_offset();
Expand Down

0 comments on commit d0f994f

Please sign in to comment.