Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beefy: small fixes #2378

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions substrate/client/consensus/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ where
.filter(|genesis| *genesis == self.persisted_state.pallet_genesis)
.ok_or(Error::ConsensusReset)?;

let mut new_session_added = false;
if *header.number() > self.best_grandpa_block() {
// update best GRANDPA finalized block we have seen
self.persisted_state.set_best_grandpa(header.clone());
Expand All @@ -475,9 +476,15 @@ where
{
if let Some(new_validator_set) = find_authorities_change::<B>(&header) {
self.init_session_at(new_validator_set, *header.number());
new_session_added = true;
}
}

if new_session_added {
crate::aux_schema::write_voter_state(&*self.backend, &self.persisted_state)
.map_err(|e| Error::Backend(e.to_string()))?;
}

// Update gossip validator votes filter.
if let Err(e) = self
.persisted_state
Expand Down Expand Up @@ -848,15 +855,10 @@ where
.fuse(),
);

self.process_new_state();
let error = loop {
// Act on changed 'state'.
self.process_new_state();

// Mutable reference used to drive the gossip engine.
let mut gossip_engine = &mut self.comms.gossip_engine;
// Use temp val and report after async section,
// to avoid having to Mutex-wrap `gossip_engine`.
let mut gossip_report: Option<PeerReport> = None;

// Wait for, and handle external events.
// The branches below only change 'state', actual voting happens afterwards,
Expand Down Expand Up @@ -884,10 +886,15 @@ where
if let Err(err) = self.triage_incoming_justif(justif) {
debug!(target: LOG_TARGET, "🥩 {}", err);
}
gossip_report = Some(peer_report);
self.comms.gossip_engine.report(peer_report.who, peer_report.cost_benefit);
},
ResponseInfo::PeerReport(peer_report) => {
self.comms.gossip_engine.report(peer_report.who, peer_report.cost_benefit);
continue;
},
ResponseInfo::Pending => {
continue;
},
ResponseInfo::PeerReport(peer_report) => gossip_report = Some(peer_report),
ResponseInfo::Pending => (),
}
},
justif = block_import_justif.next() => {
Expand Down Expand Up @@ -924,12 +931,15 @@ where
},
// Process peer reports.
report = self.comms.gossip_report_stream.next() => {
gossip_report = report;
if let Some(PeerReport { who, cost_benefit }) = report {
self.comms.gossip_engine.report(who, cost_benefit);
}
continue;
},
}
if let Some(PeerReport { who, cost_benefit }) = gossip_report {
self.comms.gossip_engine.report(who, cost_benefit);
}

// Act on changed 'state'.
self.process_new_state();
};

// return error _and_ `comms` that can be reused
Expand Down