Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/apollo_network_benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = "Benchmarking tool for the Apollo Network"
testing = []

[dependencies]
anyhow.workspace = true
apollo_metrics.workspace = true
apollo_network.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub struct BroadcastNetworkStressTestNode {
impl BroadcastNetworkStressTestNode {
/// Creates network configuration from arguments
fn create_network_config(args: &NodeArgs) -> NetworkConfig {
let peer_private_key = create_peer_private_key(args.runner.id);
let peer_private_key =
apollo_network_benchmark::peer_key::private_key_from_node_id(args.runner.id);

let mut network_config = NetworkConfig {
port: args.runner.p2p_port,
Expand Down Expand Up @@ -236,17 +237,3 @@ pub async fn race_and_kill_tasks(spawned_tasks: Vec<JoinHandle<()>>) {
task.abort();
}
}

fn create_peer_private_key(peer_index: u64) -> [u8; 32] {
let array = peer_index.to_le_bytes();
assert_eq!(array.len(), 8);
let mut private_key = [0u8; 32];
private_key[0..8].copy_from_slice(&array);

// Log the secret key
let peer_private_key_hex =
private_key.iter().map(|byte| format!("{byte:02x}")).collect::<String>();
info!("Secret Key: {peer_private_key_hex:#?}");

private_key
}
1 change: 1 addition & 0 deletions crates/apollo_network_benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod metrics;
pub mod node_args;
pub mod peer_key;
18 changes: 18 additions & 0 deletions crates/apollo_network_benchmark/src/peer_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anyhow::Context;
use libp2p::identity::Keypair;

/// Derives a deterministic ed25519 private key from a node index.
/// The index is written as little-endian bytes into the first 8 bytes of a 32-byte seed.
pub fn private_key_from_node_id(node_id: u64) -> [u8; 32] {
let mut key = [0u8; 32];
key[..8].copy_from_slice(&node_id.to_le_bytes());
key
}

/// Returns the PeerId string for a given node index.
pub fn peer_id_from_node_id(node_id: u64) -> anyhow::Result<String> {
let secret_key_bytes = private_key_from_node_id(node_id);
let keypair = Keypair::ed25519_from_bytes(secret_key_bytes)
.context("Failed to derive keypair from node id")?;
Ok(keypair.public().to_peer_id().to_string())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New exported function peer_id_from_node_id is unused

Low Severity

The newly added peer_id_from_node_id function is exported (pub) but has no callers anywhere in the codebase — the only match for peer_id_from_node_id is its definition. This may be intentional if an upstack PR in the stack will consume it, but as it stands in this PR, it introduces dead code along with unused anyhow and libp2p imports.

Fix in Cursor Fix in Web

Loading