mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 03:21:03 +00:00
4598e13015
* define slashing spans * tests and pruning for slashing-spans record * validators get slashed before nominators * apply slash to nominators as well * chill and end slashing spans * actually perform slashes * integration (tests failing) * prune metadata * fix compilation * some tests for slashing and metadata garbage collection * correctly pass session index to slash handler * test span-max property for nominators and validators * test that slashes are summed correctly * reward value computation * implement rewarding * add comment about rewards * do not adjust slash fraction in offences module * fix offences tests * remove unused new_offenders field * update runtime version * fix up some docs * fix some CI failures * remove no-std incompatible vec! invocation * try to fix span-max rounding error * Update srml/staking/src/slashing.rs Fix type: winow -> window Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * slashes from prior spans don't kick validator again * more information for nominators, suppression * ensure ledger is consistent with itself post-slash * implement slash out of unlocking funds also * slashing: create records to be applied after-the-fact * queue slashes for a few eras later * method for canceling deferred slashes * attempt to fix test in CI * storage migration for `Nominators` * update node-runtime to use SlashDeferDuration * adjust migration entry-points somewhat * fix migration compilation * add manual Vec import to migration * enable migrations feature in node-runtime * bump runtime version * update to latest master crate renames * update to use ensure-origin * Apply suggestions from code review use `ensure!` Co-Authored-By: Gavin Wood <gavin@parity.io> * fix multi-slash removal * initialize storage version to current in genesis * add test for version initialization
89 lines
2.7 KiB
Rust
89 lines
2.7 KiB
Rust
// Copyright 2019 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Storage migrations for srml-staking.
|
|
|
|
/// Indicator of a version of a storage layout.
|
|
pub type VersionNumber = u32;
|
|
|
|
// the current expected version of the storage
|
|
pub const CURRENT_VERSION: VersionNumber = 1;
|
|
|
|
#[cfg(any(test, feature = "migrate"))]
|
|
mod inner {
|
|
use crate::{Store, Module, Trait};
|
|
use support::{StorageLinkedMap, StorageValue};
|
|
use rstd::vec::Vec;
|
|
use super::{CURRENT_VERSION, VersionNumber};
|
|
|
|
// the minimum supported version of the migration logic.
|
|
const MIN_SUPPORTED_VERSION: VersionNumber = 0;
|
|
|
|
// migrate storage from v0 to v1.
|
|
//
|
|
// this upgrades the `Nominators` linked_map value type from `Vec<T::AccountId>` to
|
|
// `Option<Nominations<T::AccountId>>`
|
|
pub fn to_v1<T: Trait>(version: &mut VersionNumber) {
|
|
if *version != 0 { return }
|
|
*version += 1;
|
|
|
|
let now = <Module<T>>::current_era();
|
|
let res = <Module<T> as Store>::Nominators::translate::<T::AccountId, Vec<T::AccountId>, _, _>(
|
|
|key| key,
|
|
|targets| crate::Nominations {
|
|
targets,
|
|
submitted_in: now,
|
|
suppressed: false,
|
|
},
|
|
);
|
|
|
|
if let Err(e) = res {
|
|
support::print("Encountered error in migration of Staking::Nominators map.");
|
|
if e.is_none() {
|
|
support::print("Staking::Nominators map reinitialized");
|
|
}
|
|
}
|
|
|
|
support::print("Finished migrating Staking storage to v1.");
|
|
}
|
|
|
|
pub(super) fn perform_migrations<T: Trait>() {
|
|
<Module<T> as Store>::StorageVersion::mutate(|version| {
|
|
if *version < MIN_SUPPORTED_VERSION {
|
|
support::print("Cannot migrate staking storage because version is less than\
|
|
minimum.");
|
|
support::print(*version);
|
|
return
|
|
}
|
|
|
|
if *version == CURRENT_VERSION { return }
|
|
|
|
to_v1::<T>(version);
|
|
});
|
|
}
|
|
}
|
|
|
|
#[cfg(not(any(test, feature = "migrate")))]
|
|
mod inner {
|
|
pub(super) fn perform_migrations<T>() { }
|
|
}
|
|
|
|
/// Perform all necessary storage migrations to get storage into the expected stsate for current
|
|
/// logic. No-op if fully upgraded.
|
|
pub(crate) fn perform_migrations<T: crate::Trait>() {
|
|
inner::perform_migrations::<T>();
|
|
}
|