From f6e3a3c6e38a67f86ec0ba2bcef9474cd846c175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 09:40:47 +0200 Subject: [PATCH 01/14] frame/grandpa: migrate Config --- frame/grandpa/src/lib.rs | 82 ++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 7cfc1d61baf2f..335da33c789f4 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -67,39 +67,55 @@ pub use equivocation::{ HandleEquivocation, }; -pub trait Config: frame_system::Config { - /// The event type of this module. - type Event: From + Into<::Event>; - - /// The function call. - type Call: From>; - - /// The proof of key ownership, used for validating equivocation reports. - /// The proof must include the session index and validator count of the - /// session at which the equivocation occurred. - type KeyOwnerProof: Parameter + GetSessionNumber + GetValidatorCount; - - /// The identification of a key owner, used when reporting equivocations. - type KeyOwnerIdentification: Parameter; - - /// A system for proving ownership of keys, i.e. that a given key was part - /// of a validator set, needed for validating equivocation reports. - type KeyOwnerProofSystem: KeyOwnerProofSystem< - (KeyTypeId, AuthorityId), - Proof = Self::KeyOwnerProof, - IdentificationTuple = Self::KeyOwnerIdentification, - >; - - /// The equivocation handling subsystem, defines methods to report an - /// offence (after the equivocation has been validated) and for submitting a - /// transaction to report an equivocation (from an offchain context). - /// NOTE: when enabling equivocation handling (i.e. this type isn't set to - /// `()`) you must use this pallet's `ValidateUnsigned` in the runtime - /// definition. - type HandleEquivocation: HandleEquivocation; - - /// Weights for this pallet. - type WeightInfo: WeightInfo; +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + use super::*; + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + /// The event type of this module. + type Event: From + + Into<::Event> + + IsType<::Event>; + + /// The function call. + type Call: From>; + + /// The proof of key ownership, used for validating equivocation reports + /// The proof must include the session index and validator count of the + /// session at which the equivocation occurred. + type KeyOwnerProof: Parameter + GetSessionNumber + GetValidatorCount; + + /// The identification of a key owner, used when reporting equivocations. + type KeyOwnerIdentification: Parameter; + + /// A system for proving ownership of keys, i.e. that a given key was part + /// of a validator set, needed for validating equivocation reports. + type KeyOwnerProofSystem: KeyOwnerProofSystem< + (KeyTypeId, AuthorityId), + Proof = Self::KeyOwnerProof, + IdentificationTuple = Self::KeyOwnerIdentification, + >; + + /// The equivocation handling subsystem, defines methods to report an + /// offence (after the equivocation has been validated) and for submitting a + /// transaction to report an equivocation (from an offchain context). + /// NOTE: when enabling equivocation handling (i.e. this type isn't set to + /// `()`) you must use this pallet's `ValidateUnsigned` in the runtime + /// definition. + type HandleEquivocation: HandleEquivocation; + + /// Weights for this pallet. + type WeightInfo: WeightInfo; + } } pub trait WeightInfo { From b2d7383e9af8d3de21c86dc58ba3989cc8eca1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 09:54:51 +0200 Subject: [PATCH 02/14] frame/grandpa: migrate decl_module --- frame/grandpa/src/lib.rs | 265 ++++++++++++++++++++------------------- 1 file changed, 134 insertions(+), 131 deletions(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 335da33c789f4..231df09199ab0 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -116,6 +116,140 @@ pub mod pallet { /// Weights for this pallet. type WeightInfo: WeightInfo; } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_finalize(block_number: T::BlockNumber) { + // check for scheduled pending authority set changes + if let Some(pending_change) = >::get() { + // emit signal if we're at the block that scheduled the change + if block_number == pending_change.scheduled_at { + if let Some(median) = pending_change.forced { + Self::deposit_log(ConsensusLog::ForcedChange( + median, + ScheduledChange { + delay: pending_change.delay, + next_authorities: pending_change.next_authorities.clone(), + } + )) + } else { + Self::deposit_log(ConsensusLog::ScheduledChange( + ScheduledChange { + delay: pending_change.delay, + next_authorities: pending_change.next_authorities.clone(), + } + )); + } + } + + // enact the change if we've reached the enacting block + if block_number == pending_change.scheduled_at + pending_change.delay { + Self::set_grandpa_authorities(&pending_change.next_authorities); + Self::deposit_event( + Event::NewAuthorities(pending_change.next_authorities) + ); + >::kill(); + } + } + + // check for scheduled pending state changes + match >::get() { + StoredState::PendingPause { scheduled_at, delay } => { + // signal change to pause + if block_number == scheduled_at { + Self::deposit_log(ConsensusLog::Pause(delay)); + } + + // enact change to paused state + if block_number == scheduled_at + delay { + >::put(StoredState::Paused); + Self::deposit_event(Event::Paused); + } + }, + StoredState::PendingResume { scheduled_at, delay } => { + // signal change to resume + if block_number == scheduled_at { + Self::deposit_log(ConsensusLog::Resume(delay)); + } + + // enact change to live state + if block_number == scheduled_at + delay { + >::put(StoredState::Live); + Self::deposit_event(Event::Resumed); + } + }, + _ => {}, + } + } + } + + #[pallet::call] + impl Pallet { + type Error = Error; + + fn deposit_event() = default; + + /// Report voter equivocation/misbehavior. This method will verify the + /// equivocation proof and validate the given key ownership proof + /// against the extracted offender. If both are valid, the offence + /// will be reported. + #[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))] + fn report_equivocation( + origin: OriginFor, + equivocation_proof: EquivocationProof, + key_owner_proof: T::KeyOwnerProof, + ) -> DispatchResultWithPostInfo { + let reporter = ensure_signed(origin)?; + + Self::do_report_equivocation( + Some(reporter), + equivocation_proof, + key_owner_proof, + ) + } + + /// Report voter equivocation/misbehavior. This method will verify the + /// equivocation proof and validate the given key ownership proof + /// against the extracted offender. If both are valid, the offence + /// will be reported. + /// + /// This extrinsic must be called unsigned and it is expected that only + /// block authors will call it (validated in `ValidateUnsigned`), as such + /// if the block author is defined it will be defined as the equivocation + /// reporter. + #[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))] + fn report_equivocation_unsigned( + origin: OriginFor, + equivocation_proof: EquivocationProof, + key_owner_proof: T::KeyOwnerProof, + ) -> DispatchResultWithPostInfo { + ensure_none(origin)?; + + Self::do_report_equivocation( + T::HandleEquivocation::block_author(), + equivocation_proof, + key_owner_proof, + ) + } + + /// Note that the current authority set of the GRANDPA finality gadget has + /// stalled. This will trigger a forced authority set change at the beginning + /// of the next session, to be enacted `delay` blocks after that. The delay + /// should be high enough to safely assume that the block signalling the + /// forced change will not be re-orged (e.g. 1000 blocks). The GRANDPA voters + /// will start the new authority set using the given finalized block as base. + /// Only callable by root. + #[pallet::weight(T::WeightInfo::note_stalled())] + fn note_stalled( + origin: OriginFor, + delay: T::BlockNumber, + best_finalized_block_number: T::BlockNumber, + ) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + + Ok(Self::on_stalled(delay, best_finalized_block_number).into()) + } + } } pub trait WeightInfo { @@ -256,137 +390,6 @@ decl_storage! { } } -decl_module! { - pub struct Module for enum Call where origin: T::Origin { - type Error = Error; - - fn deposit_event() = default; - - /// Report voter equivocation/misbehavior. This method will verify the - /// equivocation proof and validate the given key ownership proof - /// against the extracted offender. If both are valid, the offence - /// will be reported. - #[weight = T::WeightInfo::report_equivocation(key_owner_proof.validator_count())] - fn report_equivocation( - origin, - equivocation_proof: EquivocationProof, - key_owner_proof: T::KeyOwnerProof, - ) -> DispatchResultWithPostInfo { - let reporter = ensure_signed(origin)?; - - Self::do_report_equivocation( - Some(reporter), - equivocation_proof, - key_owner_proof, - ) - } - - /// Report voter equivocation/misbehavior. This method will verify the - /// equivocation proof and validate the given key ownership proof - /// against the extracted offender. If both are valid, the offence - /// will be reported. - /// - /// This extrinsic must be called unsigned and it is expected that only - /// block authors will call it (validated in `ValidateUnsigned`), as such - /// if the block author is defined it will be defined as the equivocation - /// reporter. - #[weight = T::WeightInfo::report_equivocation(key_owner_proof.validator_count())] - fn report_equivocation_unsigned( - origin, - equivocation_proof: EquivocationProof, - key_owner_proof: T::KeyOwnerProof, - ) -> DispatchResultWithPostInfo { - ensure_none(origin)?; - - Self::do_report_equivocation( - T::HandleEquivocation::block_author(), - equivocation_proof, - key_owner_proof, - ) - } - - /// Note that the current authority set of the GRANDPA finality gadget has - /// stalled. This will trigger a forced authority set change at the beginning - /// of the next session, to be enacted `delay` blocks after that. The delay - /// should be high enough to safely assume that the block signalling the - /// forced change will not be re-orged (e.g. 1000 blocks). The GRANDPA voters - /// will start the new authority set using the given finalized block as base. - /// Only callable by root. - #[weight = T::WeightInfo::note_stalled()] - fn note_stalled( - origin, - delay: T::BlockNumber, - best_finalized_block_number: T::BlockNumber, - ) { - ensure_root(origin)?; - - Self::on_stalled(delay, best_finalized_block_number) - } - - fn on_finalize(block_number: T::BlockNumber) { - // check for scheduled pending authority set changes - if let Some(pending_change) = >::get() { - // emit signal if we're at the block that scheduled the change - if block_number == pending_change.scheduled_at { - if let Some(median) = pending_change.forced { - Self::deposit_log(ConsensusLog::ForcedChange( - median, - ScheduledChange { - delay: pending_change.delay, - next_authorities: pending_change.next_authorities.clone(), - } - )) - } else { - Self::deposit_log(ConsensusLog::ScheduledChange( - ScheduledChange { - delay: pending_change.delay, - next_authorities: pending_change.next_authorities.clone(), - } - )); - } - } - - // enact the change if we've reached the enacting block - if block_number == pending_change.scheduled_at + pending_change.delay { - Self::set_grandpa_authorities(&pending_change.next_authorities); - Self::deposit_event( - Event::NewAuthorities(pending_change.next_authorities) - ); - >::kill(); - } - } - - // check for scheduled pending state changes - match >::get() { - StoredState::PendingPause { scheduled_at, delay } => { - // signal change to pause - if block_number == scheduled_at { - Self::deposit_log(ConsensusLog::Pause(delay)); - } - - // enact change to paused state - if block_number == scheduled_at + delay { - >::put(StoredState::Paused); - Self::deposit_event(Event::Paused); - } - }, - StoredState::PendingResume { scheduled_at, delay } => { - // signal change to resume - if block_number == scheduled_at { - Self::deposit_log(ConsensusLog::Resume(delay)); - } - - // enact change to live state - if block_number == scheduled_at + delay { - >::put(StoredState::Live); - Self::deposit_event(Event::Resumed); - } - }, - _ => {}, - } - } - } -} impl Module { /// Get the current set of authorities, along with their respective weights. From 19ac9fb496850cbe0be00b2207d2b63261e03623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 09:57:30 +0200 Subject: [PATCH 03/14] frame/grandpa: migrate decl_event --- frame/grandpa/src/lib.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 231df09199ab0..53106f8d07724 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -187,8 +187,6 @@ pub mod pallet { impl Pallet { type Error = Error; - fn deposit_event() = default; - /// Report voter equivocation/misbehavior. This method will verify the /// equivocation proof and validate the given key ownership proof /// against the extracted offender. If both are valid, the offence @@ -250,6 +248,17 @@ pub mod pallet { Ok(Self::on_stalled(delay, best_finalized_block_number).into()) } } + + #[pallet::event] + #[pallet::generate_deposit(fn deposit_event)] + pub enum Event { + /// New authority set has been applied. \[authority_set\] + NewAuthorities(AuthorityList), + /// Current authority set has been paused. + Paused, + /// Current authority set has been resumed. + Resumed, + } } pub trait WeightInfo { @@ -326,17 +335,6 @@ pub enum StoredState { }, } -decl_event! { - pub enum Event { - /// New authority set has been applied. \[authority_set\] - NewAuthorities(AuthorityList), - /// Current authority set has been paused. - Paused, - /// Current authority set has been resumed. - Resumed, - } -} - decl_error! { pub enum Error for Module { /// Attempt to signal GRANDPA pause when the authority set isn't live From 962a744d04fcf0c9ec449da7c509c0ce4ac65a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 10:05:30 +0200 Subject: [PATCH 04/14] frame/grandpa: migrate decl_error --- frame/grandpa/src/lib.rs | 43 +++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 53106f8d07724..317fbf5e60150 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -185,8 +185,6 @@ pub mod pallet { #[pallet::call] impl Pallet { - type Error = Error; - /// Report voter equivocation/misbehavior. This method will verify the /// equivocation proof and validate the given key ownership proof /// against the extracted offender. If both are valid, the offence @@ -259,6 +257,26 @@ pub mod pallet { /// Current authority set has been resumed. Resumed, } + + #[pallet::error] + pub enum Error { + /// Attempt to signal GRANDPA pause when the authority set isn't live + /// (either paused or already pending pause). + PauseFailed, + /// Attempt to signal GRANDPA resume when the authority set isn't paused + /// (either live or already pending resume). + ResumeFailed, + /// Attempt to signal GRANDPA change with one already pending. + ChangePending, + /// Cannot signal forced change so soon after last. + TooSoon, + /// A key ownership proof provided as part of an equivocation report is invalid. + InvalidKeyOwnershipProof, + /// An equivocation proof provided as part of an equivocation report is invalid. + InvalidEquivocationProof, + /// A given equivocation report is valid but already previously reported. + DuplicateOffenceReport, + } } pub trait WeightInfo { @@ -335,27 +353,6 @@ pub enum StoredState { }, } -decl_error! { - pub enum Error for Module { - /// Attempt to signal GRANDPA pause when the authority set isn't live - /// (either paused or already pending pause). - PauseFailed, - /// Attempt to signal GRANDPA resume when the authority set isn't paused - /// (either live or already pending resume). - ResumeFailed, - /// Attempt to signal GRANDPA change with one already pending. - ChangePending, - /// Cannot signal forced change so soon after last. - TooSoon, - /// A key ownership proof provided as part of an equivocation report is invalid. - InvalidKeyOwnershipProof, - /// An equivocation proof provided as part of an equivocation report is invalid. - InvalidEquivocationProof, - /// A given equivocation report is valid but already previously reported. - DuplicateOffenceReport, - } -} - decl_storage! { trait Store for Module as GrandpaFinality { /// State of the current authority set. From c172e99a8d7512b15d961e7ff3cbaa2d374930dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 11:26:43 +0200 Subject: [PATCH 05/14] frame/grandpa: migrate decl_storage --- frame/grandpa/src/lib.rs | 100 +++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 317fbf5e60150..88ec0ac6aebee 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -277,6 +277,67 @@ pub mod pallet { /// A given equivocation report is valid but already previously reported. DuplicateOffenceReport, } + + #[pallet::type_value] + pub(super) fn DefaultForState() -> StoredState { + StoredState::Live + } + + /// State of the current authority set. + #[pallet::storage] + #[pallet::getter(fn state)] + pub(super) type State = StorageValue<_, StoredState, ValueQuery, DefaultForState>; + + /// Pending change: (signaled at, scheduled change). + #[pallet::storage] + #[pallet::getter(fn pending_change)] + pub(super) type PendingChange = StorageValue<_, StoredPendingChange>; + + /// next block number where we can force a change. + #[pallet::storage] + #[pallet::getter(fn next_forced)] + pub(super) type NextForced = StorageValue<_, T::BlockNumber>; + + /// `true` if we are currently stalled. + #[pallet::storage] + #[pallet::getter(fn stalled)] + pub(super) type Stalled = StorageValue<_, (T::BlockNumber, T::BlockNumber)>; + + /// The number of changes (both in terms of keys and underlying economic responsibilities) + /// in the "set" of Grandpa validators from genesis. + #[pallet::storage] + #[pallet::getter(fn current_set_id)] + pub(super) type CurrentSetId = StorageValue<_, SetId, ValueQuery>; + + /// A mapping from grandpa set ID to the index of the *most recent* session for which its + /// members were responsible. + /// + /// TWOX-NOTE: `SetId` is not under user control. + #[pallet::storage] + #[pallet::getter(fn session_for_set)] + pub(super) type SetIdSession = StorageMap<_, Twox64Concat, SetId, SessionIndex>; + + #[pallet::genesis_config] + pub struct GenesisConfig { + pub authorities: AuthorityList, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self { + authorities: Default::default(), + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + CurrentSetId::::put(fg_primitives::SetId::default()); + Pallet::::initialize(&self.authorities) + } + } } pub trait WeightInfo { @@ -353,39 +414,6 @@ pub enum StoredState { }, } -decl_storage! { - trait Store for Module as GrandpaFinality { - /// State of the current authority set. - State get(fn state): StoredState = StoredState::Live; - - /// Pending change: (signaled at, scheduled change). - PendingChange get(fn pending_change): Option>; - - /// next block number where we can force a change. - NextForced get(fn next_forced): Option; - - /// `true` if we are currently stalled. - Stalled get(fn stalled): Option<(T::BlockNumber, T::BlockNumber)>; - - /// The number of changes (both in terms of keys and underlying economic responsibilities) - /// in the "set" of Grandpa validators from genesis. - CurrentSetId get(fn current_set_id) build(|_| fg_primitives::SetId::default()): SetId; - - /// A mapping from grandpa set ID to the index of the *most recent* session for which its - /// members were responsible. - /// - /// TWOX-NOTE: `SetId` is not under user control. - SetIdSession get(fn session_for_set): map hasher(twox_64_concat) SetId => Option; - } - add_extra_genesis { - config(authorities): AuthorityList; - build(|config| { - Module::::initialize(&config.authorities) - }) - } -} - - impl Module { /// Get the current set of authorities, along with their respective weights. pub fn grandpa_authorities() -> AuthorityList { @@ -496,7 +524,7 @@ impl Module { // NOTE: initialize first session of first set. this is necessary for // the genesis set and session since we only update the set -> session // mapping whenever a new session starts, i.e. through `on_new_session`. - SetIdSession::insert(0, 0); + SetIdSession::::insert(0, 0); } fn do_report_equivocation( @@ -621,7 +649,7 @@ impl OneSessionHandler for Module }; if res.is_ok() { - CurrentSetId::mutate(|s| { + CurrentSetId::::mutate(|s| { *s += 1; *s }) @@ -640,7 +668,7 @@ impl OneSessionHandler for Module // if we didn't issue a change, we update the mapping to note that the current // set corresponds to the latest equivalent session (i.e. now). let session_index = >::current_index(); - SetIdSession::insert(current_set_id, &session_index); + SetIdSession::::insert(current_set_id, &session_index); } fn on_disabled(i: usize) { From e5656d4b2a938dc21edd7c61221911b253c39327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 11:58:26 +0200 Subject: [PATCH 06/14] frame/grandpa: make report_equivocation_unsigned pub(super) --- frame/grandpa/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 88ec0ac6aebee..c418292460159 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -214,7 +214,7 @@ pub mod pallet { /// if the block author is defined it will be defined as the equivocation /// reporter. #[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))] - fn report_equivocation_unsigned( + pub(super) fn report_equivocation_unsigned( origin: OriginFor, equivocation_proof: EquivocationProof, key_owner_proof: T::KeyOwnerProof, From 0781fe6dd8d9e2b836ebd39ca287eb3426dfb30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 12:02:29 +0200 Subject: [PATCH 07/14] frame/grandpa: remove unused imports --- frame/grandpa/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index c418292460159..5338fe5dc175f 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -40,10 +40,9 @@ use fg_primitives::{ GRANDPA_ENGINE_ID, }; use frame_support::{ - decl_error, decl_event, decl_module, decl_storage, dispatch::DispatchResultWithPostInfo, - storage, traits::{OneSessionHandler, KeyOwnerProofSystem}, weights::{Pays, Weight}, Parameter, + dispatch::DispatchResultWithPostInfo, + storage, traits::{OneSessionHandler, KeyOwnerProofSystem}, weights::{Pays, Weight}, }; -use frame_system::{ensure_none, ensure_root, ensure_signed}; use sp_runtime::{ generic::DigestItem, traits::Zero, From 9008771dca185a506402390c58b1d84eea4a1582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 12:05:39 +0200 Subject: [PATCH 08/14] frame/grandpa: replace deprecated Module with Pallet --- frame/grandpa/src/benchmarking.rs | 2 +- frame/grandpa/src/equivocation.rs | 6 +++--- frame/grandpa/src/lib.rs | 8 ++++---- frame/grandpa/src/mock.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frame/grandpa/src/benchmarking.rs b/frame/grandpa/src/benchmarking.rs index 5f08a5ea4bac0..1bd65944f0a35 100644 --- a/frame/grandpa/src/benchmarking.rs +++ b/frame/grandpa/src/benchmarking.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use super::{*, Module as Grandpa}; +use super::{*, Pallet as Grandpa}; use frame_benchmarking::benchmarks; use frame_system::RawOrigin; use sp_core::H256; diff --git a/frame/grandpa/src/equivocation.rs b/frame/grandpa/src/equivocation.rs index 8ab86b2fed065..24f56247d30ef 100644 --- a/frame/grandpa/src/equivocation.rs +++ b/frame/grandpa/src/equivocation.rs @@ -54,7 +54,7 @@ use sp_staking::{ SessionIndex, }; -use super::{Call, Module, Config}; +use super::{Call, Pallet, Config}; /// A trait with utility methods for handling equivocation reports in GRANDPA. /// The offence type is generic, and the trait provides , reporting an offence @@ -186,7 +186,7 @@ where } fn block_author() -> Option { - Some(>::author()) + Some(>::author()) } } @@ -203,7 +203,7 @@ pub struct GrandpaTimeSlot { /// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned` /// to local calls (i.e. extrinsics generated on this node) or that already in a block. This /// guarantees that only block authors can include unsigned equivocation reports. -impl frame_support::unsigned::ValidateUnsigned for Module { +impl frame_support::unsigned::ValidateUnsigned for Pallet { type Call = Call; fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity { if let Call::report_equivocation_unsigned(equivocation_proof, key_owner_proof) = call { diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 5338fe5dc175f..6d231f5ede682 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -413,7 +413,7 @@ pub enum StoredState { }, } -impl Module { +impl Pallet { /// Get the current set of authorities, along with their respective weights. pub fn grandpa_authorities() -> AuthorityList { storage::unhashed::get_or_default::(GRANDPA_AUTHORITIES_KEY).into() @@ -616,11 +616,11 @@ impl Module { } } -impl sp_runtime::BoundToRuntimeAppPublic for Module { +impl sp_runtime::BoundToRuntimeAppPublic for Pallet { type Public = AuthorityId; } -impl OneSessionHandler for Module +impl OneSessionHandler for Pallet where T: pallet_session::Config { type Key = AuthorityId; @@ -666,7 +666,7 @@ impl OneSessionHandler for Module // if we didn't issue a change, we update the mapping to note that the current // set corresponds to the latest equivalent session (i.e. now). - let session_index = >::current_index(); + let session_index = >::current_index(); SetIdSession::::insert(current_set_id, &session_index); } diff --git a/frame/grandpa/src/mock.rs b/frame/grandpa/src/mock.rs index d59d0d19d0e87..beadc18d8a6b1 100644 --- a/frame/grandpa/src/mock.rs +++ b/frame/grandpa/src/mock.rs @@ -64,7 +64,7 @@ frame_support::construct_runtime!( impl_opaque_keys! { pub struct TestSessionKeys { - pub grandpa_authority: super::Module, + pub grandpa_authority: super::Pallet, } } From 4cf4f9d591cef61a757882418ab6a5efc8f1e68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Tue, 4 May 2021 17:17:23 +0200 Subject: [PATCH 09/14] frame/grandpa: add RawEvent for compatibility --- frame/grandpa/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 6d231f5ede682..0ebe1c97a2306 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -257,6 +257,9 @@ pub mod pallet { Resumed, } + #[deprecated(note = "use `Event` instead")] + pub type RawEvent = Event; + #[pallet::error] pub enum Error { /// Attempt to signal GRANDPA pause when the authority set isn't live From a1c02cf778e1b221a821d652c7b4486512fb317c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Thu, 6 May 2021 10:25:47 +0200 Subject: [PATCH 10/14] frame/grandpa: create migration to new storage prefix --- frame/grandpa/Cargo.toml | 2 +- frame/grandpa/src/lib.rs | 1 + frame/grandpa/src/migrations.rs | 19 +++++ frame/grandpa/src/migrations/v4.rs | 109 +++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 frame/grandpa/src/migrations.rs create mode 100644 frame/grandpa/src/migrations/v4.rs diff --git a/frame/grandpa/Cargo.toml b/frame/grandpa/Cargo.toml index a602e8b6daddf..88b3f0c5d50ce 100644 --- a/frame/grandpa/Cargo.toml +++ b/frame/grandpa/Cargo.toml @@ -17,6 +17,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = sp-application-crypto = { version = "3.0.0", default-features = false, path = "../../primitives/application-crypto" } sp-core = { version = "3.0.0", default-features = false, path = "../../primitives/core" } sp-finality-grandpa = { version = "3.0.0", default-features = false, path = "../../primitives/finality-grandpa" } +sp-io = { version = "3.0.0", default-features = false, path = "../../primitives/io" } sp-session = { version = "3.0.0", default-features = false, path = "../../primitives/session" } sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" } @@ -31,7 +32,6 @@ log = { version = "0.4.14", default-features = false } [dev-dependencies] frame-benchmarking = { version = "3.1.0", path = "../benchmarking" } grandpa = { package = "finality-grandpa", version = "0.14.0", features = ["derive-codec"] } -sp-io = { version = "3.0.0", path = "../../primitives/io" } sp-keyring = { version = "3.0.0", path = "../../primitives/keyring" } pallet-balances = { version = "3.0.0", path = "../balances" } pallet-offences = { version = "3.0.0", path = "../offences" } diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index 0ebe1c97a2306..8ed1a780bf85c 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -53,6 +53,7 @@ use sp_staking::SessionIndex; mod equivocation; mod default_weights; +pub mod migrations; #[cfg(any(feature = "runtime-benchmarks", test))] mod benchmarking; diff --git a/frame/grandpa/src/migrations.rs b/frame/grandpa/src/migrations.rs new file mode 100644 index 0000000000000..05c24e11b3939 --- /dev/null +++ b/frame/grandpa/src/migrations.rs @@ -0,0 +1,19 @@ +// This file is part of Substrate. + +// Copyright (C) 2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// Version 4. +pub mod v4; diff --git a/frame/grandpa/src/migrations/v4.rs b/frame/grandpa/src/migrations/v4.rs new file mode 100644 index 0000000000000..37379a934facd --- /dev/null +++ b/frame/grandpa/src/migrations/v4.rs @@ -0,0 +1,109 @@ +// This file is part of Substrate. + +// Copyright (C) 2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use frame_support::{ + weights::Weight, + traits::{GetPalletVersion, PalletVersion, Get}, +}; + +/// The old prefix. +pub const OLD_PREFIX: &[u8] = b"GrandpaFinality"; + +/// Migrate the entire storage of this pallet to a new prefix. +/// +/// This new prefix must be the same as the one set in construct_runtime. For safety, use +/// `PalletInfo` to get it, as: +/// `::PalletInfo::name::`. +/// +/// The old storage prefix, `GrandpaFinality` is hardcoded in the migration code. +pub fn migrate< + T: frame_system::Config, + P: GetPalletVersion, + N: AsRef, +>(new_pallet_name: N) -> Weight { + + if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX { + log::info!( + target: "runtime::afg", + "New pallet name is equal to the old prefix. No migration needs to be done.", + ); + return 0; + } + let maybe_storage_version =

::storage_version(); + log::info!( + target: "runtime::afg", + "Running migration to v4 for grandpa with storage version {:?}", + maybe_storage_version, + ); + + match maybe_storage_version { + Some(storage_version) if storage_version <= PalletVersion::new(3, 0, 0) => { + log::info!("new prefix: {}", new_pallet_name.as_ref()); + frame_support::storage::migration::move_pallet( + OLD_PREFIX, + new_pallet_name.as_ref().as_bytes(), + ); + ::BlockWeights::get().max_block + } + _ => { + log::warn!( + target: "runtime::afg", + "Attempted to apply migration to v4 but failed because storage version is {:?}", + maybe_storage_version, + ); + 0 + }, + } +} + +/// Some checks prior to migration. This can be linked to +/// [`frame_support::traits::OnRuntimeUpgrade::pre_upgrade`] for further testing. +/// +/// Panics if anything goes wrong. +pub fn pre_migration>(new: N) { + let new = new.as_ref(); + log::info!("pre-migration grandpa test with new = {}", new); + + // the next key must exist, and start with the hash of `OLD_PREFIX`. + let next_key = sp_io::storage::next_key(OLD_PREFIX).unwrap(); + assert!(next_key.starts_with(&sp_io::hashing::twox_128(OLD_PREFIX))); + + // ensure nothing is stored in the new prefix. + assert!( + sp_io::storage::next_key(new.as_bytes()).map_or( + // either nothing is there + true, + // or we ensure that it has no common prefix with twox_128(new). + |next_key| !next_key.starts_with(&sp_io::hashing::twox_128(new.as_bytes())) + ), + "unexpected next_key({}) = {:?}", + new, + sp_core::hexdisplay::HexDisplay::from(&sp_io::storage::next_key(new.as_bytes()).unwrap()) + ); + // ensure storage version is 3. + assert!(

