Skip to content

Commit

Permalink
Polkadot Relay fix corrupt ledger migration checks (#566)
Browse files Browse the repository at this point in the history
This fixes `try-runtime` migration validation for the
`restore_corrupt_ledger_2` migration.

🚨 This fix is required to unblock CI for all other PRs, which are
currently incorrectly failing migration CI checks.

- [x] Does not require a CHANGELOG entry
  • Loading branch information
acatangiu authored Jan 29, 2025
1 parent fccb88f commit 3896e2e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2036,13 +2036,18 @@ pub mod restore_corrupt_ledger_2 {

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
assert!(pallet_staking::Ledger::<Runtime>::get(CorruptStash::get()).is_some());
Ok(Default::default())
let found_corrupted =
pallet_staking::Ledger::<Runtime>::get(CorruptStash::get()).is_some();
Ok(found_corrupted.encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
assert!(pallet_staking::Ledger::<Runtime>::get(CorruptStash::get()).is_none());
fn post_upgrade(state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let found_corrupted: bool = Decode::decode(&mut &state[..])
.map_err(|_| sp_runtime::TryRuntimeError::Corruption)?;
if found_corrupted {
assert!(pallet_staking::Ledger::<Runtime>::get(CorruptStash::get()).is_none());
}
Ok(())
}
}
Expand Down

0 comments on commit 3896e2e

Please sign in to comment.