Skip to content

Commit

Permalink
Add integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Sep 25, 2023
1 parent be5f6a4 commit 58ab603
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions substrate/frame/contracts/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,32 @@ impl<T: Config, const TEST_ALL_STEPS: bool> OnRuntimeUpgrade for Migration<T, TE
);
Ok(Default::default())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> {
if !TEST_ALL_STEPS {
return Ok(())
}

log::info!(target: LOG_TARGET, "=== POST UPGRADE CHECKS ===");

// Ensure that that the hashing algorithm is correct for all storage items.
if let Some(hash) = crate::CodeInfoOf::<T>::iter_keys().next() {
crate::CodeInfoOf::<T>::get(hash).expect("CodeInfo exists for hash; qed");
}
if let Some(hash) = crate::PristineCode::<T>::iter_keys().next() {
crate::PristineCode::<T>::get(hash).expect("PristineCode exists for hash; qed");
}
if let Some(account_id) = crate::ContractInfoOf::<T>::iter_keys().next() {
crate::ContractInfoOf::<T>::get(account_id)
.expect("ContractInfo exists for account_id; qed");
}
if let Some(nonce) = crate::DeletionQueue::<T>::iter_keys().next() {
crate::DeletionQueue::<T>::get(nonce).expect("DeletionQueue exists for nonce; qed");
}

Ok(())
}
}

/// The result of running the migration.
Expand Down

0 comments on commit 58ab603

Please sign in to comment.