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

Commit

Permalink
Add trace points; Reduce MAX_LIVE_GOSSIP_ROUNDS (#210)
Browse files Browse the repository at this point in the history
* Add trace points; Reduce MAX_LIVE_GOSSIP_ROUNDS

* log local authority id
  • Loading branch information
adoerr authored Jun 18, 2021
1 parent 7da9470 commit 600f286
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
12 changes: 9 additions & 3 deletions client/beefy/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/// The maximum number of live gossip rounds allowed, i.e. we will expire messages older than this.
use codec::{Decode, Encode};
use log::debug;
use log::{debug, trace};
use parking_lot::RwLock;

use sc_network::PeerId;
Expand All @@ -35,7 +35,7 @@ use beefy_primitives::{
use crate::keystore::BeefyKeystore;

// Limit BEEFY gossip by keeping only a bound number of voting rounds alive.
const MAX_LIVE_GOSSIP_ROUNDS: usize = 5;
const MAX_LIVE_GOSSIP_ROUNDS: usize = 3;

/// Gossip engine messages topic
pub(crate) fn topic<B: Block>() -> B::Hash
Expand Down Expand Up @@ -73,6 +73,8 @@ where
}

pub(crate) fn note_round(&self, round: NumberFor<B>) {
trace!(target: "beefy", "🥩 About to note round #{}", round);

let mut live_rounds = self.live_rounds.write();

// NOTE: ideally we'd use a VecDeque here, but currently binary search is only available on
Expand All @@ -87,7 +89,11 @@ where
}

fn is_live(live_rounds: &[NumberFor<B>], round: NumberFor<B>) -> bool {
live_rounds.binary_search(&round).is_ok()
let live = live_rounds.binary_search(&round).is_ok();

trace!(target: "beefy", "🥩 Round #{} is live: {}", round, live);

live
}
}

Expand Down
35 changes: 23 additions & 12 deletions client/beefy/src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::collections::BTreeMap;
use std::{collections::BTreeMap, hash::Hash};

use log::trace;

use beefy_primitives::{
crypto::{Public, Signature},
ValidatorSet, ValidatorSetId,
};
use sp_arithmetic::traits::AtLeast32BitUnsigned;
use sp_runtime::traits::MaybeDisplay;

struct RoundTracker {
votes: Vec<(Public, Signature)>,
Expand Down Expand Up @@ -57,10 +61,10 @@ pub(crate) struct Rounds<Hash, Number> {
validator_set: ValidatorSet<Public>,
}

impl<Hash, Number> Rounds<Hash, Number>
impl<H, N> Rounds<H, N>
where
Hash: Ord,
Number: Ord,
H: Ord + Hash,
N: Ord + AtLeast32BitUnsigned + MaybeDisplay,
{
pub(crate) fn new(validator_set: ValidatorSet<Public>) -> Self {
Rounds {
Expand All @@ -70,10 +74,10 @@ where
}
}

impl<Hash, Number> Rounds<Hash, Number>
impl<H, N> Rounds<H, N>
where
Hash: Ord,
Number: Ord,
H: Ord + Hash,
N: Ord + AtLeast32BitUnsigned + MaybeDisplay,
{
pub(crate) fn validator_set_id(&self) -> ValidatorSetId {
self.validator_set.id
Expand All @@ -83,18 +87,25 @@ where
self.validator_set.validators.clone()
}

pub(crate) fn add_vote(&mut self, round: (Hash, Number), vote: (Public, Signature)) -> bool {
pub(crate) fn add_vote(&mut self, round: (H, N), vote: (Public, Signature)) -> bool {
self.rounds.entry(round).or_default().add_vote(vote)
}

pub(crate) fn is_done(&self, round: &(Hash, Number)) -> bool {
self.rounds
pub(crate) fn is_done(&self, round: &(H, N)) -> bool {
let done = self
.rounds
.get(round)
.map(|tracker| tracker.is_done(threshold(self.validator_set.validators.len())))
.unwrap_or(false)
.unwrap_or(false);

trace!(target: "beefy", "🥩 Round #{} done: {}", round.1, done);

done
}

pub(crate) fn drop(&mut self, round: &(Hash, Number)) -> Option<Vec<Option<Signature>>> {
pub(crate) fn drop(&mut self, round: &(H, N)) -> Option<Vec<Option<Signature>>> {
trace!(target: "beefy", "🥩 About to drop round #{}", round.1);

let signatures = self.rounds.remove(round)?.votes;

Some(
Expand Down
9 changes: 7 additions & 2 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ where
///
/// Such a failure is usually an indication that the BEEFT pallet has not been deployed (yet).
fn validator_set(&self, header: &B::Header) -> Option<ValidatorSet<Public>> {
if let Some(new) = find_authorities_change::<B, Public>(header) {
let new = if let Some(new) = find_authorities_change::<B, Public>(header) {
Some(new)
} else {
let at = BlockId::hash(header.hash());
self.client.runtime_api().validator_set(&at).ok()
}
};

trace!(target: "beefy", "🥩 active validator set: {:?}", new);

new
}

fn handle_finality_notification(&mut self, notification: FinalityNotification<B>) {
Expand Down Expand Up @@ -210,6 +214,7 @@ where

if self.should_vote_on(*notification.header.number()) {
let authority_id = if let Some(id) = self.key_store.authority_id(self.rounds.validators().as_slice()) {
trace!(target: "beefy", "🥩 Local authority id: {:?}", id);
id
} else {
trace!(target: "beefy", "🥩 Missing validator id - can't vote for: {:?}", notification.header.hash());
Expand Down

0 comments on commit 600f286

Please sign in to comment.