From d0f994f721dfc723a8f00cc5a0c0be9997ea479a Mon Sep 17 00:00:00 2001 From: brentstone Date: Thu, 28 Sep 2023 18:09:34 -0600 Subject: [PATCH] WIP debugging SM v1 failure --- proof_of_stake/src/lib.rs | 23 ++++++++++++++++------- proof_of_stake/src/tests/state_machine.rs | 8 +++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/proof_of_stake/src/lib.rs b/proof_of_stake/src/lib.rs index ff2ba0cdb4..726a545600 100644 --- a/proof_of_stake/src/lib.rs +++ b/proof_of_stake/src/lib.rs @@ -4417,9 +4417,10 @@ where compute_cubic_slash_rate(storage, ¶ms, infraction_epoch)?; // Collect the enqueued slashes and update their rates - let mut eager_validator_slashes: HashMap> = - HashMap::new(); // TODO: will need to update this in storage later - let mut eager_validator_slash_rates: HashMap = HashMap::new(); + let mut eager_validator_slashes: BTreeMap> = + BTreeMap::new(); // TODO: will need to update this in storage later + let mut eager_validator_slash_rates: BTreeMap = + BTreeMap::new(); // `slashPerValidator` and `slashesMap` while also updating in storage for enqueued_slash in enqueued_slashes.iter(storage)? { @@ -4609,6 +4610,11 @@ where .or_default(); // `slashValidatorRedelegation` + tracing::debug!( + "Slashing {} redelegation to {}", + validator, + &dest_validator + ); slash_validator_redelegation( storage, params, @@ -4664,7 +4670,7 @@ fn slash_validator_redelegation( 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(); @@ -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); diff --git a/proof_of_stake/src/tests/state_machine.rs b/proof_of_stake/src/tests/state_machine.rs index eca6a2a79e..6f49c746a5 100644 --- a/proof_of_stake/src/tests/state_machine.rs +++ b/proof_of_stake/src/tests/state_machine.rs @@ -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, @@ -4893,7 +4899,7 @@ impl AbstractPosState { slash_rate: Dec, slash_amounts: &mut BTreeMap, ) { - tracing::debug!("\nSLASHING VAL REDELEGATIONS\n"); + // tracing::debug!("\nSLASHING VAL REDELEGATIONS\n"); let infraction_epoch = self.epoch - self.params.slash_processing_epoch_offset();