From f0c5e0fc3d8e42217dce1c34dfce83106126b6cc Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 09:11:19 -0700 Subject: [PATCH 1/8] better provider config + fix selector + cleanup --- src/config.rs | 26 ++++++++++++++++++--- src/main.rs | 44 +++++++++++++++++------------------- src/relay/mod.rs | 29 +++++++++++++++--------- src/relay/signer.rs | 55 +++++++++++++++++---------------------------- 4 files changed, 82 insertions(+), 72 deletions(-) diff --git a/src/config.rs b/src/config.rs index ec0f3fe..f5057fd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,9 @@ use core::fmt; use std::path::Path; +use alloy::network::EthereumWallet; use alloy::primitives::Address; -use alloy::providers::{ProviderBuilder, RootProvider}; +use alloy::providers::{Provider, ProviderBuilder}; use alloy::rpc::client::ClientBuilder; use alloy::transports::http::Http; use alloy::transports::layers::{RetryBackoffLayer, RetryBackoffService}; @@ -10,6 +11,8 @@ use reqwest::Client; use serde::{Deserialize, Serialize}; use url::Url; +pub type ThrottledTransport = RetryBackoffService>; + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { /// The global wallet configuration @@ -116,7 +119,7 @@ pub struct ProviderConfig { } impl ProviderConfig { - pub fn provider(&self) -> RootProvider>> { + pub fn provider(&self) -> impl Provider { let client = ClientBuilder::default() .layer(RetryBackoffLayer::new( self.max_rate_limit_retries, @@ -126,6 +129,23 @@ impl ProviderConfig { .http(self.rpc_endpoint.clone()); ProviderBuilder::new().on_client(client) } + + pub fn signer( + &self, + wallet: EthereumWallet, + ) -> impl Provider { + let client = ClientBuilder::default() + .layer(RetryBackoffLayer::new( + self.max_rate_limit_retries, + self.initial_backoff, + self.compute_units_per_second, + )) + .http(self.rpc_endpoint.clone()); + ProviderBuilder::default() + .with_recommended_fillers() + .wallet(wallet) + .on_client(client) + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -154,7 +174,7 @@ mod default { } pub const fn max_rate_limit_retries() -> u32 { - 1 + 10 } pub const fn initial_backoff() -> u64 { diff --git a/src/main.rs b/src/main.rs index b078300..c1cb326 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,10 +8,9 @@ pub mod utils; use std::path::PathBuf; use std::sync::Arc; -use abi::IStateBridge::IStateBridgeInstance; use alloy::network::EthereumWallet; use alloy::primitives::U256; -use alloy::providers::{Provider, ProviderBuilder}; +use alloy::providers::Provider; use alloy::rpc::types::Filter; use alloy::signers::local::MnemonicBuilder; use alloy::sol_types::SolEvent; @@ -52,6 +51,10 @@ pub async fn main() -> Result<()> { eyre::install()?; dotenv::dotenv().ok(); + // Set default log level if not set + if std::env::var("RUST_LOG").is_err() { + std::env::set_var("RUST_LOG", "info"); + } let opts = Opts::parse(); let config = Config::load(opts.config.as_deref())?; @@ -127,7 +130,7 @@ pub async fn run(config: Config) -> Result<()> { joinset.spawn(async move { relay.subscribe_roots(tx.subscribe()).await.map_err(|error| { match relay { - Relayer::Evm(EVMRelay { + Relayer::EVMRelay(EVMRelay { signer: _, world_id_address, provider, @@ -139,7 +142,7 @@ pub async fn run(config: Config) -> Result<()> { "Error subscribing to roots" ); } - Relayer::Svm(_) => { + Relayer::SvmRelay(_) => { tracing::error!(%error, "Error subscribing to roots"); } } @@ -175,6 +178,10 @@ pub async fn run(config: Config) -> Result<()> { Ok(()) } +/// Initializes the relayers for the bridged networks. +/// +/// Additionally initializes the signers from the global wallet configuration if present, +/// otherwise from the bridged network configuration. fn init_relays(cfg: Config) -> Result> { cfg.bridged_networks .iter() @@ -190,29 +197,18 @@ fn init_relays(cfg: Config) -> Result> { WalletConfig::Mnemonic { mnemonic } => { let signer = MnemonicBuilder::::default() .phrase(mnemonic) - .index(0) - .unwrap() - .build() - .expect("Failed to build wallet"); + .index(0)? + .build()?; let wallet = EthereumWallet::new(signer); - let l1_provider = ProviderBuilder::default() - .with_recommended_fillers() - .wallet(wallet) - .on_http( - cfg.canonical_network - .provider - .rpc_endpoint - .clone(), - ); - let state_bridge = IStateBridgeInstance::new( + + let alloy_signer = AlloySigner::new( bridged.state_bridge_addr, - l1_provider, + cfg.canonical_network.provider.clone(), + wallet, ); - let signer = AlloySigner::new(state_bridge); - - Ok(Relayer::Evm(EVMRelay::new( - Signer::AlloySigner(signer), + Ok(Relayer::EVMRelay(EVMRelay::new( + Signer::AlloySigner(alloy_signer), bridged.world_id_addr, bridged.provider.rpc_endpoint.clone(), ))) @@ -224,7 +220,7 @@ fn init_relays(cfg: Config) -> Result> { *gas_limit, ); - Ok(Relayer::Evm(EVMRelay::new( + Ok(Relayer::EVMRelay(EVMRelay::new( Signer::TxSitterSigner(signer), bridged.world_id_addr, bridged.provider.rpc_endpoint.clone(), diff --git a/src/relay/mod.rs b/src/relay/mod.rs index d27fa04..9b5f84b 100644 --- a/src/relay/mod.rs +++ b/src/relay/mod.rs @@ -20,16 +20,17 @@ pub(crate) trait Relay { async fn subscribe_roots(&self, rx: Receiver) -> Result<()>; } -pub enum Relayer { - Evm(EVMRelay), - Svm(SvmRelay), -} - -impl Relay for Relayer { - async fn subscribe_roots(&self, rx: Receiver) -> Result<()> { - match self { - Relayer::Evm(relay) => relay.subscribe_roots(rx).await, - Relayer::Svm(_relay) => unimplemented!(), +macro_rules! relay { + ($($relay_type:ident),+ $(,)?) => { + pub enum Relayer { + $($relay_type($relay_type),)+ + } + impl Relay for Relayer { + async fn subscribe_roots(&self, rx: Receiver) -> Result<()> { + match self { + $(Relayer::$relay_type(relay) => Ok(relay.subscribe_roots(rx).await?),)+ + } + } } } } @@ -80,3 +81,11 @@ impl Relay for EVMRelay { } pub struct SvmRelay; + +impl Relay for SvmRelay { + async fn subscribe_roots(&self, _rx: Receiver) -> Result<()> { + unimplemented!() + } +} + +relay!(EVMRelay, SvmRelay); diff --git a/src/relay/signer.rs b/src/relay/signer.rs index 5e31f64..bb3b20a 100644 --- a/src/relay/signer.rs +++ b/src/relay/signer.rs @@ -1,11 +1,5 @@ -use alloy::network::{Ethereum, EthereumWallet}; +use alloy::network::EthereumWallet; use alloy::primitives::{bytes, Address, Bytes}; -use alloy::providers::fillers::{ - BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, - NonceFiller, WalletFiller, -}; -use alloy::providers::{Identity, RootProvider}; -use alloy::transports::http::Http; use ethers_core::types::U256; use eyre::eyre::{eyre, Result}; use tracing::{error, info}; @@ -13,9 +7,10 @@ use tx_sitter_client::data::{SendTxRequest, TransactionPriority, TxStatus}; use tx_sitter_client::TxSitterClient; use crate::abi::IStateBridge::IStateBridgeInstance; +use crate::config::ProviderConfig; -/// "propogateRoot()" Selector -pub static PROPOGATE_ROOT_SELECTOR: Bytes = bytes!("21823a11"); +/// keccak256("propagateRoot()")[..4] +pub static PROPAGATE_ROOT_SELECTOR: Bytes = bytes!("380db829"); pub(crate) trait RelaySigner { /// Propogate a new Root to the State Bridge for the given network. @@ -37,44 +32,34 @@ macro_rules! signer { } } -pub type AlloySignerProvider = FillProvider< - JoinFill< - JoinFill< - Identity, - JoinFill< - GasFiller, - JoinFill>, - >, - >, - WalletFiller, - >, - RootProvider>, - Http, - Ethereum, ->; - pub struct AlloySigner { - pub(crate) state_bridge_instance: - IStateBridgeInstance, AlloySignerProvider>, + pub state_bridge_address: Address, + pub provider: ProviderConfig, + wallet: EthereumWallet, } impl AlloySigner { pub fn new( - state_bridge: IStateBridgeInstance< - Http, - AlloySignerProvider, - >, + state_bridge_address: Address, + provider: ProviderConfig, + wallet: EthereumWallet, ) -> Self { Self { - state_bridge_instance: state_bridge, + state_bridge_address, + provider, + wallet, } } } impl RelaySigner for AlloySigner { async fn propagate_root(&self) -> Result<()> { - let transport = - self.state_bridge_instance.propagateRoot().send().await?; + let state_bridge_instance = IStateBridgeInstance::new( + self.state_bridge_address, + self.provider.signer(self.wallet.clone()), + ); + + let transport = state_bridge_instance.propagateRoot().send().await?; match transport.get_receipt().await { Ok(receipt) => { @@ -116,7 +101,7 @@ impl RelaySigner for TxSitterSigner { /// This is a long running operation and should probably be awaited in a background task. async fn propagate_root(&self) -> Result<()> { let ethers_selector = ethers_core::types::Bytes::from_static( - PROPOGATE_ROOT_SELECTOR.as_ref(), + PROPAGATE_ROOT_SELECTOR.as_ref(), ); let ethers_address = ethers_core::types::Address::from_slice( self.state_bridge_address.as_ref(), From 533995f8f496533e7467fb98de6115c4e7a80a0d Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 10:32:55 -0700 Subject: [PATCH 2/8] better tracing --- src/main.rs | 10 +++++----- src/relay/mod.rs | 10 ++++++++-- src/relay/signer.rs | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index c1cb326..731501b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,10 +103,10 @@ pub async fn run(config: Config) -> Result<()> { let latest_block_number = provider.get_block_number().await?; - // Start in the past by approximately 2 hours - let start_block_number = latest_block_number - .checked_sub(config.canonical_network.start_scan) - .unwrap_or_default(); + // // Start in the past by approximately 2 hours + // let start_block_number = latest_block_number + // .checked_sub(config.canonical_network.start_scan) + // .unwrap_or_default(); let filter = Filter::new() .address(config.canonical_network.world_id_addr) @@ -115,7 +115,7 @@ pub async fn run(config: Config) -> Result<()> { let scanner = BlockScanner::new( provider.clone(), config.canonical_network.provider.window_size, - start_block_number, + latest_block_number, filter, ) .await?; diff --git a/src/relay/mod.rs b/src/relay/mod.rs index 9b5f84b..5fb1cc7 100644 --- a/src/relay/mod.rs +++ b/src/relay/mod.rs @@ -69,8 +69,14 @@ impl Relay for EVMRelay { let latest = world_id.latestRoot().call().await?._0; if latest != field { - tracing::trace!(new_root = ?field, latest_root =?latest, "Propagating root"); - self.signer.propagate_root().await?; + match self.signer.propagate_root().await { + Ok(_) => { + tracing::info!(root = %field, previous_root=%latest, provider = %self.provider, "Root propagated successfully"); + } + Err(e) => { + tracing::error!(error = %e, root = %field, previous_root=%latest, provider = %self.provider, "Failed to propagate root"); + } + } // We sleep for 2 blocks, so we don't resend the same root prior to derivation of the message on L2. std::thread::sleep(std::time::Duration::from_secs( ROOT_PROPAGATION_BACKOFF, diff --git a/src/relay/signer.rs b/src/relay/signer.rs index bb3b20a..cd56343 100644 --- a/src/relay/signer.rs +++ b/src/relay/signer.rs @@ -2,7 +2,7 @@ use alloy::network::EthereumWallet; use alloy::primitives::{bytes, Address, Bytes}; use ethers_core::types::U256; use eyre::eyre::{eyre, Result}; -use tracing::{error, info}; +use tracing::{debug, error, info}; use tx_sitter_client::data::{SendTxRequest, TransactionPriority, TxStatus}; use tx_sitter_client::TxSitterClient; @@ -63,7 +63,7 @@ impl RelaySigner for AlloySigner { match transport.get_receipt().await { Ok(receipt) => { - info!(receipt = ?receipt, "Successfully propogated Root to State Bridge."); + debug!(receipt = ?receipt, "Successfully propogated Root to State Bridge."); } Err(e) => { error!(error = ?e, "Failed to propogate Root to State Bridge."); From 94b0cbf949ecaa47aa0a782a26f669e406e98bf0 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 12:17:29 -0700 Subject: [PATCH 3/8] trying to fix replacement transaction underpriced with nonce filler --- config.stage.toml | 3 --- src/config.rs | 11 ++++----- src/main.rs | 57 +++++++++++++++++++++++++++++++++++---------- src/relay/signer.rs | 36 +++++++++++++++++++++------- 4 files changed, 78 insertions(+), 29 deletions(-) diff --git a/config.stage.toml b/config.stage.toml index 8cf0d63..3c35d45 100644 --- a/config.stage.toml +++ b/config.stage.toml @@ -12,7 +12,6 @@ address = "0xb2ead588f14e69266d1b87936b75325181377076" state_bridge_addr = "0x2F418Aa7D500B525EE8B80BB5F643A877ef82e09" world_id_addr = "0xE177F37AF0A862A02edFEa4F59C02668E9d0aAA4" provider = { rpc_endpoint = "https://eth.llamarpc.com" } -wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } [[bridged_networks]] type = "evm" @@ -21,7 +20,6 @@ address = "0xb2ead588f14e69266d1b87936b75325181377076" state_bridge_addr = "0x158379286D7083dDA05930CD3C6374954Fb511aA" world_id_addr = "0xf07d3efadD82A1F0b4C5Cc3476806d9a170147Ba" provider = { rpc_endpoint = "https://eth.llamarpc.com" } -wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } [[bridged_networks]] type = "evm" @@ -30,5 +28,4 @@ address = "0xb2ead588f14e69266d1b87936b75325181377076" state_bridge_addr = "0x5fFe37995158528d97A819bA390C1F81d74eB2b9" world_id_addr = "0x163b09b4fE21177c455D850BD815B6D583732432" provider = { rpc_endpoint = "https://eth.llamarpc.com" } -wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } diff --git a/src/config.rs b/src/config.rs index f5057fd..98ea7e5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,12 +11,12 @@ use reqwest::Client; use serde::{Deserialize, Serialize}; use url::Url; +use crate::relay::signer::AlloySignerProvider; + pub type ThrottledTransport = RetryBackoffService>; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { - /// The global wallet configuration - pub wallet: Option, /// The network from which roots will be propagated pub canonical_network: CanonicalNetworkConfig, /// The networks to which roots will be propagated @@ -77,6 +77,8 @@ impl fmt::Debug for BridgedNetworkConfig { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CanonicalNetworkConfig { pub world_id_addr: Address, + /// The global wallet configuration + pub wallet: Option, /// The number of blocks in the past to start scanning for new root events #[serde(default = "default::start_scan")] pub start_scan: u64, @@ -130,10 +132,7 @@ impl ProviderConfig { ProviderBuilder::new().on_client(client) } - pub fn signer( - &self, - wallet: EthereumWallet, - ) -> impl Provider { + pub fn signer(&self, wallet: EthereumWallet) -> AlloySignerProvider { let client = ClientBuilder::default() .layer(RetryBackoffLayer::new( self.max_rate_limit_retries, diff --git a/src/main.rs b/src/main.rs index 731501b..7c18eaa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use alloy::sol_types::SolEvent; use alloy_signer_local::coins_bip39::English; use clap::Parser; use config::{NetworkType, WalletConfig}; -use eyre::eyre::{eyre, OptionExt, Result}; +use eyre::eyre::{eyre, Result}; use futures::StreamExt; use relay::signer::{AlloySigner, Signer, TxSitterSigner}; use relay::{EVMRelay, Relay, Relayer}; @@ -183,28 +183,45 @@ pub async fn run(config: Config) -> Result<()> { /// Additionally initializes the signers from the global wallet configuration if present, /// otherwise from the bridged network configuration. fn init_relays(cfg: Config) -> Result> { + // Optinally use a global wallet configuration for all networks without a specific wallet configuration. + let global_signer = if let Some(wallet) = cfg.canonical_network.wallet { + match wallet { + WalletConfig::Mnemonic { mnemonic } => { + let signer = MnemonicBuilder::::default() + .phrase(mnemonic) + .index(0)? + .build()?; + let wallet = EthereumWallet::new(signer); + + let provider = + cfg.canonical_network.provider.signer(wallet.clone()); + + Some(Arc::new(provider)) + } + _ => None, + } + } else { + None + }; cfg.bridged_networks .iter() .map(|bridged| { - let wallet_config = bridged - .wallet - .as_ref() - .or(cfg.wallet.as_ref()) - .ok_or_eyre("No wallet configuration found")?; - + let wallet_config = bridged.wallet.as_ref(); match bridged.ty { NetworkType::Evm => match wallet_config { - WalletConfig::Mnemonic { mnemonic } => { + Some(WalletConfig::Mnemonic { mnemonic }) => { let signer = MnemonicBuilder::::default() .phrase(mnemonic) .index(0)? .build()?; let wallet = EthereumWallet::new(signer); - + let provider = cfg + .canonical_network + .provider + .signer(wallet.clone()); let alloy_signer = AlloySigner::new( bridged.state_bridge_addr, - cfg.canonical_network.provider.clone(), - wallet, + Arc::new(provider), ); Ok(Relayer::EVMRelay(EVMRelay::new( @@ -213,7 +230,7 @@ fn init_relays(cfg: Config) -> Result> { bridged.provider.rpc_endpoint.clone(), ))) } - WalletConfig::TxSitter { url, gas_limit } => { + Some(WalletConfig::TxSitter { url, gas_limit }) => { let signer = TxSitterSigner::new( url.as_str(), bridged.state_bridge_addr, @@ -226,6 +243,22 @@ fn init_relays(cfg: Config) -> Result> { bridged.provider.rpc_endpoint.clone(), ))) } + None => { + if let Some(global_signer) = &global_signer { + let alloy_signer = AlloySigner::new( + bridged.state_bridge_addr, + global_signer.clone(), + ); + + Ok(Relayer::EVMRelay(EVMRelay::new( + Signer::AlloySigner(alloy_signer), + bridged.world_id_addr, + bridged.provider.rpc_endpoint.clone(), + ))) + } else { + Err(eyre!("No wallet configuration found")) + } + } }, NetworkType::Svm => unimplemented!(), NetworkType::Scroll => unimplemented!(), diff --git a/src/relay/signer.rs b/src/relay/signer.rs index cd56343..3ed23f5 100644 --- a/src/relay/signer.rs +++ b/src/relay/signer.rs @@ -1,5 +1,12 @@ -use alloy::network::EthereumWallet; +use std::sync::Arc; + +use alloy::network::{Ethereum, EthereumWallet}; use alloy::primitives::{bytes, Address, Bytes}; +use alloy::providers::fillers::{ + BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, + NonceFiller, WalletFiller, +}; +use alloy::providers::{Identity, RootProvider}; use ethers_core::types::U256; use eyre::eyre::{eyre, Result}; use tracing::{debug, error, info}; @@ -7,7 +14,7 @@ use tx_sitter_client::data::{SendTxRequest, TransactionPriority, TxStatus}; use tx_sitter_client::TxSitterClient; use crate::abi::IStateBridge::IStateBridgeInstance; -use crate::config::ProviderConfig; +use crate::config::ThrottledTransport; /// keccak256("propagateRoot()")[..4] pub static PROPAGATE_ROOT_SELECTOR: Bytes = bytes!("380db829"); @@ -32,22 +39,35 @@ macro_rules! signer { } } +pub type AlloySignerProvider = FillProvider< + JoinFill< + JoinFill< + Identity, + JoinFill< + GasFiller, + JoinFill>, + >, + >, + WalletFiller, + >, + RootProvider, + ThrottledTransport, + Ethereum, +>; + pub struct AlloySigner { pub state_bridge_address: Address, - pub provider: ProviderConfig, - wallet: EthereumWallet, + pub provider: Arc, } impl AlloySigner { pub fn new( state_bridge_address: Address, - provider: ProviderConfig, - wallet: EthereumWallet, + provider: Arc, ) -> Self { Self { state_bridge_address, provider, - wallet, } } } @@ -56,7 +76,7 @@ impl RelaySigner for AlloySigner { async fn propagate_root(&self) -> Result<()> { let state_bridge_instance = IStateBridgeInstance::new( self.state_bridge_address, - self.provider.signer(self.wallet.clone()), + self.provider.clone(), ); let transport = state_bridge_instance.propagateRoot().send().await?; From 9185904559eda1276ad98ef684e9c7956ace2ec7 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 13:05:03 -0700 Subject: [PATCH 4/8] fix: nonce management --- src/config.rs | 10 ++++++++-- src/main.rs | 2 ++ src/relay/signer.rs | 13 ++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 98ea7e5..31ee9c9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,9 @@ use std::path::Path; use alloy::network::EthereumWallet; use alloy::primitives::Address; +use alloy::providers::fillers::{ + BlobGasFiller, CachedNonceManager, ChainIdFiller, GasFiller, NonceFiller, +}; use alloy::providers::{Provider, ProviderBuilder}; use alloy::rpc::client::ClientBuilder; use alloy::transports::http::Http; @@ -140,8 +143,11 @@ impl ProviderConfig { self.compute_units_per_second, )) .http(self.rpc_endpoint.clone()); - ProviderBuilder::default() - .with_recommended_fillers() + ProviderBuilder::new() + .filler(ChainIdFiller::default()) + .filler(NonceFiller::new(CachedNonceManager::default())) + .filler(BlobGasFiller) + .filler(GasFiller::default()) .wallet(wallet) .on_client(client) } diff --git a/src/main.rs b/src/main.rs index 7c18eaa..8f467aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ use telemetry_batteries::metrics::statsd::StatsdBattery; use telemetry_batteries::tracing::datadog::DatadogBattery; use telemetry_batteries::tracing::TracingShutdownHandle; use tokio::task::JoinSet; +use tracing::info; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -245,6 +246,7 @@ fn init_relays(cfg: Config) -> Result> { } None => { if let Some(global_signer) = &global_signer { + info!(network = %bridged.name, "Using global wallet configuration for bridged network"); let alloy_signer = AlloySigner::new( bridged.state_bridge_addr, global_signer.clone(), diff --git a/src/relay/signer.rs b/src/relay/signer.rs index 3ed23f5..9fb764d 100644 --- a/src/relay/signer.rs +++ b/src/relay/signer.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use alloy::network::{Ethereum, EthereumWallet}; use alloy::primitives::{bytes, Address, Bytes}; use alloy::providers::fillers::{ - BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, - NonceFiller, WalletFiller, + BlobGasFiller, CachedNonceManager, ChainIdFiller, FillProvider, GasFiller, + JoinFill, NonceFiller, WalletFiller, }; use alloy::providers::{Identity, RootProvider}; use ethers_core::types::U256; @@ -42,11 +42,14 @@ macro_rules! signer { pub type AlloySignerProvider = FillProvider< JoinFill< JoinFill< - Identity, JoinFill< - GasFiller, - JoinFill>, + JoinFill< + JoinFill, + NonceFiller, + >, + BlobGasFiller, >, + GasFiller, >, WalletFiller, >, From 56f1f9999de204c30c73ed0acf5774b6e8d7087f Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 13:07:00 -0700 Subject: [PATCH 5/8] fix: config --- config.stage.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config.stage.toml b/config.stage.toml index 3c35d45..3a298e0 100644 --- a/config.stage.toml +++ b/config.stage.toml @@ -12,6 +12,8 @@ address = "0xb2ead588f14e69266d1b87936b75325181377076" state_bridge_addr = "0x2F418Aa7D500B525EE8B80BB5F643A877ef82e09" world_id_addr = "0xE177F37AF0A862A02edFEa4F59C02668E9d0aAA4" provider = { rpc_endpoint = "https://eth.llamarpc.com" } +# Optionally Define a custom L1 Signer for this network +# wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } [[bridged_networks]] type = "evm" @@ -20,6 +22,8 @@ address = "0xb2ead588f14e69266d1b87936b75325181377076" state_bridge_addr = "0x158379286D7083dDA05930CD3C6374954Fb511aA" world_id_addr = "0xf07d3efadD82A1F0b4C5Cc3476806d9a170147Ba" provider = { rpc_endpoint = "https://eth.llamarpc.com" } +# Optionally Define a custom L1 Signer for this network +# wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } [[bridged_networks]] type = "evm" @@ -28,4 +32,6 @@ address = "0xb2ead588f14e69266d1b87936b75325181377076" state_bridge_addr = "0x5fFe37995158528d97A819bA390C1F81d74eB2b9" world_id_addr = "0x163b09b4fE21177c455D850BD815B6D583732432" provider = { rpc_endpoint = "https://eth.llamarpc.com" } +# Optionally Define a custom L1 Signer for this network +# wallet = { type = "mnemonic", mnemonic = "your mnemonic here" } From c2b4ed3a1b075b2769193d4ee15c8c270bbff0d0 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 13:08:46 -0700 Subject: [PATCH 6/8] reset lookback --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8f467aa..b283b34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,9 +105,9 @@ pub async fn run(config: Config) -> Result<()> { let latest_block_number = provider.get_block_number().await?; // // Start in the past by approximately 2 hours - // let start_block_number = latest_block_number - // .checked_sub(config.canonical_network.start_scan) - // .unwrap_or_default(); + let start_block_number = latest_block_number + .checked_sub(config.canonical_network.start_scan) + .unwrap_or_default(); let filter = Filter::new() .address(config.canonical_network.world_id_addr) @@ -116,7 +116,7 @@ pub async fn run(config: Config) -> Result<()> { let scanner = BlockScanner::new( provider.clone(), config.canonical_network.provider.window_size, - latest_block_number, + start_block_number, filter, ) .await?; From 2d99062f195bcf30dc5011785b943fec15472534 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 13:33:09 -0700 Subject: [PATCH 7/8] clippy --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 31ee9c9..3081537 100644 --- a/src/config.rs +++ b/src/config.rs @@ -147,7 +147,7 @@ impl ProviderConfig { .filler(ChainIdFiller::default()) .filler(NonceFiller::new(CachedNonceManager::default())) .filler(BlobGasFiller) - .filler(GasFiller::default()) + .filler(GasFiller) .wallet(wallet) .on_client(client) } From 3f5adca95354fc1d65a7d189cfb1cd7b1212ecdb Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 24 Oct 2024 13:50:31 -0700 Subject: [PATCH 8/8] cleanup tx fillers --- src/config.rs | 24 ++++++++++++++++++------ src/relay/signer.rs | 20 ++++++++------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3081537..a675ba0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,8 @@ use std::path::Path; use alloy::network::EthereumWallet; use alloy::primitives::Address; use alloy::providers::fillers::{ - BlobGasFiller, CachedNonceManager, ChainIdFiller, GasFiller, NonceFiller, + BlobGasFiller, CachedNonceManager, ChainIdFiller, GasFiller, JoinFill, + NonceFiller, }; use alloy::providers::{Provider, ProviderBuilder}; use alloy::rpc::client::ClientBuilder; @@ -14,7 +15,7 @@ use reqwest::Client; use serde::{Deserialize, Serialize}; use url::Url; -use crate::relay::signer::AlloySignerProvider; +use crate::relay::signer::{AlloySignerProvider, TxFillers}; pub type ThrottledTransport = RetryBackoffService>; @@ -143,14 +144,25 @@ impl ProviderConfig { self.compute_units_per_second, )) .http(self.rpc_endpoint.clone()); + ProviderBuilder::new() - .filler(ChainIdFiller::default()) - .filler(NonceFiller::new(CachedNonceManager::default())) - .filler(BlobGasFiller) - .filler(GasFiller) + .filler(Self::tx_fillers()) .wallet(wallet) .on_client(client) } + + fn tx_fillers() -> TxFillers { + JoinFill::new( + GasFiller, + JoinFill::new( + BlobGasFiller, + JoinFill::new( + NonceFiller::new(CachedNonceManager::default()), + ChainIdFiller::default(), + ), + ), + ) + } } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/relay/signer.rs b/src/relay/signer.rs index 9fb764d..b5f2ee7 100644 --- a/src/relay/signer.rs +++ b/src/relay/signer.rs @@ -39,20 +39,16 @@ macro_rules! signer { } } -pub type AlloySignerProvider = FillProvider< +pub type TxFillers = JoinFill< + GasFiller, JoinFill< - JoinFill< - JoinFill< - JoinFill< - JoinFill, - NonceFiller, - >, - BlobGasFiller, - >, - GasFiller, - >, - WalletFiller, + BlobGasFiller, + JoinFill, ChainIdFiller>, >, +>; + +pub type AlloySignerProvider = FillProvider< + JoinFill, WalletFiller>, RootProvider, ThrottledTransport, Ethereum,