mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 18:01:03 +00:00
client/beefy: fix voter initialization (#12274)
Fix corner case where voter gets a single burst of finality notifications just when it starts. The notification stream was consumed by "wait_for_pallet" logic, then main loop would subscribe to finality notifications, but by that time some notifications might've been lost. Fix this by subscribing the main loop to notifications before waiting for pallet to become available. Share the same stream with the main loop so that notifications for blocks before pallet available are ignored, while _all_ notifications after pallet available are processed. Add regression test for this. Signed-off-by: acatangiu <adrian@parity.io>
This commit is contained in:
@@ -24,10 +24,10 @@ use std::{
|
||||
};
|
||||
|
||||
use codec::{Codec, Decode, Encode};
|
||||
use futures::StreamExt;
|
||||
use futures::{stream::Fuse, StreamExt};
|
||||
use log::{debug, error, info, log_enabled, trace, warn};
|
||||
|
||||
use sc_client_api::{Backend, FinalityNotification, HeaderBackend};
|
||||
use sc_client_api::{Backend, FinalityNotification, FinalityNotifications, HeaderBackend};
|
||||
use sc_network_gossip::GossipEngine;
|
||||
|
||||
use sp_api::{BlockId, ProvideRuntimeApi};
|
||||
@@ -723,12 +723,11 @@ where
|
||||
|
||||
/// Wait for BEEFY runtime pallet to be available.
|
||||
/// Should be called only once during worker initialization.
|
||||
async fn wait_for_runtime_pallet(&mut self) {
|
||||
async fn wait_for_runtime_pallet(&mut self, finality: &mut Fuse<FinalityNotifications<B>>) {
|
||||
let mut gossip_engine = &mut self.gossip_engine;
|
||||
let mut finality_stream = self.client.finality_notification_stream().fuse();
|
||||
loop {
|
||||
futures::select! {
|
||||
notif = finality_stream.next() => {
|
||||
notif = finality.next() => {
|
||||
let notif = match notif {
|
||||
Some(notif) => notif,
|
||||
None => break
|
||||
@@ -762,11 +761,13 @@ where
|
||||
pub(crate) async fn run(mut self) {
|
||||
info!(target: "beefy", "🥩 run BEEFY worker, best grandpa: #{:?}.", self.best_grandpa_block_header.number());
|
||||
let mut block_import_justif = self.links.from_block_import_justif_stream.subscribe().fuse();
|
||||
// Subscribe to finality notifications before waiting for runtime pallet and reuse stream,
|
||||
// so we process notifications for all finalized blocks after pallet is available.
|
||||
let mut finality_notifications = self.client.finality_notification_stream().fuse();
|
||||
|
||||
self.wait_for_runtime_pallet().await;
|
||||
self.wait_for_runtime_pallet(&mut finality_notifications).await;
|
||||
trace!(target: "beefy", "🥩 BEEFY pallet available, starting voter.");
|
||||
|
||||
let mut finality_notifications = self.client.finality_notification_stream().fuse();
|
||||
let mut votes = Box::pin(
|
||||
self.gossip_engine
|
||||
.messages_for(topic::<B>())
|
||||
|
||||
Reference in New Issue
Block a user