Skip to content

Commit

Permalink
fix: syncronizer shutdown race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
daltoncoder committed May 10, 2024
1 parent 892c733 commit 4f9c61b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where

tokio::select! {
_ = &mut shutdown_future => break,
checkpoint_hash = checkpoint_fut => {
Some(checkpoint_hash) = checkpoint_fut => {
// get the checkpoint from the blockstore
let checkpoint = node
.provider()
Expand Down
2 changes: 1 addition & 1 deletion core/e2e/tests/syncronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn e2e_syncronize_state() -> Result<()> {
let (pubkey, syncronizer) = swarm.get_non_genesis_committee_syncronizer().pop().unwrap();

// Wait for the syncronizer to detect that we are behind and send the checkpoint hash.
let ckpt_hash = syncronizer.next_checkpoint_hash().await;
let ckpt_hash = syncronizer.next_checkpoint_hash().await.unwrap();

// Get the hash for this checkpoint from our blockstore. The syncronizer should have downloaded
// it.
Expand Down
3 changes: 2 additions & 1 deletion core/interfaces/src/syncronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::collection::Collection;
pub trait SyncronizerInterface<C: Collection>: BuildGraph + Sized + Send + Sync {
/// Returns the blake3hash of the next checkpoint to load, after
/// it has already downloaded by the blockstore server.
/// If it returns None it means the Node is not ever going to checkpoint and should be shutting down
#[pending]
async fn next_checkpoint_hash(&self) -> Blake3Hash;
async fn next_checkpoint_hash(&self) -> Option<Blake3Hash>;
}
4 changes: 2 additions & 2 deletions core/syncronizer/src/syncronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ impl<C: Collection> fdi::BuildGraph for Syncronizer<C> {
impl<C: Collection> SyncronizerInterface<C> for Syncronizer<C> {
/// Returns a socket that will send accross the blake3hash of the checkpoint
/// Will send it after it has already downloaded from the blockstore server
async fn next_checkpoint_hash(&self) -> Blake3Hash {
async fn next_checkpoint_hash(&self) -> Option<Blake3Hash> {
let State::Running(rx) = &self.state else {
panic!("syncronizer must be started");
};
rx.recv().await.unwrap()
rx.recv().await.ok()
}
}

Expand Down

0 comments on commit 4f9c61b

Please sign in to comment.