Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalajiarun committed Jan 10, 2024
1 parent 69cbc5b commit d93c02a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 45 deletions.
31 changes: 19 additions & 12 deletions consensus/src/dag/anchor_election/leader_reputation_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
dag::{anchor_election::AnchorElection, storage::CommitEvent},
dag::{
anchor_election::{AnchorElection, CommitHistory},
storage::CommitEvent,
},
liveness::{
leader_reputation::{LeaderReputation, MetadataBackend, ReputationHeuristic, VotingPowerRatio},
leader_reputation::{
LeaderReputation, MetadataBackend, ReputationHeuristic, VotingPowerRatio,
},
proposer_election::ProposerElection,
},
};
Expand Down Expand Up @@ -121,16 +126,6 @@ impl LeaderReputationAdapter {
data_source: backend,
}
}

pub(crate) fn get_voting_power_participation_ratio(&self, round: u64) -> VotingPowerRatio {
let mut voting_power_ratio = self.reputation.get_voting_power_participation_ratio(round);
// TODO: fix this once leader reputation is fixed
if voting_power_ratio < 0.67 {
voting_power_ratio = 1.0;
}

voting_power_ratio
}
}

impl AnchorElection for LeaderReputationAdapter {
Expand All @@ -142,3 +137,15 @@ impl AnchorElection for LeaderReputationAdapter {
self.data_source.push(commit_event)
}
}

impl CommitHistory for LeaderReputationAdapter {
fn get_voting_power_participation_ratio(&self, round: Round) -> VotingPowerRatio {
let mut voting_power_ratio = self.reputation.get_voting_power_participation_ratio(round);
// TODO: fix this once leader reputation is fixed
if voting_power_ratio < 0.67 {
voting_power_ratio = 1.0;
}

voting_power_ratio
}
}
6 changes: 5 additions & 1 deletion consensus/src/dag/anchor_election/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::dag::storage::CommitEvent;
use crate::{dag::storage::CommitEvent, liveness::leader_reputation::VotingPowerRatio};
use aptos_consensus_types::common::{Author, Round};

