Skip to content

Commit

Permalink
Sync from the beginning of time when a full node starts up. (MystenLa…
Browse files Browse the repository at this point in the history
…bs#2358)

(Previously the full node would not do anything until a new tx came in
over gossip)
  • Loading branch information
mystenmark authored Jun 1, 2022
1 parent 48098f0 commit 6e8e0c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
20 changes: 17 additions & 3 deletions crates/sui-core/src/authority_active/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ use super::ActiveAuthority;
pub async fn gossip_process<A>(active_authority: &ActiveAuthority<A>, degree: usize)
where
A: AuthorityAPI + Send + Sync + 'static + Clone,
{
gossip_process_with_start_seq(active_authority, degree, None).await
}

pub async fn gossip_process_with_start_seq<A>(
active_authority: &ActiveAuthority<A>,
degree: usize,
start_seq: Option<TxSequenceNumber>,
) where
A: AuthorityAPI + Send + Sync + 'static + Clone,
{
// A copy of the committee
let committee = &active_authority.net.committee;
Expand Down Expand Up @@ -93,7 +103,7 @@ where

peer_names.insert(name);
gossip_tasks.push(async move {
let peer_gossip = PeerGossip::new(name, active_authority);
let peer_gossip = PeerGossip::new(name, active_authority, start_seq);
// Add more duration if we make more than 1 to ensure overlap
debug!("Starting gossip from peer {:?}", name);
peer_gossip
Expand Down Expand Up @@ -185,12 +195,16 @@ impl<A> PeerGossip<A>
where
A: AuthorityAPI + Send + Sync + 'static + Clone,
{
pub fn new(peer_name: AuthorityName, active_authority: &ActiveAuthority<A>) -> PeerGossip<A> {
pub fn new(
peer_name: AuthorityName,
active_authority: &ActiveAuthority<A>,
start_seq: Option<TxSequenceNumber>,
) -> PeerGossip<A> {
PeerGossip {
peer_name,
client: active_authority.net.authority_clients[&peer_name].clone(),
state: active_authority.state.clone(),
max_seq: None,
max_seq: start_seq,
aggregator: active_authority.net.clone(),
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sui_config::NodeConfig;
use sui_core::authority_server::ValidatorService;
use sui_core::{
authority::{AuthorityState, AuthorityStore},
authority_active::{gossip::gossip_process, ActiveAuthority},
authority_active::{gossip::gossip_process_with_start_seq, ActiveAuthority},
authority_client::NetworkAuthorityClient,
checkpoints::CheckpointStore,
};
Expand Down Expand Up @@ -91,10 +91,12 @@ impl SuiNode {

// Start following validators
Some(tokio::task::spawn(async move {
gossip_process(
gossip_process_with_start_seq(
&active_authority,
// listen to all authorities (note that gossip_process caps this to total minus 1.)
active_authority.state.committee.voting_rights.len(),
// start receiving the earliest TXes the validator has.
Some(0),
)
.await;
}))
Expand Down
5 changes: 1 addition & 4 deletions crates/sui/tests/full_node_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,12 @@ async fn test_full_node_cold_sync() -> Result<(), anyhow::Error> {
let (_, _, _, _) = transfer_coin(&mut context).await?;
let (_, _, _, _) = transfer_coin(&mut context).await?;
let (_, _, _, _) = transfer_coin(&mut context).await?;
let (_transfered_object, sender, _receiver, digest) = transfer_coin(&mut context).await?;

sleep(Duration::from_millis(1000)).await;

let node = start_full_node(&working_dir).await?;

// Note: currently we have to send one tx after starting the full node in order for it
// to start syncing, because the node doesn't request old txes immediately upon startup.
let (_transfered_object, sender, _receiver, digest) = transfer_coin(&mut context).await?;

wait_for_tx(digest, node.state().clone()).await;

let txes = node.state().get_transactions_from_addr(sender).await?;
Expand Down

0 comments on commit 6e8e0c9

Please sign in to comment.