Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
client/beefy: tweak main loop event processing order
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Sep 16, 2022
1 parent d48e199 commit 3cb39f7
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,22 @@ where
// The branches below only change 'state', actual voting happen afterwards,
// based on the new resulting 'state'.
futures::select_biased! {
// Use `select_biased!` to prioritize order below.
// Make sure to pump gossip engine.
_ = gossip_engine => {
error!(target: "beefy", "🥩 Gossip engine has terminated, closing worker.");
return;
},
// Keep track of connected peers.
net_event = network_events.next() => {
if let Some(net_event) = net_event {
self.handle_network_event(net_event);
} else {
error!(target: "beefy", "🥩 Network events stream terminated, closing worker.");
return;
}
},
// Process finality notifications first since these drive the voter.
notification = finality_notifications.next() => {
if let Some(notification) = notification {
self.handle_finality_notification(&notification);
Expand All @@ -829,6 +845,7 @@ where
return;
}
},
// Process incoming justifications as these can make some in-flight votes obsolete.
justif = block_import_justif.next() => {
if let Some(justif) = justif {
// Block import justifications have already been verified to be valid
Expand All @@ -841,14 +858,14 @@ where
return;
}
},
// TODO: join this stream's branch with the one above; how? .. ¯\_(ツ)_/¯
justif = self.on_demand_justifications.next().fuse() => {
if let Some(justif) = justif {
if let Err(err) = self.triage_incoming_justif(justif) {
debug!(target: "beefy", "🥩 {}", err);
}
}
},
// Finally process incoming votes.
vote = votes.next() => {
if let Some(vote) = vote {
// Votes have already been verified to be valid by the gossip validator.
Expand All @@ -860,18 +877,6 @@ where
return;
}
},
net_event = network_events.next() => {
if let Some(net_event) = net_event {
self.handle_network_event(net_event);
} else {
error!(target: "beefy", "🥩 Network events stream terminated, closing worker.");
return;
}
},
_ = gossip_engine => {
error!(target: "beefy", "🥩 Gossip engine has terminated, closing worker.");
return;
}
}

// Handle pending justifications and/or votes for now GRANDPA finalized blocks.
Expand Down

0 comments on commit 3cb39f7

Please sign in to comment.