a wrapper network for rebroadcasting GRANDPA messages periodically (#1513)

This commit is contained in:
Robert Habermeier
2019-01-21 16:33:07 -03:00
committed by GitHub
parent 3c7d6c7b72
commit 9ae1316c86
3 changed files with 168 additions and 5 deletions
+12 -3
View File
@@ -238,7 +238,7 @@ pub trait Network: Clone {
fn commit_messages(&self, set_id: u64) -> Self::In;
/// Send message over the commit channel.
fn send_commit(&self, set_id: u64, message: Vec<u8>);
fn send_commit(&self, round: u64, set_id: u64, message: Vec<u8>);
}
/// Bridge between NetworkService, gossiping consensus messages and Grandpa
@@ -289,7 +289,7 @@ impl<B: BlockT, S: network::specialization::NetworkSpecialization<B>, H: ExHashT
self.service.consensus_gossip().write().messages_for(commit_topic::<B>(set_id))
}
fn send_commit(&self, set_id: u64, message: Vec<u8>) {
fn send_commit(&self, _round: u64, set_id: u64, message: Vec<u8>) {
let topic = commit_topic::<B>(set_id);
self.service.gossip_consensus_message(topic, message, true);
}
@@ -1496,6 +1496,10 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
let chain_info = client.info()?;
let genesis_hash = chain_info.chain.genesis_hash;
// we shadow network with the wrapping/rebroadcasting network to avoid
// accidental reuse.
let (broadcast_worker, network) = communication::rebroadcasting_network(network);
let (last_round_number, last_state) = match Backend::get_aux(&**client.backend(), LAST_COMPLETED_KEY)? {
None => (0, RoundState::genesis((genesis_hash, <NumberFor<Block>>::zero()))),
Some(raw) => LastCompleted::decode(&mut &raw[..])
@@ -1601,7 +1605,12 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
trigger_authority_set_change(new, authority_set_change)
},
}))
}).map_err(|e| warn!("GRANDPA Voter failed: {:?}", e));
});
let voter_work = voter_work
.join(broadcast_worker)
.map(|((), ())| ())
.map_err(|e| warn!("GRANDPA Voter failed: {:?}", e));
Ok(voter_work.select(on_exit).then(|_| Ok(())))
}