-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dag] bootstrap logic #9455
Merged
Merged
[dag] bootstrap logic #9455
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
use super::{ | ||
anchor_election::RoundRobinAnchorElection, | ||
dag_driver::DagDriver, | ||
dag_fetcher::{DagFetcher, FetchRequestHandler}, | ||
dag_handler::NetworkHandler, | ||
dag_network::DAGNetworkSender, | ||
dag_store::Dag, | ||
order_rule::OrderRule, | ||
rb_handler::NodeBroadcastHandler, | ||
storage::DAGStorage, | ||
types::DAGMessage, | ||
CertifiedNode, | ||
}; | ||
use crate::{network::IncomingDAGRequest, state_replication::PayloadClient}; | ||
use aptos_channels::{aptos_channel, message_queues::QueueStyle}; | ||
use aptos_consensus_types::common::Author; | ||
use aptos_infallible::RwLock; | ||
use aptos_reliable_broadcast::{RBNetworkSender, ReliableBroadcast}; | ||
use aptos_types::{ | ||
epoch_state::EpochState, ledger_info::LedgerInfo, validator_signer::ValidatorSigner, | ||
}; | ||
use futures::stream::{AbortHandle, Abortable}; | ||
use std::sync::Arc; | ||
use tokio_retry::strategy::ExponentialBackoff; | ||
|
||
pub fn bootstrap_dag( | ||
self_peer: Author, | ||
signer: ValidatorSigner, | ||
epoch_state: Arc<EpochState>, | ||
latest_ledger_info: LedgerInfo, | ||
storage: Arc<dyn DAGStorage>, | ||
rb_network_sender: Arc<dyn RBNetworkSender<DAGMessage>>, | ||
dag_network_sender: Arc<dyn DAGNetworkSender>, | ||
time_service: aptos_time_service::TimeService, | ||
payload_client: Arc<dyn PayloadClient>, | ||
) -> ( | ||
AbortHandle, | ||
AbortHandle, | ||
aptos_channel::Sender<Author, IncomingDAGRequest>, | ||
futures_channel::mpsc::UnboundedReceiver<Vec<Arc<CertifiedNode>>>, | ||
) { | ||
let validators = epoch_state.verifier.get_ordered_account_addresses(); | ||
let current_round = latest_ledger_info.round(); | ||
|
||
let (ordered_nodes_tx, ordered_nodes_rx) = futures_channel::mpsc::unbounded(); | ||
let (dag_rpc_tx, dag_rpc_rx) = aptos_channel::new(QueueStyle::FIFO, 64, None); | ||
|
||
// A backoff policy that starts at 100ms and doubles each iteration. | ||
let rb_backoff_policy = ExponentialBackoff::from_millis(2).factor(50); | ||
let rb = Arc::new(ReliableBroadcast::new( | ||
validators.clone(), | ||
rb_network_sender, | ||
rb_backoff_policy, | ||
time_service.clone(), | ||
)); | ||
|
||
let dag = Arc::new(RwLock::new(Dag::new(epoch_state.clone(), storage.clone()))); | ||
|
||
let anchor_election = Box::new(RoundRobinAnchorElection::new(validators)); | ||
let order_rule = OrderRule::new( | ||
epoch_state.clone(), | ||
latest_ledger_info, | ||
dag.clone(), | ||
anchor_election, | ||
ordered_nodes_tx, | ||
); | ||
|
||
let (dag_fetcher, fetch_requester, node_fetch_waiter, certified_node_fetch_waiter) = | ||
DagFetcher::new( | ||
epoch_state.clone(), | ||
dag_network_sender, | ||
dag.clone(), | ||
time_service.clone(), | ||
); | ||
let fetch_requester = Arc::new(fetch_requester); | ||
|
||
let dag_driver = DagDriver::new( | ||
self_peer, | ||
epoch_state.clone(), | ||
dag.clone(), | ||
payload_client, | ||
rb, | ||
current_round, | ||
time_service, | ||
storage.clone(), | ||
order_rule, | ||
fetch_requester, | ||
); | ||
let rb_handler = | ||
NodeBroadcastHandler::new(dag.clone(), signer, epoch_state.clone(), storage.clone()); | ||
let fetch_handler = FetchRequestHandler::new(dag, epoch_state.clone()); | ||
|
||
let dag_handler = NetworkHandler::new( | ||
epoch_state, | ||
dag_rpc_rx, | ||
rb_handler, | ||
dag_driver, | ||
fetch_handler, | ||
node_fetch_waiter, | ||
certified_node_fetch_waiter, | ||
); | ||
|
||
let (nh_abort_handle, nh_abort_registration) = AbortHandle::new_pair(); | ||
let (df_abort_handle, df_abort_registration) = AbortHandle::new_pair(); | ||
|
||
tokio::spawn(Abortable::new(dag_handler.start(), nh_abort_registration)); | ||
tokio::spawn(Abortable::new(dag_fetcher.start(), df_abort_registration)); | ||
|
||
( | ||
nh_abort_handle, | ||
df_abort_handle, | ||
dag_rpc_tx, | ||
ordered_nodes_rx, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are those used for shutdown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that was my idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically we don't need those since dropping the sender would result in the task stops if it's something like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am planning to introduce an interval timer for garbage collection. Let me keep it for now, and we can clean up later if it becomes unnecessary.