::storage_version().unwrap().major == 3); +} + +/// Some checks for after migration. This can be linked to +/// [`frame_support::traits::OnRuntimeUpgrade::post_upgrade`] for further testing. +/// +/// Panics if anything goes wrong. +pub fn post_migration() { + log::info!("post-migration grandpa"); + // ensure we've been updated to v4 by the automatic write of crate version -> storage version. + assert!(

::storage_version().unwrap().major == 4); +} From 7ae74a03967a71a33c2fc4d8ba92c519f1ba69b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Thu, 6 May 2021 13:19:01 +0200 Subject: [PATCH 11/14] frame/grandpa: bump version to 4.0.0 --- Cargo.lock | 2 +- bin/node-template/runtime/Cargo.toml | 2 +- bin/node/cli/Cargo.toml | 2 +- bin/node/executor/Cargo.toml | 2 +- bin/node/runtime/Cargo.toml | 2 +- bin/node/testing/Cargo.toml | 2 +- frame/grandpa/Cargo.toml | 2 +- frame/offences/benchmarking/Cargo.toml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f7bce5aaa3c6..ad4f19f49c908 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5004,7 +5004,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" -version = "3.0.0" +version = "4.0.0" dependencies = [ "finality-grandpa", "frame-benchmarking", diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index 8f7d39f18bc4d..455a439389fcc 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = pallet-aura = { version = "3.0.0", default-features = false, path = "../../../frame/aura" } pallet-balances = { version = "3.0.0", default-features = false, path = "../../../frame/balances" } frame-support = { version = "3.0.0", default-features = false, path = "../../../frame/support" } -pallet-grandpa = { version = "3.0.0", default-features = false, path = "../../../frame/grandpa" } +pallet-grandpa = { version = "4.0.0", default-features = false, path = "../../../frame/grandpa" } pallet-randomness-collective-flip = { version = "3.0.0", default-features = false, path = "../../../frame/randomness-collective-flip" } pallet-sudo = { version = "3.0.0", default-features = false, path = "../../../frame/sudo" } frame-system = { version = "3.0.0", default-features = false, path = "../../../frame/system" } diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index ccba896a20682..b43836c7b915f 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -89,7 +89,7 @@ frame-support = { version = "3.0.0", default-features = false, path = "../../../ pallet-im-online = { version = "3.0.0", default-features = false, path = "../../../frame/im-online" } pallet-authority-discovery = { version = "3.0.0", path = "../../../frame/authority-discovery" } pallet-staking = { version = "3.0.0", path = "../../../frame/staking" } -pallet-grandpa = { version = "3.0.0", path = "../../../frame/grandpa" } +pallet-grandpa = { version = "4.0.0", path = "../../../frame/grandpa" } # node-specific dependencies node-runtime = { version = "2.0.0", path = "../runtime" } diff --git a/bin/node/executor/Cargo.toml b/bin/node/executor/Cargo.toml index 54a44d59c2591..bd9e223e87cf8 100644 --- a/bin/node/executor/Cargo.toml +++ b/bin/node/executor/Cargo.toml @@ -31,7 +31,7 @@ frame-system = { version = "3.0.0", path = "../../../frame/system" } node-testing = { version = "2.0.0", path = "../testing" } pallet-balances = { version = "3.0.0", path = "../../../frame/balances" } pallet-contracts = { version = "3.0.0", path = "../../../frame/contracts" } -pallet-grandpa = { version = "3.0.0", path = "../../../frame/grandpa" } +pallet-grandpa = { version = "4.0.0", path = "../../../frame/grandpa" } pallet-im-online = { version = "3.0.0", path = "../../../frame/im-online" } pallet-indices = { version = "3.0.0", path = "../../../frame/indices" } pallet-session = { version = "3.0.0", path = "../../../frame/session" } diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 512f32d66a66c..9a1c4340365a9 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -59,7 +59,7 @@ pallet-democracy = { version = "3.0.0", default-features = false, path = "../../ pallet-election-provider-multi-phase = { version = "3.0.0", default-features = false, path = "../../../frame/election-provider-multi-phase" } pallet-elections-phragmen = { version = "4.0.0", default-features = false, path = "../../../frame/elections-phragmen" } pallet-gilt = { version = "3.0.0", default-features = false, path = "../../../frame/gilt" } -pallet-grandpa = { version = "3.0.0", default-features = false, path = "../../../frame/grandpa" } +pallet-grandpa = { version = "4.0.0", default-features = false, path = "../../../frame/grandpa" } pallet-im-online = { version = "3.0.0", default-features = false, path = "../../../frame/im-online" } pallet-indices = { version = "3.0.0", default-features = false, path = "../../../frame/indices" } pallet-identity = { version = "3.0.0", default-features = false, path = "../../../frame/identity" } diff --git a/bin/node/testing/Cargo.toml b/bin/node/testing/Cargo.toml index 5ae277b35be2c..e929029765ee7 100644 --- a/bin/node/testing/Cargo.toml +++ b/bin/node/testing/Cargo.toml @@ -19,7 +19,7 @@ sc-client-db = { version = "0.9.0", path = "../../../client/db/", features = ["k sc-client-api = { version = "3.0.0", path = "../../../client/api/" } codec = { package = "parity-scale-codec", version = "2.0.0" } pallet-contracts = { version = "3.0.0", path = "../../../frame/contracts" } -pallet-grandpa = { version = "3.0.0", path = "../../../frame/grandpa" } +pallet-grandpa = { version = "4.0.0", path = "../../../frame/grandpa" } pallet-indices = { version = "3.0.0", path = "../../../frame/indices" } sp-keyring = { version = "3.0.0", path = "../../../primitives/keyring" } node-executor = { version = "2.0.0", path = "../executor" } diff --git a/frame/grandpa/Cargo.toml b/frame/grandpa/Cargo.toml index 88b3f0c5d50ce..2698a4716e81f 100644 --- a/frame/grandpa/Cargo.toml +++ b/frame/grandpa/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-grandpa" -version = "3.0.0" +version = "4.0.0" authors = ["Parity Technologies "] edition = "2018" license = "Apache-2.0" diff --git a/frame/offences/benchmarking/Cargo.toml b/frame/offences/benchmarking/Cargo.toml index 6c249ebcc61d8..e4deed22a2ca2 100644 --- a/frame/offences/benchmarking/Cargo.toml +++ b/frame/offences/benchmarking/Cargo.toml @@ -19,7 +19,7 @@ frame-support = { version = "3.0.0", default-features = false, path = "../../sup frame-system = { version = "3.0.0", default-features = false, path = "../../system" } pallet-babe = { version = "3.0.0", default-features = false, path = "../../babe" } pallet-balances = { version = "3.0.0", default-features = false, path = "../../balances" } -pallet-grandpa = { version = "3.0.0", default-features = false, path = "../../grandpa" } +pallet-grandpa = { version = "4.0.0", default-features = false, path = "../../grandpa" } pallet-im-online = { version = "3.0.0", default-features = false, path = "../../im-online" } pallet-offences = { version = "3.0.0", default-features = false, features = ["runtime-benchmarks"], path = "../../offences" } pallet-session = { version = "3.0.0", default-features = false, path = "../../session" } From 1c8e18a1ce66048142af5b5ddf82997791ac9e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Wed, 12 May 2021 18:13:14 +0200 Subject: [PATCH 12/14] frame/grandpa: address review comments --- frame/grandpa/src/migrations/v4.rs | 37 ++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/frame/grandpa/src/migrations/v4.rs b/frame/grandpa/src/migrations/v4.rs index 37379a934facd..a3328ef77f41e 100644 --- a/frame/grandpa/src/migrations/v4.rs +++ b/frame/grandpa/src/migrations/v4.rs @@ -19,6 +19,7 @@ use frame_support::{ weights::Weight, traits::{GetPalletVersion, PalletVersion, Get}, }; +use sp_io::hashing::twox_128; /// The old prefix. pub const OLD_PREFIX: &[u8] = b"GrandpaFinality"; @@ -74,25 +75,37 @@ pub fn migrate< /// [`frame_support::traits::OnRuntimeUpgrade::pre_upgrade`] for further testing. /// /// Panics if anything goes wrong. -pub fn pre_migration>(new: N) { +pub fn pre_migration< + T: frame_system::Config, + P: GetPalletVersion + 'static, + N: AsRef, +>(new: N) { let new = new.as_ref(); log::info!("pre-migration grandpa test with new = {}", new); // the next key must exist, and start with the hash of `OLD_PREFIX`. - let next_key = sp_io::storage::next_key(OLD_PREFIX).unwrap(); - assert!(next_key.starts_with(&sp_io::hashing::twox_128(OLD_PREFIX))); + let next_key = sp_io::storage::next_key(&twox_128(OLD_PREFIX)).unwrap(); + assert!(next_key.starts_with(&twox_128(OLD_PREFIX))); + + // The pallet version is already stored using the pallet name + let storage_key = PalletVersion::storage_key::().unwrap(); // ensure nothing is stored in the new prefix. assert!( - sp_io::storage::next_key(new.as_bytes()).map_or( + sp_io::storage::next_key(&twox_128(new.as_bytes())).map_or( // either nothing is there true, - // or we ensure that it has no common prefix with twox_128(new). - |next_key| !next_key.starts_with(&sp_io::hashing::twox_128(new.as_bytes())) + // or we ensure that it has no common prefix with twox_128(new), + // or isn't the pallet version that is already stored using the pallet name + |next_key| { + !next_key.starts_with(&twox_128(new.as_bytes())) || next_key == storage_key + }, ), "unexpected next_key({}) = {:?}", new, - sp_core::hexdisplay::HexDisplay::from(&sp_io::storage::next_key(new.as_bytes()).unwrap()) + sp_core::hexdisplay::HexDisplay::from( + &sp_io::storage::next_key(&twox_128(new.as_bytes())).unwrap() + ), ); // ensure storage version is 3. assert!(

