diff --git a/bin/silius/src/cli/args.rs b/bin/silius/src/cli/args.rs index 13e098f4..b399c40f 100644 --- a/bin/silius/src/cli/args.rs +++ b/bin/silius/src/cli/args.rs @@ -226,11 +226,11 @@ pub struct P2PArgs { pub enable_p2p: bool, /// Sets the p2p listen address. - #[clap(long, default_value = "0.0.0.0")] + #[clap(long = "p2p.addr", default_value = "0.0.0.0")] pub p2p_listen_address: Ipv4Addr, /// The ipv4 address to broadcast to peers about which address we are listening on. - #[clap(long)] + #[clap(long = "p2p.baddr")] pub p2p_broadcast_address: Option, /// The udp4 port to broadcast to peers in order to reach back for discovery. @@ -586,9 +586,9 @@ mod tests { let args = vec![ "p2popts", "--enable-p2p", - "--p2p-listen-address", + "--p2p.addr", "0.0.0.0", - "--p2p-broadcast-address", + "--p2p.baddr", "127.0.0.1", "--discovery.port", "4337", diff --git a/crates/grpc/src/uopool.rs b/crates/grpc/src/uopool.rs index d5ca4efb..85866adc 100644 --- a/crates/grpc/src/uopool.rs +++ b/crates/grpc/src/uopool.rs @@ -14,7 +14,7 @@ use expanded_pathbuf::ExpandedPathBuf; use eyre::Result; use futures::channel::mpsc::unbounded; use futures::StreamExt; -use libp2p_identity::Keypair; +use libp2p_identity::{secp256k1, Keypair}; use silius_p2p::config::Config; use silius_p2p::network::{EntrypointChannels, Network}; use silius_primitives::consts::p2p::DB_FOLDER_NAME; @@ -29,6 +29,7 @@ use silius_uopool::{ mempool_id, validate::validator::StandardUserOperationValidator, MempoolId, Reputation, UoPool as UserOperationPool, UoPoolBuilder, }; +use std::env; use std::fmt::{Debug, Display}; use std::os::unix::prelude::PermissionsExt; use std::path::PathBuf; @@ -431,8 +432,17 @@ where let content = std::fs::read(node_key_file).expect("discovery secret file currupted"); Keypair::from_protobuf_encoding(&content).expect("discovery secret file currupted") + } else if let Ok(p2p_private_seed) = env::var("P2P_PRIVATE_SEED") { + // Mostly test purpose + let private_bytes = p2p_private_seed.as_bytes().to_vec(); + let keypair: secp256k1::Keypair = + secp256k1::SecretKey::try_from_bytes(private_bytes) + .expect("Env P2P_PRIVATE_SEED is not valid private bytes") + .into(); + keypair.into() } else { info!("The p2p spec private key is not exist. Creating one now!"); + let keypair = Keypair::generate_secp256k1(); std::fs::write( node_key_file.clone(), diff --git a/crates/p2p/src/network.rs b/crates/p2p/src/network.rs index 364a90bb..02dd440f 100644 --- a/crates/p2p/src/network.rs +++ b/crates/p2p/src/network.rs @@ -252,11 +252,13 @@ impl Network { pub fn poll_network(&mut self, cx: &mut Context) -> Poll { let mut msg_to_publish = Vec::new(); for (chain, ep, waiting_to_publish_ch, _) in self.entrypoint_channels.iter_mut() { - while let Ok(Some((pub_userop, verified_block))) = waiting_to_publish_ch.try_next() { - info!("Got userop {pub_userop:?} from ep {ep:} verified in {verified_block:?} to publish to p2p network!"); + while let Ok(Some((pub_userop, verified_at_block_hash))) = + waiting_to_publish_ch.try_next() + { + info!("Got userop {pub_userop:?} from ep {ep:?} verified in {verified_at_block_hash:?} to publish to p2p network!"); let pub_msg = UserOperationsWithEntryPoint::new( *ep, - verified_block, + verified_at_block_hash, chain.id().into(), vec![pub_userop], ); diff --git a/crates/p2p/src/request_response/behaviour.rs b/crates/p2p/src/request_response/behaviour.rs index 571d2c69..9fed1df0 100644 --- a/crates/p2p/src/request_response/behaviour.rs +++ b/crates/p2p/src/request_response/behaviour.rs @@ -176,8 +176,8 @@ impl Behaviour { if connections.is_empty() { return Some(request); } - let ix = (request.request_id.0 as usize) % connections.len(); - let conn = &mut connections[ix]; + let id = (request.request_id.0 as usize) % connections.len(); + let conn = &mut connections[id]; conn.pending_inbound_responses.insert(request.request_id); self.pending_events.push_back(ToSwarm::NotifyHandler { peer_id: *peer, diff --git a/crates/uopool/src/uopool.rs b/crates/uopool/src/uopool.rs index 62ae5553..69445f7f 100644 --- a/crates/uopool/src/uopool.rs +++ b/crates/uopool/src/uopool.rs @@ -32,7 +32,7 @@ use silius_primitives::{ }; use std::collections::{HashMap, HashSet}; use std::fmt::{Debug, Display}; -use tracing::trace; +use tracing::{info, trace}; pub type VecUo = Vec; pub type VecCh = Vec; @@ -232,7 +232,7 @@ where if let Some(code_hashes) = res.code_hashes { let _ = self.mempool.set_code_hashes(&uo_hash, &code_hashes); } - + info!("{uo_hash:?} added to the mempool {:?}", self.id); trace!("{uo:?} added to the mempool {:?}", self.id); // update reputation diff --git a/docs/P2P.md b/docs/P2P.md index 80a98da5..688dab7b 100644 --- a/docs/P2P.md +++ b/docs/P2P.md @@ -17,6 +17,9 @@ cargo run -- bundler --eth-client-address http://localhost:8545 --mnemonic-file cargo run -- bundler --eth-client-address http://localhost:8545 --mnemonic-file ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --http.port 4000 --eth-client-proxy-address http://localhost:8545 --p2p-broadcast-address 127.0.0.1 --bootnodes "enr:-Iu4QBh2tesC8BokO61v1w43MnbfHF5H95ZJNHVEQaRq_MjFFuxmeVQnoEXxUDk5qKJCHM944gC72Xg4dYwRkGt9zA4BgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKRdyIA8OvArCcZbt3hoJHu4nVe6CblqjO0CnrbGACi-IN0Y3CCEPGDdWRwghDx" --enable-p2p --discovery.port 4338 --p2p.port 4338 --datadir ./.local/node1 ``` +## Run silius with env p2p key +P2P_PRIVATE_SEED=1 cargo run -- bundler --eth-client-address http://localhost:8545 --mnemonic-file ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --http.port 4000 --eth-client-proxy-address http://localhost:8545 --p2p-broadcast-address 127.0.0.1 --bootnodes "enr:-Iu4QBh2tesC8BokO61v1w43MnbfHF5H95ZJNHVEQaRq_MjFFuxmeVQnoEXxUDk5qKJCHM944gC72Xg4dYwRkGt9zA4BgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKRdyIA8OvArCcZbt3hoJHu4nVe6CblqjO0CnrbGACi-IN0Y3CCEPGDdWRwghDx" --enable-p2p --discovery.port 4338 --p2p.port 4338 --datadir ./.local/node1 + ## Run cluster of Silius bundler