Skip to content

Commit

Permalink
properly update a simple epoched object considering last update
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Feb 23, 2024
1 parent 2e0aac2 commit 92b6353
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 16 additions & 9 deletions crates/proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,8 @@ where
// Promote the next below-capacity validator to consensus
promote_next_below_capacity_validator_to_consensus(
storage,
pipeline_epoch,
current_epoch,
params.pipeline_len,
)?;
}

Expand Down Expand Up @@ -2289,8 +2290,8 @@ where
validator_state_handle(validator).set(
storage,
ValidatorState::Jailed,
pipeline_epoch,
0,
current_epoch,
params.pipeline_len,
)?;
return Ok(());
}
Expand Down Expand Up @@ -2701,10 +2702,14 @@ where

// Remove the validator from the set starting at the update epoch and up
// thru the pipeline epoch.
let pipeline_epoch = current_epoch + params.pipeline_len;
for epoch in
Epoch::iter_bounds_inclusive(validator_set_update_epoch, pipeline_epoch)
{
let start = validator_set_update_epoch
.0
.checked_sub(current_epoch.0)
.unwrap(); // Safe unwrap
let end = params.pipeline_len;

for offset in start..=end {
let epoch = current_epoch + offset;
let prev_state = validator_state_handle(validator)
.get(storage, epoch, params)?
.expect("Expected to find a valid validator.");
Expand All @@ -2719,9 +2724,11 @@ where
// For the pipeline epoch only:
// promote the next max inactive validator to the active
// validator set at the pipeline offset
if epoch == pipeline_epoch {
if offset == params.pipeline_len {
promote_next_below_capacity_validator_to_consensus(
storage, epoch,
storage,
current_epoch,
offset,
)?;
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/proof_of_stake/src/validator_set_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,13 @@ where
/// consensus set already.
pub fn promote_next_below_capacity_validator_to_consensus<S>(
storage: &mut S,
epoch: Epoch,
current_epoch: Epoch,
offset: u64,
) -> namada_storage::Result<()>
where
S: StorageRead + StorageWrite,
{
let epoch = current_epoch + offset;
let below_cap_set = below_capacity_validator_set_handle().at(&epoch);
let max_below_capacity_amount =
get_max_below_capacity_validator_amount(&below_cap_set, storage)?;
Expand All @@ -550,8 +552,8 @@ where
validator_state_handle(&promoted_validator).set(
storage,
ValidatorState::Consensus,
epoch,
0,
current_epoch,
offset,
)?;
}

Expand Down

0 comments on commit 92b6353

Please sign in to comment.