Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request stacks-network#4847 from stacks-network/feat/expos…
Browse files Browse the repository at this point in the history
…e-node-is-synced

Expose whether the node is synced in `/v2/info`
  • Loading branch information
smcclellan authored Jun 25, 2024
2 parents c6dc1c2 + 4634479 commit 17d917c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/rpc/api/core-node/get-info.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"stacks_tip": "b1807a2d3f7f8c7922f7c1d60d7c34145ade05d789640dc7dc9ec1021e07bb54",
"stacks_tip_consensus_hash": "17f76e597bab45646956f38dd39573085d72cbc0",
"unanchored_tip": "0000000000000000000000000000000000000000000000000000000000000000",
"exit_at_block_height": null
"exit_at_block_height": null,
"is_fully_synced": false
}
7 changes: 6 additions & 1 deletion docs/rpc/api/core-node/get-info.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"stacks_tip",
"stacks_tip_consensus_hash",
"unanchored_tip",
"exit_at_block_height"
"exit_at_block_height",
"is_fully_synced"
],
"properties": {
"peer_version": {
Expand Down Expand Up @@ -71,6 +72,10 @@
"exit_at_block_height": {
"type": "integer",
"description": "the block height at which the testnet network will be reset. not applicable for mainnet"
},
"is_fully_synced": {
"type": "boolean",
"description": "indicates whether the node has fully synchronized with the network"
}
}
}
1 change: 1 addition & 0 deletions stacks-signer/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ pub(crate) mod tests {
unanchored_tip: None,
unanchored_seq: Some(0),
exit_at_block_height: None,
is_fully_synced: false,
genesis_chainstate_hash: Sha256Sum::zero(),
node_public_key: Some(public_key_buf),
node_public_key_hash: Some(public_key_hash),
Expand Down
6 changes: 6 additions & 0 deletions stackslib/src/net/api/getinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub struct RPCPeerInfoData {
pub unanchored_tip: Option<StacksBlockId>,
pub unanchored_seq: Option<u16>,
pub exit_at_block_height: Option<u64>,
pub is_fully_synced: bool,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub node_public_key: Option<StacksPublicKeyBuffer>,
Expand All @@ -105,6 +106,7 @@ impl RPCPeerInfoData {
chainstate: &StacksChainState,
exit_at_block_height: Option<u64>,
genesis_chainstate_hash: &Sha256Sum,
ibd: bool,
) -> RPCPeerInfoData {
let server_version = version_string(
"stacks-node",
Expand All @@ -130,6 +132,7 @@ impl RPCPeerInfoData {
let public_key_buf = StacksPublicKeyBuffer::from_public_key(&public_key);
let public_key_hash = Hash160::from_node_public_key(&public_key);
let stackerdb_contract_ids = network.get_local_peer().stacker_dbs.clone();
let is_fully_synced = !ibd;

RPCPeerInfoData {
peer_version: network.burnchain.peer_version,
Expand All @@ -146,6 +149,7 @@ impl RPCPeerInfoData {
unanchored_tip: unconfirmed_tip,
unanchored_seq: unconfirmed_seq,
exit_at_block_height: exit_at_block_height,
is_fully_synced,
genesis_chainstate_hash: genesis_chainstate_hash.clone(),
node_public_key: Some(public_key_buf),
node_public_key_hash: Some(public_key_hash),
Expand Down Expand Up @@ -212,13 +216,15 @@ impl RPCRequestHandler for RPCPeerInfoRequestHandler {
_contents: HttpRequestContents,
node: &mut StacksNodeState,
) -> Result<(HttpResponsePreamble, HttpResponseContents), NetError> {
let ibd = node.ibd;
let rpc_peer_info =
node.with_node_state(|network, _sortdb, chainstate, _mempool, rpc_args| {
RPCPeerInfoData::from_network(
network,
chainstate,
rpc_args.exit_at_block_height.clone(),
&rpc_args.genesis_chainstate_hash,
ibd,
)
});
let mut preamble = HttpResponsePreamble::ok_json(&preamble);
Expand Down
8 changes: 4 additions & 4 deletions stackslib/src/net/api/tests/getinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ fn test_try_parse_request() {

#[test]
fn test_getinfo_compat() {
let old_getinfo_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null}"#;
let getinfo_no_pubkey_hash_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"node_public_key":"029b27d345e7bd2a6627262cefe6e97d9bc482f41ec32ec76a7bec391bb441798d"}"#;
let getinfo_no_pubkey_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"node_public_key_hash":"046e6f832a83ff0da4a550907d3a44412cc1e4bf"}"#;
let getinfo_full_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"node_public_key":"029b27d345e7bd2a6627262cefe6e97d9bc482f41ec32ec76a7bec391bb441798d","node_public_key_hash":"046e6f832a83ff0da4a550907d3a44412cc1e4bf"}"#;
let old_getinfo_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"is_fully_synced":false}"#;
let getinfo_no_pubkey_hash_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"is_fully_synced":false,"node_public_key":"029b27d345e7bd2a6627262cefe6e97d9bc482f41ec32ec76a7bec391bb441798d"}"#;
let getinfo_no_pubkey_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"is_fully_synced":false,"node_public_key_hash":"046e6f832a83ff0da4a550907d3a44412cc1e4bf"}"#;
let getinfo_full_json = r#"{"peer_version":402653189,"pox_consensus":"b712eb731b613eebae814a8f416c5c15bc8391ec","burn_block_height":727631,"stable_pox_consensus":"53b5ed79842080500d7d83daa36aa1069dedf983","stable_burn_block_height":727624,"server_version":"stacks-node 0.0.1 (feat/faster-inv-generation:68f33190a, release build, linux [x86_64])","network_id":1,"parent_network_id":3652501241,"stacks_tip_height":52537,"stacks_tip":"b3183f2ac588e12319ff0fde78f97e62c92a218d87828c35710c29aaf7adbedc","stacks_tip_consensus_hash":"b712eb731b613eebae814a8f416c5c15bc8391ec","genesis_chainstate_hash":"74237aa39aa50a83de11a4f53e9d3bb7d43461d1de9873f402e5453ae60bc59b","unanchored_tip":"e76f68d607480e9984b4062b2691fb60a88423177898f5780b40ace17ae8982a","unanchored_seq":0,"exit_at_block_height":null,"is_fully_synced":false,"node_public_key":"029b27d345e7bd2a6627262cefe6e97d9bc482f41ec32ec76a7bec391bb441798d","node_public_key_hash":"046e6f832a83ff0da4a550907d3a44412cc1e4bf"}"#;

// they all parse
for json_obj in &[
Expand Down
3 changes: 3 additions & 0 deletions stackslib/src/net/api/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ impl<'a> TestRPC<'a> {
&mut peer_1_stacks_node.chainstate,
&mut peer_1_mempool,
&rpc_args,
false,
);
convo_1.chat(&mut node_state).unwrap();
}
Expand Down Expand Up @@ -1010,6 +1011,7 @@ impl<'a> TestRPC<'a> {
&mut peer_2_stacks_node.chainstate,
&mut peer_2_mempool,
&rpc_args,
false,
);
convo_2.chat(&mut node_state).unwrap();
}
Expand Down Expand Up @@ -1056,6 +1058,7 @@ impl<'a> TestRPC<'a> {
&mut peer_1_stacks_node.chainstate,
&mut peer_1_mempool,
&rpc_args,
false,
);
convo_1.chat(&mut node_state).unwrap();
}
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ pub struct StacksNodeState<'a> {
inner_mempool: Option<&'a mut MemPoolDB>,
inner_rpc_args: Option<&'a RPCHandlerArgs<'a>>,
relay_message: Option<StacksMessageType>,
/// Are we in Initial Block Download (IBD) phase?
ibd: bool,
}

