Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove grandpa StoredPendingChange shim #8788

Merged
2 commits merged into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,8 @@ pub trait WeightInfo {
fn note_stalled() -> Weight;
}

/// A stored pending change, old format.
// TODO: remove shim
// https://github.com/paritytech/substrate/issues/1614
#[derive(Encode, Decode)]
pub struct OldStoredPendingChange<N> {
/// The block number this was scheduled at.
pub scheduled_at: N,
/// The delay in blocks until it will be applied.
pub delay: N,
/// The next authority set.
pub next_authorities: AuthorityList,
}

/// A stored pending change.
#[derive(Encode)]
#[derive(Encode, Decode)]
pub struct StoredPendingChange<N> {
/// The block number this was scheduled at.
pub scheduled_at: N,
Expand All @@ -134,20 +121,6 @@ pub struct StoredPendingChange<N> {
pub forced: Option<N>,
}

impl<N: Decode> Decode for StoredPendingChange<N> {
fn decode<I: codec::Input>(value: &mut I) -> core::result::Result<Self, codec::Error> {
let old = OldStoredPendingChange::decode(value)?;
let forced = <Option<N>>::decode(value).unwrap_or(None);

Ok(StoredPendingChange {
scheduled_at: old.scheduled_at,
delay: old.delay,
next_authorities: old.next_authorities,
forced,
})
}
}

/// Current state of the GRANDPA authority set. State transitions must happen in
/// the same order of states defined below, e.g. `Paused` implies a prior
/// `PendingPause`.
Expand Down
18 changes: 1 addition & 17 deletions frame/grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use super::{Call, Event, *};
use crate::mock::*;
use codec::{Decode, Encode};
use codec::Encode;
use fg_primitives::ScheduledChange;
use frame_support::{
assert_err, assert_ok, assert_noop,
Expand Down Expand Up @@ -127,22 +127,6 @@ fn cannot_schedule_change_when_one_pending() {
});
}

#[test]
fn new_decodes_from_old() {
let old = OldStoredPendingChange {
scheduled_at: 5u32,
delay: 100u32,
next_authorities: to_authorities(vec![(1, 5), (2, 10), (3, 2)]),
};

let encoded = old.encode();
let new = StoredPendingChange::<u32>::decode(&mut &encoded[..]).unwrap();
assert!(new.forced.is_none());
assert_eq!(new.scheduled_at, old.scheduled_at);
assert_eq!(new.delay, old.delay);
assert_eq!(new.next_authorities, old.next_authorities);
}

#[test]
fn dispatch_forced_change() {
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
Expand Down