diff --git a/Makefile b/Makefile index f3fb7e31..e4581f1a 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,13 @@ build: cargo build --release run-silius: - cargo run --release -- bundler --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws + cargo run --release -- bundler --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws run-silius-bundling: - cargo run --release -- bundling --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 + cargo run --release -- bundling --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 run-silius-uopool: - cargo run --release -- uopool --eth-client-address ws://127.0.0.1:8546 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 + cargo run --release -- uopool --eth-client-address http://127.0.0.1:8545 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 run-silius-rpc: cargo run --release -- rpc --http --ws diff --git a/README.md b/README.md index c6cf5b61..c0847614 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ cargo run --release -- create-wallet --output-path ${HOME}/.silius --chain-id 5 Run bundler (with user operation pool and JSON-RPC API): ```bash -cargo run --release -- bundler --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws +cargo run --release -- bundler --eth-client-address http://127.0.0.1:8545 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws ``` Run only bundling component: @@ -69,7 +69,7 @@ cargo run --release -- rpc --http --ws ### Docker ```bash -docker run --net=host -v ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266:/data/silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 -v ./db:/data/silius/db ghcr.io/vid201/silius:latest bundler --eth-client-address ws://127.0.0.1:8546 --datadir data/silius --mnemonic-file data/silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789 --http --http.addr 0.0.0.0 --http.port 3000 --http.api eth,debug,web3 --ws --ws.addr 0.0.0.0 --ws.port 3001 --ws.api eth,debug,web3 --eth-client-proxy-address http://127.0.0.1:8545 +docker run --net=host -v ./bundler-spec-tests/keys/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266:/data/silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 -v ./db:/data/silius/db ghcr.io/vid201/silius:latest bundler --eth-client-address http://127.0.0.1:8545 --datadir data/silius --mnemonic-file data/silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789 --http --http.addr 0.0.0.0 --http.port 3000 --http.api eth,debug,web3 --ws --ws.addr 0.0.0.0 --ws.port 3001 --ws.api eth,debug,web3 --eth-client-proxy-address http://127.0.0.1:8545 ``` ## Supported networks diff --git a/bin/silius/src/bundler.rs b/bin/silius/src/bundler.rs index 3105bbd6..51654f66 100644 --- a/bin/silius/src/bundler.rs +++ b/bin/silius/src/bundler.rs @@ -2,10 +2,7 @@ use crate::{ cli::args::{BundlerAndUoPoolArgs, BundlerArgs, CreateWalletArgs, RpcArgs, UoPoolArgs}, utils::unwrap_path_or_home, }; -use ethers::{ - providers::{Middleware, Provider, Ws}, - types::Address, -}; +use ethers::{providers::Middleware, types::Address}; use silius_grpc::{ bundler_client::BundlerClient, bundler_service_run, uo_pool_client::UoPoolClient, uopool_service_run, @@ -22,13 +19,16 @@ use silius_rpc::{ use std::{collections::HashSet, future::pending, net::SocketAddr, sync::Arc}; use tracing::info; -pub async fn launch_bundler( +pub async fn launch_bundler( bundler_args: BundlerArgs, uopool_args: UoPoolArgs, common_args: BundlerAndUoPoolArgs, rpc_args: RpcArgs, - eth_client: Arc>, -) -> eyre::Result<()> { + eth_client: Arc, +) -> eyre::Result<()> +where + M: Middleware + Clone + 'static, +{ launch_uopool( uopool_args.clone(), eth_client.clone(), @@ -65,13 +65,16 @@ pub async fn launch_bundler( Ok(()) } -pub async fn launch_bundling( +pub async fn launch_bundling( args: BundlerArgs, - eth_client: Arc>, + eth_client: Arc, chain: Option, entry_points: Vec
, uopool_grpc_listen_address: String, -) -> eyre::Result<()> { +) -> eyre::Result<()> +where + M: Middleware + Clone + 'static, +{ info!("Starting bundling gRPC service..."); let eth_client_version = check_connected_chain(eth_client.clone(), chain).await?; @@ -125,12 +128,15 @@ pub async fn launch_bundling( Ok(()) } -pub async fn launch_uopool( +pub async fn launch_uopool( args: UoPoolArgs, - eth_client: Arc>, + eth_client: Arc, chain: Option, entry_points: Vec
, -) -> eyre::Result<()> { +) -> eyre::Result<()> +where + M: Middleware + Clone + 'static, +{ info!("Starting uopool gRPC service..."); let eth_client_version = check_connected_chain(eth_client.clone(), chain).await?; @@ -288,10 +294,10 @@ pub fn create_wallet(args: CreateWalletArgs) -> eyre::Result<()> { Ok(()) } -async fn check_connected_chain( - eth_client: Arc>, - chain: Option, -) -> eyre::Result { +async fn check_connected_chain(eth_client: Arc, chain: Option) -> eyre::Result +where + M: Middleware + Clone + 'static, +{ let chain_id = eth_client.get_chainid().await?; let chain_conn = Chain::from(chain_id); diff --git a/bin/silius/src/cli/args.rs b/bin/silius/src/cli/args.rs index f411492a..5f83c7a2 100644 --- a/bin/silius/src/cli/args.rs +++ b/bin/silius/src/cli/args.rs @@ -98,7 +98,7 @@ pub struct UoPoolArgs { #[derive(Debug, Clone, Parser)] pub struct BundlerAndUoPoolArgs { /// Ethereum execution client RPC endpoint. - #[clap(long, default_value = "ws://127.0.0.1:8546")] + #[clap(long, default_value = "http://127.0.0.1:8545")] pub eth_client_address: String, /// Chain information. diff --git a/bin/silius/src/cli/commands.rs b/bin/silius/src/cli/commands.rs index 9d142344..57799f6e 100644 --- a/bin/silius/src/cli/commands.rs +++ b/bin/silius/src/cli/commands.rs @@ -1,7 +1,7 @@ use super::args::{BundlerAndUoPoolArgs, BundlerArgs, CreateWalletArgs, RpcArgs, UoPoolArgs}; use crate::{ bundler::{create_wallet, launch_bundler, launch_bundling, launch_rpc, launch_uopool}, - utils::create_ws_provider, + utils::{create_http_provider, create_ws_provider}, }; use clap::Parser; use std::{future::pending, sync::Arc}; @@ -29,8 +29,14 @@ pub struct BundlerCommand { impl BundlerCommand { /// Execute the command pub async fn execute(self) -> eyre::Result<()> { - let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?); - launch_bundler(self.bundler, self.uopool, self.common, self.rpc, eth_client).await?; + if self.common.eth_client_address.clone().starts_with("http") { + let eth_client = Arc::new(create_http_provider(&self.common.eth_client_address)?); + launch_bundler(self.bundler, self.uopool, self.common, self.rpc, eth_client).await?; + } else { + let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?); + launch_bundler(self.bundler, self.uopool, self.common, self.rpc, eth_client).await?; + } + pending().await } } @@ -54,15 +60,28 @@ pub struct BundlingCommand { impl BundlingCommand { /// Execute the command pub async fn execute(self) -> eyre::Result<()> { - let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?); - launch_bundling( - self.bundler, - eth_client, - self.common.chain, - self.common.entry_points, - self.uopool_grpc_listen_address, - ) - .await?; + if self.common.eth_client_address.clone().starts_with("http") { + let eth_client = Arc::new(create_http_provider(&self.common.eth_client_address)?); + launch_bundling( + self.bundler, + eth_client, + self.common.chain, + self.common.entry_points, + self.uopool_grpc_listen_address, + ) + .await?; + } else { + let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?); + launch_bundling( + self.bundler, + eth_client, + self.common.chain, + self.common.entry_points, + self.uopool_grpc_listen_address, + ) + .await?; + } + pending().await } } @@ -82,14 +101,26 @@ pub struct UoPoolCommand { impl UoPoolCommand { /// Execute the command pub async fn execute(self) -> eyre::Result<()> { - let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?); - launch_uopool( - self.uopool, - eth_client, - self.common.chain, - self.common.entry_points, - ) - .await?; + if self.common.eth_client_address.clone().starts_with("http") { + let eth_client = Arc::new(create_http_provider(&self.common.eth_client_address)?); + launch_uopool( + self.uopool, + eth_client, + self.common.chain, + self.common.entry_points, + ) + .await?; + } else { + let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?); + launch_uopool( + self.uopool, + eth_client, + self.common.chain, + self.common.entry_points, + ) + .await?; + } + pending().await } } diff --git a/bin/silius/src/utils.rs b/bin/silius/src/utils.rs index a6d13904..44b67972 100644 --- a/bin/silius/src/utils.rs +++ b/bin/silius/src/utils.rs @@ -1,6 +1,6 @@ use dirs::home_dir; use ethers::{ - providers::{Provider, Ws}, + providers::{Http, Provider, Ws}, types::{Address, U256}, }; use expanded_pathbuf::ExpandedPathBuf; @@ -68,6 +68,12 @@ where Ok(()) } +/// Creates ethers provider with HTTP connection +pub fn create_http_provider(addr: &str) -> eyre::Result> { + let provider = Provider::::try_from(addr)?; + Ok(provider) +} + /// Creates ethers provider with WebSockets connection pub async fn create_ws_provider(addr: &str) -> eyre::Result> { let provider = Provider::::connect_with_reconnects(addr, usize::MAX).await?; diff --git a/crates/bundler/src/bundler.rs b/crates/bundler/src/bundler.rs index bc7c8173..bfdc9220 100644 --- a/crates/bundler/src/bundler.rs +++ b/crates/bundler/src/bundler.rs @@ -1,6 +1,6 @@ use ethers::{ prelude::{LocalWallet, SignerMiddleware}, - providers::{Middleware, PubsubClient}, + providers::Middleware, signers::Signer, types::{ transaction::eip2718::TypedTransaction, Address, Eip1559TransactionRequest, H256, U256, U64, @@ -31,7 +31,6 @@ type EthClientType = Arc, LocalWallet>>; pub struct Bundler where M: Middleware + 'static, - ::Provider: PubsubClient, { /// Wallet instance representing the bundler's wallet. pub wallet: Wallet, @@ -56,7 +55,6 @@ where impl Bundler where M: Middleware + 'static, - ::Provider: PubsubClient, { /// Create a new `Bundler` instance /// if `send_bundle_mode` is `SendBundleMode::Flashbots` and `relay_endpoints` is `None`, the default Flashbots relay endpoint will be used @@ -467,7 +465,7 @@ mod test { use alloy_sol_types::{sol, SolCall}; use ethers::{ contract::abigen, - providers::{Http, Middleware, Provider, PubsubClient, Ws}, + providers::{Http, Middleware, Provider, Ws}, signers::Signer, types::{ transaction::eip2718::TypedTransaction, Address, Eip1559TransactionRequest, @@ -519,7 +517,6 @@ mod test { struct TestContext where M: Middleware + 'static, - ::Provider: PubsubClient, { pub bundler: Bundler, pub entry_point: Address, diff --git a/crates/grpc/src/builder.rs b/crates/grpc/src/builder.rs index 109818b8..ae5e7e46 100644 --- a/crates/grpc/src/builder.rs +++ b/crates/grpc/src/builder.rs @@ -1,6 +1,6 @@ use crate::uopool::{GAS_INCREASE_PERC, MAX_UOS_PER_UNSTAKED_SENDER}; use ethers::{ - providers::{Middleware, PubsubClient}, + providers::Middleware, types::{Address, U256}, }; use silius_contracts::EntryPoint; @@ -18,7 +18,6 @@ use std::sync::Arc; pub struct UoPoolBuilder where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, { @@ -38,7 +37,6 @@ where impl UoPoolBuilder where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, E: Debug + Display, diff --git a/crates/grpc/src/bundler.rs b/crates/grpc/src/bundler.rs index 084ae74c..3887628c 100644 --- a/crates/grpc/src/bundler.rs +++ b/crates/grpc/src/bundler.rs @@ -2,7 +2,7 @@ use crate::proto::bundler::*; use crate::proto::uopool::{GetSortedRequest, HandlePastEventRequest}; use crate::uo_pool_client::UoPoolClient; use async_trait::async_trait; -use ethers::providers::{Middleware, PubsubClient}; +use ethers::providers::Middleware; use ethers::types::{Address, H256, U256}; use parking_lot::Mutex; use silius_bundler::Bundler; @@ -14,7 +14,6 @@ use tracing::{error, info, warn}; pub struct BundlerService where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, { pub bundlers: Vec>, pub running: Arc>, @@ -29,7 +28,6 @@ fn is_running(running: Arc>) -> bool { impl BundlerService where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, { pub fn new( bundlers: Vec>, @@ -163,7 +161,6 @@ where impl bundler_server::Bundler for BundlerService where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, { async fn set_bundler_mode( &self, @@ -217,7 +214,6 @@ pub fn bundler_service_run( relay_endpoints: Option>, ) where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, { let bundlers: Vec> = eps .iter() diff --git a/crates/grpc/src/uopool.rs b/crates/grpc/src/uopool.rs index 4bbcc3a2..ce475bb8 100644 --- a/crates/grpc/src/uopool.rs +++ b/crates/grpc/src/uopool.rs @@ -6,14 +6,12 @@ use crate::{ }; use async_trait::async_trait; use dashmap::DashMap; -use ethers::providers::PubsubClient; use ethers::{ providers::Middleware, types::{Address, U256}, }; use expanded_pathbuf::ExpandedPathBuf; use eyre::Result; -use silius_contracts::entry_point::EntryPointErr; use silius_primitives::reputation::ReputationEntry; use silius_primitives::{uopool::AddError, Chain, UoPoolMode}; use silius_uopool::{ @@ -37,7 +35,6 @@ type StandardUserPool = pub struct UoPoolService where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, { @@ -48,7 +45,6 @@ where impl UoPoolService where M: Middleware + Clone + 'static, - ::Provider: PubsubClient, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, E: Debug + Display, @@ -72,9 +68,7 @@ where #[async_trait] impl uo_pool_server::UoPool for UoPoolService where - EntryPointErr: From<::Error>, M: Middleware + Clone + 'static, - ::Provider: PubsubClient, P: Mempool + Send + Sync + 'static, R: Reputation, Error = E> + Send + Sync + 'static, E: Debug + Display + 'static, @@ -362,9 +356,7 @@ pub async fn uopool_service_run( upool_mode: UoPoolMode, ) -> Result<()> where - EntryPointErr: From<::Error>, M: Middleware + Clone + 'static, - ::Provider: PubsubClient, { tokio::spawn(async move { let mut builder = tonic::transport::Server::builder(); diff --git a/crates/uopool/src/uopool.rs b/crates/uopool/src/uopool.rs index 1aaf8630..452233e6 100644 --- a/crates/uopool/src/uopool.rs +++ b/crates/uopool/src/uopool.rs @@ -10,7 +10,7 @@ use crate::{ }; use ethers::{ prelude::LogMeta, - providers::{Middleware, PubsubClient}, + providers::Middleware, types::{Address, BlockNumber, U256, U64}, }; use eyre::format_err; @@ -40,7 +40,6 @@ const LATEST_SCAN_DEPTH: u64 = 1000; /// Architecturally, the [UoPool](UoPool) is the backend service managed by the [UoPoolService](UoPoolService) and serves requests from the [RPC API](EthApiServer). pub struct UoPool, P, R, E> where - ::Provider: PubsubClient, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, E: Debug, @@ -63,7 +62,6 @@ where impl, P, R, E> UoPool where - ::Provider: PubsubClient, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, E: Debug + Display, diff --git a/docker-compose.yml b/docker-compose.yml index 6549285a..3c959be4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: command: - bundler - --eth-client-address - - ws://127.0.0.1:8546 + - http://127.0.0.1:8545 - --datadir - data/silius - --mnemonic-file diff --git a/tests/src/common/mod.rs b/tests/src/common/mod.rs index 428a8b24..bc8ed701 100644 --- a/tests/src/common/mod.rs +++ b/tests/src/common/mod.rs @@ -5,7 +5,7 @@ use self::gen::{ }; use ethers::{ prelude::{MiddlewareBuilder, NonceManagerMiddleware, SignerMiddleware}, - providers::{Middleware, Provider, Ws}, + providers::{Http, Middleware, Provider}, signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}, types::{Address, TransactionRequest, U256}, utils::{Geth, GethInstance}, @@ -16,7 +16,7 @@ use tempdir::TempDir; pub mod gen; pub const SEED_PHRASE: &str = "test test test test test test test test test test test junk"; -pub type ClientType = NonceManagerMiddleware, LocalWallet>>; +pub type ClientType = NonceManagerMiddleware, LocalWallet>>; pub struct DeployedContract { contract: C, @@ -123,7 +123,7 @@ pub async fn deploy_test_coin( Ok(DeployedContract::new(factory, addr)) } -pub async fn setup_geth() -> eyre::Result<(GethInstance, ClientType, Provider)> { +pub async fn setup_geth() -> eyre::Result<(GethInstance, ClientType, Provider)> { let chain_id: u64 = 1337; let tmp_dir = TempDir::new("test_geth")?; let wallet = MnemonicBuilder::::default() @@ -131,9 +131,8 @@ pub async fn setup_geth() -> eyre::Result<(GethInstance, ClientType, Provider::connect(geth.ws_endpoint()) - .await? - .interval(Duration::from_millis(5u64)); + let provider = + Provider::::try_from(geth.endpoint())?.interval(Duration::from_millis(5u64)); let client = SignerMiddleware::new(provider.clone(), wallet.clone().with_chain_id(chain_id)) .nonce_manager(wallet.address()); diff --git a/tests/src/simulation_tests.rs b/tests/src/simulation_tests.rs index a68cc75f..12ee8822 100644 --- a/tests/src/simulation_tests.rs +++ b/tests/src/simulation_tests.rs @@ -11,7 +11,7 @@ use crate::common::{ }; use ethers::abi::Token; use ethers::prelude::BaseContract; -use ethers::providers::{Provider, PubsubClient, Ws}; +use ethers::providers::{Http, Provider}; use ethers::types::transaction::eip2718::TypedTransaction; use ethers::types::Address; use ethers::utils::{parse_units, GethInstance}; @@ -57,7 +57,6 @@ const GAS_INCREASE_PERC: u64 = 10; struct TestContext where M: Middleware + 'static, - ::Provider: PubsubClient, V: UserOperationValidator + 'static, P: Mempool + Send + Sync, R: Reputation, Error = E> + Send + Sync, @@ -76,7 +75,7 @@ where type Context = TestContext< ClientType, - StandardUserOperationValidator, MemoryMempool, MemoryReputation, eyre::Error>, + StandardUserOperationValidator, MemoryMempool, MemoryReputation, eyre::Error>, MemoryMempool, MemoryReputation, eyre::Error, @@ -152,7 +151,12 @@ async fn setup() -> eyre::Result { let pool = UoPool::< ClientType, - StandardUserOperationValidator, MemoryMempool, MemoryReputation, eyre::Error>, + StandardUserOperationValidator< + Provider, + MemoryMempool, + MemoryReputation, + eyre::Error, + >, MemoryMempool, MemoryReputation, eyre::Error,