mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 10:21:05 +00:00
This reverts commit c0a1926704.
This commit is contained in:
@@ -35,4 +35,3 @@ std = [
|
||||
"session/std",
|
||||
"finality-tracker/std",
|
||||
]
|
||||
migrate-authorities = []
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
//!
|
||||
//! In the future, it will also handle misbehavior reports, and on-chain
|
||||
//! finality notifications.
|
||||
//!
|
||||
//! For full integration with GRANDPA, the `GrandpaApi` should be implemented.
|
||||
//! The necessary items are re-exported via the `fg_primitives` crate.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
@@ -29,7 +32,9 @@ pub use substrate_finality_grandpa_primitives as fg_primitives;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use codec::{self as codec, Encode, Decode, Error};
|
||||
use support::{decl_event, decl_storage, decl_module, dispatch::Result, storage};
|
||||
use support::{
|
||||
decl_event, decl_storage, decl_module, dispatch::Result,
|
||||
};
|
||||
use sr_primitives::{
|
||||
generic::{DigestItem, OpaqueDigestItemId}, traits::Zero, Perbill,
|
||||
};
|
||||
@@ -37,10 +42,8 @@ use sr_staking_primitives::{
|
||||
SessionIndex,
|
||||
offence::{Offence, Kind},
|
||||
};
|
||||
use fg_primitives::{
|
||||
GRANDPA_AUTHORITIES_KEY, GRANDPA_ENGINE_ID, ScheduledChange, ConsensusLog, SetId, RoundNumber,
|
||||
};
|
||||
pub use fg_primitives::{AuthorityId, AuthorityList, AuthorityWeight, VersionedAuthorityList};
|
||||
use fg_primitives::{GRANDPA_ENGINE_ID, ScheduledChange, ConsensusLog, SetId, RoundNumber};
|
||||
pub use fg_primitives::{AuthorityId, AuthorityWeight};
|
||||
use system::{ensure_signed, DigestOf};
|
||||
|
||||
mod mock;
|
||||
@@ -61,7 +64,7 @@ pub struct OldStoredPendingChange<N> {
|
||||
/// The delay in blocks until it will be applied.
|
||||
pub delay: N,
|
||||
/// The next authority set.
|
||||
pub next_authorities: AuthorityList,
|
||||
pub next_authorities: Vec<(AuthorityId, AuthorityWeight)>,
|
||||
}
|
||||
|
||||
/// A stored pending change.
|
||||
@@ -72,7 +75,7 @@ pub struct StoredPendingChange<N> {
|
||||
/// The delay in blocks until it will be applied.
|
||||
pub delay: N,
|
||||
/// The next authority set.
|
||||
pub next_authorities: AuthorityList,
|
||||
pub next_authorities: Vec<(AuthorityId, AuthorityWeight)>,
|
||||
/// If defined it means the change was forced and the given block number
|
||||
/// indicates the median last finalized block when the change was signaled.
|
||||
pub forced: Option<N>,
|
||||
@@ -123,7 +126,7 @@ pub enum StoredState<N> {
|
||||
decl_event!(
|
||||
pub enum Event {
|
||||
/// New authority set has been applied.
|
||||
NewAuthorities(AuthorityList),
|
||||
NewAuthorities(Vec<(AuthorityId, AuthorityWeight)>),
|
||||
/// Current authority set has been paused.
|
||||
Paused,
|
||||
/// Current authority set has been resumed.
|
||||
@@ -133,12 +136,8 @@ decl_event!(
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as GrandpaFinality {
|
||||
/// DEPRECATED
|
||||
///
|
||||
/// This used to store the current authority set, which has been migrated to the well-known
|
||||
/// GRANDPA_AUTHORITES_KEY unhashed key.
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
pub(crate) Authorities get(fn authorities): AuthorityList;
|
||||
/// The current authority set.
|
||||
Authorities get(fn authorities): Vec<(AuthorityId, AuthorityWeight)>;
|
||||
|
||||
/// State of the current authority set.
|
||||
State get(fn state): StoredState<T::BlockNumber> = StoredState::Live;
|
||||
@@ -160,7 +159,7 @@ decl_storage! {
|
||||
SetIdSession get(fn session_for_set): map SetId => Option<SessionIndex>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(authorities): AuthorityList;
|
||||
config(authorities): Vec<(AuthorityId, AuthorityWeight)>;
|
||||
build(|config| Module::<T>::initialize_authorities(&config.authorities))
|
||||
}
|
||||
}
|
||||
@@ -175,11 +174,6 @@ decl_module! {
|
||||
// FIXME: https://github.com/paritytech/substrate/issues/1112
|
||||
}
|
||||
|
||||
fn on_initialize() {
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
Self::migrate_authorities();
|
||||
}
|
||||
|
||||
fn on_finalize(block_number: T::BlockNumber) {
|
||||
// check for scheduled pending authority set changes
|
||||
if let Some(pending_change) = <PendingChange<T>>::get() {
|
||||
@@ -205,7 +199,7 @@ decl_module! {
|
||||
|
||||
// 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);
|
||||
Authorities::put(&pending_change.next_authorities);
|
||||
Self::deposit_event(
|
||||
Event::NewAuthorities(pending_change.next_authorities)
|
||||
);
|
||||
@@ -247,16 +241,8 @@ decl_module! {
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Get the current set of authorities, along with their respective weights.
|
||||
pub fn grandpa_authorities() -> AuthorityList {
|
||||
storage::unhashed::get_or_default::<VersionedAuthorityList>(GRANDPA_AUTHORITIES_KEY).into()
|
||||
}
|
||||
|
||||
/// Set the current set of authorities, along with their respective weights.
|
||||
fn set_grandpa_authorities(authorities: &AuthorityList) {
|
||||
storage::unhashed::put(
|
||||
GRANDPA_AUTHORITIES_KEY,
|
||||
&VersionedAuthorityList::from(authorities),
|
||||
);
|
||||
pub fn grandpa_authorities() -> Vec<(AuthorityId, AuthorityWeight)> {
|
||||
Authorities::get()
|
||||
}
|
||||
|
||||
/// Schedule GRANDPA to pause starting in the given number of blocks.
|
||||
@@ -307,7 +293,7 @@ impl<T: Trait> Module<T> {
|
||||
/// No change should be signaled while any change is pending. Returns
|
||||
/// an error if a change is already pending.
|
||||
pub fn schedule_change(
|
||||
next_authorities: AuthorityList,
|
||||
next_authorities: Vec<(AuthorityId, AuthorityWeight)>,
|
||||
in_blocks: T::BlockNumber,
|
||||
forced: Option<T::BlockNumber>,
|
||||
) -> Result {
|
||||
@@ -343,20 +329,10 @@ impl<T: Trait> Module<T> {
|
||||
<system::Module<T>>::deposit_log(log.into());
|
||||
}
|
||||
|
||||
fn initialize_authorities(authorities: &AuthorityList) {
|
||||
fn initialize_authorities(authorities: &[(AuthorityId, AuthorityWeight)]) {
|
||||
if !authorities.is_empty() {
|
||||
assert!(
|
||||
Self::grandpa_authorities().is_empty(),
|
||||
"Authorities are already initialized!"
|
||||
);
|
||||
Self::set_grandpa_authorities(authorities);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
fn migrate_authorities() {
|
||||
if Authorities::exists() {
|
||||
Self::set_grandpa_authorities(&Authorities::take());
|
||||
assert!(Authorities::get().is_empty(), "Authorities are already initialized!");
|
||||
Authorities::put(authorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use runtime_io;
|
||||
use support::{impl_outer_origin, impl_outer_event, parameter_types};
|
||||
use primitives::H256;
|
||||
use codec::{Encode, Decode};
|
||||
use crate::{AuthorityId, AuthorityList, GenesisConfig, Trait, Module, ConsensusLog};
|
||||
use crate::{AuthorityId, GenesisConfig, Trait, Module, ConsensusLog};
|
||||
use substrate_finality_grandpa_primitives::GRANDPA_ENGINE_ID;
|
||||
|
||||
impl_outer_origin!{
|
||||
@@ -75,7 +75,7 @@ impl_outer_event!{
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_authorities(vec: Vec<(u64, u64)>) -> AuthorityList {
|
||||
pub fn to_authorities(vec: Vec<(u64, u64)>) -> Vec<(AuthorityId, u64)> {
|
||||
vec.into_iter()
|
||||
.map(|(id, weight)| (UintAuthorityId(id).to_public_key::<AuthorityId>(), weight))
|
||||
.collect()
|
||||
|
||||
@@ -308,21 +308,3 @@ fn time_slot_have_sane_ord() {
|
||||
];
|
||||
assert!(FIXTURE.windows(2).all(|f| f[0] < f[1]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "migrate-authorities")]
|
||||
fn authorities_migration() {
|
||||
use sr_primitives::traits::OnInitialize;
|
||||
|
||||
with_externalities(&mut new_test_ext(vec![]), || {
|
||||
let authorities = to_authorities(vec![(1, 1), (2, 1), (3, 1)]);
|
||||
|
||||
Authorities::put(authorities.clone());
|
||||
assert!(Grandpa::grandpa_authorities().is_empty());
|
||||
|
||||
Grandpa::on_initialize(1);
|
||||
|
||||
assert!(!Authorities::exists());
|
||||
assert_eq!(Grandpa::grandpa_authorities(), authorities);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user