From 871e924038b3cc5d02fe82b992b7a07873d01dfe Mon Sep 17 00:00:00 2001 From: aidan46 Date: Tue, 4 Feb 2025 11:27:00 +0800 Subject: [PATCH 01/21] feat: Move bootstrap node into collator --- Cargo.lock | 4 + node/Cargo.toml | 4 + node/src/cli.rs | 46 +++++++++- node/src/command.rs | 14 +++- node/src/{service.rs => service/mod.rs} | 12 +++ node/src/service/p2p/bootstrap.rs | 106 ++++++++++++++++++++++++ node/src/service/p2p/mod.rs | 31 +++++++ zombienet/local-testnet.toml | 8 +- zombienet/private.pem | 3 + 9 files changed, 224 insertions(+), 4 deletions(-) rename node/src/{service.rs => service/mod.rs} (97%) create mode 100644 node/src/service/p2p/bootstrap.rs create mode 100644 node/src/service/p2p/mod.rs create mode 100644 zombienet/private.pem diff --git a/Cargo.lock b/Cargo.lock index fcf4cdeb1..fd04c78da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13794,10 +13794,13 @@ dependencies = [ "cumulus-primitives-parachain-inherent 0.7.0", "cumulus-relay-chain-interface", "docify", + "ed25519-dalek", "frame-benchmarking 28.0.0", "frame-benchmarking-cli", "futures", + "hex", "jsonrpsee 0.24.7", + "libp2p 0.54.1", "log", "pallet-transaction-payment-rpc", "parity-scale-codec", @@ -13835,6 +13838,7 @@ dependencies = [ "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", + "thiserror 2.0.8", ] [[package]] diff --git a/node/Cargo.toml b/node/Cargo.toml index 59f24419b..d796dd506 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -29,10 +29,13 @@ cumulus-primitives-core = { workspace = true, default-features = true } cumulus-primitives-parachain-inherent = { workspace = true, default-features = true } cumulus-relay-chain-interface = { workspace = true, default-features = true } docify = { workspace = true } +ed25519-dalek = { workspace = true, features = ["pem", "pkcs8"] } frame-benchmarking = { workspace = true, default-features = true } frame-benchmarking-cli = { workspace = true, default-features = true } futures = { workspace = true } +hex = { workspace = true, features = ["std"] } jsonrpsee = { features = ["server"], workspace = true } +libp2p = { workspace = true, features = ["identify", "macros", "noise", "rendezvous", "tcp", "tokio", "yamux"] } log = { workspace = true, default-features = true } pallet-transaction-payment-rpc = { workspace = true, default-features = true } polkadot-cli = { features = ["rococo-native"], workspace = true, default-features = true } @@ -66,6 +69,7 @@ sp-keystore = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } sp-timestamp = { workspace = true, default-features = true } substrate-frame-rpc-system = { workspace = true, default-features = true } +thiserror = { workspace = true } xcm.workspace = true [build-dependencies] diff --git a/node/src/cli.rs b/node/src/cli.rs index f836aee96..cb63f2332 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -1,4 +1,7 @@ -use std::path::PathBuf; +use std::{path::PathBuf, str::FromStr}; + +use ed25519_dalek::{pkcs8::DecodePrivateKey, SigningKey}; +use libp2p::{identity::Keypair, Multiaddr}; /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] @@ -64,7 +67,7 @@ pub struct Cli { pub subcommand: Option, #[command(flatten)] - pub run: cumulus_client_cli::RunCmd, + pub run: RunCmd, /// Disable automatic hardware benchmarks. /// @@ -109,3 +112,42 @@ impl RelayChainCli { } } } + +#[derive(Debug, clap::Parser)] +#[group(skip)] +pub struct RunCmd { + #[clap(flatten)] + pub base: cumulus_client_cli::RunCmd, + + /// P2P ED25519 private key + #[arg(long, value_parser = keypair_value_parser)] + pub p2p_key: Option, + + /// Listen address that the bootstrap node binds to. + #[arg(long)] + pub p2p_listen_address: Option, +} + +impl std::ops::Deref for RunCmd { + type Target = cumulus_client_cli::RunCmd; + + fn deref(&self) -> &Self::Target { + &self.base + } +} + +/// Parses a ED25519 private key into a Keypair. +/// Takes in a private key or the path to a PEM file, depending on the @ prefix. +pub(crate) fn keypair_value_parser(src: &str) -> Result { + let key = if let Some(stripped) = src.strip_prefix('@') { + let path = PathBuf::from_str(stripped) + .map_err(|e| e.to_string())? + .canonicalize() + .map_err(|e| e.to_string())?; + SigningKey::read_pkcs8_pem_file(path).map_err(|e| e.to_string())? + } else { + let hex_key = hex::decode(src).map_err(|e| e.to_string())?; + SigningKey::try_from(hex_key.as_slice()).map_err(|e| e.to_string())? + }; + Keypair::ed25519_from_bytes(key.to_bytes()).map_err(|e| e.to_string()) +} diff --git a/node/src/command.rs b/node/src/command.rs index e6694815c..616c3c895 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -12,7 +12,7 @@ use sc_service::config::{BasePath, PrometheusConfig}; use crate::{ chain_spec, cli::{Cli, RelayChainCli, Subcommand}, - service::new_partial, + service::{new_partial, p2p::BootstrapConfig}, }; fn load_spec(id: &str) -> std::result::Result, String> { @@ -225,6 +225,17 @@ pub fn run() -> Result<()> { let collator_options = cli.run.collator_options(); runner.run_node_until_exit(|config| async move { + let bootstrap_config = if config.role.is_authority() { + let p2p_key = cli.run.p2p_key.ok_or("Could not find p2p key")?; + let p2p_listen_address = cli + .run + .p2p_listen_address + .ok_or("Could not find p2p listen address")?; + Some(BootstrapConfig::new(p2p_key, p2p_listen_address)) + } else { + None + }; + let hwbench = (!cli.no_hardware_benchmarks) .then_some(config.database.path().map(|database_path| { let _ = std::fs::create_dir_all(database_path); @@ -268,6 +279,7 @@ pub fn run() -> Result<()> { collator_options, id, hwbench, + bootstrap_config, ) .await .map(|r| r.0) diff --git a/node/src/service.rs b/node/src/service/mod.rs similarity index 97% rename from node/src/service.rs rename to node/src/service/mod.rs index c1bb46f52..53ff3925a 100644 --- a/node/src/service.rs +++ b/node/src/service/mod.rs @@ -38,6 +38,10 @@ use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerH use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_keystore::KeystorePtr; +pub mod p2p; + +use crate::service::p2p::{run_bootstrap_node, BootstrapConfig}; + #[docify::export(wasm_executor)] type ParachainExecutor = WasmExecutor; @@ -245,6 +249,7 @@ pub async fn start_parachain_node( collator_options: CollatorOptions, para_id: ParaId, hwbench: Option, + bootstrap_config: Option, ) -> sc_service::error::Result<(TaskManager, Arc)> { let parachain_config = prepare_node_config(parachain_config); @@ -332,6 +337,13 @@ pub async fn start_parachain_node( }) }; + if parachain_config.role.is_authority() { + let bootstrap_config = bootstrap_config.ok_or("Could not find bootstrap config")?; + task_manager + .spawn_handle() + .spawn("p2p", None, run_bootstrap_node(bootstrap_config)); + } + sc_service::spawn_tasks(sc_service::SpawnTasksParams { rpc_builder, client: client.clone(), diff --git a/node/src/service/p2p/bootstrap.rs b/node/src/service/p2p/bootstrap.rs new file mode 100644 index 000000000..11f339889 --- /dev/null +++ b/node/src/service/p2p/bootstrap.rs @@ -0,0 +1,106 @@ +use std::time::Duration; + +use libp2p::{ + futures::StreamExt, + identify, + identity::Keypair, + noise, rendezvous, + swarm::{NetworkBehaviour, SwarmEvent}, + tcp, yamux, Multiaddr, Swarm, SwarmBuilder, +}; +use log::{debug, info}; + +use crate::service::p2p::{P2PError, DEFAULT_REGISTRATION_TTL}; + +#[derive(NetworkBehaviour)] +pub struct BootstrapBehaviour { + pub rendezvous: rendezvous::server::Behaviour, + pub identify: identify::Behaviour, +} + +pub struct BootstrapConfig { + address: Multiaddr, + keypair: Keypair, +} + +impl BootstrapConfig { + pub fn new(keypair: Keypair, address: Multiaddr) -> Self { + Self { address, keypair } + } + + pub fn create_swarm(self) -> Result<(Swarm, Multiaddr), P2PError> { + let swarm = SwarmBuilder::with_existing_identity(self.keypair) + .with_tokio() + .with_tcp( + tcp::Config::default(), + noise::Config::new, + yamux::Config::default, + ) + .map_err(|_| P2PError::InvalidTcpConfig)? + .with_behaviour(|key| BootstrapBehaviour { + // Rendezvous server behaviour for serving new peers to connecting nodes. + rendezvous: rendezvous::server::Behaviour::new( + rendezvous::server::Config::default().with_max_ttl(DEFAULT_REGISTRATION_TTL), // Max TTL of 24 hours + ), + // The identify behaviour is used to share the external address and the public key with connecting clients. + identify: identify::Behaviour::new(identify::Config::new( + "identify/1.0.0".to_string(), + key.public(), + )), + }) + .map_err(|_| P2PError::InvalidBehaviourConfig)? + .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(10))) + .build(); + + Ok((swarm, self.address)) + } +} + +/// Run the rendezvous point (bootstrap node). +/// Listens on the given [`Multiaddr`] +pub(crate) async fn bootstrap( + mut swarm: Swarm, + addr: Multiaddr, +) -> Result<(), P2PError> { + info!("Starting P2P bootstrap node at {addr}"); + swarm.listen_on(addr)?; + loop { + match swarm.select_next_some().await { + SwarmEvent::NewListenAddr { address, .. } => { + info!("Listening on {}", address); + } + SwarmEvent::Behaviour(BootstrapBehaviourEvent::Rendezvous( + rendezvous::server::Event::PeerRegistered { peer, registration }, + )) => { + info!( + "Peer {} registered for namespace '{}' for {} seconds", + peer, registration.namespace, registration.ttl + ); + } + SwarmEvent::Behaviour(BootstrapBehaviourEvent::Rendezvous( + rendezvous::server::Event::DiscoverServed { + enquirer, + registrations, + }, + )) => { + if !registrations.is_empty() { + info!( + "Served peer {} with {} new registrations", + enquirer, + registrations.len() + ); + } + } + SwarmEvent::Behaviour(BootstrapBehaviourEvent::Rendezvous( + rendezvous::server::Event::RegistrationExpired(registration), + )) => { + info!( + "Registration for peer {} expired in namespace {}", + registration.record.peer_id(), + registration.namespace + ); + } + other => debug!("Encountered event: {other:?}"), + } + } +} diff --git a/node/src/service/p2p/mod.rs b/node/src/service/p2p/mod.rs new file mode 100644 index 000000000..02075b51c --- /dev/null +++ b/node/src/service/p2p/mod.rs @@ -0,0 +1,31 @@ +use bootstrap::bootstrap; +use log::info; + +mod bootstrap; + +pub(crate) use bootstrap::BootstrapConfig; + +const DEFAULT_REGISTRATION_TTL: u64 = 86400; + +#[derive(Debug, thiserror::Error)] +pub enum P2PError { + #[error(transparent)] + Io(#[from] std::io::Error), + #[error(transparent)] + Dial(#[from] libp2p::swarm::DialError), + #[error("Invalid TCP config for swarm")] + InvalidTcpConfig, + #[error("Invalid behaviour config for swarm")] + InvalidBehaviourConfig, + #[error(transparent)] + P2PTransport(#[from] libp2p::TransportError), +} + +/// Runs a bootstrap node from the given config. +/// The `CancellationToken` is used for a graceful shutdown if the user presses ctrl+c +pub async fn run_bootstrap_node(config: BootstrapConfig) { + info!("Starting P2P bootstrap node"); + let (swarm, addr) = config.create_swarm().expect("Could not create swarm"); + + bootstrap(swarm, addr).await.expect("Could not run bootstrap node"); +} diff --git a/zombienet/local-testnet.toml b/zombienet/local-testnet.toml index 0dce2b278..f1e742cd1 100644 --- a/zombienet/local-testnet.toml +++ b/zombienet/local-testnet.toml @@ -27,7 +27,13 @@ id = 1000 # run charlie as parachain collator [[parachains.collators]] -args = ["--detailed-log-output", "--pool-type=fork-aware", "-lparachain=debug,xcm=trace,runtime=trace,txpool=debug,basic-authorship=debug"] +args = [ + "--detailed-log-output", + "--p2p-key=@zombienet/private.pem", + "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", + "--pool-type=fork-aware", + "-lparachain=debug,xcm=trace,runtime=trace,txpool=debug,basic-authorship=debug", +] command = "target/release/polka-storage-node" name = "charlie" validator = true diff --git a/zombienet/private.pem b/zombienet/private.pem new file mode 100644 index 000000000..88991529d --- /dev/null +++ b/zombienet/private.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEINlpjs5GO9zSDW0tkrCr+2v0b5bQv+BQuzD3KF+EO316 +-----END PRIVATE KEY----- From 46e8ff29411dca0ebec3f9f3032d4b2618b203de Mon Sep 17 00:00:00 2001 From: aidan46 Date: Tue, 4 Feb 2025 16:51:40 +0800 Subject: [PATCH 02/21] fix: Remove p2p bootstrap from sp-server --- node/src/cli.rs | 4 +- node/src/service/p2p/mod.rs | 4 +- storage-provider/server/src/config.rs | 12 +- storage-provider/server/src/main.rs | 38 ++----- storage-provider/server/src/p2p/bootstrap.rs | 109 ------------------- storage-provider/server/src/p2p/mod.rs | 65 +---------- 6 files changed, 23 insertions(+), 209 deletions(-) delete mode 100644 storage-provider/server/src/p2p/bootstrap.rs diff --git a/node/src/cli.rs b/node/src/cli.rs index cb63f2332..3a7ee53a0 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -120,11 +120,11 @@ pub struct RunCmd { pub base: cumulus_client_cli::RunCmd, /// P2P ED25519 private key - #[arg(long, value_parser = keypair_value_parser)] + #[arg(long, value_parser = keypair_value_parser, required = false)] pub p2p_key: Option, /// Listen address that the bootstrap node binds to. - #[arg(long)] + #[arg(long, required = false)] pub p2p_listen_address: Option, } diff --git a/node/src/service/p2p/mod.rs b/node/src/service/p2p/mod.rs index 02075b51c..ea2e5f5ea 100644 --- a/node/src/service/p2p/mod.rs +++ b/node/src/service/p2p/mod.rs @@ -27,5 +27,7 @@ pub async fn run_bootstrap_node(config: BootstrapConfig) { info!("Starting P2P bootstrap node"); let (swarm, addr) = config.create_swarm().expect("Could not create swarm"); - bootstrap(swarm, addr).await.expect("Could not run bootstrap node"); + bootstrap(swarm, addr) + .await + .expect("Could not run bootstrap node"); } diff --git a/storage-provider/server/src/config.rs b/storage-provider/server/src/config.rs index ca458b019..dcb088d87 100644 --- a/storage-provider/server/src/config.rs +++ b/storage-provider/server/src/config.rs @@ -12,7 +12,7 @@ use serde::Deserialize; use url::Url; use crate::{ - p2p::{deser_keypair, keypair_value_parser, string_to_peer_id_option, NodeType}, + p2p::{deser_keypair, keypair_value_parser, string_to_peer_id}, DEFAULT_NODE_ADDRESS, }; @@ -111,11 +111,6 @@ pub struct ConfigurationArgs { #[arg(long, required = false)] pub(crate) post_parameters: PathBuf, - /// P2P Node type, can be either a bootstrap node or a registration node. - #[serde(default = "NodeType::default")] - #[arg(long, default_value_t = NodeType::Bootstrap, required = false)] - pub(crate) node_type: NodeType, - /// P2P ED25519 private key #[serde(deserialize_with = "deser_keypair")] #[arg(long, value_parser = keypair_value_parser, required = false)] @@ -127,10 +122,9 @@ pub struct ConfigurationArgs { pub(crate) rendezvous_point_address: Multiaddr, /// PeerID of the bootstrap node used by the registration node. - /// Optional because it is not used by the bootstrap node. - #[serde(default, deserialize_with = "string_to_peer_id_option")] + #[serde(deserialize_with = "string_to_peer_id")] #[arg(long, required = false)] - pub(crate) rendezvous_point: Option, + pub(crate) rendezvous_point: PeerId, /// TTL of the p2p registration in seconds #[serde(default = "default_registration_ttl")] diff --git a/storage-provider/server/src/main.rs b/storage-provider/server/src/main.rs index fb5b0fac2..15e779ae0 100644 --- a/storage-provider/server/src/main.rs +++ b/storage-provider/server/src/main.rs @@ -14,10 +14,7 @@ use std::{env::temp_dir, net::SocketAddr, path::PathBuf, sync::Arc, time::Durati use clap::Parser; use libp2p::{identity::Keypair, Multiaddr, PeerId}; -use p2p::{ - run_bootstrap_node, run_register_node, BootstrapConfig, NodeType, P2PError, P2PState, - RegisterConfig, -}; +use p2p::{run_register_node, P2PError, P2PState, RegisterConfig}; use pipeline::types::PipelineMessage; use polka_storage_proofs::{ porep::{self, PoRepParameters}, @@ -260,9 +257,6 @@ pub struct Server { /// The number of prove commits to be run in parallel. parallel_prove_commits: usize, - /// P2P Network node type, can either be a bootstrap or registration node - node_type: NodeType, - /// P2P ED25519 private key p2p_key: Keypair, @@ -272,7 +266,7 @@ pub struct Server { /// PeerID of the bootstrap node used by the registration node. /// Optional because it is not used by the bootstrap node. - rendezvous_point: Option, + rendezvous_point: PeerId, /// TTL of the p2p registration in seconds registration_ttl: u64, @@ -356,7 +350,6 @@ impl TryFrom for Server { porep_parameters, post_parameters, parallel_prove_commits: args.parallel_prove_commits.get(), - node_type: args.node_type, p2p_key: args.p2p_key, rendezvous_point_address: args.rendezvous_point_address, rendezvous_point: args.rendezvous_point, @@ -488,7 +481,6 @@ impl Server { }; let p2p_state = P2PState { - node_type: self.node_type, p2p_key: self.p2p_key, rendezvous_point_address: self.rendezvous_point_address, rendezvous_point: self.rendezvous_point, @@ -566,23 +558,11 @@ fn spawn_p2p_task( p2p_state: P2PState, cancellation_token: CancellationToken, ) -> Result>, ServerError> { - match p2p_state.node_type { - NodeType::Bootstrap => { - let config = - BootstrapConfig::new(p2p_state.p2p_key, p2p_state.rendezvous_point_address); - Ok(tokio::spawn(run_bootstrap_node(config, cancellation_token))) - } - NodeType::Register => { - let Some(rendezvous_point) = p2p_state.rendezvous_point else { - return Err(ServerError::P2P(P2PError::InvalidBehaviourConfig)); - }; - let config = RegisterConfig::new( - p2p_state.p2p_key, - p2p_state.rendezvous_point_address, - rendezvous_point, - p2p_state.registration_ttl, - ); - Ok(tokio::spawn(run_register_node(config, cancellation_token))) - } - } + let config = RegisterConfig::new( + p2p_state.p2p_key, + p2p_state.rendezvous_point_address, + p2p_state.rendezvous_point, + p2p_state.registration_ttl, + ); + Ok(tokio::spawn(run_register_node(config, cancellation_token))) } diff --git a/storage-provider/server/src/p2p/bootstrap.rs b/storage-provider/server/src/p2p/bootstrap.rs deleted file mode 100644 index 7f6ca1b24..000000000 --- a/storage-provider/server/src/p2p/bootstrap.rs +++ /dev/null @@ -1,109 +0,0 @@ -use std::time::Duration; - -use libp2p::{ - futures::StreamExt, - identify, - identity::Keypair, - noise, rendezvous, - swarm::{NetworkBehaviour, SwarmEvent}, - tcp, yamux, Multiaddr, Swarm, SwarmBuilder, -}; - -use super::P2PError; -use crate::config::DEFAULT_REGISTRATION_TTL; - -#[derive(NetworkBehaviour)] -pub struct BootstrapBehaviour { - pub rendezvous: rendezvous::server::Behaviour, - pub identify: identify::Behaviour, -} - -pub struct BootstrapConfig { - address: Multiaddr, - keypair: Keypair, -} - -impl BootstrapConfig { - pub fn new(keypair: Keypair, address: Multiaddr) -> Self { - Self { address, keypair } - } - - pub fn create_swarm(self) -> Result<(Swarm, Multiaddr), P2PError> { - let swarm = SwarmBuilder::with_existing_identity(self.keypair) - .with_tokio() - .with_tcp( - tcp::Config::default(), - noise::Config::new, - yamux::Config::default, - ) - .map_err(|_| P2PError::InvalidTcpConfig)? - .with_behaviour(|key| BootstrapBehaviour { - // Rendezvous server behaviour for serving new peers to connecting nodes. - rendezvous: rendezvous::server::Behaviour::new( - rendezvous::server::Config::default().with_max_ttl(DEFAULT_REGISTRATION_TTL), // Max TTL of 24 hours - ), - // The identify behaviour is used to share the external address and the public key with connecting clients. - identify: identify::Behaviour::new(identify::Config::new( - "identify/1.0.0".to_string(), - key.public(), - )), - }) - .map_err(|_| P2PError::InvalidBehaviourConfig)? - .with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(10))) - .build(); - - Ok((swarm, self.address)) - } -} - -/// Run the rendezvous point (bootstrap node). -/// Listens on the given [`Multiaddr`] -pub(crate) async fn bootstrap( - mut swarm: Swarm, - addr: Multiaddr, -) -> Result<(), P2PError> { - tracing::info!("Starting P2P bootstrap node at {addr}"); - swarm.listen_on(addr)?; - while let Some(event) = swarm.next().await { - match event { - SwarmEvent::NewListenAddr { address, .. } => { - tracing::info!("Listening on {}", address); - } - SwarmEvent::Behaviour(BootstrapBehaviourEvent::Rendezvous( - rendezvous::server::Event::PeerRegistered { peer, registration }, - )) => { - tracing::info!( - "Peer {} registered for namespace '{}' for {} seconds", - peer, - registration.namespace, - registration.ttl - ); - } - SwarmEvent::Behaviour(BootstrapBehaviourEvent::Rendezvous( - rendezvous::server::Event::DiscoverServed { - enquirer, - registrations, - }, - )) => { - if !registrations.is_empty() { - tracing::info!( - "Served peer {} with {} new registrations", - enquirer, - registrations.len() - ); - } - } - SwarmEvent::Behaviour(BootstrapBehaviourEvent::Rendezvous( - rendezvous::server::Event::RegistrationExpired(registration), - )) => { - tracing::info!( - "Registration for peer {} expired in namespace {}", - registration.record.peer_id(), - registration.namespace - ); - } - other => tracing::debug!("Encountered event: {other:?}"), - } - } - Ok(()) -} diff --git a/storage-provider/server/src/p2p/mod.rs b/storage-provider/server/src/p2p/mod.rs index 83814adac..109bfb437 100644 --- a/storage-provider/server/src/p2p/mod.rs +++ b/storage-provider/server/src/p2p/mod.rs @@ -1,38 +1,17 @@ -use std::{fmt::Display, path::PathBuf, str::FromStr}; +use std::{path::PathBuf, str::FromStr}; -use bootstrap::bootstrap; -use clap::ValueEnum; use ed25519_dalek::{pkcs8::DecodePrivateKey, SigningKey}; use libp2p::{identity::Keypair, rendezvous::Namespace, Multiaddr, PeerId}; use register::register; -use serde::{de, Deserialize}; +use serde::de; use tokio_util::sync::CancellationToken; -mod bootstrap; mod register; -pub(crate) use bootstrap::BootstrapConfig; pub(crate) use register::RegisterConfig; const P2P_NAMESPACE: &str = "polka-storage"; -#[derive(Default, Debug, Clone, Copy, ValueEnum, Deserialize)] -#[serde(rename_all = "lowercase")] -pub enum NodeType { - #[default] - Bootstrap, - Register, -} - -impl Display for NodeType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - NodeType::Bootstrap => write!(f, "bootstrap"), - NodeType::Register => write!(f, "register"), - } - } -} - #[derive(Debug, thiserror::Error)] pub enum P2PError { #[error(transparent)] @@ -55,9 +34,6 @@ pub enum P2PError { /// Holds all the information needed for spawning a node. /// Node can be either a bootstrap or a registration node. pub(crate) struct P2PState { - /// P2P Node type, bootstrap or registration - pub(crate) node_type: NodeType, - /// P2P ED25519 private key pub(crate) p2p_key: Keypair, @@ -67,7 +43,7 @@ pub(crate) struct P2PState { /// PeerID of the bootstrap node used by the registration node. /// Optional because it is not used by the bootstrap node. - pub(crate) rendezvous_point: Option, + pub(crate) rendezvous_point: PeerId, /// TTL of the p2p registration in seconds pub(crate) registration_ttl: u64, @@ -99,38 +75,9 @@ pub(crate) fn keypair_value_parser(src: &str) -> Result { /// Parses a string to an optional Peer ID. /// Used in the [`ConfigurationArgs`] rendezvous_point field. -pub(crate) fn string_to_peer_id_option<'de, D: de::Deserializer<'de>>( - d: D, -) -> Result, D::Error> { - let s: Option = de::Deserialize::deserialize(d)?; - match s { - Some(s) => Ok(Some(PeerId::from_str(&s).map_err(de::Error::custom)?)), - None => Ok(None), - } -} - -/// Runs a bootstrap node from the given config. -/// The `CancellationToken` is used for a graceful shutdown if the user presses ctrl+c -pub async fn run_bootstrap_node( - config: BootstrapConfig, - token: CancellationToken, -) -> Result<(), P2PError> { - tracing::info!("Starting P2P bootstrap node"); - let (swarm, addr) = config.create_swarm()?; - - tokio::select! { - res = bootstrap(swarm, addr) => { - if let Err(e) = res { - tracing::error!("Failed to start P2P node. Reason: {e}"); - return Err(e); - } - }, - _ = token.cancelled() => { - tracing::info!("P2P node has been stopped by the cancellation token..."); - }, - } - - Ok(()) +pub(crate) fn string_to_peer_id<'de, D: de::Deserializer<'de>>(d: D) -> Result { + let s: String = de::Deserialize::deserialize(d)?; + PeerId::from_str(&s).map_err(de::Error::custom) } /// Runs a registration node from the given config. From 77d9923c7546eb3f999f88ba9d920ce2fe4792a9 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Tue, 4 Feb 2025 16:51:55 +0800 Subject: [PATCH 03/21] fix: Update examples --- examples/rpc_publish.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/rpc_publish.sh b/examples/rpc_publish.sh index e308473fb..82b2fb76a 100755 --- a/examples/rpc_publish.sh +++ b/examples/rpc_publish.sh @@ -29,6 +29,7 @@ CONFIG="/tmp/config.toml" P2P_PUBLIC_KEY="/tmp/public.pem" P2P_PRIVATE_KEY="/tmp/private.pem" P2P_ADDRESS="/ip4/127.0.0.1/tcp/62649" +P2P_BOOTSTRAP_PEER_ID="12D3KooWJsSUCM8ZMHd6ms8YcE324raSWDHLdMN3caDSNNAoKLfH" # Generate ED25519 private key to be replaced with a polka-storage-provider-client command # Generate ED25519 private key @@ -54,7 +55,8 @@ post_proof = '2KiB' porep_parameters = '2KiB.porep.params' post_parameters = '2KiB.post.params' rendezvous_point_address = '$P2P_ADDRESS' -p2p_key = '@$P2P_PRIVATE_KEY'" > "$CONFIG" +p2p_key = '@$P2P_PRIVATE_KEY' +rendezvous_point = '$P2P_BOOTSTRAP_PEER_ID'" > "$CONFIG" # Setup balances From 8ebf35d679966fa5f03a7c5c6979c4348334604d Mon Sep 17 00:00:00 2001 From: aidan46 Date: Tue, 4 Feb 2025 17:07:34 +0800 Subject: [PATCH 04/21] fix: local-testnet.toml formatting --- zombienet/local-testnet.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zombienet/local-testnet.toml b/zombienet/local-testnet.toml index f1e742cd1..48c6b11e8 100644 --- a/zombienet/local-testnet.toml +++ b/zombienet/local-testnet.toml @@ -28,11 +28,11 @@ id = 1000 # run charlie as parachain collator [[parachains.collators]] args = [ - "--detailed-log-output", - "--p2p-key=@zombienet/private.pem", - "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", - "--pool-type=fork-aware", - "-lparachain=debug,xcm=trace,runtime=trace,txpool=debug,basic-authorship=debug", + "--detailed-log-output", + "--p2p-key=@zombienet/private.pem", + "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", + "--pool-type=fork-aware", + "-lparachain=debug,xcm=trace,runtime=trace,txpool=debug,basic-authorship=debug", ] command = "target/release/polka-storage-node" name = "charlie" From 264870c7088cd290daab26db80507b94831abe4f Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 13:00:11 +0800 Subject: [PATCH 05/21] fix: Update Keypair comment --- node/src/cli.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/node/src/cli.rs b/node/src/cli.rs index 3a7ee53a0..7c9e6cdcd 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -119,11 +119,14 @@ pub struct RunCmd { #[clap(flatten)] pub base: cumulus_client_cli::RunCmd, - /// P2P ED25519 private key + /// Key used in the P2P network of Storage Providers and Collators. + /// This key generates the Peer ID that storage providers use to register. + /// It must be an ED25519 private key, either in PEM format or passed in directly. #[arg(long, value_parser = keypair_value_parser, required = false)] pub p2p_key: Option, - /// Listen address that the bootstrap node binds to. + /// Listen address in the P2P network of Storage Providers and Collators + /// that the bootstrap node binds to. #[arg(long, required = false)] pub p2p_listen_address: Option, } From 4f04d8614b44d296d16ca6251338f06919fa7e5a Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 13:03:16 +0800 Subject: [PATCH 06/21] fix: Add explicit error message to missing arguments --- node/src/command.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/node/src/command.rs b/node/src/command.rs index 616c3c895..9c3e6bdc1 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -226,11 +226,18 @@ pub fn run() -> Result<()> { runner.run_node_until_exit(|config| async move { let bootstrap_config = if config.role.is_authority() { - let p2p_key = cli.run.p2p_key.ok_or("Could not find p2p key")?; + let p2p_key = cli + .run + .p2p_key + .ok_or( + "This node is configured as authority, so it will be used as Bootstrap node for Storage Provider & Collator network, but the key is missing. Set the --p2p-key argument of the node." + )?; let p2p_listen_address = cli .run .p2p_listen_address - .ok_or("Could not find p2p listen address")?; + .ok_or( + "This node is configured as authority, so it will be used as Bootstrap node for Storage Provider & Collator network, but the listen address is missing. Set the --p2p-listen-address argument of the node." + )?; Some(BootstrapConfig::new(p2p_key, p2p_listen_address)) } else { None From 5e9e80a0433fec5a09917f0852247c75cb88a809 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 13:09:57 +0800 Subject: [PATCH 07/21] fix: Change bootstrap config handling in node --- node/src/service/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/node/src/service/mod.rs b/node/src/service/mod.rs index 53ff3925a..7862ba5b4 100644 --- a/node/src/service/mod.rs +++ b/node/src/service/mod.rs @@ -337,11 +337,10 @@ pub async fn start_parachain_node( }) }; - if parachain_config.role.is_authority() { - let bootstrap_config = bootstrap_config.ok_or("Could not find bootstrap config")?; + if let Some(config) = bootstrap_config { task_manager .spawn_handle() - .spawn("p2p", None, run_bootstrap_node(bootstrap_config)); + .spawn("p2p", None, run_bootstrap_node(config)); } sc_service::spawn_tasks(sc_service::SpawnTasksParams { From dedd16c0db8b5569ef7f6d0e79998c034ade96e3 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 13:41:33 +0800 Subject: [PATCH 08/21] fix: Add p2p args to kube zombienet --- zombienet/local-kube-testnet.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zombienet/local-kube-testnet.toml b/zombienet/local-kube-testnet.toml index d0b8d377d..beaebe840 100644 --- a/zombienet/local-kube-testnet.toml +++ b/zombienet/local-kube-testnet.toml @@ -25,7 +25,12 @@ id = 1000 # run charlie as parachain collator [[parachains.collators]] -args = ["--detailed-log-output", "-lparachain=debug,xcm=trace,runtime=trace"] +args = [ + "--detailed-log-output", + "--p2p-key=@zombienet/private.pem", + "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", + "-lparachain=debug,xcm=trace,runtime=trace", +] command = "polka-storage-node" image = "polkadotstorage.azurecr.io/parachain-node:0.1.0" name = "charlie" From 793e52d3322142a599ab56a2b1472e2eab4778d6 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 14:28:52 +0800 Subject: [PATCH 09/21] fix: Add p2p key gen to maat --- Cargo.lock | 1 + maat/Cargo.toml | 5 ++--- maat/src/lib.rs | 24 +++++++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd04c78da..63d8f5875 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8959,6 +8959,7 @@ dependencies = [ "bls12_381", "bs58", "cid 0.11.1", + "ed25519-dalek", "futures", "hex", "libp2p 0.54.1", diff --git a/maat/Cargo.toml b/maat/Cargo.toml index e609c6f8f..b08a255ef 100644 --- a/maat/Cargo.toml +++ b/maat/Cargo.toml @@ -23,6 +23,7 @@ bls12_381 = { workspace = true } bs58.workspace = true cid.workspace = true codec = { workspace = true } +ed25519-dalek = { workspace = true, features = ["pem"] } futures.workspace = true hex = { workspace = true } libp2p = { workspace = true, features = ["ecdsa", "identify"] } @@ -33,6 +34,7 @@ serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["std"] } storagext = { workspace = true } subxt = { workspace = true, features = ["substrate-compat"] } +tempfile = { workspace = true } thiserror.workspace = true tokio = { workspace = true, features = ["full"] } tokio-util = { workspace = true, features = ["rt"] } @@ -43,8 +45,5 @@ zombienet-configuration.workspace = true zombienet-sdk.workspace = true zombienet-support.workspace = true -[dev-dependencies] -tempfile = { workspace = true } - [lints] workspace = true diff --git a/maat/src/lib.rs b/maat/src/lib.rs index 7e5825f7f..d5ca1508a 100644 --- a/maat/src/lib.rs +++ b/maat/src/lib.rs @@ -1,5 +1,13 @@ -use std::path::PathBuf; +use std::{ + fs::File, + io::Write, + path::{Path, PathBuf}, +}; +use ed25519_dalek::{ + pkcs8::{spki::der::pem::LineEnding, EncodePrivateKey}, + SigningKey, +}; use storagext::PolkaStorageConfig; use subxt::{ ext::{ @@ -8,6 +16,7 @@ use subxt::{ }, tx::PairSigner, }; +use tempfile::tempdir; use tracing::level_filters::LevelFilter; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer}; use zombienet_configuration::shared::node::{Buildable, Initial, NodeConfigBuilder}; @@ -92,6 +101,10 @@ pub fn local_testnet_config() -> NetworkConfig { .display() .to_string(); let polka_storage_node_binary_path = binding.as_str(); + let temp_dir = tempdir().unwrap(); + let file_path = temp_dir.path().join("private_key.pem"); + generate_pem_file(&file_path); + let p2p_arg = format!("--p2p-key={}", file_path.display()); NetworkConfigBuilder::new() .with_relaychain(|relaychain| { @@ -111,6 +124,8 @@ pub fn local_testnet_config() -> NetworkConfig { .with_args(vec![ ("--pool-type", "fork-aware").into(), ("-lruntime=trace,parachain=debug").into(), + ("--p2p-listen-address=/ip4/127.0.0.1/tcp/62649").into(), + (p2p_arg.as_str()).into(), ]) }) }) @@ -138,3 +153,10 @@ where let keypair = Pair::from_string(s, None).unwrap(); PairSigner::::new(keypair) } + +fn generate_pem_file>(path: P) { + let signing_key = SigningKey::from([0; 32]); + let pem = signing_key.to_pkcs8_pem(LineEnding::default()).unwrap(); + let mut file = File::create(path).unwrap(); + write!(file, "{}", *pem).unwrap(); +} From c6e096441960867d0b74ba561db2e709f0427ff0 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 14:31:14 +0800 Subject: [PATCH 10/21] fix: Generate p2p key for zombienet --- Justfile | 5 ++++- zombienet/local-kube-testnet.toml | 8 ++++---- zombienet/local-testnet.toml | 2 +- zombienet/private.pem | 3 --- 4 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 zombienet/private.pem diff --git a/Justfile b/Justfile index ea7fb4da3..d5fc77987 100644 --- a/Justfile +++ b/Justfile @@ -24,8 +24,10 @@ release: lint release-testnet: cargo build --release --features polka-storage-runtime/testnet --bin polka-storage-node -# Run the testnet without building +# Generate a private key for the P2P network and +# run the testnet without building run-testnet: + openssl genpkey -algorithm ED25519 -out /tmp/private.pem zombienet -p native spawn zombienet/local-testnet.toml # Run the testing building it before @@ -152,6 +154,7 @@ load-to-minikube: minikube image load ghcr.io/polka-storage-node:"$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "polka-storage-node") | .version')" kube-testnet: + openssl genpkey -algorithm ED25519 -out /tmp/private.pem zombienet -p kubernetes spawn zombienet/local-kube-testnet.toml # The tarpaulin calls for test coverage have the following options: diff --git a/zombienet/local-kube-testnet.toml b/zombienet/local-kube-testnet.toml index beaebe840..c6f3ff655 100644 --- a/zombienet/local-kube-testnet.toml +++ b/zombienet/local-kube-testnet.toml @@ -26,10 +26,10 @@ id = 1000 # run charlie as parachain collator [[parachains.collators]] args = [ - "--detailed-log-output", - "--p2p-key=@zombienet/private.pem", - "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", - "-lparachain=debug,xcm=trace,runtime=trace", + "--detailed-log-output", + "--p2p-key=@/tmp/private.pem", + "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", + "-lparachain=debug,xcm=trace,runtime=trace", ] command = "polka-storage-node" image = "polkadotstorage.azurecr.io/parachain-node:0.1.0" diff --git a/zombienet/local-testnet.toml b/zombienet/local-testnet.toml index 48c6b11e8..5ff8caf11 100644 --- a/zombienet/local-testnet.toml +++ b/zombienet/local-testnet.toml @@ -29,7 +29,7 @@ id = 1000 [[parachains.collators]] args = [ "--detailed-log-output", - "--p2p-key=@zombienet/private.pem", + "--p2p-key=@/tmp/private.pem", "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", "--pool-type=fork-aware", "-lparachain=debug,xcm=trace,runtime=trace,txpool=debug,basic-authorship=debug", diff --git a/zombienet/private.pem b/zombienet/private.pem deleted file mode 100644 index 88991529d..000000000 --- a/zombienet/private.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEINlpjs5GO9zSDW0tkrCr+2v0b5bQv+BQuzD3KF+EO316 ------END PRIVATE KEY----- From 625aa70f2540e80ff64113d3aca2d90d793838e2 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Wed, 5 Feb 2025 15:14:12 +0800 Subject: [PATCH 11/21] fix: Move keypair_value_parser to primitives --- Cargo.lock | 8 ++++---- node/Cargo.toml | 3 +-- node/src/cli.rs | 20 ++------------------ primitives/Cargo.toml | 4 ++++ primitives/src/lib.rs | 2 ++ primitives/src/p2p.rs | 20 ++++++++++++++++++++ storage-provider/server/Cargo.toml | 2 -- storage-provider/server/src/config.rs | 3 ++- storage-provider/server/src/p2p/mod.rs | 20 ++------------------ 9 files changed, 37 insertions(+), 45 deletions(-) create mode 100644 primitives/src/p2p.rs diff --git a/Cargo.lock b/Cargo.lock index 63d8f5875..28f56d1b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13795,11 +13795,9 @@ dependencies = [ "cumulus-primitives-parachain-inherent 0.7.0", "cumulus-relay-chain-interface", "docify", - "ed25519-dalek", "frame-benchmarking 28.0.0", "frame-benchmarking-cli", "futures", - "hex", "jsonrpsee 0.24.7", "libp2p 0.54.1", "log", @@ -13808,6 +13806,7 @@ dependencies = [ "polka-storage-runtime", "polkadot-cli", "polkadot-primitives 7.0.0", + "primitives", "sc-basic-authorship", "sc-chain-spec", "sc-cli", @@ -13933,9 +13932,7 @@ dependencies = [ "ciborium", "cid 0.11.1", "clap", - "ed25519-dalek", "futures", - "hex", "hyper 1.5.2", "integer-encoding", "jsonrpsee 0.24.7", @@ -16063,7 +16060,10 @@ version = "0.1.0" dependencies = [ "cid 0.11.1", "clap", + "ed25519-dalek", "filecoin-proofs", + "hex", + "libp2p 0.54.1", "parity-scale-codec", "rand", "scale-decode 0.14.0", diff --git a/node/Cargo.toml b/node/Cargo.toml index d796dd506..24554e75e 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -15,6 +15,7 @@ name = "polka-storage-node" [dependencies] polka-storage-runtime.workspace = true +primitives = { workspace = true, features = ["p2p"] } clap = { features = ["derive"], workspace = true } codec = { workspace = true, default-features = true } @@ -29,11 +30,9 @@ cumulus-primitives-core = { workspace = true, default-features = true } cumulus-primitives-parachain-inherent = { workspace = true, default-features = true } cumulus-relay-chain-interface = { workspace = true, default-features = true } docify = { workspace = true } -ed25519-dalek = { workspace = true, features = ["pem", "pkcs8"] } frame-benchmarking = { workspace = true, default-features = true } frame-benchmarking-cli = { workspace = true, default-features = true } futures = { workspace = true } -hex = { workspace = true, features = ["std"] } jsonrpsee = { features = ["server"], workspace = true } libp2p = { workspace = true, features = ["identify", "macros", "noise", "rendezvous", "tcp", "tokio", "yamux"] } log = { workspace = true, default-features = true } diff --git a/node/src/cli.rs b/node/src/cli.rs index 7c9e6cdcd..b4665576c 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -1,7 +1,7 @@ -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; -use ed25519_dalek::{pkcs8::DecodePrivateKey, SigningKey}; use libp2p::{identity::Keypair, Multiaddr}; +use primitives::p2p::keypair_value_parser; /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] @@ -138,19 +138,3 @@ impl std::ops::Deref for RunCmd { &self.base } } - -/// Parses a ED25519 private key into a Keypair. -/// Takes in a private key or the path to a PEM file, depending on the @ prefix. -pub(crate) fn keypair_value_parser(src: &str) -> Result { - let key = if let Some(stripped) = src.strip_prefix('@') { - let path = PathBuf::from_str(stripped) - .map_err(|e| e.to_string())? - .canonicalize() - .map_err(|e| e.to_string())?; - SigningKey::read_pkcs8_pem_file(path).map_err(|e| e.to_string())? - } else { - let hex_key = hex::decode(src).map_err(|e| e.to_string())?; - SigningKey::try_from(hex_key.as_slice()).map_err(|e| e.to_string())? - }; - Keypair::ed25519_from_bytes(key.to_bytes()).map_err(|e| e.to_string()) -} diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index bfb842d0f..89701b40c 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -11,7 +11,10 @@ version = "0.1.0" cid = { workspace = true, default-features = false, features = ["alloc"] } clap = { workspace = true, features = ["derive"], optional = true } codec = { workspace = true, features = ["derive"] } +ed25519-dalek = { workspace = true, optional = true, features = ["pem"] } filecoin-proofs = { workspace = true, optional = true } +hex = { workspace = true, optional = true } +libp2p = { workspace = true, optional = true } scale-decode = { workspace = true, features = ["derive"] } scale-encode = { workspace = true, features = ["derive"] } scale-info = { workspace = true, features = ["derive"] } @@ -35,6 +38,7 @@ workspace = true builder = [] clap = ["dep:clap", "std"] default = ["std"] +p2p = ["dep:ed25519-dalek", "dep:hex", "dep:libp2p"] serde = ["dep:serde"] std = [ "cid/scale-codec", diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 7a29b5c47..38059f4f3 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -1,6 +1,8 @@ #![cfg_attr(not(feature = "std"), no_std)] // no_std by default, requires "std" for std-support pub mod commitment; +#[cfg(feature = "p2p")] +pub mod p2p; pub mod pallets; pub mod proofs; pub mod randomness; diff --git a/primitives/src/p2p.rs b/primitives/src/p2p.rs new file mode 100644 index 000000000..366457283 --- /dev/null +++ b/primitives/src/p2p.rs @@ -0,0 +1,20 @@ +use std::{path::PathBuf, str::FromStr}; + +use ed25519_dalek::{pkcs8::DecodePrivateKey, SigningKey}; +use libp2p::identity::Keypair; + +/// Parses a ED25519 private key into a Keypair. +/// Takes in a private key or the path to a PEM file, depending on the @ prefix. +pub fn keypair_value_parser(src: &str) -> Result { + let key = if let Some(stripped) = src.strip_prefix('@') { + let path = PathBuf::from_str(stripped) + .map_err(|e| e.to_string())? + .canonicalize() + .map_err(|e| e.to_string())?; + SigningKey::read_pkcs8_pem_file(path).map_err(|e| e.to_string())? + } else { + let hex_key = hex::decode(src).map_err(|e| e.to_string())?; + SigningKey::try_from(hex_key.as_slice()).map_err(|e| e.to_string())? + }; + Keypair::ed25519_from_bytes(key.to_bytes()).map_err(|e| e.to_string()) +} diff --git a/storage-provider/server/Cargo.toml b/storage-provider/server/Cargo.toml index 597cdc4f3..f871435e4 100644 --- a/storage-provider/server/Cargo.toml +++ b/storage-provider/server/Cargo.toml @@ -26,9 +26,7 @@ chrono = { workspace = true, features = ["serde"] } ciborium = { workspace = true } cid = { workspace = true, features = ["serde", "std"] } clap = { workspace = true, features = ["derive"] } -ed25519-dalek = { workspace = true, features = ["pem", "std"] } futures = { workspace = true } -hex = { workspace = true, features = ["std"] } hyper = { workspace = true } integer-encoding = { workspace = true } jsonrpsee = { workspace = true, features = ["http-client", "macros", "server", "ws-client"] } diff --git a/storage-provider/server/src/config.rs b/storage-provider/server/src/config.rs index dcb088d87..37312b9f3 100644 --- a/storage-provider/server/src/config.rs +++ b/storage-provider/server/src/config.rs @@ -7,12 +7,13 @@ use std::{ use clap::Args; use libp2p::{identity::Keypair, Multiaddr, PeerId}; use polka_storage_provider_common::config::sealing::SealingConfiguration; +use primitives::p2p::keypair_value_parser; use primitives::proofs::{RegisteredPoStProof, RegisteredSealProof}; use serde::Deserialize; use url::Url; use crate::{ - p2p::{deser_keypair, keypair_value_parser, string_to_peer_id}, + p2p::{deser_keypair, string_to_peer_id}, DEFAULT_NODE_ADDRESS, }; diff --git a/storage-provider/server/src/p2p/mod.rs b/storage-provider/server/src/p2p/mod.rs index 109bfb437..137c601c5 100644 --- a/storage-provider/server/src/p2p/mod.rs +++ b/storage-provider/server/src/p2p/mod.rs @@ -1,7 +1,7 @@ -use std::{path::PathBuf, str::FromStr}; +use std::str::FromStr; -use ed25519_dalek::{pkcs8::DecodePrivateKey, SigningKey}; use libp2p::{identity::Keypair, rendezvous::Namespace, Multiaddr, PeerId}; +use primitives::p2p::keypair_value_parser; use register::register; use serde::de; use tokio_util::sync::CancellationToken; @@ -57,22 +57,6 @@ pub(crate) fn deser_keypair<'de, D: de::Deserializer<'de>>(d: D) -> Result Result { - let key = if let Some(stripped) = src.strip_prefix('@') { - let path = PathBuf::from_str(stripped) - .map_err(|e| e.to_string())? - .canonicalize() - .map_err(|e| e.to_string())?; - SigningKey::read_pkcs8_pem_file(path).map_err(|e| e.to_string())? - } else { - let hex_key = hex::decode(src).map_err(|e| e.to_string())?; - SigningKey::try_from(hex_key.as_slice()).map_err(|e| e.to_string())? - }; - Keypair::ed25519_from_bytes(key.to_bytes()).map_err(|e| e.to_string()) -} - /// Parses a string to an optional Peer ID. /// Used in the [`ConfigurationArgs`] rendezvous_point field. pub(crate) fn string_to_peer_id<'de, D: de::Deserializer<'de>>(d: D) -> Result { From 30ae8e9ba1e41d54b8f4b91cea711f2f285708d2 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Thu, 6 Feb 2025 12:54:38 +0800 Subject: [PATCH 12/21] fix: Remove deref on RunCmd --- node/src/cli.rs | 7 ------- node/src/command.rs | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/node/src/cli.rs b/node/src/cli.rs index b4665576c..f900029f3 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -131,10 +131,3 @@ pub struct RunCmd { pub p2p_listen_address: Option, } -impl std::ops::Deref for RunCmd { - type Target = cumulus_client_cli::RunCmd; - - fn deref(&self) -> &Self::Target { - &self.base - } -} diff --git a/node/src/command.rs b/node/src/command.rs index 9c3e6bdc1..9dd0ee670 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -221,8 +221,8 @@ pub fn run() -> Result<()> { } } None => { - let runner = cli.create_runner(&cli.run.normalize())?; - let collator_options = cli.run.collator_options(); + let runner = cli.create_runner(&cli.run.base.normalize())?; + let collator_options = cli.run.base.collator_options(); runner.run_node_until_exit(|config| async move { let bootstrap_config = if config.role.is_authority() { From 82ebd77b800aee0e91d22dd5b9bee716c2ff6cce Mon Sep 17 00:00:00 2001 From: aidan46 Date: Thu, 6 Feb 2025 13:26:36 +0800 Subject: [PATCH 13/21] fix: Move p2p deps into std feature gate --- maat/src/lib.rs | 3 +-- node/Cargo.toml | 2 +- primitives/Cargo.toml | 4 +++- primitives/src/lib.rs | 4 ++-- primitives/src/p2p.rs | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/maat/src/lib.rs b/maat/src/lib.rs index d5ca1508a..121ffd89f 100644 --- a/maat/src/lib.rs +++ b/maat/src/lib.rs @@ -104,7 +104,6 @@ pub fn local_testnet_config() -> NetworkConfig { let temp_dir = tempdir().unwrap(); let file_path = temp_dir.path().join("private_key.pem"); generate_pem_file(&file_path); - let p2p_arg = format!("--p2p-key={}", file_path.display()); NetworkConfigBuilder::new() .with_relaychain(|relaychain| { @@ -125,7 +124,7 @@ pub fn local_testnet_config() -> NetworkConfig { ("--pool-type", "fork-aware").into(), ("-lruntime=trace,parachain=debug").into(), ("--p2p-listen-address=/ip4/127.0.0.1/tcp/62649").into(), - (p2p_arg.as_str()).into(), + (format!("--p2p-key={}", file_path.display()).as_str()).into(), ]) }) }) diff --git a/node/Cargo.toml b/node/Cargo.toml index 24554e75e..b06999723 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -15,7 +15,7 @@ name = "polka-storage-node" [dependencies] polka-storage-runtime.workspace = true -primitives = { workspace = true, features = ["p2p"] } +primitives = { workspace = true, features = ["std"] } clap = { features = ["derive"], workspace = true } codec = { workspace = true, default-features = true } diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 89701b40c..cf60784d9 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -38,13 +38,15 @@ workspace = true builder = [] clap = ["dep:clap", "std"] default = ["std"] -p2p = ["dep:ed25519-dalek", "dep:hex", "dep:libp2p"] serde = ["dep:serde"] std = [ "cid/scale-codec", "cid/std", "codec/std", + "dep:ed25519-dalek", "dep:filecoin-proofs", + "dep:hex", + "dep:libp2p", "scale-info/std", "serde/std", "sha2/std", diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 38059f4f3..4f3d5e55f 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -1,13 +1,13 @@ #![cfg_attr(not(feature = "std"), no_std)] // no_std by default, requires "std" for std-support pub mod commitment; -#[cfg(feature = "p2p")] -pub mod p2p; pub mod pallets; pub mod proofs; pub mod randomness; pub mod sector; +#[cfg(feature = "std")] +pub mod p2p; #[cfg(feature = "testing")] pub mod testing { // NOTE(@jmg-duarte,22/01/2025): Since there's only one thing, star import for now. diff --git a/primitives/src/p2p.rs b/primitives/src/p2p.rs index 366457283..3132a4784 100644 --- a/primitives/src/p2p.rs +++ b/primitives/src/p2p.rs @@ -5,6 +5,7 @@ use libp2p::identity::Keypair; /// Parses a ED25519 private key into a Keypair. /// Takes in a private key or the path to a PEM file, depending on the @ prefix. +#[cfg(feature = "std")] pub fn keypair_value_parser(src: &str) -> Result { let key = if let Some(stripped) = src.strip_prefix('@') { let path = PathBuf::from_str(stripped) From 81dacd86a256a1ad6b25258dff9eb622e762e5eb Mon Sep 17 00:00:00 2001 From: aidan46 Date: Thu, 6 Feb 2025 15:00:33 +0800 Subject: [PATCH 14/21] fix: Cargo fmt --- node/src/cli.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/node/src/cli.rs b/node/src/cli.rs index f900029f3..7ca019150 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -130,4 +130,3 @@ pub struct RunCmd { #[arg(long, required = false)] pub p2p_listen_address: Option, } - From 797c63c67ba6499ad5c75f452a6307a12fead8e9 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Thu, 6 Feb 2025 15:08:11 +0800 Subject: [PATCH 15/21] fix: Cargo fmt --- storage-provider/server/src/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/storage-provider/server/src/config.rs b/storage-provider/server/src/config.rs index 37312b9f3..9cc8c7d95 100644 --- a/storage-provider/server/src/config.rs +++ b/storage-provider/server/src/config.rs @@ -7,8 +7,10 @@ use std::{ use clap::Args; use libp2p::{identity::Keypair, Multiaddr, PeerId}; use polka_storage_provider_common::config::sealing::SealingConfiguration; -use primitives::p2p::keypair_value_parser; -use primitives::proofs::{RegisteredPoStProof, RegisteredSealProof}; +use primitives::{ + p2p::keypair_value_parser, + proofs::{RegisteredPoStProof, RegisteredSealProof}, +}; use serde::Deserialize; use url::Url; From 3757a292aa82cc53a4db11ed189716723ceda259 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Mon, 10 Feb 2025 12:07:13 +0100 Subject: [PATCH 16/21] fix: Add polka-storage map to key generation --- Justfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Justfile b/Justfile index d5fc77987..214624ba9 100644 --- a/Justfile +++ b/Justfile @@ -27,7 +27,7 @@ release-testnet: # Generate a private key for the P2P network and # run the testnet without building run-testnet: - openssl genpkey -algorithm ED25519 -out /tmp/private.pem + openssl genpkey -algorithm ED25519 -out /tmp/polka-storage/private.pem zombienet -p native spawn zombienet/local-testnet.toml # Run the testing building it before @@ -154,7 +154,7 @@ load-to-minikube: minikube image load ghcr.io/polka-storage-node:"$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "polka-storage-node") | .version')" kube-testnet: - openssl genpkey -algorithm ED25519 -out /tmp/private.pem + openssl genpkey -algorithm ED25519 -out /tmp/polka-storage/private.pem zombienet -p kubernetes spawn zombienet/local-kube-testnet.toml # The tarpaulin calls for test coverage have the following options: From ffd177aa985c842305c8d5fcb76b9655f06948e3 Mon Sep 17 00:00:00 2001 From: aidan46 Date: Mon, 10 Feb 2025 12:08:56 +0100 Subject: [PATCH 17/21] docs: Update Peer ID docs --- docs/src/storage-provider-cli/server.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/storage-provider-cli/server.md b/docs/src/storage-provider-cli/server.md index a7ffaa46a..38dc00126 100644 --- a/docs/src/storage-provider-cli/server.md +++ b/docs/src/storage-provider-cli/server.md @@ -5,6 +5,8 @@ This chapter covers the Polka Storage Provider server. ## P2P Key generation The Polka Storage Provider server runs a p2p node that is used to map Peer ID's to Multi-addresses. +The generated Peer ID is used for on-chain registration and inside the P2P network. +Both these Peer ID's must be the same. The server can run either a bootstrap node, used to aid in discovery, or a registration node, which registers to a bootstrap node with their Peer ID to Multi-address mapping. For both of these node types, the server needs an ed25519 private key. From f9a809739d8db5d3895e8596091a6c73da8942af Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 11 Feb 2025 10:27:25 +0100 Subject: [PATCH 18/21] fix: Rename deserialize peer id function --- storage-provider/server/src/config.rs | 4 ++-- storage-provider/server/src/p2p/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/storage-provider/server/src/config.rs b/storage-provider/server/src/config.rs index 9cc8c7d95..66e0c2603 100644 --- a/storage-provider/server/src/config.rs +++ b/storage-provider/server/src/config.rs @@ -15,7 +15,7 @@ use serde::Deserialize; use url::Url; use crate::{ - p2p::{deser_keypair, string_to_peer_id}, + p2p::{deser_keypair, deserialize_string_to_peer_id}, DEFAULT_NODE_ADDRESS, }; @@ -125,7 +125,7 @@ pub struct ConfigurationArgs { pub(crate) rendezvous_point_address: Multiaddr, /// PeerID of the bootstrap node used by the registration node. - #[serde(deserialize_with = "string_to_peer_id")] + #[serde(deserialize_with = "deserialize_string_to_peer_id")] #[arg(long, required = false)] pub(crate) rendezvous_point: PeerId, diff --git a/storage-provider/server/src/p2p/mod.rs b/storage-provider/server/src/p2p/mod.rs index 137c601c5..3fde23334 100644 --- a/storage-provider/server/src/p2p/mod.rs +++ b/storage-provider/server/src/p2p/mod.rs @@ -59,7 +59,7 @@ pub(crate) fn deser_keypair<'de, D: de::Deserializer<'de>>(d: D) -> Result>(d: D) -> Result { +pub(crate) fn deserialize_string_to_peer_id<'de, D: de::Deserializer<'de>>(d: D) -> Result { let s: String = de::Deserialize::deserialize(d)?; PeerId::from_str(&s).map_err(de::Error::custom) } From 51ba80051b9bf0b5574bd3b63894d025a69f0286 Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 11 Feb 2025 10:29:24 +0100 Subject: [PATCH 19/21] fix: Generate Peer ID in rpc_publish example --- examples/rpc_publish.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/rpc_publish.sh b/examples/rpc_publish.sh index 82b2fb76a..fa5d3e39b 100755 --- a/examples/rpc_publish.sh +++ b/examples/rpc_publish.sh @@ -29,7 +29,6 @@ CONFIG="/tmp/config.toml" P2P_PUBLIC_KEY="/tmp/public.pem" P2P_PRIVATE_KEY="/tmp/private.pem" P2P_ADDRESS="/ip4/127.0.0.1/tcp/62649" -P2P_BOOTSTRAP_PEER_ID="12D3KooWJsSUCM8ZMHd6ms8YcE324raSWDHLdMN3caDSNNAoKLfH" # Generate ED25519 private key to be replaced with a polka-storage-provider-client command # Generate ED25519 private key @@ -38,6 +37,9 @@ openssl genpkey -algorithm ED25519 -out "$P2P_PRIVATE_KEY" # https://github.com/openssl/openssl/commit/6c03fa21ed4bbc9fd6d3013fdf9f4646d231f831 openssl pkey -in "$P2P_PRIVATE_KEY" -pubout -out "$P2P_PUBLIC_KEY" +# Generate Peer ID +P2P_BOOTSTRAP_PEER_ID="$(target/release/polka-storage-provider-client generate-peer-id --pubkey "$P2P_PUBLIC_KEY")" + # Convert file to CARv2 format target/release/mater-cli convert -q --overwrite "$INPUT_FILE" "$INPUT_TMP_FILE" && From 88f8da50d28de11db1042ff4555ffac26763269b Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 11 Feb 2025 13:56:03 +0100 Subject: [PATCH 20/21] fix: Key generation in examples and zombienet --- Justfile | 8 ++++-- examples/rpc_publish.sh | 6 ++--- examples/start_sp.sh | 42 +++++++++++++++++++------------ zombienet/local-kube-testnet.toml | 2 +- zombienet/local-testnet.toml | 2 +- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Justfile b/Justfile index 214624ba9..0a50abda9 100644 --- a/Justfile +++ b/Justfile @@ -27,7 +27,9 @@ release-testnet: # Generate a private key for the P2P network and # run the testnet without building run-testnet: - openssl genpkey -algorithm ED25519 -out /tmp/polka-storage/private.pem + mkdir -p /tmp/zombienet + openssl genpkey -algorithm ED25519 -out /tmp/zombienet/private.pem + openssl pkey -in /tmp/zombienet/private.pem -pubout -out /tmp/zombienet/public.pem # Generate public key so script can get the Peer ID zombienet -p native spawn zombienet/local-testnet.toml # Run the testing building it before @@ -154,7 +156,9 @@ load-to-minikube: minikube image load ghcr.io/polka-storage-node:"$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "polka-storage-node") | .version')" kube-testnet: - openssl genpkey -algorithm ED25519 -out /tmp/polka-storage/private.pem + mkdir -p /tmp/zombienet + openssl genpkey -algorithm ED25519 -out /tmp/zombienet/private.pem + openssl pkey -in /tmp/zombienet/private.pem -pubout -out /tmp/zombienet/public.pem # Generate public key so script can get the Peer ID zombienet -p kubernetes spawn zombienet/local-kube-testnet.toml # The tarpaulin calls for test coverage have the following options: diff --git a/examples/rpc_publish.sh b/examples/rpc_publish.sh index fa5d3e39b..8b08d8ee2 100755 --- a/examples/rpc_publish.sh +++ b/examples/rpc_publish.sh @@ -26,12 +26,12 @@ INPUT_TMP_FILE="/tmp/$INPUT_FILE_NAME.car" # Config file location CONFIG="/tmp/config.toml" # P2P Node variables -P2P_PUBLIC_KEY="/tmp/public.pem" -P2P_PRIVATE_KEY="/tmp/private.pem" +P2P_PUBLIC_KEY="/tmp/polka-storage/public.pem" +P2P_PRIVATE_KEY="/tmp/polka-storage/private.pem" P2P_ADDRESS="/ip4/127.0.0.1/tcp/62649" -# Generate ED25519 private key to be replaced with a polka-storage-provider-client command # Generate ED25519 private key +mkdir -p /tmp/storage-provider openssl genpkey -algorithm ED25519 -out "$P2P_PRIVATE_KEY" # -outpubkey is only available in OpenSSL 3.4.0 onwards # https://github.com/openssl/openssl/commit/6c03fa21ed4bbc9fd6d3013fdf9f4646d231f831 diff --git a/examples/start_sp.sh b/examples/start_sp.sh index eca6231d1..b1122b0e7 100755 --- a/examples/start_sp.sh +++ b/examples/start_sp.sh @@ -8,18 +8,29 @@ export DISABLE_XT_WAIT_WARNING=1 CLIENT="//Alice" PROVIDER="//Charlie" -P2P_PUBLIC_KEY="/tmp/public.pem" -P2P_PRIVATE_KEY="/tmp/private.pem" P2P_ADDRESS="/ip4/127.0.0.1/tcp/62649" +P2P_PUBLIC_KEY="/tmp/polka-storage/public.pem" +P2P_PRIVATE_KEY="/tmp/polka-storage/private.pem" +P2P_BOOTSTRAP_PUBLIC_KEY="/tmp/zombienet/public.pem" +# Config file location +CONFIG="/tmp/storage-provider/config.toml" # Generate ED25519 private key +mkdir -p /tmp/storage-provider openssl genpkey -algorithm ED25519 -out "$P2P_PRIVATE_KEY" # -outpubkey is only available in OpenSSL 3.4.0 onwards # https://github.com/openssl/openssl/commit/6c03fa21ed4bbc9fd6d3013fdf9f4646d231f831 openssl pkey -in "$P2P_PRIVATE_KEY" -pubout -out "$P2P_PUBLIC_KEY" # Generate Peer ID -PEER_ID="$(target/release/polka-storage-provider-client generate-peer-id --pubkey "$P2P_PUBLIC_KEY")" +P2P_SP_PEER_ID="$(target/release/polka-storage-provider-client generate-peer-id --pubkey "$P2P_PUBLIC_KEY")" + +echo "Generated new peer ID for $PROVIDER: $P2P_SP_PEER_ID" + +# Get bootstrap P2P Peer ID. This works after running zombienet locally or in kubernetes +P2P_BOOTSTRAP_PEER_ID="$(target/release/polka-storage-provider-client generate-peer-id --pubkey "$P2P_BOOTSTRAP_PUBLIC_KEY")" + +echo "Peer ID for bootstrap node: $P2P_BOOTSTRAP_PEER_ID" # Setup balances RUST_LOG=debug target/release/storagext-cli --sr25519-key "$CLIENT" market add-balance 250000000000 & @@ -31,22 +42,21 @@ wait # It's a test setup based on the local verifying keys, everyone can run those extrinsics currently. # Each of the keys is different, because the processes are running in parallel. # If they were running in parallel on the same account, they'd conflict with each other on the transaction nonce. -RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "$PEER_ID" & +RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Charlie" storage-provider register "$P2P_SP_PEER_ID" & RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Alice" proofs set-porep-verifying-key @2KiB.porep.vk.scale & RUST_LOG=debug target/release/storagext-cli --sr25519-key "//Bob" proofs set-post-verifying-key @2KiB.post.vk.scale & wait -echo '{ - "seal_proof": "2KiB", - "post_proof": "2KiB", - "porep_parameters": "2KiB.porep.params", - "post_parameters": "2KiB.post.params", - "p2p_key": "@/tmp/private.pem", - "rendezvous_point_address": "/ip4/127.0.0.1/tcp/62649", - "sealing_configuration": { - "fill_percentage": 75 - } -}' > /tmp/storage_provider.config.json +echo "seal_proof = '2KiB' +post_proof = '2KiB' +porep_parameters = '2KiB.porep.params' +post_parameters = '2KiB.post.params' +rendezvous_point_address = '$P2P_ADDRESS' +p2p_key = '@$P2P_PRIVATE_KEY' +rendezvous_point = '$P2P_BOOTSTRAP_PEER_ID' +[sealing_configuration] +fill_percentage = 75" > "$CONFIG" + RUST_LOG=debug target/release/polka-storage-provider-server \ --sr25519-key "$PROVIDER" \ - --config /tmp/storage_provider.config.json + --config "$CONFIG" diff --git a/zombienet/local-kube-testnet.toml b/zombienet/local-kube-testnet.toml index c6f3ff655..92c89e562 100644 --- a/zombienet/local-kube-testnet.toml +++ b/zombienet/local-kube-testnet.toml @@ -27,7 +27,7 @@ id = 1000 [[parachains.collators]] args = [ "--detailed-log-output", - "--p2p-key=@/tmp/private.pem", + "--p2p-key=@/tmp/zombienet/private.pem", "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", "-lparachain=debug,xcm=trace,runtime=trace", ] diff --git a/zombienet/local-testnet.toml b/zombienet/local-testnet.toml index 5ff8caf11..60ea29229 100644 --- a/zombienet/local-testnet.toml +++ b/zombienet/local-testnet.toml @@ -29,7 +29,7 @@ id = 1000 [[parachains.collators]] args = [ "--detailed-log-output", - "--p2p-key=@/tmp/private.pem", + "--p2p-key=@/tmp/zombienet/private.pem", "--p2p-listen-address=/ip4/127.0.0.1/tcp/62649", "--pool-type=fork-aware", "-lparachain=debug,xcm=trace,runtime=trace,txpool=debug,basic-authorship=debug", From a9f46b0ebf30e00d919ca662a391757dc34e38be Mon Sep 17 00:00:00 2001 From: aidan Date: Tue, 11 Feb 2025 14:01:14 +0100 Subject: [PATCH 21/21] fix: Cargo fmt --- storage-provider/server/src/p2p/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage-provider/server/src/p2p/mod.rs b/storage-provider/server/src/p2p/mod.rs index 3fde23334..7200aba60 100644 --- a/storage-provider/server/src/p2p/mod.rs +++ b/storage-provider/server/src/p2p/mod.rs @@ -59,7 +59,9 @@ pub(crate) fn deser_keypair<'de, D: de::Deserializer<'de>>(d: D) -> Result>(d: D) -> Result { +pub(crate) fn deserialize_string_to_peer_id<'de, D: de::Deserializer<'de>>( + d: D, +) -> Result { let s: String = de::Deserialize::deserialize(d)?; PeerId::from_str(&s).map_err(de::Error::custom) }