Skip to content

Commit

Permalink
Fix peer best update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Nov 10, 2024
1 parent 39ea1fb commit 526f1a9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/subcoin-network/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ where

self.peers.entry(peer_id).and_modify(|e| {
if peer_best > e.best_number {
e.best_number = peer_best;
peer_best_updated = true;
tracing::debug!(
"Tip of {peer_id:?} updated from #{} to #{peer_best}",
e.best_number
);
e.best_number = peer_best;
peer_best_updated = true;
}
});

Expand Down
24 changes: 24 additions & 0 deletions crates/subcoin-node/src/substrate_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,27 @@ impl sc_cli::SubstrateCli for SubstrateCli {
Ok(Box::new(chain_spec))
}
}

#[cfg(test)]
mod tests {
use super::*;
use sc_cli::SubstrateCli;
use sc_client_api::HeaderBackend;
use subcoin_service::{new_node, NodeComponents, SubcoinConfiguration};
use tokio::runtime::Handle;

#[tokio::test]
async fn subcoin_mainnet_chain_is_stable_unless_breaking_changes() {
let runtime_handle = Handle::current();
let mainnet_chain_spec = SubstrateCli.load_spec("bitcoin-mainnet").unwrap();
let config =
subcoin_test_service::full_test_configuration(runtime_handle, mainnet_chain_spec);
let NodeComponents { client, .. } =
new_node(SubcoinConfiguration::test_config(&config)).expect("Failed to create node");

assert_eq!(
format!("{:?}", client.info().genesis_hash),
"0x594ab67f8a784863e7597996bdc3bf37fee1ddc704a17897821a2b0507f99a58"
);
}
}
19 changes: 13 additions & 6 deletions crates/subcoin-test-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sc_service::config::{
WasmExecutionMethod, WasmtimeInstantiationStrategy,
};
use sc_service::error::Error as ServiceError;
use sc_service::{BasePath, Configuration, Role};
use sc_service::{BasePath, ChainSpec, Configuration, Role};
use sp_consensus::BlockOrigin;
use sp_keyring::sr25519::Keyring as Sr25519Keyring;
use std::sync::Arc;
Expand All @@ -36,7 +36,10 @@ pub fn block_data() -> Vec<Block> {
vec![block0, block1, block2, block3]
}

pub fn test_configuration(tokio_handle: tokio::runtime::Handle) -> Configuration {
pub fn full_test_configuration(
tokio_handle: tokio::runtime::Handle,
chain_spec: Box<dyn ChainSpec>,
) -> Configuration {
let tmp = tempfile::tempdir().unwrap();
let base_path = BasePath::new(tmp.path());
let root = base_path.path().to_path_buf();
Expand All @@ -48,9 +51,6 @@ pub fn test_configuration(tokio_handle: tokio::runtime::Handle) -> Configuration
None,
);

let spec = subcoin_service::chain_spec::config(bitcoin::Network::Bitcoin)
.expect("Failed to create chain spec");

Configuration {
impl_name: "subcoin-test-node".to_string(),
impl_version: "1.0".to_string(),
Expand All @@ -65,7 +65,7 @@ pub fn test_configuration(tokio_handle: tokio::runtime::Handle) -> Configuration
trie_cache_maximum_size: Some(64 * 1024 * 1024),
state_pruning: Some(PruningMode::ArchiveAll),
blocks_pruning: BlocksPruning::KeepAll,
chain_spec: Box::new(spec),
chain_spec,
executor: ExecutorConfiguration {
wasm_method: WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
Expand Down Expand Up @@ -108,6 +108,13 @@ pub fn test_configuration(tokio_handle: tokio::runtime::Handle) -> Configuration
}
}

pub fn test_configuration(tokio_handle: tokio::runtime::Handle) -> Configuration {
let spec = subcoin_service::chain_spec::config(bitcoin::Network::Bitcoin)
.expect("Failed to create chain spec");

full_test_configuration(tokio_handle, Box::new(spec))
}

pub fn new_test_node(tokio_handle: tokio::runtime::Handle) -> Result<NodeComponents, ServiceError> {
let config = test_configuration(tokio_handle);
subcoin_service::new_node(SubcoinConfiguration {
Expand Down

0 comments on commit 526f1a9

Please sign in to comment.