Skip to content

Commit

Permalink
add migration for validators selfvotes in voterlist (capsule-corp-ter…
Browse files Browse the repository at this point in the history
  • Loading branch information
Leouarz committed Jan 26, 2023
1 parent cd31714 commit 6772932
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
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.5"
version = "1.2.6"
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.5"
version = "1.2.6"
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.5"
version = "1.2.6"
edition = "2021"
build = "build.rs"

Expand Down
20 changes: 16 additions & 4 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod custom_migration {
use super::*;
use frame_election_provider_support::SortedListProvider;
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use pallet_staking::{Nominators, Pallet};
use pallet_staking::{Pallet, Validators};

pub struct Upgrade;
impl OnRuntimeUpgrade for Upgrade {
Expand All @@ -198,9 +198,21 @@ mod custom_migration {
}

fn on_runtime_upgrade() -> Weight {
<Runtime as pallet_staking::Config>::VoterList::unsafe_regenerate(
Nominators::<Runtime>::iter().map(|(id, _)| id),
Pallet::<Runtime>::weight_of_fn(),
let prev_count = <Runtime as pallet_staking::Config>::VoterList::count();
let weight_of_cached = Pallet::<Runtime>::weight_of_fn();
for (v, _) in Validators::<Runtime>::iter() {
let weight = weight_of_cached(&v);
let _ =
<Runtime as pallet_staking::Config>::VoterList::on_insert(v.clone(), weight)
.map_err(|err| {
log::info!("failed to insert {:?} into VoterList: {:?}", v, err);
});
}
log::info!(
"injected a total of {} new voters, prev count: {} next count: {}, updating.",
Validators::<Runtime>::count(),
prev_count,
<Runtime as pallet_staking::Config>::VoterList::count(),
);
debug_assert_eq!(<Runtime as pallet_staking::Config>::VoterList::try_state(), Ok(()));
Weight::MAX
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: 12,
spec_version: 13,

/// 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 6772932

Please sign in to comment.