Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Sep 23, 2023
1 parent 6468916 commit af252f1
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 30 deletions.
1 change: 1 addition & 0 deletions bin/silius/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ log = "0.4.19"
pin-utils = "0.1"
silius-bundler = { path = "../../crates/bundler" }
silius-grpc = { path = "../../crates/grpc" }
silius-p2p = { path = "../../crates/p2p" }
silius-primitives = { path = "../../crates/primitives" }
silius-rpc = { path = "../../crates/rpc" }
tokio = { workspace = true }
Expand Down
69 changes: 68 additions & 1 deletion bin/silius/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use crate::utils::{parse_address, parse_u256, parse_uopool_mode};
use clap::Parser;
use ethers::types::{Address, U256};
use expanded_pathbuf::ExpandedPathBuf;
use silius_p2p::config::{Config, ListenAddr};
use silius_primitives::UoPoolMode;
use std::net::SocketAddr;
use std::net::{Ipv4Addr, SocketAddr};

#[derive(Clone, Debug, Parser)]
pub struct UoPoolServiceOpts {
Expand Down Expand Up @@ -110,6 +111,46 @@ impl RpcServiceOpts {
}
}

#[derive(Clone, Debug, Parser, PartialEq)]
pub struct P2POpts {
/// enable p2p
#[clap(long)]
pub enable_p2p: bool,

/// Sets the p2p listen address.
#[clap(long, 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)]
pub p2p_broadcast_address: Ipv4Addr,

/// The udp4 port to broadcast to peers in order to reach back for discovery.
#[clap(long, default_value = "4337")]
pub udp4_port: u16,

#[clap(long, default_value = "4337")]
pub tcp4_port: u16,
}

