Skip to content

Commit

Permalink
Add diagnostics
Browse files Browse the repository at this point in the history
Added a command-line option to perform diagnostics upon startup. Various statistics will be
collected as they are encountered and written to a file once populated.
  • Loading branch information
hansieodendaal committed Mar 10, 2025
1 parent 9039b78 commit 1f4de2b
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 73 deletions.
14 changes: 12 additions & 2 deletions integration_tests/src/p2pool_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub async fn spawn_p2pool_node_and_wait_for_start(
node_config.p2p_service.peer_exchange_interval = Duration::from_secs(1);
node_config.p2p_service.meta_data_exchange_interval = Duration::from_secs(1);
node_config.network_silence_delay = 0;
node_config.diagnostic_mode_timer = 10;
// Each spawned p2pool node will use different ports
node_config.p2p_port = get_port(18000..18499, Duration::from_secs(20)).ok_or("p2p_port no free port")?;
node_config.grpc_port = get_port(18500..18999, Duration::from_secs(20)).ok_or("grpc_port no free port")?;
Expand Down Expand Up @@ -171,6 +172,7 @@ pub async fn spawn_p2pool_node_and_wait_for_start(
user_agent: None,
peer_publish_interval: Some(node_config.p2p_service.peer_info_publish_interval.as_secs()),
debug_print_chain: true,
diagnostic_mode: true,
max_connections: None,
randomx_disabled: false,
sha3x_disabled: false,
Expand Down Expand Up @@ -379,6 +381,10 @@ pub fn to_args_command_line(args: StartArgs) -> Vec<String> {
args_vec.push("--debug-print-chain".to_string());
}

if args.diagnostic_mode {
args_vec.push("--diagnostic-mode".to_string());
}

if let Some(max_connections) = args.max_connections {
args_vec.push(format!("--max-connections={}", max_connections));
}
Expand Down Expand Up @@ -487,8 +493,12 @@ pub async fn verify_peer_connected(world: &mut TariWorld, p2pool_name: String, p
)
.into());
}
if counter % 10 == 0 {
debug!(target: LOG_TARGET, "{}: waiting for '{}' to show peer connected", counter, connections_url);
if counter % 50 == 0 {
debug!(
target: LOG_TARGET,
"Iteration {}: waiting {:.2?} for '{}' to show peer connected",
counter, start.elapsed(), connections_url
);
}
counter += 1;

Expand Down
25 changes: 21 additions & 4 deletions integration_tests/tests/features/Sync.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,35 @@
Feature: Sync p2pool nodes

@critical
Scenario: New node sync with peers
Scenario: New node sync with peers on startup
Given I have a base node BASE_NODE_A
And I have a p2pool seed node SEED in squad DOLPHINS connected to base node BASE_NODE_A
And I have a p2pool node NODE_A in squad DOLPHINS connected to base node BASE_NODE_A
And I add 10 blocks to p2pool node NODE_A
And p2pool node NODE_A stats is at height 10
# Add new node, it syncs
# Add new nodes, they sync
And I have a p2pool node NODE_B in squad DOLPHINS connected to base node BASE_NODE_A
And p2pool node NODE_A stats shows connected to peer NODE_B
And p2pool node NODE_B stats is at height 10
And I have a p2pool node NODE_C in squad DOLPHINS connected to base node BASE_NODE_A
And I have a p2pool node NODE_D in squad DOLPHINS connected to base node BASE_NODE_A
And p2pool node NODE_D stats shows connected to peer NODE_A
And p2pool node NODE_D stats shows connected to peer NODE_B
And p2pool node NODE_D stats shows connected to peer NODE_C
And p2pool node NODE_D stats is at height 10
Then I wait 1 seconds and stop

@critical
Scenario: Node will load up blocks from storage on startup
Given I have a base node BASE_NODE_A
And I have a p2pool seed node SEED in squad DOLPHINS connected to base node BASE_NODE_A
And I have a p2pool node NODE_A in squad DOLPHINS connected to base node BASE_NODE_A
And I add 10 blocks to p2pool node NODE_A
And p2pool node NODE_A stats is at height 10
# Stop the node
And I stop p2pool node NODE_A
# Start-up node again, it loads blocks from storage
And I re-start p2pool node NODE_A
And p2pool node NODE_A stats is at height 10

@critical
Scenario: New node can be offline and then sync with peers
Given I have a base node BASE_NODE_A
Expand Down
5 changes: 5 additions & 0 deletions p2pool/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ pub struct StartArgs {
#[arg(long)]
pub debug_print_chain: bool,

/// If set, basic connectivity statistics about seeds and normal peers will be collected and printed to a csv file.
#[arg(long, short, alias = "diag")]
pub diagnostic_mode: bool,

#[arg(long)]
pub max_connections: Option<u32>,

#[arg(long, default_value_t = false)]
pub randomx_disabled: bool,

#[arg(long, default_value_t = false)]
pub sha3x_disabled: bool,

Expand Down
17 changes: 13 additions & 4 deletions p2pool/src/cli/commands/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,26 @@ pub async fn server(
));
let coinbase_extras_sha3x = Arc::new(RwLock::new(HashMap::<String, Vec<u8>>::new()));

let (stats_tx, stats_rx) = tokio::sync::broadcast::channel(1000);
let stats_broadcast_client = StatsBroadcastClient::new(stats_tx);
let stats_collector = StatsCollector::new(shutdown_signal.clone(), stats_rx);

let swarm = crate::server::p2p::setup::new_swarm(&config).await?;
let squad = config.p2p_service.squad_override.clone().unwrap_or_else(|| {
let squad_id =
(*swarm.local_peer_id().to_bytes().last().unwrap_or(&0) as usize) % max(1, config.p2p_service.num_squads);
format!("{}_{}", config.p2p_service.squad_prefix.clone(), squad_id)
});
info!(target: LOG_TARGET, "Swarm created. Our id: {}, our squad:{}", swarm.local_peer_id(), squad);

let (stats_tx, stats_rx) = tokio::sync::broadcast::channel(1000);
let stats_broadcast_client = StatsBroadcastClient::new(stats_tx);
let diagnostic_mode = if args.diagnostic_mode {
Some((
Duration::from_secs(config.diagnostic_mode_timer),
*swarm.local_peer_id(),
))
} else {
None
};
let stats_collector = StatsCollector::new(shutdown_signal.clone(), stats_rx, diagnostic_mode);

if let Some(path) = args.export_libp2p_info.clone() {
let libp2p_info = LibP2pInfo {
peer_id: *swarm.local_peer_id(),
Expand Down
2 changes: 2 additions & 0 deletions p2pool/src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Config {
pub block_cache_file: PathBuf,
pub minimum_sha3_target_difficulty: Option<u64>,
pub minimum_randomx_target_difficulty: Option<u64>,
pub diagnostic_mode_timer: u64,
}

impl Default for Config {
Expand All @@ -47,6 +48,7 @@ impl Default for Config {
block_cache_file: PathBuf::from("block_cache"),
minimum_sha3_target_difficulty: None,
minimum_randomx_target_difficulty: None,
diagnostic_mode_timer: 60,
}
}
}
Expand Down
Loading

0 comments on commit 1f4de2b

Please sign in to comment.