mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-21 18:24:32 +00:00
add message when syncing is done
This commit is contained in:
parent
764c4663a0
commit
a133490b31
1 changed files with 35 additions and 15 deletions
|
@ -10,6 +10,7 @@ use tower::{Service, ServiceExt};
|
|||
use tracing::instrument;
|
||||
|
||||
use cuprate_consensus::{BlockChainContext, BlockChainContextRequest, BlockChainContextResponse};
|
||||
use cuprate_consensus_context::RawBlockChainContext;
|
||||
use cuprate_p2p::{
|
||||
block_downloader::{BlockBatch, BlockDownloaderConfig, ChainSvcRequest, ChainSvcResponse},
|
||||
NetworkInterface, PeerSetRequest, PeerSetResponse,
|
||||
|
@ -73,20 +74,7 @@ where
|
|||
check_update_blockchain_context(&mut context_svc, &mut blockchain_ctx).await?;
|
||||
let raw_blockchain_context = blockchain_ctx.unchecked_blockchain_context();
|
||||
|
||||
let PeerSetResponse::MostPoWSeen {
|
||||
cumulative_difficulty,
|
||||
..
|
||||
} = clearnet_interface
|
||||
.peer_set()
|
||||
.ready()
|
||||
.await?
|
||||
.call(PeerSetRequest::MostPoWSeen)
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
if cumulative_difficulty <= raw_blockchain_context.cumulative_difficulty {
|
||||
if !check_behind_peers(raw_blockchain_context, &mut clearnet_interface).await? {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -99,11 +87,18 @@ where
|
|||
loop {
|
||||
tokio::select! {
|
||||
() = stop_current_block_downloader.notified() => {
|
||||
tracing::info!("Stopping block downloader");
|
||||
tracing::info!("Received stop signal, stopping block downloader");
|
||||
break;
|
||||
}
|
||||
batch = block_batch_stream.next() => {
|
||||
let Some(batch) = batch else {
|
||||
check_update_blockchain_context(&mut context_svc, &mut blockchain_ctx).await?;
|
||||
let raw_blockchain_context = blockchain_ctx.unchecked_blockchain_context();
|
||||
|
||||
if check_behind_peers(raw_blockchain_context, &mut clearnet_interface).await? {
|
||||
tracing::info!("Synchronised with the network.");
|
||||
}
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
|
@ -117,6 +112,31 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns if we are behind the current connected network peers.
|
||||
async fn check_behind_peers(
|
||||
raw_blockchain_context: &RawBlockChainContext,
|
||||
mut clearnet_interface: &mut NetworkInterface<ClearNet>,
|
||||
) -> Result<bool, tower::BoxError> {
|
||||
let PeerSetResponse::MostPoWSeen {
|
||||
cumulative_difficulty,
|
||||
..
|
||||
} = clearnet_interface
|
||||
.peer_set()
|
||||
.ready()
|
||||
.await?
|
||||
.call(PeerSetRequest::MostPoWSeen)
|
||||
.await?
|
||||
else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
if cumulative_difficulty <= raw_blockchain_context.cumulative_difficulty {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Checks if we should update the given [`BlockChainContext`] and updates it if needed.
|
||||
async fn check_update_blockchain_context<C>(
|
||||
context_svc: C,
|
||||
|
|
Loading…
Reference in a new issue