impl<'a> StacksNodeState<'a> {
Expand All @@ -661,6 +663,7 @@ impl<'a> StacksNodeState<'a> {
inner_chainstate: &'a mut StacksChainState,
inner_mempool: &'a mut MemPoolDB,
inner_rpc_args: &'a RPCHandlerArgs<'a>,
ibd: bool,
) -> StacksNodeState<'a> {
StacksNodeState {
inner_network: Some(inner_network),
Expand All @@ -669,6 +672,7 @@ impl<'a> StacksNodeState<'a> {
inner_mempool: Some(inner_mempool),
inner_rpc_args: Some(inner_rpc_args),
relay_message: None,
ibd,
}
}

Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/net/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5452,7 +5452,7 @@ impl PeerNetwork {
PeerNetwork::with_network_state(self, |ref mut network, ref mut network_state| {
let http_stacks_msgs = PeerNetwork::with_http(network, |ref mut net, ref mut http| {
let mut node_state =
StacksNodeState::new(net, sortdb, chainstate, mempool, handler_args);
StacksNodeState::new(net, sortdb, chainstate, mempool, handler_args, ibd);
http.run(network_state, &mut node_state, http_poll_state)
});
network_result.consume_http_uploads(http_stacks_msgs);
Expand Down

0 comments on commit 17d917c

Please sign in to comment.