Skip to content

Commit 0395f24

Browse files
committed
feat: check if validator participating in fastlane
1 parent 21a1ef3 commit 0395f24

File tree

8 files changed

+50
-10
lines changed

8 files changed

+50
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ expanded-pathbuf = "0.1.2"
7272
eyre = "0.6.11"
7373
jsonrpsee = { version = "0.21.0", features = ["server", "macros", "client"] }
7474
metrics = "0.22.0"
75+
reqwest = { version = "0.11.4", features = ["json"] }
7576
lazy_static = "1.4.0"
7677
serde = "1.0.193"
7778
serde_json = "1.0.109"

bin/silius/src/bundler.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use silius_primitives::{
2525
bundler::BundleStrategy,
2626
constants::{
2727
entry_point,
28-
fastlane_relay_endpoints::FASTLANE_POLYGON,
28+
fastlane_relay_endpoints::{FASTLANE_POLYGON, POLYGON_NODE},
2929
flashbots_relay_endpoints,
3030
storage::DATABASE_FOLDER_NAME,
3131
supported_chains::CHAINS,
@@ -241,15 +241,21 @@ where
241241
}
242242
BundleStrategy::Fastlane => {
243243
let relay_endpoint: String =
244-
match chain_conn.named().expect("Fastlane is only supported on Polygon") {
244+
match chain_conn.named().expect("Fastlane is only supported on Polygon mainnet") {
245245
NamedChain::Polygon => FASTLANE_POLYGON.into(),
246-
_ => panic!("Fastlane is only supported on Polygon"),
246+
_ => panic!("Fastlane is only supported on Polygon mainnet"),
247247
};
248248

249249
let relay_client =
250250
create_http_provider(&relay_endpoint, Duration::from_millis(75)).await?;
251-
let client =
252-
Arc::new(FastlaneClient::new(eth_client.clone(), relay_client, wallet.clone()));
251+
let polygon_client =
252+
create_http_provider(POLYGON_NODE, Duration::from_millis(75)).await?;
253+
let client = Arc::new(FastlaneClient::new(
254+
eth_client.clone(),
255+
polygon_client,
256+
relay_client,
257+
wallet.clone(),
258+
));
253259

254260
bundler_service_run(
255261
SocketAddr::new(args.bundler_addr, args.bundler_port),

crates/bundler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tokio = { workspace = true }
3030
# misc
3131
bytes = "1.5.0"
3232
eyre = { workspace = true }
33+
reqwest = { workspace = true }
3334
serde = { workspace = true, features = ["derive"] }
3435
tracing = { workspace = true }
3536
url = "2.5.0"

crates/bundler/src/fastlane.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,27 @@ use ethers::{
1111
Address, BlockNumber, H256,
1212
},
1313
};
14-
use silius_primitives::{simulation::StorageMap, Wallet};
14+
use serde::Deserialize;
15+
use silius_primitives::{
16+
constants::fastlane_relay_endpoints::FASTLANE_VALIDATORS, simulation::StorageMap, Wallet,
17+
};
1518
use std::{collections::HashMap, sync::Arc};
1619
use tracing::trace;
1720

1821
/// A type alias for the Ethereum Conditional Signer client
1922
#[derive(Clone)]
2023
pub struct FastlaneClient<M> {
2124
pub client: SignerMiddleware<Arc<M>, LocalWallet>,
25+
pub polygon_client: Provider<Http>,
2226
pub relay_client: Provider<Http>,
2327
}
2428

29+
/// Validators participating in the Fastlane relay network
30+
#[derive(Deserialize, Debug)]
31+
pub struct FastlaneValidators {
32+
validators: Vec<Address>,
33+
}
34+
2535
#[async_trait::async_trait]
2636
impl<M> SendBundleOp for FastlaneClient<M>
2737
where
@@ -65,6 +75,19 @@ where
6575
options.timestamp_max = Some(block.timestamp.as_u64() + 420); // around 15 minutes
6676
}
6777

78+
// check if the current validator is participating in the Fastlane protocol
79+
let fastlane_validators =
80+
reqwest::get(FASTLANE_VALIDATORS).await?.json::<FastlaneValidators>().await?;
81+
let current_validator: Address =
82+
self.polygon_client.request("bor_getCurrentProposer", ()).await?;
83+
84+
if !fastlane_validators.validators.contains(&current_validator) {
85+
trace!("Current validator is not participating in the Fastlane protocol");
86+
return Err(eyre::eyre!(
87+
"Current validator is not participating in the Fastlane protocol"
88+
));
89+
}
90+
6891
let tx =
6992
self.relay_client.send_raw_transaction_conditional(signed_tx, prefix, options).await?;
7093
let tx_hash = tx.tx_hash();
@@ -85,13 +108,19 @@ where
85108
///
86109
/// # Arguments
87110
/// * `eth_client` - Connection to the Ethereum execution client
111+
/// * `polygon_client` - Connection to the Polygon execution client
88112
/// * `relay_client` - Connection to the Fastlane relay client
89113
/// * `wallet` - A [Wallet](Wallet) instance
90114
///
91115
/// # Returns
92116
/// * `ConditionalClient` - A [Ethereum Signer Middleware](ConditionalClient)
93-
pub fn new(eth_client: Arc<M>, relay_client: Provider<Http>, wallet: Wallet) -> Self {
117+
pub fn new(
118+
eth_client: Arc<M>,
119+
polygon_client: Provider<Http>,
120+
relay_client: Provider<Http>,
121+
wallet: Wallet,
122+
) -> Self {
94123
let signer = SignerMiddleware::new(eth_client, wallet.clone().signer);
95-
Self { client: signer, relay_client }
124+
Self { client: signer, polygon_client, relay_client }
96125
}
97126
}

crates/p2p/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ futures-bounded = "0.2.3"
4848
parking_lot = { workspace = true }
4949

5050
# rpc
51-
reqwest = { version = "0.11.4" }
51+
reqwest = { workspace = true }
5252

5353
# tokio
5454
tokio = { workspace = true }

crates/primitives/src/constants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ pub mod flashbots_relay_endpoints {
8686
pub mod fastlane_relay_endpoints {
8787
// polygon
8888
pub const FASTLANE_POLYGON: &str = "https://polygon-rpc.fastlane.xyz/";
89+
pub const FASTLANE_VALIDATORS: &str = "https://www.fastlane.xyz/api/4337";
90+
pub const POLYGON_NODE: &str = "https://polygon-rpc.com";
8991
}
9092

9193
/// Supported chains

examples/simple-account/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ alloy-sol-types = "0.5.4"
2323
ethers = { workspace = true }
2424

2525
# rpc
26-
reqwest = { version = "0.11.4", features = ["json"] }
26+
reqwest = { workspace = true }
2727

2828
# tokio
2929
tokio = { workspace = true }

0 commit comments

Comments
 (0)