Skip to content

Commit

Permalink
feat: check if validator participating in fastlane
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Nov 2, 2024
1 parent 21a1ef3 commit 0395f24
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 11 additions & 5 deletions bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions crates/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
35 changes: 32 additions & 3 deletions crates/bundler/src/fastlane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ 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;

/// A type alias for the Ethereum Conditional Signer client
#[derive(Clone)]
pub struct FastlaneClient<M> {
pub client: SignerMiddleware<Arc<M>, LocalWallet>,
pub polygon_client: Provider<Http>,
pub relay_client: Provider<Http>,
}

/// Validators participating in the Fastlane relay network
#[derive(Deserialize, Debug)]
pub struct FastlaneValidators {
validators: Vec<Address>,
}

#[async_trait::async_trait]
impl<M> SendBundleOp for FastlaneClient<M>
where
Expand Down Expand Up @@ -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::<FastlaneValidators>().await?;
let current_validator: Address =
self.polygon_client.request("bor_getCurrentProposer", ()).await?;

if !fastlane_validators.validators.contains(&current_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();
Expand All @@ -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<M>, relay_client: Provider<Http>, wallet: Wallet) -> Self {
pub fn new(
eth_client: Arc<M>,
polygon_client: Provider<Http>,
relay_client: Provider<Http>,
wallet: Wallet,
) -> Self {
let signer = SignerMiddleware::new(eth_client, wallet.clone().signer);
Self { client: signer, relay_client }
Self { client: signer, polygon_client, relay_client }
}
}
2 changes: 1 addition & 1 deletion crates/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 0395f24

Please sign in to comment.