mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Update contract multi-block migration (#14313)
* move migrate sequence to config * remove commented out code * Update frame/contracts/src/lib.rs Co-authored-by: PG Herveou <pgherveou@gmail.com> * remove Migrations generic * make runtime use noop migrations * restrict is_upgrade_supported * Update contract multi-block migration Ensure that we do as many steps as possible given the weight limit passed to on_idle * undo is_upgrade_supported change * Update bin/node/runtime/src/lib.rs Co-authored-by: PG Herveou <pgherveou@gmail.com> * wip * fix comment (#14316) * fix test * fix * Update frame/contracts/src/migration.rs Co-authored-by: Juan <juangirini@gmail.com> * fix test doc * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Fix compilation with feature runtime-benchmarks * fix example * fix cargo doc --document-private-items * private links * Remove dup comment * add doc for MigrationInProgress * PR review remove duplicate asserts * simplify upper bound * fix link * typo * typo * no unwrap() * correct log message * missing * fix typo * PR comment * Add example with single element tuple * Improve migration message * Update frame/contracts/src/benchmarking/mod.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/migration.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/migration.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * use saturating_accrue instead of += * add more doc * Contracts: Better migration types (#14418) * Add explicit error, if try-runtime runs a noop migration * use mut remaining_weight --------- Co-authored-by: Juan Girini <juangirini@gmail.com> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
This commit is contained in:
@@ -80,6 +80,7 @@
|
||||
//! an [`eDSL`](https://wiki.haskell.org/Embedded_domain_specific_language) that enables writing
|
||||
//! WebAssembly based smart contracts in the Rust programming language.
|
||||
|
||||
#![allow(rustdoc::private_intra_doc_links)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(feature = "runtime-benchmarks", recursion_limit = "1024")]
|
||||
|
||||
@@ -328,19 +329,35 @@ pub mod pallet {
|
||||
/// # struct Runtime {};
|
||||
/// type Migrations = (v9::Migration<Runtime>, v10::Migration<Runtime>, v11::Migration<Runtime>);
|
||||
/// ```
|
||||
///
|
||||
/// If you have a single migration step, you can use a tuple with a single element:
|
||||
/// ```
|
||||
/// use pallet_contracts::migration::v9;
|
||||
/// # struct Runtime {};
|
||||
/// type Migrations = (v9::Migration<Runtime>,);
|
||||
/// ```
|
||||
type Migrations: MigrateSequence;
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_idle(_block: T::BlockNumber, remaining_weight: Weight) -> Weight {
|
||||
fn on_idle(_block: T::BlockNumber, mut remaining_weight: Weight) -> Weight {
|
||||
use migration::MigrateResult::*;
|
||||
|
||||
let (result, weight) = Migration::<T>::migrate(remaining_weight);
|
||||
let remaining_weight = remaining_weight.saturating_sub(weight);
|
||||
loop {
|
||||
let (result, weight) = Migration::<T>::migrate(remaining_weight);
|
||||
remaining_weight.saturating_reduce(weight);
|
||||
|
||||
if !matches!(result, Completed | NoMigrationInProgress) {
|
||||
return 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,
|
||||
// Migration is still in progress, we can start the next step.
|
||||
InProgress { .. } => continue,
|
||||
// Either no migration is in progress, or we are done with all migrations, we
|
||||
// can do some more other work with the remaining weight.
|
||||
Completed | NoMigrationInProgress => break,
|
||||
}
|
||||
}
|
||||
|
||||
ContractInfo::<T>::process_deletion_queue_batch(remaining_weight)
|
||||
@@ -987,6 +1004,8 @@ pub mod pallet {
|
||||
pub(crate) type DeletionQueueCounter<T: Config> =
|
||||
StorageValue<_, DeletionQueueManager<T>, ValueQuery>;
|
||||
|
||||
/// A migration can span across multiple blocks. This storage defines a cursor to track the
|
||||
/// progress of the migration, enabling us to resume from the last completed position.
|
||||
#[pallet::storage]
|
||||
pub(crate) type MigrationInProgress<T: Config> =
|
||||
StorageValue<_, migration::Cursor, OptionQuery>;
|
||||
|
||||
Reference in New Issue
Block a user