pub trait AnchorElection: Send + Sync {
Expand All @@ -10,6 +10,10 @@ pub trait AnchorElection: Send + Sync {
fn update_reputation(&self, commit_event: CommitEvent);
}

pub trait CommitHistory: Send + Sync {
fn get_voting_power_participation_ratio(&self, round: Round) -> VotingPowerRatio;
}

mod leader_reputation_adapter;
mod round_robin;

Expand Down
12 changes: 11 additions & 1 deletion consensus/src/dag/anchor_election/round_robin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::dag::{anchor_election::AnchorElection, storage::CommitEvent};
use super::CommitHistory;
use crate::{
dag::{anchor_election::AnchorElection, storage::CommitEvent},
liveness::leader_reputation::VotingPowerRatio,
};
use aptos_consensus_types::common::{Author, Round};

pub struct RoundRobinAnchorElection {
Expand All @@ -21,3 +25,9 @@ impl AnchorElection for RoundRobinAnchorElection {

fn update_reputation(&self, _event: CommitEvent) {}
}

impl CommitHistory for RoundRobinAnchorElection {
fn get_voting_power_participation_ratio(&self, _round: Round) -> VotingPowerRatio {
1.0
}
}
38 changes: 16 additions & 22 deletions consensus/src/dag/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

use super::{
adapter::{OrderedNotifierAdapter, TLedgerInfoProvider},
anchor_election::{AnchorElection, RoundRobinAnchorElection},
anchor_election::{AnchorElection, CommitHistory, RoundRobinAnchorElection},
dag_driver::DagDriver,
dag_fetcher::{DagFetcher, DagFetcherService, FetchRequestHandler},
dag_handler::NetworkHandler,
dag_network::TDAGNetworkSender,
dag_state_sync::{DagStateSynchronizer, StateSyncTrigger},
dag_store::Dag,
health::{
ChainHealthBackoff, HealthBackoff, NoChainHealth, PipelineLatencyBasedBackpressure,
TChainHealth,
},
health::{ChainHealthBackoff, HealthBackoff, PipelineLatencyBasedBackpressure, TChainHealth},
order_rule::OrderRule,
rb_handler::NodeBroadcastHandler,
storage::{CommitEvent, DAGStorage},
Expand Down Expand Up @@ -77,7 +74,7 @@ struct BootstrapBaseState {
order_rule: OrderRule,
ledger_info_provider: Arc<dyn TLedgerInfoProvider>,
ordered_notifier: Arc<OrderedNotifierAdapter>,
may_be_leader_reputation: Option<Arc<LeaderReputationAdapter>>,
commit_history: Arc<dyn CommitHistory>,
}

#[enum_dispatch(TDagMode)]
Expand Down Expand Up @@ -435,15 +432,15 @@ impl DagBootstrapper {
&self,
) -> (
Arc<dyn AnchorElection>,
Option<Arc<LeaderReputationAdapter>>,
Arc<dyn CommitHistory>,
Option<Vec<CommitEvent>>,
) {
match &self.onchain_config.anchor_election_mode {
AnchorElectionMode::RoundRobin => {
let election = Arc::new(RoundRobinAnchorElection::new(
self.epoch_state.verifier.get_ordered_account_addresses(),
));
(election, None, None)
(election.clone(), election, None)
},
AnchorElectionMode::LeaderReputation(reputation_type) => {
let (commit_events, leader_reputation) = match reputation_type {
Expand All @@ -465,7 +462,7 @@ impl DagBootstrapper {

(
leader_reputation.clone(),
Some(leader_reputation),
leader_reputation,
Some(commit_events),
)
},
Expand All @@ -475,6 +472,7 @@ impl DagBootstrapper {
fn bootstrap_dag_store(
&self,
anchor_election: Arc<dyn AnchorElection>,
commit_history: Arc<dyn CommitHistory>,
commit_events: Option<Vec<CommitEvent>>,
dag_window_size_config: u64,
) -> BootstrapBaseState {
Expand Down Expand Up @@ -530,7 +528,7 @@ impl DagBootstrapper {
order_rule,
ledger_info_provider,
ordered_notifier,
may_be_leader_reputation: None,
commit_history,
}
}

Expand Down Expand Up @@ -560,7 +558,7 @@ impl DagBootstrapper {
ledger_info_provider,
order_rule,
ordered_notifier,
may_be_leader_reputation,
commit_history,
} = base_state;

let state_sync_trigger = StateSyncTrigger::new(
Expand Down Expand Up @@ -591,13 +589,10 @@ impl DagBootstrapper {
)),
);

let chain_health: Arc<dyn TChainHealth> = match may_be_leader_reputation {
Some(adapter) => ChainHealthBackoff::new(
ChainHealthBackoffConfig::new(self.config.chain_backoff_config.clone()),
adapter.clone(),
),
None => NoChainHealth::new(),
};
let chain_health: Arc<dyn TChainHealth> = ChainHealthBackoff::new(
ChainHealthBackoffConfig::new(self.config.chain_backoff_config.clone()),
commit_history.clone(),
);
let pipeline_health = PipelineLatencyBasedBackpressure::new(
PipelineBackpressureConfig::new(self.config.pipeline_backpressure_config.clone()),
ordered_notifier.clone(),
Expand Down Expand Up @@ -647,15 +642,14 @@ impl DagBootstrapper {
}

fn full_bootstrap(&self) -> (BootstrapBaseState, NetworkHandler, DagFetcherService) {
let (anchor_election, may_be_leader_reputation, commit_events) =
self.build_anchor_election();
let (anchor_election, commit_history, commit_events) = self.build_anchor_election();

let mut base_state = self.bootstrap_dag_store(
let base_state = self.bootstrap_dag_store(
anchor_election.clone(),
commit_history,
commit_events,
self.onchain_config.dag_ordering_causal_history_window as u64,
);
base_state.may_be_leader_reputation = may_be_leader_reputation;

let (handler, fetch_service) = self.bootstrap_components(&base_state);
(base_state, handler, fetch_service)
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/dag/health/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl HealthBackoff {
.unwrap_or((u64::MAX, u64::MAX));
let voting_power_ratio = self.chain_health.voting_power_ratio(round);

let max_txns_per_round = vec![
let max_txns_per_round = [
payload_config.max_sending_txns_per_round,
chain_backoff.0,
pipeline_backoff.0,
Expand All @@ -47,7 +47,7 @@ impl HealthBackoff {
.min()
.expect("must not be empty");

let max_size_per_round_bytes = vec![
let max_size_per_round_bytes = [
payload_config.max_sending_size_per_round_bytes,
chain_backoff.1,
pipeline_backoff.1,
Expand Down
18 changes: 12 additions & 6 deletions consensus/src/dag/health/chain_health.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
counters::CHAIN_HEALTH_BACKOFF_TRIGGERED,
dag::anchor_election::LeaderReputationAdapter,
dag::anchor_election::CommitHistory,
liveness::{leader_reputation::VotingPowerRatio, proposal_generator::ChainHealthBackoffConfig},
};
use aptos_config::config::ChainHealthBackoffValues;
Expand Down Expand Up @@ -39,19 +39,24 @@ impl TChainHealth for NoChainHealth {

pub struct ChainHealthBackoff {
config: ChainHealthBackoffConfig,
adapter: Arc<LeaderReputationAdapter>,
commit_history: Arc<dyn CommitHistory>,
}

impl ChainHealthBackoff {
pub fn new(
config: ChainHealthBackoffConfig,
adapter: Arc<LeaderReputationAdapter>,
commit_history: Arc<dyn CommitHistory>,
) -> Arc<Self> {
Arc::new(Self { adapter, config })
Arc::new(Self {
commit_history,
config,
})
}

fn get_chain_health_backoff(&self, round: Round) -> Option<&ChainHealthBackoffValues> {
let voting_power_ratio = self.adapter.get_voting_power_participation_ratio(round);
let voting_power_ratio = self
.commit_history
.get_voting_power_participation_ratio(round);
let chain_health_backoff = self.config.get_backoff(voting_power_ratio);

chain_health_backoff
Expand Down Expand Up @@ -83,6 +88,7 @@ impl TChainHealth for ChainHealthBackoff {
}

fn voting_power_ratio(&self, round: Round) -> VotingPowerRatio {
self.adapter.get_voting_power_participation_ratio(round)
self.commit_history
.get_voting_power_participation_ratio(round)
}
}
2 changes: 1 addition & 1 deletion consensus/src/dag/round_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl ResponsiveCheck for OptimisticResponsive {
&mut self,
highest_strong_links_round: Round,
_strong_links: Vec<NodeCertificate>,
minimum_delay: Duration,
_minimum_delay: Duration,
) {
let new_round = highest_strong_links_round + 1;
let _ = self.event_sender.send(new_round).await;
Expand Down

0 comments on commit d93c02a

Please sign in to comment.