referrerpolicy=no-referrer-when-downgrade

Trait polkadot_sdk_frame::traits::GetStorageVersion

pub trait GetStorageVersion {
    type InCodeStorageVersion;

    // Required methods
    fn in_code_storage_version() -> Self::InCodeStorageVersion;
    fn on_chain_storage_version() -> StorageVersion;

    // Provided method
    fn current_storage_version() -> Self::InCodeStorageVersion { ... }
}
Expand description

Provides information about a pallet’s storage versions.

Every pallet has two storage versions:

  1. An in-code storage version
  2. An on-chain storage version

The in-code storage version is the version of the pallet as defined in the runtime blob, and the on-chain storage version is the version of the pallet stored on-chain.

Storage versions should be only ever be out of sync when a pallet has been updated to a new version and the in-code version is incremented, but the migration has not yet been executed on-chain as part of a runtime upgrade.

It is the responsibility of the developer to ensure that the on-chain storage version is set correctly during a migration so that it matches the in-code storage version.

Required Associated Types§

type InCodeStorageVersion

This type is generated by the pallet macro.

If the storage_version attribute isn’t specified, this is set to NoStorageVersionSet to signify that it is missing.

If the storage_version attribute is specified, this is be set to a StorageVersion corresponding to the attribute.

The intention of using NoStorageVersionSet instead of defaulting to a StorageVersion of zero is to prevent developers from forgetting to set storage_version when it is required, like in the case that they wish to compare the in-code storage version to the on-chain storage version.

Required Methods§

fn in_code_storage_version() -> Self::InCodeStorageVersion

Returns the in-code storage version as specified in the storage_version attribute, or NoStorageVersionSet if the attribute is missing.

fn on_chain_storage_version() -> StorageVersion

Returns the storage version of the pallet as last set in the actual on-chain storage.

Provided Methods§

fn current_storage_version() -> Self::InCodeStorageVersion

👎Deprecated: This method has been renamed to in_code_storage_version and will be removed after March 2024.

DEPRECATED: Use Self::current_storage_version instead.

Returns the in-code storage version as specified in the storage_version attribute, or NoStorageVersionSet if the attribute is missing.

Object Safety§

This trait is not object safe.

Implementors§