diff --git a/Cargo.lock b/Cargo.lock index a04261a..c78378f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -663,6 +663,7 @@ dependencies = [ "derive_more 2.0.1", "futures", "futures-utils-wasm", + "governor", "parking_lot", "serde", "serde_json", @@ -2652,6 +2653,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + [[package]] name = "futures-util" version = "0.3.31" @@ -2762,6 +2769,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "governor" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be93b4ec2e4710b04d9264c0c7350cdd62a8c20e5e4ac732552ebb8f0debe8eb" +dependencies = [ + "cfg-if", + "futures-sink", + "futures-timer", + "futures-util", + "getrandom 0.3.3", + "no-std-compat", + "nonzero_ext", + "parking_lot", + "portable-atomic", + "quanta", + "smallvec", + "spinning_top", + "web-time", +] + [[package]] name = "group" version = "0.13.0" @@ -3653,12 +3681,24 @@ dependencies = [ "tempfile", ] +[[package]] +name = "no-std-compat" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" + [[package]] name = "nohash-hasher" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "nonzero_ext" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -4201,6 +4241,21 @@ dependencies = [ "cc", ] +[[package]] +name = "quanta" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3ab5a9d756f0d97bdc89019bd2e4ea098cf9cde50ee7564dde6b81ccc8f06c7" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi 0.11.0+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -4299,6 +4354,15 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "raw-cpuid" +version = "11.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6df7ab838ed27997ba19a4664507e6f82b41fe6e20be42929332156e5e85146" +dependencies = [ + "bitflags 2.9.1", +] + [[package]] name = "rayon" version = "1.10.0" @@ -4561,6 +4625,7 @@ name = "revive-dt-node" version = "0.1.0" dependencies = [ "alloy", + "alloy-transport", "anyhow", "revive-common", "revive-dt-common", @@ -5584,6 +5649,15 @@ dependencies = [ "sp-debug-derive", ] +[[package]] +name = "spinning_top" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" +dependencies = [ + "lock_api", +] + [[package]] name = "spki" version = "0.7.3" @@ -6571,6 +6645,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "widestring" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index d8b4213..d48dcc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ revive-dt-node-pool = { version = "0.1.0", path = "crates/node-pool" } revive-dt-report = { version = "0.1.0", path = "crates/report" } revive-dt-solc-binaries = { version = "0.1.0", path = "crates/solc-binaries" } +alloy-transport = { version = "1.0.22", features = ["throttle"] } alloy-primitives = "1.2.1" alloy-sol-types = "1.2.1" anyhow = "1.0" diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index b895165..171a479 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -11,6 +11,7 @@ rust-version.workspace = true [dependencies] anyhow = { workspace = true } alloy = { workspace = true } +alloy-transport = { workspace = true } tracing = { workspace = true } tokio = { workspace = true } diff --git a/crates/node/src/kitchensink.rs b/crates/node/src/kitchensink.rs index 832760a..305625d 100644 --- a/crates/node/src/kitchensink.rs +++ b/crates/node/src/kitchensink.rs @@ -27,13 +27,17 @@ use alloy::{ ext::DebugApi, fillers::{CachedNonceManager, ChainIdFiller, FillProvider, NonceFiller, TxFiller}, }, - rpc::types::{ - EIP1186AccountProofResponse, TransactionReceipt, - eth::{Block, Header, Transaction}, - trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, + rpc::{ + client::ClientBuilder, + types::{ + EIP1186AccountProofResponse, TransactionReceipt, + eth::{Block, Header, Transaction}, + trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, + }, }, signers::local::PrivateKeySigner, }; +use alloy_transport::layers::ThrottleLayer; use anyhow::Context; use revive_common::EVMVersion; use revive_dt_common::fs::clear_directory; @@ -63,6 +67,7 @@ pub struct KitchensinkNode { wallet: Arc, nonce_manager: CachedNonceManager, chain_id_filler: ChainIdFiller, + throttle: ThrottleLayer, /// This vector stores [`File`] objects that we use for logging which we want to flush when the /// node object is dropped. We do not store them in a structured fashion at the moment (in /// separate fields) as the logic that we need to apply to them is all the same regardless of @@ -341,7 +346,14 @@ impl KitchensinkNode { KitchenSinkNetwork, >, > { - ProviderBuilder::new() + let client = ClientBuilder::default() + .layer(ThrottleLayer { + throttle: self.throttle.throttle.clone(), + }) + .connect(&self.rpc_url) + .await?; + + Ok(ProviderBuilder::new() .disable_recommended_fillers() .network::() .filler(FallbackGasFiller::new( @@ -352,9 +364,7 @@ impl KitchensinkNode { .filler(self.chain_id_filler.clone()) .filler(NonceFiller::new(self.nonce_manager.clone())) .wallet(self.wallet.clone()) - .connect(&self.rpc_url) - .await - .map_err(Into::into) + .connect_client(client)) } } @@ -538,6 +548,7 @@ impl Node for KitchensinkNode { wallet: Arc::new(wallet), chain_id_filler: Default::default(), nonce_manager: Default::default(), + throttle: ThrottleLayer::new(250), // We know that we only need to be storing 4 files so we can specify that when creating // the vector. It's the stdout and stderr of the substrate-node and the eth-rpc. logs_file_to_flush: Vec::with_capacity(4),