mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 19:51:02 +00:00
Fix deadlock in tests that are using with_gossip (#2533)
* fixed gossip related tests deadlock * cleaning sync tests log * fixed typo in logs * send GRANDPA messages without holding validator lock * Revert "fixed gossip related tests deadlock" This reverts commit d3fe55e45e32b7ea2e9f05f1c511972c708209ad.
This commit is contained in:
committed by
Gavin Wood
parent
dfbaedd535
commit
42fa5f6209
@@ -425,6 +425,8 @@ struct Inner<Block: BlockT> {
|
||||
next_rebroadcast: Instant,
|
||||
}
|
||||
|
||||
type MaybeMessage<Block> = Option<(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)>;
|
||||
|
||||
impl<Block: BlockT> Inner<Block> {
|
||||
fn new(config: crate::Config) -> Self {
|
||||
Inner {
|
||||
@@ -437,11 +439,9 @@ impl<Block: BlockT> Inner<Block> {
|
||||
}
|
||||
|
||||
/// Note a round in a set has started.
|
||||
fn note_round<F>(&mut self, round: Round, set_id: SetId, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
fn note_round(&mut self, round: Round, set_id: SetId) -> MaybeMessage<Block> {
|
||||
if self.local_view.round == round && self.local_view.set_id == set_id {
|
||||
return
|
||||
return None;
|
||||
}
|
||||
|
||||
debug!(target: "afg", "Voter {} noting beginning of round {:?} to network.",
|
||||
@@ -451,28 +451,28 @@ impl<Block: BlockT> Inner<Block> {
|
||||
self.local_view.set_id = set_id;
|
||||
|
||||
self.live_topics.push(round, set_id);
|
||||
self.multicast_neighbor_packet(send_neighbor);
|
||||
self.multicast_neighbor_packet()
|
||||
}
|
||||
|
||||
/// Note that a voter set with given ID has started. Does nothing if the last
|
||||
/// call to the function was with the same `set_id`.
|
||||
fn note_set<F>(&mut self, set_id: SetId, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
if self.local_view.set_id == set_id { return }
|
||||
fn note_set(&mut self, set_id: SetId) -> MaybeMessage<Block> {
|
||||
if self.local_view.set_id == set_id {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.local_view.update_set(set_id);
|
||||
self.live_topics.push(Round(0), set_id);
|
||||
self.multicast_neighbor_packet(send_neighbor);
|
||||
self.multicast_neighbor_packet()
|
||||
}
|
||||
|
||||
/// Note that we've imported a commit finalizing a given block.
|
||||
fn note_commit_finalized<F>(&mut self, finalized: NumberFor<Block>, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
fn note_commit_finalized(&mut self, finalized: NumberFor<Block>) -> MaybeMessage<Block> {
|
||||
if self.local_view.last_commit.as_ref() < Some(&finalized) {
|
||||
self.local_view.last_commit = Some(finalized);
|
||||
self.multicast_neighbor_packet(send_neighbor)
|
||||
self.multicast_neighbor_packet()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,9 +560,7 @@ impl<Block: BlockT> Inner<Block> {
|
||||
(neighbor_topics, Action::Discard(cb))
|
||||
}
|
||||
|
||||
fn multicast_neighbor_packet<F>(&self, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
fn multicast_neighbor_packet(&self) -> MaybeMessage<Block> {
|
||||
let packet = NeighborPacket {
|
||||
round: self.local_view.round,
|
||||
set_id: self.local_view.set_id,
|
||||
@@ -570,7 +568,7 @@ impl<Block: BlockT> Inner<Block> {
|
||||
};
|
||||
|
||||
let peers = self.peers.inner.keys().cloned().collect();
|
||||
send_neighbor(peers, packet);
|
||||
Some((peers, packet))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,21 +594,24 @@ impl<Block: BlockT> GossipValidator<Block> {
|
||||
pub(super) fn note_round<F>(&self, round: Round, set_id: SetId, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
self.inner.write().note_round(round, set_id, send_neighbor);
|
||||
self.inner.write().note_round(round, set_id)
|
||||
.map(|(to, msg)| send_neighbor(to, msg));
|
||||
}
|
||||
|
||||
/// Note that a voter set with given ID has started.
|
||||
pub(super) fn note_set<F>(&self, set_id: SetId, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
self.inner.write().note_set(set_id, send_neighbor);
|
||||
self.inner.write().note_set(set_id)
|
||||
.map(|(to, msg)| send_neighbor(to, msg));
|
||||
}
|
||||
|
||||
/// Note that we've imported a commit finalizing a given block.
|
||||
pub(super) fn note_commit_finalized<F>(&self, finalized: NumberFor<Block>, send_neighbor: F)
|
||||
where F: FnOnce(Vec<PeerId>, NeighborPacket<NumberFor<Block>>)
|
||||
{
|
||||
self.inner.write().note_commit_finalized(finalized, send_neighbor);
|
||||
self.inner.write().note_commit_finalized(finalized)
|
||||
.map(|(to, msg)| send_neighbor(to, msg));
|
||||
}
|
||||
|
||||
fn report(&self, who: PeerId, cost_benefit: i32) {
|
||||
|
||||
Reference in New Issue
Block a user