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

Commit

Permalink
beefy: authority set changes fixes (#139)
Browse files Browse the repository at this point in the history
* node: fix grandpa peers set config

* gadget: update best finalized number only when finalized with beefy

* gadget: process authorities changes regardless of vote status
  • Loading branch information
andresilva committed Apr 6, 2021
1 parent 0092db3 commit 0c02f26
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,29 @@ where
fn handle_finality_notification(&mut self, notification: FinalityNotification<B>) {
debug!(target: "beefy", "🥩 Finality notification: {:?}", notification);

if let Some(new) = find_authorities_change::<B, P::Public>(&notification.header) {
debug!(target: "beefy", "🥩 New validator set: {:?}", new);

if let Some(metrics) = self.metrics.as_ref() {
metrics.beefy_validator_set_id.set(new.id);
}

self.rounds = round::Rounds::new(new);

// NOTE: currently we act as if this block has been finalized by BEEFY as we perform
// the validator set changes instantly (insecure). Once proper validator set changes
// are implemented this should be removed
self.best_finalized_block = *notification.header.number();
};

if self.should_vote_on(*notification.header.number()) {
let local_id = if let Some(id) = &self.local_id {
let local_id = if let Some(ref id) = self.local_id {
id
} else {
error!(target: "beefy", "🥩 Missing validator id - can't vote for: {:?}", notification.header.hash());
return;
};

if let Some(new) = find_authorities_change::<B, P::Public>(&notification.header) {
debug!(target: "beefy", "🥩 New validator set: {:?}", new);

if let Some(metrics) = self.metrics.as_ref() {
metrics.beefy_validator_set_id.set(new.id);
}

self.rounds = round::Rounds::new(new);
};

let mmr_root = if let Some(hash) = find_mmr_root_digest::<B, P::Public>(&notification.header) {
hash
} else {
Expand All @@ -264,7 +269,7 @@ where
validator_set_id: self.rounds.validator_set_id(),
};

let signature = match self.sign_commitment(local_id, commitment.encode().as_ref()) {
let signature = match self.sign_commitment(&local_id, commitment.encode().as_ref()) {
Ok(sig) => sig,
Err(err) => {
warn!(target: "beefy", "🥩 Error signing commitment: {:?}", err);
Expand Down Expand Up @@ -295,8 +300,6 @@ where
(message.id, message.signature),
);
}

self.best_finalized_block = *notification.header.number();
}

fn handle_vote(&mut self, round: (MmrRootHash, NumberFor<B>), vote: (P::Public, S)) {
Expand All @@ -316,6 +319,7 @@ where
info!(target: "beefy", "🥩 Round #{} concluded, committed: {:?}.", round.1, signed_commitment);

self.signed_commitment_sender.notify(signed_commitment);
self.best_finalized_block = round.1;
}
}
}
Expand Down

0 comments on commit 0c02f26

Please sign in to comment.