pallet_example_mbm/lib.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18#![cfg_attr(not(feature = "std"), no_std)]
19
20//! # Multi-Block Migrations Example Pallet
21//!
22//! This pallet serves as a minimal example of a pallet that uses the [Multi-Block Migrations
23//! Framework](frame_support::migrations). You can observe how to configure it in a runtime in the
24//! `kitchensink-runtime` crate.
25//!
26//! ## Introduction and Purpose
27//!
28//! The primary purpose of this pallet is to demonstrate the concept of Multi-Block Migrations in
29//! Substrate. It showcases the migration of values from in the
30//! [`MyMap`](`pallet::MyMap`) storage map a `u32` to a `u64` data type using the
31//! [`SteppedMigration`](`frame_support::migrations::SteppedMigration`) implementation from the
32//! [`migrations::v1`] module.
33//!
34//! The [`MyMap`](`pallet::MyMap`) storage item is defined in this `pallet`, and is
35//! aliased to [`v0::MyMap`](`migrations::v1::v0::MyMap`) in the [`migrations::v1`]
36//! module.
37//!
38//! ## How to Read the Documentation
39//!
40//! To access and navigate this documentation in your browser, use the following command:
41//!
42//! - `cargo doc --package pallet-example-mbm --open`
43//!
44//! This documentation is organized to help you understand the pallet's components, features, and
45//! migration process.
46//!
47//! ## Example Usage
48//!
49//! To use this pallet and understand multi-block migrations, you can refer to the
50//! [`migrations::v1`] module, which contains a step-by-step migration example.
51//!
52//! ## Pallet Structure
53//!
54//! The pallet is structured as follows:
55//!
56//! - [`migrations`]: Contains migration-related modules and migration logic.
57//! - [`v1`](`migrations::v1`): Demonstrates the migration process for changing the data type in
58//! the storage map.
59//! - [`pallet`]: Defines the pallet configuration and storage items.
60//!
61//! ## Migration Safety
62//!
63//! When working with migrations, it's crucial to ensure the safety of your migrations. The
64//! preferred tool to test migrations is
65//! [`try-runtime-cli`](https://github.com/paritytech/try-runtime-cli). Support will be added to
66//! dry-run MBMs once they are stable
67//! (tracked: <https://github.com/paritytech/try-runtime-cli/issues/17>).
68
69pub mod migrations;
70mod mock;
71
72pub use pallet::*;
73
74#[frame_support::pallet]
75pub mod pallet {
76 use frame_support::{pallet_prelude::StorageMap, Blake2_128Concat};
77
78 #[pallet::pallet]
79 pub struct Pallet<T>(_);
80
81 #[pallet::config]
82 pub trait Config: frame_system::Config {}
83
84 /// Define a storage item to illustrate multi-block migrations.
85 #[pallet::storage]
86 pub type MyMap<T: Config> = StorageMap<_, Blake2_128Concat, u32, u64>;
87}