::storage_version().unwrap().major == 3); @@ -104,6 +117,12 @@ pub fn pre_migration>(new: N) { /// Panics if anything goes wrong. pub fn post_migration() { log::info!("post-migration grandpa"); - // ensure we've been updated to v4 by the automatic write of crate version -> storage version. - assert!(

::storage_version().unwrap().major == 4); + + // Assert that nothing remains at the old prefix + assert!( + sp_io::storage::next_key(&twox_128(OLD_PREFIX)).map_or( + true, + |next_key| !next_key.starts_with(&twox_128(OLD_PREFIX)) + ) + ); } From 20653267038df8df85cfef559a919e3fa5cf7544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Thu, 20 May 2021 11:49:27 +0200 Subject: [PATCH 13/14] Try using version 3.1 instead --- Cargo.lock | 2 +- bin/node-template/runtime/Cargo.toml | 2 +- bin/node/cli/Cargo.toml | 2 +- bin/node/executor/Cargo.toml | 2 +- bin/node/runtime/Cargo.toml | 2 +- bin/node/testing/Cargo.toml | 2 +- frame/grandpa/Cargo.toml | 2 +- frame/grandpa/src/migrations.rs | 4 ++-- frame/grandpa/src/migrations/{v4.rs => v3_1.rs} | 4 ++-- frame/offences/benchmarking/Cargo.toml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) rename frame/grandpa/src/migrations/{v4.rs => v3_1.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index 1ade7ab8777d2..a596ef8c319c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5005,7 +5005,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" -version = "4.0.0" +version = "3.1.0" dependencies = [ "finality-grandpa", "frame-benchmarking", diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index 455a439389fcc..6234f8958aad8 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = pallet-aura = { version = "3.0.0", default-features = false, path = "../../../frame/aura" } pallet-balances = { version = "3.0.0", default-features = false, path = "../../../frame/balances" } frame-support = { version = "3.0.0", default-features = false, path = "../../../frame/support" } -pallet-grandpa = { version = "4.0.0", default-features = false, path = "../../../frame/grandpa" } +pallet-grandpa = { version = "3.1.0", default-features = false, path = "../../../frame/grandpa" } pallet-randomness-collective-flip = { version = "3.0.0", default-features = false, path = "../../../frame/randomness-collective-flip" } pallet-sudo = { version = "3.0.0", default-features = false, path = "../../../frame/sudo" } frame-system = { version = "3.0.0", default-features = false, path = "../../../frame/system" } diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index b43836c7b915f..9fcd0875e8dca 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -89,7 +89,7 @@ frame-support = { version = "3.0.0", default-features = false, path = "../../../ pallet-im-online = { version = "3.0.0", default-features = false, path = "../../../frame/im-online" } pallet-authority-discovery = { version = "3.0.0", path = "../../../frame/authority-discovery" } pallet-staking = { version = "3.0.0", path = "../../../frame/staking" } -pallet-grandpa = { version = "4.0.0", path = "../../../frame/grandpa" } +pallet-grandpa = { version = "3.1.0", path = "../../../frame/grandpa" } # node-specific dependencies node-runtime = { version = "2.0.0", path = "../runtime" } diff --git a/bin/node/executor/Cargo.toml b/bin/node/executor/Cargo.toml index bd9e223e87cf8..b08d1d78b4aaa 100644 --- a/bin/node/executor/Cargo.toml +++ b/bin/node/executor/Cargo.toml @@ -31,7 +31,7 @@ frame-system = { version = "3.0.0", path = "../../../frame/system" } node-testing = { version = "2.0.0", path = "../testing" } pallet-balances = { version = "3.0.0", path = "../../../frame/balances" } pallet-contracts = { version = "3.0.0", path = "../../../frame/contracts" } -pallet-grandpa = { version = "4.0.0", path = "../../../frame/grandpa" } +pallet-grandpa = { version = "3.1.0", path = "../../../frame/grandpa" } pallet-im-online = { version = "3.0.0", path = "../../../frame/im-online" } pallet-indices = { version = "3.0.0", path = "../../../frame/indices" } pallet-session = { version = "3.0.0", path = "../../../frame/session" } diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 9a1c4340365a9..10cf823c17399 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -59,7 +59,7 @@ pallet-democracy = { version = "3.0.0", default-features = false, path = "../../ pallet-election-provider-multi-phase = { version = "3.0.0", default-features = false, path = "../../../frame/election-provider-multi-phase" } pallet-elections-phragmen = { version = "4.0.0", default-features = false, path = "../../../frame/elections-phragmen" } pallet-gilt = { version = "3.0.0", default-features = false, path = "../../../frame/gilt" } -pallet-grandpa = { version = "4.0.0", default-features = false, path = "../../../frame/grandpa" } +pallet-grandpa = { version = "3.1.0", default-features = false, path = "../../../frame/grandpa" } pallet-im-online = { version = "3.0.0", default-features = false, path = "../../../frame/im-online" } pallet-indices = { version = "3.0.0", default-features = false, path = "../../../frame/indices" } pallet-identity = { version = "3.0.0", default-features = false, path = "../../../frame/identity" } diff --git a/bin/node/testing/Cargo.toml b/bin/node/testing/Cargo.toml index e929029765ee7..706816ddae671 100644 --- a/bin/node/testing/Cargo.toml +++ b/bin/node/testing/Cargo.toml @@ -19,7 +19,7 @@ sc-client-db = { version = "0.9.0", path = "../../../client/db/", features = ["k sc-client-api = { version = "3.0.0", path = "../../../client/api/" } codec = { package = "parity-scale-codec", version = "2.0.0" } pallet-contracts = { version = "3.0.0", path = "../../../frame/contracts" } -pallet-grandpa = { version = "4.0.0", path = "../../../frame/grandpa" } +pallet-grandpa = { version = "3.1.0", path = "../../../frame/grandpa" } pallet-indices = { version = "3.0.0", path = "../../../frame/indices" } sp-keyring = { version = "3.0.0", path = "../../../primitives/keyring" } node-executor = { version = "2.0.0", path = "../executor" } diff --git a/frame/grandpa/Cargo.toml b/frame/grandpa/Cargo.toml index 2698a4716e81f..c6cfa96f7da1b 100644 --- a/frame/grandpa/Cargo.toml +++ b/frame/grandpa/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-grandpa" -version = "4.0.0" +version = "3.1.0" authors = ["Parity Technologies "] edition = "2018" license = "Apache-2.0" diff --git a/frame/grandpa/src/migrations.rs b/frame/grandpa/src/migrations.rs index 05c24e11b3939..b0c8578c33e07 100644 --- a/frame/grandpa/src/migrations.rs +++ b/frame/grandpa/src/migrations.rs @@ -15,5 +15,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -/// Version 4. -pub mod v4; +/// Version 3.1. +pub mod v3_1; diff --git a/frame/grandpa/src/migrations/v4.rs b/frame/grandpa/src/migrations/v3_1.rs similarity index 96% rename from frame/grandpa/src/migrations/v4.rs rename to frame/grandpa/src/migrations/v3_1.rs index a3328ef77f41e..e22133b9b1855 100644 --- a/frame/grandpa/src/migrations/v4.rs +++ b/frame/grandpa/src/migrations/v3_1.rs @@ -47,7 +47,7 @@ pub fn migrate< let maybe_storage_version =

