grandpa: track multiple live rounds in voter set state (#3298)

* grandpa: track multiple live rounds in voter set state

* grandpa: don't assume rounds are completed in-order

* grandpa: fix tests

* grandpa: don't assume round is being tracked on Environment::completed

* grandpa: fix missing import in test
This commit is contained in:
André Silva
2019-08-08 09:56:49 +02:00
committed by Gavin Wood
parent 0f0df9850a
commit 6565e1f8aa
7 changed files with 247 additions and 205 deletions
@@ -20,7 +20,7 @@ use futures::prelude::*;
use futures::future::{self, Loop as FutureLoop};
use grandpa::{
BlockNumberOps, Error as GrandpaError, round::State as RoundState, voter, voter_set::VoterSet
BlockNumberOps, Error as GrandpaError, voter, voter_set::VoterSet
};
use log::{debug, info, warn};
@@ -36,7 +36,6 @@ use crate::{
use crate::authorities::SharedAuthoritySet;
use crate::communication::NetworkBridge;
use crate::consensus_changes::SharedConsensusChanges;
use crate::environment::{CompletedRound, CompletedRounds, HasVoted};
use fg_primitives::AuthorityId;
struct ObserverChain<'a, Block: BlockT, B, E, RA>(&'a Client<B, E, Block, RA>);
@@ -238,22 +237,11 @@ pub fn run_grandpa_observer<B, E, Block: BlockT<Hash=H256>, N, RA, SC>(
VoterCommand::ChangeAuthorities(new) => {
// start the new authority set using the block where the
// set changed (not where the signal happened!) as the base.
let genesis_state = RoundState::genesis((new.canon_hash, new.canon_number));
let set_state = VoterSetState::Live::<Block> {
// always start at round 0 when changing sets.
completed_rounds: CompletedRounds::new(
CompletedRound {
number: 0,
state: genesis_state,
base: (new.canon_hash, new.canon_number),
votes: Vec::new(),
},
new.set_id,
&*authority_set.inner().read(),
),
current_round: HasVoted::No,
};
let set_state = VoterSetState::live(
new.set_id,
&*authority_set.inner().read(),
(new.canon_hash, new.canon_number),
);
#[allow(deprecated)]
crate::aux_schema::write_voter_set_state(&**client.backend(), &set_state)?;