Skip to content

Commit

Permalink
[consensus] extend the number of events leader reputation seeks
Browse files Browse the repository at this point in the history
It's oversight from the decoupled execution that we don't seek further enough to have all required block events.

The target round is current round - exclude_round (was 4 before decoupled execution), and the seek length is window_size + 10.
it ends up being the case that all events we fetch have higher round than the target round and being filtered out.

This commit takes the exclude_round into consideration when seeking events so hopefully it can get enough events back.

Closes: aptos-labs#841
  • Loading branch information
zekun000 authored and aptos-bot committed May 7, 2022
1 parent c1234eb commit 3752f96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions consensus/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ pub static COMMITTED_VOTES_IN_WINDOW: Lazy<IntGauge> = Lazy::new(|| {
.unwrap()
});

/// The number of block events the LeaderReputation uses
pub static LEADER_REPUTATION_WINDOW_SIZE: Lazy<IntGauge> = Lazy::new(|| {
register_int_gauge!(
"aptos_leader_reputation_window_size",
"Total number of new block events in the current reputation window"
)
.unwrap()
});

//////////////////////
// RoundState COUNTERS
//////////////////////
Expand Down
1 change: 1 addition & 0 deletions consensus/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl EpochManager {
ConsensusProposerType::LeaderReputation(heuristic_config) => {
let backend = Box::new(AptosDBBackend::new(
proposers.len(),
onchain_config.leader_reputation_exclude_round() + 10,
self.storage.aptos_db(),
));
let heuristic = Box::new(ActiveInactiveHeuristic::new(
Expand Down
12 changes: 8 additions & 4 deletions consensus/src/liveness/leader_reputation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
counters::{COMMITTED_PROPOSALS_IN_WINDOW, COMMITTED_VOTES_IN_WINDOW},
counters::{
COMMITTED_PROPOSALS_IN_WINDOW, COMMITTED_VOTES_IN_WINDOW, LEADER_REPUTATION_WINDOW_SIZE,
},
liveness::proposer_election::{next, ProposerElection},
};
use aptos_crypto::HashValue;
Expand All @@ -29,27 +31,28 @@ pub trait MetadataBackend: Send + Sync {

pub struct AptosDBBackend {
window_size: usize,
seek_len: u64,
aptos_db: Arc<dyn DbReader>,
window: Mutex<Vec<(u64, NewBlockEvent)>>,
}

impl AptosDBBackend {
pub fn new(window_size: usize, aptos_db: Arc<dyn DbReader>) -> Self {
pub fn new(window_size: usize, seek_len: u64, aptos_db: Arc<dyn DbReader>) -> Self {
Self {
window_size,
seek_len,
aptos_db,
window: Mutex::new(vec![]),
}
}

fn refresh_window(&self, target_round: Round) -> anyhow::Result<()> {
// assumes target round is not too far from latest commit
let buffer = 10;
let events = self.aptos_db.get_events(
&new_block_event_key(),
u64::max_value(),
Order::Descending,
self.window_size as u64 + buffer,
self.window_size as u64 + self.seek_len,
)?;
let mut result = vec![];
for (v, e) in events {
Expand Down Expand Up @@ -139,6 +142,7 @@ impl ReputationHeuristic for ActiveInactiveHeuristic {

COMMITTED_PROPOSALS_IN_WINDOW.set(committed_proposals as i64);
COMMITTED_VOTES_IN_WINDOW.set(committed_votes as i64);
LEADER_REPUTATION_WINDOW_SIZE.set(history.len() as i64);

candidates
.iter()
Expand Down

0 comments on commit 3752f96

Please sign in to comment.