impl P2POpts {
pub fn to_config(&self) -> Config {
Config {
listen_addr: silius_p2p::config::ListenAddress::Ipv4(ListenAddr {
addr: self.p2p_listen_address,
udp_port: self.udp4_port,
tcp_port: self.tcp4_port,
}),
ipv4_addr: Some(self.p2p_broadcast_address),
ipv6_addr: None,
enr_udp4_port: Some(self.udp4_port),
enr_tcp4_port: Some(self.tcp4_port),
enr_udp6_port: None,
enr_tcp6_port: None,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -118,6 +159,32 @@ mod tests {
str::FromStr,
};

#[test]
fn p2p_opts() {
let args = vec![
"p2popts",
"--enable-p2p",
"--p2p-listen-address",
"0.0.0.0",
"--p2p-broadcast-address",
"127.0.0.1",
"--tcp4-port",
"4337",
"--udp4-port",
"4337",
];
assert_eq!(
P2POpts {
enable_p2p: true,
p2p_listen_address: Ipv4Addr::new(0, 0, 0, 0),
p2p_broadcast_address: Ipv4Addr::new(127, 0, 0, 1),
tcp4_port: 4337,
udp4_port: 4337
},
P2POpts::try_parse_from(args).unwrap()
)
}

#[test]
fn bundler_opts() {
let args = vec![
Expand Down
11 changes: 8 additions & 3 deletions bin/silius/src/silius-uopool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ethers::{
types::{Address, U256},
};
use silius::{
cli::UoPoolServiceOpts,
cli::{P2POpts, UoPoolServiceOpts},
utils::{parse_address, parse_u256, unwrap_path_or_home},
};
use silius_grpc::uopool_service_run;
Expand All @@ -22,8 +22,8 @@ pub struct Opt {
#[clap(flatten)]
pub uopool_opts: UoPoolServiceOpts,

#[clap(long, value_delimiter=',', value_parser=parse_address)]
pub entry_points: Vec<Address>,
#[clap(long, value_parser=parse_address)]
pub entry_points: Address,

#[clap(long, default_value= "dev", value_parser = SUPPORTED_CHAINS)]
pub chain: Option<String>,
Expand All @@ -34,6 +34,9 @@ pub struct Opt {

#[clap(long, value_parser=parse_u256)]
pub max_verification_gas: U256,

#[clap(flatten)]
pub p2p_opts: P2POpts,
}

#[tokio::main]
Expand Down Expand Up @@ -78,6 +81,8 @@ async fn main() -> Result<()> {
opt.uopool_opts.min_priority_fee_per_gas,
opt.uopool_opts.whitelist,
opt.uopool_opts.uo_pool_mode,
opt.enable_p2p,
opt.p2p_opts.to_config(),
)
.await?;

Expand Down
13 changes: 9 additions & 4 deletions bin/silius/src/silius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ethers::{
};
use expanded_pathbuf::ExpandedPathBuf;
use silius::{
cli::{BundlerServiceOpts, RpcServiceOpts, UoPoolServiceOpts},
cli::{BundlerServiceOpts, P2POpts, RpcServiceOpts, UoPoolServiceOpts},
utils::{parse_address, parse_u256, run_until_ctrl_c, unwrap_path_or_home},
};
use silius_grpc::{
Expand All @@ -32,12 +32,15 @@ pub struct Opt {
#[clap(long)]
pub mnemonic_file: ExpandedPathBuf,

#[clap(long, value_delimiter=',', value_parser=parse_address)]
pub entry_points: Vec<Address>,
#[clap(long, value_parser=parse_address)]
pub entry_points: Address,

#[clap(long)]
pub no_uopool: bool,

#[clap(flatten)]
pub p2p_opts: P2POpts,

#[clap(flatten)]
pub uopool_opts: UoPoolServiceOpts,

Expand Down Expand Up @@ -129,6 +132,8 @@ fn main() -> Result<()> {
opt.uopool_opts.min_priority_fee_per_gas,
opt.uopool_opts.whitelist,
opt.uopool_opts.uo_pool_mode,
opt.p2p_opts.enable_p2p,
opt.p2p_opts.to_config()
)
.await?;
info!(
Expand All @@ -149,7 +154,7 @@ fn main() -> Result<()> {
bundler_service_run(
opt.bundler_opts.bundler_grpc_listen_address,
wallet,
opt.entry_points,
vec![opt.entry_points],
opt.eth_client_address.clone(),
chain,
opt.bundler_opts.beneficiary,
Expand Down
3 changes: 3 additions & 0 deletions crates/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ async-trait = { workspace = true }
dashmap = "5.4.0"
ethers = { workspace = true }
expanded-pathbuf = { workspace = true }
futures = "0.3.28"
libp2p-identity = "0.2.3"
parking_lot = { workspace = true }
prost = "0.11"
serde_json = { workspace = true }
silius-bundler = { path = "../bundler" }
silius-contracts = { path = "../contracts" }
silius-primitives = { path = "../primitives" }
silius-uopool = { path = "../uopool" }
silius-p2p = { path = "../p2p" }
tokio = { workspace = true }
tonic = { version = "0.8", default-features = false, features = [
"codegen",
Expand Down
31 changes: 31 additions & 0 deletions crates/grpc/src/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use ethers::providers::Middleware;
use silius_p2p::network::Network;
use silius_primitives::reputation::ReputationEntry;
use silius_uopool::{Mempool, Reputation, VecCh, VecUo};

use crate::builder::UoPoolBuilder;

/// The Integrator is for the integrations between p2p network and the uopool
pub struct NetworkIntegrator<M, P, R, E>
where
M: Middleware + Clone + 'static,
P: Mempool<UserOperations = VecUo, CodeHashes = VecCh, Error = E> + Send + Sync,
R: Reputation<ReputationEntries = Vec<ReputationEntry>, Error = E> + Send + Sync,
{
network: Network,
uopool_builder: UoPoolBuilder<M, P, R, E>,
}

impl<M, P, R, E> NetworkIntegrator<M, P, R, E>
where
M: Middleware + Clone + 'static,
P: Mempool<UserOperations = VecUo, CodeHashes = VecCh, Error = E> + Send + Sync,
R: Reputation<ReputationEntries = Vec<ReputationEntry>, Error = E> + Send + Sync,
{
pub fn new(network: Network, uopool_builder: UoPoolBuilder<M, P, R, E>) -> Self {
Self {
network,
uopool_builder,
}
}
}
Loading

0 comments on commit af252f1

Please sign in to comment.