grandpa: allow noting same set in gossip with different authorities (#5323)

* grandpa: allow noting same set in gossip with different authorities

* grandpa: add test for note_set behavior
This commit is contained in:
André Silva
2020-03-20 18:07:10 +00:00
committed by GitHub
parent 5688f0b293
commit 459557aadc
@@ -722,7 +722,15 @@ impl<Block: BlockT> Inner<Block> {
last_commit: None,
}),
Some(ref mut v) => if v.set_id == set_id {
return None
if self.authorities != authorities {
debug!(target: "afg",
"Gossip validator noted set {:?} twice with different authorities. \
Was the authority set hard forked?",
set_id,
);
self.authorities = authorities;
}
return None;
} else {
v
},
@@ -788,6 +796,7 @@ impl<Block: BlockT> Inner<Block> {
// ensure authority is part of the set.
if !self.authorities.contains(&full.message.id) {
debug!(target: "afg", "Message from unknown voter: {}", full.message.id);
telemetry!(CONSENSUS_DEBUG; "afg.bad_msg_signature"; "signature" => ?full.message.id);
return Action::Discard(cost::UNKNOWN_VOTER);
}
@@ -1380,6 +1389,11 @@ impl<Block: BlockT> GossipValidator<Block> {
(action, broadcast_topics, peer_reply)
}
#[cfg(test)]
fn inner(&self) -> &parking_lot::RwLock<Inner<Block>> {
&self.inner
}
}
impl<Block: BlockT> sc_network_gossip::Validator<Block> for GossipValidator<Block> {
@@ -2555,4 +2569,19 @@ mod tests {
&commit(0, 1, 2),
));
}
#[test]
fn allow_noting_different_authorities_for_same_set() {
let (val, _) = GossipValidator::<Block>::new(config(), voter_set_state(), None);
let a1 = vec![AuthorityId::default()];
val.note_set(SetId(1), a1.clone(), |_, _| {});
assert_eq!(val.inner().read().authorities, a1);
let a2 = vec![AuthorityId::default(), AuthorityId::default()];
val.note_set(SetId(1), a2.clone(), |_, _| {});
assert_eq!(val.inner().read().authorities, a2);
}
}