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

Update contract multi-block migration #14313

Merged
merged 45 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5c14529
move migrate sequence to config
juangirini Jun 6, 2023
e8c493c
remove commented out code
juangirini Jun 6, 2023
0e62930
Update frame/contracts/src/lib.rs
juangirini Jun 6, 2023
14a7175
remove Migrations generic
juangirini Jun 6, 2023
2601d79
make runtime use noop migrations
juangirini Jun 6, 2023
e88854a
restrict is_upgrade_supported
juangirini Jun 6, 2023
a8caaf2
Update contract multi-block migration
pgherveou Jun 6, 2023
1400ab0
undo is_upgrade_supported change
juangirini Jun 7, 2023
cc7609c
Update bin/node/runtime/src/lib.rs
juangirini Jun 7, 2023
92360cd
wip
pgherveou Jun 7, 2023
137ecc8
fix comment (#14316)
pgherveou Jun 7, 2023
cfaf7e8
Merge branch 'jg/remove-default-migrate-sequence' into pg/more_migrat…
pgherveou Jun 7, 2023
27e5cf8
fix test
pgherveou Jun 7, 2023
2935e99
fix
pgherveou Jun 7, 2023
a4bb302
Update frame/contracts/src/migration.rs
pgherveou Jun 7, 2023
f3e81ce
fix test doc
pgherveou Jun 7, 2023
f10f5bd
Apply suggestions from code review
pgherveou Jun 8, 2023
dc556df
Fix compilation with feature runtime-benchmarks
pgherveou Jun 8, 2023
a7ef997
fix example
pgherveou Jun 8, 2023
6a89133
fix cargo doc --document-private-items
pgherveou Jun 9, 2023
86e6696
private links
pgherveou Jun 9, 2023
6417dde
Remove dup comment
pgherveou Jun 9, 2023
e6bb63d
add doc for MigrationInProgress
pgherveou Jun 9, 2023
1841f23
PR review remove duplicate asserts
pgherveou Jun 9, 2023
0236ca0
simplify upper bound
pgherveou Jun 9, 2023
4686c03
fix link
pgherveou Jun 9, 2023
5e029e1
typo
pgherveou Jun 9, 2023
c7846be
typo
pgherveou Jun 9, 2023
d4349fb
no unwrap()
pgherveou Jun 9, 2023
7511bac
correct log message
pgherveou Jun 9, 2023
e4e5ba1
Merge branch 'master' into pg/more_migratinons_per_block
pgherveou Jun 9, 2023
3545f04
missing
pgherveou Jun 9, 2023
08f84fb
fix typo
pgherveou Jun 12, 2023
85f334f
PR comment
pgherveou Jun 12, 2023
103d50c
Add example with single element tuple
pgherveou Jun 13, 2023
dbb20d3
Improve migration message
pgherveou Jun 13, 2023
3b3c179
Update frame/contracts/src/benchmarking/mod.rs
pgherveou Jun 15, 2023
fc977cb
Update frame/contracts/src/migration.rs
pgherveou Jun 15, 2023
d45d570
Update frame/contracts/src/migration.rs
pgherveou Jun 15, 2023
9d5b6b8
use saturating_accrue instead of +=
pgherveou Jun 15, 2023
fe412a7
add more doc
pgherveou Jun 15, 2023
921dc43
Merge branch 'master' into pg/more_migratinons_per_block
pgherveou Jun 19, 2023
8643fcd
Contracts: Better migration types (#14418)
pgherveou Jun 20, 2023
7a2c272
Add explicit error, if try-runtime runs a noop migration
pgherveou Jun 20, 2023
030554d
use mut remaining_weight
pgherveou Jun 20, 2023
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
5 changes: 5 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use frame_system::{
pub use node_primitives::{AccountId, Signature};
use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Index, Moment};
use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter};
use pallet_contracts::NoopMigration;
use pallet_election_provider_multi_phase::SolutionAccuracyOf;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
Expand Down Expand Up @@ -1240,6 +1241,10 @@ impl pallet_contracts::Config for Runtime {
type MaxStorageKeyLen = ConstU32<128>;
type UnsafeUnstableInterface = ConstBool<false>;
type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>;
#[cfg(not(feature = "runtime-benchmarks"))]
type Migrations = ();
#[cfg(feature = "runtime-benchmarks")]
type Migrations = (NoopMigration<1>, NoopMigration<2>);
}

impl pallet_sudo::Config for Runtime {
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ benchmarks! {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 2);
}

// This benchmarks the weight of executing Migration::migrate when there are no migration in progress.
// This benchmarks the weight of executing 1 `NoopMigraton`
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
#[pov_mode = Measured]
migrate {
StorageVersion::new(0).put::<Pallet<T>>();
Expand Down
27 changes: 20 additions & 7 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ mod address;
mod benchmarking;
mod exec;
mod gas;
mod migration;
mod schedule;
mod storage;
mod wasm;

pub mod chain_extension;
pub mod migration;
pub mod weights;

#[cfg(test)]
Expand Down Expand Up @@ -319,18 +319,31 @@ pub mod pallet {
/// The maximum length of the debug buffer in bytes.
#[pallet::constant]
type MaxDebugBufferLen: Get<u32>;

/// The sequence of migration steps that will be applied during a migration.
type Migrations: MigrateSequence;
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_idle(_block: T::BlockNumber, remaining_weight: Weight) -> Weight {
use migration::MigrateResult::*;

let (result, weight) = Migration::<T>::migrate(remaining_weight);
let remaining_weight = remaining_weight.saturating_sub(weight);

if !matches!(result, Completed | NoMigrationInProgress) {
return weight
let mut remaining_weight = remaining_weight;
pgherveou marked this conversation as resolved.
Show resolved Hide resolved

loop {
let (result, weight) = Migration::<T>::migrate(remaining_weight);
remaining_weight.saturating_reduce(weight);

match result {
// There is not enough weight to perform a migration, or make any progress, we
// just return the remaining weight.
NoMigrationPerformed | InProgress { steps_done: 0 } => return remaining_weight,
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that the same as just break?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this case means that there might be a migration in progress, but we did not have enough gas to make any kind of progress, so you want to exit early here, are doing any work in this function is unsafe is there an actual migration going on.

// Migration is still in progress, we can start the next step.
InProgress { .. } => {},
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
// There are no migration in progress, or we are done with all migrations, we
// can do some more work with the remaining weight.
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
Completed | NoMigrationInProgress => break,
}
}

ContractInfo::<T>::process_deletion_queue_batch(remaining_weight)
Expand Down
Loading
Loading