Skip to content

Commit

Permalink
fix: more try-runtime unwraps. (#4648)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanlen authored Mar 15, 2024
1 parent be7b312 commit b0a6a66
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion state-chain/pallets/cf-broadcast/src/migrations/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> {
broadcasts_with_failed_broadcasters,
broadcast_retry_queue,
timeout_broadcasts,
} = MigrationVerification::<T>::decode(&mut &state[..]).unwrap();
} = MigrationVerification::<T>::decode(&mut &state[..])
.expect("Pre-migration should encode valid MigrationVerification");

// Ensure all failed broadcasters storage are migrated.
broadcasts_with_failed_broadcasters.into_iter().for_each(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ impl<T: Config<Instance3, TargetChain = Bitcoin>> OnRuntimeUpgrade for Migration

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
let number_of_channels_in_lookup_pre_migration = <u32>::decode(&mut &state[..]).unwrap();
let number_of_channels_in_lookup_pre_migration = <u32>::decode(&mut &state[..])
.expect("Pre-migration should insert number of channels in lookup storage.");
ensure!(
DepositChannelLookup::<T, Instance3>::iter_keys().count() as u32 ==
number_of_channels_in_lookup_pre_migration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> {

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
let number_of_channels_in_lookup_pre_migration = <u32>::decode(&mut &state[..]).unwrap();
let number_of_channels_in_lookup_pre_migration =
<u32>::decode(&mut &state[..]).expect("Pre-migration should encode a u32.");
ensure!(
DepositChannelLookup::<T, I>::iter_keys().count() as u32 ==
number_of_channels_in_lookup_pre_migration,
Expand Down
3 changes: 2 additions & 1 deletion state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,8 @@ impl_runtime_apis! {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
let weight = Executive::try_runtime_upgrade(checks).unwrap();
let weight = Executive::try_runtime_upgrade(checks)
.inspect_err(|e| log::error!("try_runtime_upgrade failed with: {:?}", e)).unwrap();
(weight, BlockWeights::get().max_block)
}

Expand Down

0 comments on commit b0a6a66

Please sign in to comment.