Skip to content

Commit

Permalink
logging and small optimisations in commit rule
Browse files Browse the repository at this point in the history
  • Loading branch information
akichidis committed Nov 24, 2023
1 parent 72cdc1e commit f5c98ab
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
22 changes: 22 additions & 0 deletions mysticeti-core/src/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,28 @@ impl BlockStore {
}
parents.contains(earlier_block)
}

// Returns all the ancestors of the later_block to the `earlier_round`, assuming that there is
// a path to them.
pub fn linked_to_round(
&self,
later_block: &Data<StatementBlock>,
earlier_round: RoundNumber,
) -> Vec<Data<StatementBlock>> {
let mut parents = vec![later_block.clone()];
for r in (earlier_round..later_block.round()).rev() {
parents = self
.get_blocks_by_round(r)
.into_iter()
.filter(|block| {
parents
.iter()
.any(|x| x.includes().contains(block.reference()))
})
.collect();
}
parents
}
}

impl BlockStoreInner {
Expand Down
54 changes: 28 additions & 26 deletions mysticeti-core/src/consensus/base_committer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashSet;
use std::collections::HashMap;
use std::{fmt::Display, sync::Arc};

use crate::metrics::{Metrics, UtilizationTimerVecExt};
use crate::runtime::timestamp_utc;
use crate::types::Stake;
use crate::{
block_store::BlockStore,
committee::{Committee, QuorumThreshold, StakeAggregator},
Expand Down Expand Up @@ -154,27 +155,20 @@ impl BaseCommitter {
&self,
potential_certificate: &Data<StatementBlock>,
leader_block: &Data<StatementBlock>,
all_votes: &mut HashSet<BlockReference>,
all_votes: &mut HashMap<BlockReference, bool>,
) -> bool {
let _timer = self
.metrics
.utilization_timer
.utilization_timer("Basecommitter::is_certificate");
let mut votes_stake_aggregator = StakeAggregator::<QuorumThreshold>::new();
for reference in potential_certificate.includes() {
let is_vote = if all_votes.contains(reference) {
true
let is_vote = if let Some(is_vote) = all_votes.get(reference) {
*is_vote
} else {
let potential_vote = self
.block_store
.get_block(*reference)
.expect("We should have the whole sub-dag by now");
if self.is_vote(&potential_vote, leader_block) {
all_votes.insert(*reference);
true
} else {
false
}
let is_vote = self.is_vote(&potential_vote, leader_block);
all_votes.insert(*reference, is_vote);
is_vote
};

if is_vote {
Expand Down Expand Up @@ -205,18 +199,21 @@ impl BaseCommitter {
// are in the decision round of the target leader and are linked to the anchor.
let wave = self.wave_number(leader_round);
let decision_round = self.decision_round(wave);
let potential_certificates = self.block_store.linked_to_round(anchor, decision_round);

/*
let decision_blocks = self.block_store.get_blocks_by_round(decision_round);
let potential_certificates: Vec<_> = decision_blocks
.iter()
.filter(|block| self.block_store.linked(anchor, block))
.collect();
.collect();*/

// Use those potential certificates to determine which (if any) of the target leader
// blocks can be committed.
let mut certified_leader_blocks: Vec<_> = leader_blocks
.into_iter()
.filter(|leader_block| {
let mut all_votes = HashSet::new();
let mut all_votes = HashMap::new();
potential_certificates.iter().any(|potential_certificate| {
self.is_certificate(potential_certificate, leader_block, &mut all_votes)
})
Expand Down Expand Up @@ -276,10 +273,23 @@ impl BaseCommitter {
let decision_blocks = self.block_store.get_blocks_by_round(decision_round);
let start = timestamp_utc();

tracing::debug!("enough_leader_support for leader: {}", leader_block.round());
// quickly reject if there isn't enough stake to support the leader from the potential certificates
let total_stake: Stake = decision_blocks
.iter()
.map(|b| self.committee.get_stake(b.author()).unwrap())
.sum();
if total_stake < self.committee.quorum_threshold() {
tracing::debug!(
"Not enough support for: {}. Stake not enough: {} < {}",
leader_block.round(),
total_stake,
self.committee.quorum_threshold()
);
return false;
}

let mut certificate_stake_aggregator = StakeAggregator::<QuorumThreshold>::new();
let mut all_votes = HashSet::new();
let mut all_votes = HashMap::new();
for decision_block in &decision_blocks {
let authority = decision_block.reference().authority;
if self.is_certificate(decision_block, leader_block, &mut all_votes) {
Expand Down Expand Up @@ -315,10 +325,6 @@ impl BaseCommitter {
leader_round: RoundNumber,
leaders: impl Iterator<Item = &'a LeaderStatus>,
) -> LeaderStatus {
let _timer = self
.metrics
.utilization_timer
.utilization_timer("Basecommitter::try_indirect_decide");
// The anchor is the first committed leader with round higher than the decision round of the
// target leader. We must stop the iteration upon encountering an undecided leader.
let anchors = leaders.filter(|x| leader_round + self.options.wave_length <= x.round());
Expand Down Expand Up @@ -348,10 +354,6 @@ impl BaseCommitter {
leader: AuthorityIndex,
leader_round: RoundNumber,
) -> LeaderStatus {
let _timer = self
.metrics
.utilization_timer
.utilization_timer("Basecommitter::try_direct_decide");
// Check whether the leader has enough blame. That is, whether there are 2f+1 non-votes
// for that leader (which ensure there will never be a certificate for that leader).
let voting_round = leader_round + 1;
Expand Down
2 changes: 1 addition & 1 deletion mysticeti-core/src/consensus/universal_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl UniversalCommitter {
last_decided_round,
highest_known_round
);
for round in (last_decided_round..=highest_known_round).rev() {
for round in (last_decided_round..=highest_known_round.saturating_sub(2)).rev() {
for committer in self.committers.iter().rev() {
// Skip committers that don't have a leader for this round.
let Some(leader) = committer.elect_leader(round) else {
Expand Down
4 changes: 0 additions & 4 deletions mysticeti-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ impl<H: BlockHandler> Core<H> {

// Note that generally when you update this function you also want to change genesis initialization above
pub fn add_blocks(&mut self, blocks: Vec<Data<StatementBlock>>) -> Vec<Data<StatementBlock>> {
let _timer = self
.metrics
.utilization_timer
.utilization_timer("Core::add_blocks");
let _guard = self
.metrics
.code_scope_latency
Expand Down

0 comments on commit f5c98ab

Please sign in to comment.