Trait frame_support::migrations::SteppedMigration

source ·
pub trait SteppedMigration {
    type Cursor: FullCodec + MaxEncodedLen;
    type Identifier: FullCodec + MaxEncodedLen;

    // Required methods
    fn id() -> Self::Identifier;
    fn step(
        cursor: Option<Self::Cursor>,
        meter: &mut WeightMeter,
    ) -> Result<Option<Self::Cursor>, SteppedMigrationError>;

    // Provided methods
    fn max_steps() -> Option<u32> { ... }
    fn transactional_step(
        cursor: Option<Self::Cursor>,
        meter: &mut WeightMeter,
    ) -> Result<Option<Self::Cursor>, SteppedMigrationError> { ... }
    fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> { ... }
    fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> { ... }
}
Expand description

A migration that can proceed in multiple steps.

Required Associated Types§

source

type Cursor: FullCodec + MaxEncodedLen

The cursor type that stores the progress (aka. state) of this migration.

source

type Identifier: FullCodec + MaxEncodedLen

The unique identifier type of this migration.

Required Methods§

source

fn id() -> Self::Identifier

The unique identifier of this migration.

If two migrations have the same identifier, then they are assumed to be identical.

source

fn step( cursor: Option<Self::Cursor>, meter: &mut WeightMeter, ) -> Result<Option<Self::Cursor>, SteppedMigrationError>

Try to migrate as much as possible with the given weight.

ANY STORAGE CHANGES MUST BE ROLLED-BACK BY THE CALLER UPON ERROR. This is necessary since the caller cannot return a cursor in the error case. Self::transactional_step is provided as convenience for a caller. A cursor of None implies that the migration is at its end. A migration that once returned Nonce is guaranteed to never be called again.

Provided Methods§

source

fn max_steps() -> Option<u32>

The maximum number of steps that this migration can take.

This can be used to enforce progress and prevent migrations becoming stuck forever. A migration that exceeds its max steps is treated as failed. None means that there is no limit.

source

fn transactional_step( cursor: Option<Self::Cursor>, meter: &mut WeightMeter, ) -> Result<Option<Self::Cursor>, SteppedMigrationError>

Same as Self::step, but rolls back pending changes in the error case.

source

fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError>

Hook for testing that is run before the migration is started.

Returns some bytes which are passed into post_upgrade after the migration is completed. This is not run for the real migration, so panicking is not an issue here.

source

fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError>

Hook for testing that is run after the migration is completed.

Should be used to verify the state of the chain after the migration. The state parameter is the return value from pre_upgrade. This is not run for the real migration, so panicking is not an issue here.

Object Safety§

This trait is not object safe.

Implementors§