Skip to content

Commit

Permalink
add migration for bagslist unsafe_regenerate (#298)
Browse files Browse the repository at this point in the history
* add migration for bagslist unsafe_regenerate

* format and upgrade versions
  • Loading branch information
Leouarz authored Jan 24, 2023
1 parent c032dec commit cd31714
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
target/
/weights

# These are backup files generated by rustfmt
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/alphanet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "alphanet-runtime"
authors = [ "Ternoa" ]
version = "1.2.4"
version = "1.2.5"
edition = "2021"
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ternoa-runtime-common"
authors = [ "Ternoa" ]
version = "1.2.1"
version = "1.2.5"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion runtime/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mainnet-runtime"
authors = [ "Ternoa" ]
version = "1.2.4"
version = "1.2.5"
edition = "2021"
build = "build.rs"

Expand Down
34 changes: 34 additions & 0 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,47 @@ pub type UncheckedExtrinsic =
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;

/// Custom runtime upgrade to execute unsafe_regenerate on the bagslist
mod custom_migration {
use super::*;
use frame_election_provider_support::SortedListProvider;
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use pallet_staking::{Nominators, Pallet};

pub struct Upgrade;
impl OnRuntimeUpgrade for Upgrade {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
log::info!("Pre-upgrade for bagslist");
Ok(Vec::new())
}

fn on_runtime_upgrade() -> Weight {
<Runtime as pallet_staking::Config>::VoterList::unsafe_regenerate(
Nominators::<Runtime>::iter().map(|(id, _)| id),
Pallet::<Runtime>::weight_of_fn(),
);
debug_assert_eq!(<Runtime as pallet_staking::Config>::VoterList::try_state(), Ok(()));
Weight::MAX
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), &'static str> {
log::info!("Post-upgrade for bagslist");
Ok(())
}
}
}

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
custom_migration::Upgrade,
>;

impl_runtime_apis! {
Expand Down
2 changes: 1 addition & 1 deletion runtime/mainnet/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
/// Version of the runtime specification. A full-node will not attempt to use its native
/// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
/// `spec_version` and `authoring_version` are the same between Wasm and native.
spec_version: 11,
spec_version: 12,

/// Version of the implementation of the specification. Nodes are free to ignore this; it
/// serves only as an indication that the code is different; as long as the other two versions
Expand Down

0 comments on commit cd31714

Please sign in to comment.