Skip to content
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

Gossip recently verified block hashes to peers #2729

Merged
merged 13 commits into from
Oct 7, 2021
9 changes: 9 additions & 0 deletions zebra-state/src/service/chain_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ impl TipAction {
}
}

/// Returns the block height of this tip action,
/// regardless of the underlying variant.
pub fn best_tip_height(&self) -> block::Height {
match self {
Grow { block } => block.height,
Reset { height, .. } => *height,
}
}

/// Returns a [`Grow`] based on `block`.
pub(crate) fn grow_with(block: ChainTipBlock) -> Self {
Grow { block }
Expand Down
24 changes: 20 additions & 4 deletions zebrad/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use tower::util::BoxService;
use crate::{
components::{
mempool::{self, Mempool},
sync,
tokio::{RuntimeRun, TokioComponent},
ChainSync, Inbound,
},
Expand Down Expand Up @@ -105,11 +106,26 @@ impl StartCmd {
.send((peer_set.clone(), address_book, mempool.clone()))
.map_err(|_| eyre!("could not send setup data to inbound service"))?;

let syncer_error_future = syncer.sync();

let sync_gossip_task_handle = tokio::spawn(sync::gossip_best_tip_block_hashes(
sync_status.clone(),
chain_tip_change,
peer_set.clone(),
));

let mempool_crawler_task_handle = mempool::Crawler::spawn(peer_set, mempool, sync_status);

select! {
result = syncer.sync().fuse() => result,
_ = mempool::Crawler::spawn(peer_set, mempool, sync_status).fuse() => {
unreachable!("The mempool crawler only stops if it panics");
}
sync_result = syncer_error_future.fuse() => sync_result,

sync_gossip_result = sync_gossip_task_handle.fuse() => sync_gossip_result
.expect("unexpected panic in the chain tip block gossip task")
.map_err(|e| eyre!(e)),

mempool_crawl_result = mempool_crawler_task_handle.fuse() => mempool_crawl_result
.expect("unexpected panic in the mempool crawler")
.map_err(|e| eyre!(e)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion zebrad/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mod inbound;
pub mod mempool;
pub mod metrics;
mod sync;
pub mod sync;
pub mod tokio;
pub mod tracing;

Expand Down
Loading