diff --git a/Cargo.lock b/Cargo.lock index a22a5e14..5e79ceae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6984,6 +6984,7 @@ dependencies = [ "ethers-flashbots-test", "eyre", "jsonrpsee", + "reqwest", "serde", "silius-contracts", "silius-primitives", diff --git a/Cargo.toml b/Cargo.toml index f9dedd54..ba2c6675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,6 +72,7 @@ expanded-pathbuf = "0.1.2" eyre = "0.6.11" jsonrpsee = { version = "0.21.0", features = ["server", "macros", "client"] } metrics = "0.22.0" +reqwest = { version = "0.11.4", features = ["json"] } lazy_static = "1.4.0" serde = "1.0.193" serde_json = "1.0.109" diff --git a/bin/silius/src/bundler.rs b/bin/silius/src/bundler.rs index 88284cb0..24a07c0d 100644 --- a/bin/silius/src/bundler.rs +++ b/bin/silius/src/bundler.rs @@ -25,7 +25,7 @@ use silius_primitives::{ bundler::BundleStrategy, constants::{ entry_point, - fastlane_relay_endpoints::FASTLANE_POLYGON, + fastlane_relay_endpoints::{FASTLANE_POLYGON, POLYGON_NODE}, flashbots_relay_endpoints, storage::DATABASE_FOLDER_NAME, supported_chains::CHAINS, @@ -241,15 +241,21 @@ where } BundleStrategy::Fastlane => { let relay_endpoint: String = - match chain_conn.named().expect("Fastlane is only supported on Polygon") { + match chain_conn.named().expect("Fastlane is only supported on Polygon mainnet") { NamedChain::Polygon => FASTLANE_POLYGON.into(), - _ => panic!("Fastlane is only supported on Polygon"), + _ => panic!("Fastlane is only supported on Polygon mainnet"), }; let relay_client = create_http_provider(&relay_endpoint, Duration::from_millis(75)).await?; - let client = - Arc::new(FastlaneClient::new(eth_client.clone(), relay_client, wallet.clone())); + let polygon_client = + create_http_provider(POLYGON_NODE, Duration::from_millis(75)).await?; + let client = Arc::new(FastlaneClient::new( + eth_client.clone(), + polygon_client, + relay_client, + wallet.clone(), + )); bundler_service_run( SocketAddr::new(args.bundler_addr, args.bundler_port), diff --git a/crates/bundler/Cargo.toml b/crates/bundler/Cargo.toml index b3374f35..298ea76f 100644 --- a/crates/bundler/Cargo.toml +++ b/crates/bundler/Cargo.toml @@ -30,6 +30,7 @@ tokio = { workspace = true } # misc bytes = "1.5.0" eyre = { workspace = true } +reqwest = { workspace = true } serde = { workspace = true, features = ["derive"] } tracing = { workspace = true } url = "2.5.0" diff --git a/crates/bundler/src/fastlane.rs b/crates/bundler/src/fastlane.rs index d855fead..18771c5d 100644 --- a/crates/bundler/src/fastlane.rs +++ b/crates/bundler/src/fastlane.rs @@ -11,7 +11,10 @@ use ethers::{ Address, BlockNumber, H256, }, }; -use silius_primitives::{simulation::StorageMap, Wallet}; +use serde::Deserialize; +use silius_primitives::{ + constants::fastlane_relay_endpoints::FASTLANE_VALIDATORS, simulation::StorageMap, Wallet, +}; use std::{collections::HashMap, sync::Arc}; use tracing::trace; @@ -19,9 +22,16 @@ use tracing::trace; #[derive(Clone)] pub struct FastlaneClient { pub client: SignerMiddleware, LocalWallet>, + pub polygon_client: Provider, pub relay_client: Provider, } +/// Validators participating in the Fastlane relay network +#[derive(Deserialize, Debug)] +pub struct FastlaneValidators { + validators: Vec
, +} + #[async_trait::async_trait] impl SendBundleOp for FastlaneClient where @@ -65,6 +75,19 @@ where options.timestamp_max = Some(block.timestamp.as_u64() + 420); // around 15 minutes } + // check if the current validator is participating in the Fastlane protocol + let fastlane_validators = + reqwest::get(FASTLANE_VALIDATORS).await?.json::().await?; + let current_validator: Address = + self.polygon_client.request("bor_getCurrentProposer", ()).await?; + + if !fastlane_validators.validators.contains(¤t_validator) { + trace!("Current validator is not participating in the Fastlane protocol"); + return Err(eyre::eyre!( + "Current validator is not participating in the Fastlane protocol" + )); + } + let tx = self.relay_client.send_raw_transaction_conditional(signed_tx, prefix, options).await?; let tx_hash = tx.tx_hash(); @@ -85,13 +108,19 @@ where /// /// # Arguments /// * `eth_client` - Connection to the Ethereum execution client + /// * `polygon_client` - Connection to the Polygon execution client /// * `relay_client` - Connection to the Fastlane relay client /// * `wallet` - A [Wallet](Wallet) instance /// /// # Returns /// * `ConditionalClient` - A [Ethereum Signer Middleware](ConditionalClient) - pub fn new(eth_client: Arc, relay_client: Provider, wallet: Wallet) -> Self { + pub fn new( + eth_client: Arc, + polygon_client: Provider, + relay_client: Provider, + wallet: Wallet, + ) -> Self { let signer = SignerMiddleware::new(eth_client, wallet.clone().signer); - Self { client: signer, relay_client } + Self { client: signer, polygon_client, relay_client } } } diff --git a/crates/p2p/Cargo.toml b/crates/p2p/Cargo.toml index aad9013c..8f4236fa 100644 --- a/crates/p2p/Cargo.toml +++ b/crates/p2p/Cargo.toml @@ -48,7 +48,7 @@ futures-bounded = "0.2.3" parking_lot = { workspace = true } # rpc -reqwest = { version = "0.11.4" } +reqwest = { workspace = true } # tokio tokio = { workspace = true } diff --git a/crates/primitives/src/constants.rs b/crates/primitives/src/constants.rs index bfded0d1..1f280ce4 100644 --- a/crates/primitives/src/constants.rs +++ b/crates/primitives/src/constants.rs @@ -86,6 +86,8 @@ pub mod flashbots_relay_endpoints { pub mod fastlane_relay_endpoints { // polygon pub const FASTLANE_POLYGON: &str = "https://polygon-rpc.fastlane.xyz/"; + pub const FASTLANE_VALIDATORS: &str = "https://www.fastlane.xyz/api/4337"; + pub const POLYGON_NODE: &str = "https://polygon-rpc.com"; } /// Supported chains diff --git a/examples/simple-account/Cargo.toml b/examples/simple-account/Cargo.toml index 3da28efb..d2b7a6df 100644 --- a/examples/simple-account/Cargo.toml +++ b/examples/simple-account/Cargo.toml @@ -23,7 +23,7 @@ alloy-sol-types = "0.5.4" ethers = { workspace = true } # rpc -reqwest = { version = "0.11.4", features = ["json"] } +reqwest = { workspace = true } # tokio tokio = { workspace = true }