Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

configuration: optionally read pending configs in migration #7489

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions runtime/parachains/src/configuration/migration/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ executor_params : pre.executor_params,
let v7 = translate(v6);
v7::ActiveConfig::<T>::set(Some(v7));

let pending_v6 = v6::PendingConfigs::<T>::get()
.defensive_proof("Could not decode old pending")
.unwrap_or_default();
// Allowed to be empty.
let pending_v6 = v6::PendingConfigs::<T>::get().unwrap_or_default();
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
let mut pending_v7 = Vec::new();

for (session, v6) in pending_v6.into_iter() {
Expand Down Expand Up @@ -291,4 +290,20 @@ mod tests {
}
});
}

// Test that migration doesn't panic in case there're no pending configurations upgrades in pallet's storage.
#[test]
fn test_migrate_to_v7_no_pending() {
let v6 = V6HostConfiguration::<primitives::BlockNumber>::default();

new_test_ext(Default::default()).execute_with(|| {
// Implant the v6 version in the state.
v6::ActiveConfig::<Test>::set(Some(v6));
// Ensure there're no pending configs.
v6::PendingConfigs::<Test>::set(None);

// Shouldn't fail.
migrate_to_v7::<Test>();
});
}
}