Skip to content

Commit

Permalink
WIP minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Aug 9, 2023
1 parent 24b1161 commit 187cb90
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions proof_of_stake/src/tests/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ impl StateMachineTest for ConcretePosState {
new_validator,
amount,
} => {
println!("\nCONCRETE Redelegate");

let current_epoch = state.current_epoch();
let pipeline = current_epoch + params.pipeline_len;

Expand Down Expand Up @@ -553,6 +555,9 @@ impl StateMachineTest for ConcretePosState {

// Post-condition: Source validator stake at pipeline epoch
// is reduced by the redelegation amount

// TODO: shouldn't this be reduced by the redelegation
// amount post-slashing tho?
let src_validator_stake_pipeline_post =
crate::read_validator_stake(
&state.s,
Expand Down Expand Up @@ -2631,7 +2636,7 @@ impl AbstractPosState {
.filter(|s| *bond_epoch <= s.epoch)
.fold(BTreeMap::new(), |mut acc, s| {
let cur = acc.entry(s.epoch).or_default();
*cur += s.rate;
*cur = cmp::min(Dec::one(), *cur + s.rate);
acc
});
tracing::debug!(
Expand Down Expand Up @@ -2699,13 +2704,13 @@ impl AbstractPosState {
.validator_states
.get(&pipeline_epoch)
.unwrap()
.get(&new_validator)
.get(new_validator)
.unwrap();
if *pipeline_state != ValidatorState::Jailed {
self.update_validator_sets(&new_validator, change);
self.update_validator_sets(new_validator, change);
}
self.update_bond(&new_id, change);
self.update_validator_total_stake(&new_validator, change);
self.update_validator_total_stake(new_validator, change);
}

/// Update validator's total stake with bonded or unbonded change at the
Expand Down Expand Up @@ -2995,6 +3000,8 @@ impl AbstractPosState {
- self.params.unbonding_len
- self.params.cubic_slashing_window_length
- 1;

let cubic_rate = self.cubic_slash_rate();
// Now need to basically do the end_of_epoch() procedure
// from the Informal Systems model
for (validator, slashes) in slashes_this_epoch {
Expand All @@ -3011,6 +3018,7 @@ impl AbstractPosState {
&slashes,
stake_at_infraction,
infraction_epoch,
cubic_rate,
);

// Slash any redelegations from this validator on the
Expand Down Expand Up @@ -3039,6 +3047,7 @@ impl AbstractPosState {
&slashes,
redelegation.amount.change(),
infraction_epoch,
cubic_rate,
);
}
}
Expand All @@ -3055,6 +3064,7 @@ impl AbstractPosState {
slashes: &[Slash],
slashable_stake: token::Change,
infraction_epoch: Epoch,
cubic_rate: Dec,
) {
tracing::debug!(
"Val {} slashable stake at infraction {}",
Expand All @@ -3063,7 +3073,6 @@ impl AbstractPosState {
);

let mut total_rate = Dec::zero();
let cubic_rate = self.cubic_slash_rate();

for slash in slashes {
debug_assert_eq!(slash.epoch, infraction_epoch);
Expand Down Expand Up @@ -3106,7 +3115,7 @@ impl AbstractPosState {
if start <= infraction_epoch {
let slashes_for_this_unbond = self
.validator_slashes
.get(&validator)
.get(validator)
.cloned()
.unwrap_or_default()
.iter()
Expand Down Expand Up @@ -3163,7 +3172,7 @@ impl AbstractPosState {
let mut recent_unbonds = token::Change::default();
let unbond_records = self
.unbond_records
.get(&validator)
.get(validator)
.unwrap()
.get(&(self.epoch + offset))
.cloned()
Expand All @@ -3177,7 +3186,7 @@ impl AbstractPosState {
if start <= infraction_epoch {
let slashes_for_this_unbond = self
.validator_slashes
.get(&validator)
.get(validator)
.cloned()
.unwrap_or_default()
.iter()
Expand Down Expand Up @@ -3248,7 +3257,7 @@ impl AbstractPosState {
tracing::debug!("Updating ABSTRACT voting powers");
sum_post_bonds += self
.total_bonded
.get(&validator)
.get(validator)
.and_then(|bonded| bonded.get(&(self.epoch + offset)))
.cloned()
.unwrap_or_default()
Expand Down

0 comments on commit 187cb90

Please sign in to comment.