Skip to content

Commit

Permalink
Merge pull request #2951 from autonomys/fix-pot-verification-on-itera…
Browse files Browse the repository at this point in the history
…tions-change

Fix PoT verification when number of iterations change
  • Loading branch information
nazar-pc committed Jul 29, 2024
2 parents 5438c64 + 699bce6 commit 2e4cb25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,13 @@ impl<T: Config> Pallet<T> {
T::EraChangeTrigger::trigger::<T>(block_number);

{
let pot_slot_iterations =
PotSlotIterations::<T>::get().expect("Always initialized during genesis; qed");
// This is what we had after previous block
frame_system::Pallet::<T>::deposit_log(DigestItem::pot_slot_iterations(
pot_slot_iterations,
));

let mut maybe_pot_slot_iterations_update = PotSlotIterationsUpdate::<T>::get();
// Check PoT slot iterations update and apply it if it is time to do so, while also
// removing corresponding storage item
Expand All @@ -976,15 +983,11 @@ impl<T: Config> Pallet<T> {
PotSlotIterations::<T>::put(update.slot_iterations);
update.slot_iterations
} else {
PotSlotIterations::<T>::get().expect("Always initialized during genesis; qed")
pot_slot_iterations
};
let pot_entropy_injection_interval = T::PotEntropyInjectionInterval::get();
let pot_entropy_injection_delay = T::PotEntropyInjectionDelay::get();

frame_system::Pallet::<T>::deposit_log(DigestItem::pot_slot_iterations(
pot_slot_iterations,
));

let mut entropy = PotEntropy::<T>::get();
let lookback_in_blocks = pot_entropy_injection_interval
* BlockNumberFor::<T>::from(T::PotEntropyInjectionLookbackDepth::get());
Expand Down
6 changes: 3 additions & 3 deletions crates/sc-consensus-subspace/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ where
}

let future_slot = slot + self.chain_constants.block_authoring_delay();
let slot_to_check = Slot::from(
let first_slot_to_check = Slot::from(
future_slot
.checked_sub(checkpoints.len() as u64 - 1)
.ok_or(VerificationError::InvalidProofOfTime)?,
Expand All @@ -303,13 +303,13 @@ where
.pot_parameters_change
.as_ref()
.and_then(|parameters_change| {
(parameters_change.slot == slot_to_check)
(parameters_change.slot <= first_slot_to_check)
.then_some(parameters_change.slot_iterations)
})
.unwrap_or(subspace_digest_items.pot_slot_iterations);

let mut pot_input = PotNextSlotInput {
slot: slot_to_check,
slot: first_slot_to_check,
slot_iterations,
seed,
};
Expand Down

0 comments on commit 2e4cb25

Please sign in to comment.