Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
client/beefy: make sure to persist state after voting
  • Loading branch information
acatangiu committed Feb 1, 2023
commit fe5b265d751d59b1d3beb254a2b52f684c076d02
23 changes: 11 additions & 12 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ where
let best_grandpa = self.best_grandpa_block();
self.gossip_validator.note_round(block_num);
match self.voting_oracle().triage_round(block_num, best_grandpa)? {
RoundAction::Process => self.handle_vote(vote, false)?,
RoundAction::Process => self.handle_vote(vote)?,
RoundAction::Enqueue => {
debug!(target: LOG_TARGET, "🥩 Buffer vote for round: {:?}.", block_num);
if self.pending_votes.len() < MAX_BUFFERED_VOTE_ROUNDS {
Expand Down Expand Up @@ -545,7 +545,6 @@ where
fn handle_vote(
&mut self,
vote: VoteMessage<NumberFor<B>, AuthorityId, Signature>,
self_vote: bool,
) -> Result<(), Error> {
let rounds = self
.persisted_state
Expand All @@ -569,15 +568,13 @@ where
self.finalize(finality_proof)?;
},
VoteImportResult::Ok => {
let mandatory_round = self
// Persist state after handling mandatory block vote.
if self
.voting_oracle()
.mandatory_pending()
.map(|(mandatory_num, _)| mandatory_num == block_number)
.unwrap_or(false);
// Persist state after handling self vote to avoid double voting in case
// of voter restarts.
// Also persist state after handling mandatory block vote.
if self_vote || mandatory_round {
.unwrap_or(false)
{
crate::aux_schema::write_voter_state(&*self.backend, &self.persisted_state)
.map_err(|e| Error::Backend(e.to_string()))?;
}
Expand Down Expand Up @@ -686,7 +683,7 @@ where
for (num, votes) in votes_to_handle.into_iter() {
debug!(target: LOG_TARGET, "🥩 Handle buffered votes for: {:?}.", num);
for v in votes.into_iter() {
if let Err(err) = self.handle_vote(v, false) {
if let Err(err) = self.handle_vote(v) {
error!(target: LOG_TARGET, "🥩 Error handling buffered vote: {}", err);
};
}
Expand Down Expand Up @@ -794,15 +791,17 @@ where

debug!(target: LOG_TARGET, "🥩 Sent vote message: {:?}", message);

if let Err(err) = self.handle_vote(message, true) {
if let Err(err) = self.handle_vote(message) {
error!(target: LOG_TARGET, "🥩 Error handling self vote: {}", err);
}

self.gossip_engine.gossip_message(topic::<B>(), encoded_message, false);

// Persist state after vote to avoid double voting in case of voter restarts.
self.persisted_state.best_voted = target_number;
metric_set!(self, beefy_best_voted, target_number);

Ok(())
crate::aux_schema::write_voter_state(&*self.backend, &self.persisted_state)
.map_err(|e| Error::Backend(e.to_string()))
}

fn process_new_state(&mut self) {
Expand Down