::storage_version(); log::info!( target: "runtime::afg", - "Running migration to v4 for grandpa with storage version {:?}", + "Running migration to v3.1 for grandpa with storage version {:?}", maybe_storage_version, ); @@ -63,7 +63,7 @@ pub fn migrate< _ => { log::warn!( target: "runtime::afg", - "Attempted to apply migration to v4 but failed because storage version is {:?}", + "Attempted to apply migration to v3.1 but failed because storage version is {:?}", maybe_storage_version, ); 0 diff --git a/frame/offences/benchmarking/Cargo.toml b/frame/offences/benchmarking/Cargo.toml index e4deed22a2ca2..acfb5b1b0dc89 100644 --- a/frame/offences/benchmarking/Cargo.toml +++ b/frame/offences/benchmarking/Cargo.toml @@ -19,7 +19,7 @@ frame-support = { version = "3.0.0", default-features = false, path = "../../sup frame-system = { version = "3.0.0", default-features = false, path = "../../system" } pallet-babe = { version = "3.0.0", default-features = false, path = "../../babe" } pallet-balances = { version = "3.0.0", default-features = false, path = "../../balances" } -pallet-grandpa = { version = "4.0.0", default-features = false, path = "../../grandpa" } +pallet-grandpa = { version = "3.1.0", default-features = false, path = "../../grandpa" } pallet-im-online = { version = "3.0.0", default-features = false, path = "../../im-online" } pallet-offences = { version = "3.0.0", default-features = false, features = ["runtime-benchmarks"], path = "../../offences" } pallet-session = { version = "3.0.0", default-features = false, path = "../../session" } From 5266da41522714b29f39b73d6fe724d1e1d939cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Thu, 20 May 2021 13:48:14 +0200 Subject: [PATCH 14/14] frame/grandpa: tweak log text to say cancelled --- frame/grandpa/src/migrations/v3_1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/grandpa/src/migrations/v3_1.rs b/frame/grandpa/src/migrations/v3_1.rs index e22133b9b1855..fc626578098da 100644 --- a/frame/grandpa/src/migrations/v3_1.rs +++ b/frame/grandpa/src/migrations/v3_1.rs @@ -63,7 +63,7 @@ pub fn migrate< _ => { log::warn!( target: "runtime::afg", - "Attempted to apply migration to v3.1 but failed because storage version is {:?}", + "Attempted to apply migration to v3.1 but cancelled because storage version is {:?}", maybe_storage_version, ); 0