Minor gossip changes (#2038)

* core: gossip: don't expire messages based on time

* core: gossip: allow forcing resend of gossip messages

* core: grandpa: fix tests
This commit is contained in:
André Silva
2019-03-19 12:13:05 +01:00
committed by Robert Habermeier
parent 002143d0a2
commit e56a5cd00b
7 changed files with 70 additions and 70 deletions
@@ -130,12 +130,12 @@ impl<B: BlockT, N: Network<B>> Future for BroadcastWorker<B, N> {
if rebroadcast {
let SetId(set_id) = self.set_id;
if let Some((Round(c_round), ref c_commit)) = self.last_commit {
self.network.send_commit(c_round, set_id, c_commit.clone());
self.network.send_commit(c_round, set_id, c_commit.clone(), true);
}
let Round(round) = self.round_messages.0;
for message in self.round_messages.1.iter().cloned() {
self.network.send_message(round, set_id, message);
self.network.send_message(round, set_id, message, true);
}
for (&announce_hash, &Round(round)) in &self.announcements {
@@ -143,6 +143,7 @@ impl<B: BlockT, N: Network<B>> Future for BroadcastWorker<B, N> {
}
}
}
loop {
match self.incoming_broadcast.poll().expect("UnboundedReceiver does not yield errors; qed") {
Async::NotReady => return Ok(Async::NotReady),
@@ -168,7 +169,7 @@ impl<B: BlockT, N: Network<B>> Future for BroadcastWorker<B, N> {
}
// always send out to network.
self.network.send_commit(round.0, self.set_id.0, commit);
self.network.send_commit(round.0, self.set_id.0, commit, false);
}
Broadcast::Message(round, set_id, message) => {
if self.set_id == set_id {
@@ -182,7 +183,7 @@ impl<B: BlockT, N: Network<B>> Future for BroadcastWorker<B, N> {
}
// always send out to network.
self.network.send_message(round.0, set_id.0, message);
self.network.send_message(round.0, set_id.0, message, false);
}
Broadcast::Announcement(round, set_id, hash) => {
if self.set_id == set_id {
@@ -215,7 +216,7 @@ impl<B: BlockT, N: Network<B>> Network<B> for BroadcastHandle<B, N> {
self.network.messages_for(round, set_id)
}
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>) {
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>, _force: bool) {
let _ = self.relay.unbounded_send(Broadcast::Message(Round(round), SetId(set_id), message));
}
@@ -231,7 +232,7 @@ impl<B: BlockT, N: Network<B>> Network<B> for BroadcastHandle<B, N> {
self.network.commit_messages(set_id)
}
fn send_commit(&self, round: u64, set_id: u64, message: Vec<u8>) {
fn send_commit(&self, round: u64, set_id: u64, message: Vec<u8>, _force: bool) {
let _ = self.relay.unbounded_send(Broadcast::Commit(Round(round), SetId(set_id), message));
}
@@ -350,7 +351,7 @@ impl<Block: BlockT, N: Network<Block>> Sink for OutgoingMessages<Block, N>
// announce our block hash to peers and propagate the
// message.
self.network.announce(self.round, self.set_id, target_hash);
self.network.send_message(self.round, self.set_id, message.encode());
self.network.send_message(self.round, self.set_id, message.encode(), false);
// forward the message to the inner sender.
let _ = self.sender.unbounded_send(signed);
@@ -526,7 +527,7 @@ impl<Block: BlockT, N: Network<Block>> Sink for CommitsOut<Block, N> {
message: compact_commit,
});
self.network.send_commit(round, self.set_id, Encode::encode(&message));
self.network.send_commit(round, self.set_id, Encode::encode(&message), false);
Ok(AsyncSink::Ready)
}
+9 -6
View File
@@ -283,6 +283,7 @@ impl TopicTracker {
);
return true;
}
false
}
}
@@ -358,6 +359,7 @@ impl<Block: BlockT> GossipValidator<Block> {
-> network_gossip::ValidationResult<Block::Hash>
{
use grandpa::Message as GrandpaMessage;
if self.is_expired(full.round, full.set_id) {
return network_gossip::ValidationResult::Expired;
}
@@ -392,6 +394,7 @@ impl<Block: BlockT> GossipValidator<Block> {
let precommits_signed_by: Vec<String> = full.message.auth_data.iter().map(move |(_, a)| {
format!("{}", a)
}).collect();
telemetry!(CONSENSUS_INFO; "afg.received_commit_msg";
"contains_precommits_signed_by" => ?precommits_signed_by,
"round" => ?full.round,
@@ -442,7 +445,7 @@ pub trait Network<Block: BlockT>: Clone {
fn messages_for(&self, round: u64, set_id: u64) -> Self::In;
/// Send a message at a specific round out.
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>);
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>, force: bool);
/// Clean up messages for a round.
fn drop_round_messages(&self, round: u64, set_id: u64);
@@ -455,7 +458,7 @@ pub trait Network<Block: BlockT>: Clone {
fn commit_messages(&self, set_id: u64) -> Self::In;
/// Send message over the commit channel.
fn send_commit(&self, round: u64, set_id: u64, message: Vec<u8>);
fn send_commit(&self, round: u64, set_id: u64, message: Vec<u8>, force: bool);
/// Inform peers that a block with given hash should be downloaded.
fn announce(&self, round: u64, set_id: u64, block: Block::Hash);
@@ -508,9 +511,9 @@ impl<B: BlockT, S: network::specialization::NetworkSpecialization<B>,> Network<B
NetworkStream { outer: rx, inner: None }
}
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>) {
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>, force: bool) {
let topic = message_topic::<B>(round, set_id);
self.service.gossip_consensus_message(topic, GRANDPA_ENGINE_ID, message);
self.service.gossip_consensus_message(topic, GRANDPA_ENGINE_ID, message, force);
}
fn drop_round_messages(&self, round: u64, set_id: u64) {
@@ -533,9 +536,9 @@ impl<B: BlockT, S: network::specialization::NetworkSpecialization<B>,> Network<B
NetworkStream { outer: rx, inner: None }
}
fn send_commit(&self, _round: u64, set_id: u64, message: Vec<u8>) {
fn send_commit(&self, _round: u64, set_id: u64, message: Vec<u8>, force: bool) {
let topic = commit_topic::<B>(set_id);
self.service.gossip_consensus_message(topic, GRANDPA_ENGINE_ID, message);
self.service.gossip_consensus_message(topic, GRANDPA_ENGINE_ID, message, force);
}
fn announce(&self, round: u64, _set_id: u64, block: B::Hash) {
+7 -5
View File
@@ -193,9 +193,10 @@ impl Network<Block> for MessageRouting {
Box::new(messages)
}
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>) {
fn send_message(&self, round: u64, set_id: u64, message: Vec<u8>, force: bool) {
let inner = self.inner.lock();
inner.peer(self.peer_id).gossip_message(make_topic(round, set_id), GRANDPA_ENGINE_ID, message);
inner.peer(self.peer_id)
.gossip_message(make_topic(round, set_id), GRANDPA_ENGINE_ID, message, force);
}
fn drop_round_messages(&self, round: u64, set_id: u64) {
@@ -214,7 +215,7 @@ impl Network<Block> for MessageRouting {
self.validator.note_set(set_id);
let inner = self.inner.lock();
let peer = inner.peer(self.peer_id);
let messages = peer.consensus_gossip_messages_for(
let messages = peer.consensus_gossip_messages_for(
GRANDPA_ENGINE_ID,
make_commit_topic(set_id),
);
@@ -226,9 +227,10 @@ impl Network<Block> for MessageRouting {
Box::new(messages)
}
fn send_commit(&self, _round: u64, set_id: u64, message: Vec<u8>) {
fn send_commit(&self, _round: u64, set_id: u64, message: Vec<u8>, force: bool) {
let inner = self.inner.lock();
inner.peer(self.peer_id).gossip_message(make_commit_topic(set_id), GRANDPA_ENGINE_ID, message);
inner.peer(self.peer_id)
.gossip_message(make_commit_topic(set_id), GRANDPA_ENGINE_ID, message, force);
}
fn announce(&self, _round: u64, _set_id: u64, _block: H256) {