Skip to content

Commit

Permalink
feat: add sync progress grpc (#3722)
Browse files Browse the repository at this point in the history
Description
---
Add sync progress grpc.  We do have `GetSyncInfo`, which returns block sync information. This returns the current state as well and the state of headersync. Problem is, that even with this information you will encounter scenario where after block sync is again a header sync. So doing some kind of progress bar have to be done with this in mind.

How Has This Been Tested?
---
Manually.
  • Loading branch information
Cifko authored Jan 24, 2022
1 parent ea7a467 commit d47ad5e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
17 changes: 17 additions & 0 deletions applications/tari_app_grpc/proto/base_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ service BaseNode {
rpc SubmitTransaction(SubmitTransactionRequest) returns (SubmitTransactionResponse);
// Get the base node sync information
rpc GetSyncInfo(Empty) returns (SyncInfoResponse);
// Get the base node sync information
rpc GetSyncProgress(Empty) returns (SyncProgressResponse);
// Get the base node tip information
rpc GetTipInfo(Empty) returns (TipInfoResponse);
// Search for blocks containing the specified kernels
Expand Down Expand Up @@ -316,6 +318,21 @@ message SyncInfoResponse {
repeated bytes peer_node_id = 3;
}

message SyncProgressResponse {
uint64 tip_height = 1;
uint64 local_height = 2;
SyncState state = 3;
}

enum SyncState {
STARTUP = 0;
HEADER_STARTING = 1;
HEADER = 2;
BLOCK_STARTING = 3;
BLOCK = 4;
DONE = 5;
}

// This is the message that is returned for a miner after it asks for a new block.
message GetNewBlockResult{
// This is the header hash of the completed block
Expand Down
50 changes: 49 additions & 1 deletion applications/tari_base_node/src/grpc/base_node_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ use tari_app_utilities::consts;
use tari_common_types::types::{Commitment, PublicKey, Signature};
use tari_comms::{Bytes, CommsNode};
use tari_core::{
base_node::{comms_interface::CommsInterfaceError, LocalNodeCommsInterface, StateMachineHandle},
base_node::{
comms_interface::CommsInterfaceError,
state_machine_service::states::StateInfo,
LocalNodeCommsInterface,
StateMachineHandle,
},
blocks::{Block, BlockHeader, NewBlockTemplate},
chain_storage::{ChainStorageError, PrunedOutput},
consensus::{emission::Emission, ConsensusManager, NetworkConsensus},
Expand Down Expand Up @@ -1299,6 +1304,49 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
Ok(Response::new(rx))
}

async fn get_sync_progress(
&self,
_request: Request<tari_rpc::Empty>,
) -> Result<Response<tari_rpc::SyncProgressResponse>, Status> {
let state = self
.state_machine_handle
.get_status_info_watch()
.borrow()
.state_info
.clone();
let response = match state {
StateInfo::HeaderSync(None) => tari_rpc::SyncProgressResponse {
tip_height: 0,
local_height: 0,
state: tari_rpc::SyncState::HeaderStarting.into(),
},
StateInfo::HeaderSync(Some(info)) => tari_rpc::SyncProgressResponse {
tip_height: info.tip_height,
local_height: info.local_height,
state: tari_rpc::SyncState::Header.into(),
},
StateInfo::BlockSyncStarting => tari_rpc::SyncProgressResponse {
tip_height: 0,
local_height: 0,
state: tari_rpc::SyncState::BlockStarting.into(),
},
StateInfo::BlockSync(info) => tari_rpc::SyncProgressResponse {
tip_height: info.tip_height,
local_height: info.local_height,
state: tari_rpc::SyncState::Block.into(),
},
_ => tari_rpc::SyncProgressResponse {
tip_height: 0,
local_height: 0,
state: match state.is_synced() {
true => tari_rpc::SyncState::Done.into(),
false => tari_rpc::SyncState::Startup.into(),
},
},
};
Ok(Response::new(response))
}

async fn get_sync_info(
&self,
_request: Request<tari_rpc::Empty>,
Expand Down

0 comments on commit d47ad5e

Please sign in to comment.