From 26fbeddda6d586365900156967258c82c084dddd Mon Sep 17 00:00:00 2001 From: halo3mic <46010359+halo3mic@users.noreply.github.com> Date: Sat, 4 May 2024 17:45:24 +0100 Subject: [PATCH 1/2] bump alloy & specify dep rev --- Cargo.lock | 55 +++++++++++++++++--------------- crates/primitives/Cargo.toml | 2 +- crates/revm/Cargo.toml | 10 +++--- crates/revm/src/db/alloydb.rs | 17 +++++----- examples/uniswap_v2_usdc_swap.rs | 8 ++--- 5 files changed, 48 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a57162cde..fcfa74fc4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,20 +47,20 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-eips", "alloy-primitives", "alloy-rlp", "alloy-serde", + "c-kzg", "serde", - "sha2", ] [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -68,33 +68,36 @@ dependencies = [ "c-kzg", "once_cell", "serde", + "sha2", ] [[package]] name = "alloy-genesis" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-primitives", "alloy-serde", "serde", + "serde_json", ] [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-primitives", "serde", "serde_json", "thiserror", + "tracing", ] [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-consensus", "alloy-eips", @@ -102,17 +105,17 @@ dependencies = [ "alloy-primitives", "alloy-rpc-types", "alloy-signer", + "alloy-sol-types", "async-trait", "futures-utils-wasm", - "serde", "thiserror", ] [[package]] name = "alloy-primitives" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" +checksum = "525448f6afc1b70dd0f9d0a8145631bf2f5e434678ab23ab18409ca264cae6b3" dependencies = [ "alloy-rlp", "arbitrary", @@ -138,8 +141,9 @@ dependencies = [ [[package]] name = "alloy-provider" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ + "alloy-eips", "alloy-json-rpc", "alloy-network", "alloy-primitives", @@ -153,6 +157,7 @@ dependencies = [ "auto_impl", "dashmap", "futures", + "futures-utils-wasm", "lru", "reqwest 0.12.2", "serde_json", @@ -186,7 +191,7 @@ dependencies = [ [[package]] name = "alloy-rpc-client" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -206,7 +211,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-consensus", "alloy-eips", @@ -224,7 +229,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types-trace" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -236,7 +241,7 @@ dependencies = [ [[package]] name = "alloy-serde" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-primitives", "serde", @@ -246,7 +251,7 @@ dependencies = [ [[package]] name = "alloy-signer" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-primitives", "async-trait", @@ -258,9 +263,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" +checksum = "89c80a2cb97e7aa48611cbb63950336f9824a174cdf670527cc6465078a26ea1" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -276,9 +281,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +checksum = "c58894b58ac50979eeac6249661991ac40b9d541830d9a725f7714cc9ef08c23" dependencies = [ "const-hex", "dunce", @@ -291,9 +296,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" +checksum = "399287f68d1081ed8b1f4903c49687658b95b142207d7cb4ae2f4813915343ef" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -304,7 +309,7 @@ dependencies = [ [[package]] name = "alloy-transport" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-json-rpc", "base64 0.22.0", @@ -322,7 +327,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git#bfd0fda492e560c3463d521958793c81bbeadfc1" +source = "git+https://github.com/alloy-rs/alloy.git?rev=44b8a6d#44b8a6da656602fd9fd2c52f28ecffa4acaed96c" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -3636,9 +3641,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" +checksum = "5aa0cefd02f532035d83cfec82647c6eb53140b0485220760e669f4bad489e36" dependencies = [ "paste", "proc-macro2", diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index b9fbb9fceb..32ab4efb40 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -17,7 +17,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [dependencies] -alloy-primitives = { version = "0.7", default-features = false, features = [ +alloy-primitives = { version = "0.7.2", default-features = false, features = [ "rlp", ] } hashbrown = "0.14" diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 2a517a4a17..a10599acd8 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -41,9 +41,9 @@ ethers-providers = { version = "2.0", optional = true } ethers-core = { version = "2.0", optional = true } # alloydb -alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", optional = true, default-features = false } -alloy-rpc-types = {git = "https://github.com/alloy-rs/alloy.git", optional = true, default-features = false } -alloy-transport = {git = "https://github.com/alloy-rs/alloy.git", optional = true, default-features = false } +alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", optional = true, default-features = false } +alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", optional = true, default-features = false } +alloy-transport = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", optional = true, default-features = false } [dev-dependencies] alloy-sol-types = { version = "0.7.0", default-features = false, features = ["std"] } @@ -53,9 +53,9 @@ criterion = "0.5" indicatif = "0.17" reqwest = { version = "0.12" } -alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", default-features = false, features = ["reqwest"] } +alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", default-features = false, features = ["reqwest"] } # needed for enabling TLS to use HTTPS connections when testing alloy DB -alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git" } +alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git" , rev = "44b8a6d" } [features] default = ["std", "c-kzg", "secp256k1", "portable"] diff --git a/crates/revm/src/db/alloydb.rs b/crates/revm/src/db/alloydb.rs index a9541991d9..a5690aa1da 100644 --- a/crates/revm/src/db/alloydb.rs +++ b/crates/revm/src/db/alloydb.rs @@ -15,13 +15,13 @@ pub struct AlloyDB> { /// The provider to fetch the data from. provider: P, /// The block number on which the queries will be based on. - block_number: Option, + block_number: BlockId, _marker: std::marker::PhantomData (T, N)>, } impl> AlloyDB { /// Create a new AlloyDB instance, with a [Provider] and a block (Use None for latest). - pub fn new(provider: P, block_number: Option) -> Self { + pub fn new(provider: P, block_number: BlockId) -> Self { Self { provider, block_number, @@ -63,7 +63,7 @@ impl> AlloyDB { } /// Set the block number on which the queries will be based on. - pub fn set_block_number(&mut self, block_number: Option) { + pub fn set_block_number(&mut self, block_number: BlockId) { self.block_number = block_number; } } @@ -79,7 +79,7 @@ impl> DatabaseRef for AlloyD let balance = self.provider.get_balance(address, self.block_number); let code = self .provider - .get_code_at(address, self.block_number.unwrap_or_default()); + .get_code_at(address, self.block_number); tokio::join!(nonce, balance, code) }; @@ -92,7 +92,7 @@ impl> DatabaseRef for AlloyD Ok(Some(AccountInfo::new( balance, - nonce.to::(), + nonce, code_hash, code, ))) @@ -161,13 +161,12 @@ mod tests { #[test] fn can_get_basic() { let client = ProviderBuilder::new() - .on_reqwest_http( + .on_http( "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" .parse() .unwrap(), - ) - .unwrap(); - let alloydb = AlloyDB::new(client, Some(BlockId::from(16148323))); + ); + let alloydb = AlloyDB::new(client, BlockId::from(16148323)); // ETH/USDT pair on Uniswap V2 let address: Address = "0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852" diff --git a/examples/uniswap_v2_usdc_swap.rs b/examples/uniswap_v2_usdc_swap.rs index 9171da10ac..0729256133 100644 --- a/examples/uniswap_v2_usdc_swap.rs +++ b/examples/uniswap_v2_usdc_swap.rs @@ -1,5 +1,6 @@ use alloy_provider::{network::Ethereum, ProviderBuilder, RootProvider}; use alloy_sol_types::{sol, SolCall, SolValue}; +use alloy_rpc_types::BlockId; use alloy_transport_http::Http; use anyhow::{anyhow, Result}; use reqwest::Client; @@ -18,14 +19,13 @@ type AlloyCacheDB = CacheDB, Ethereum, Arc Result<()> { let client = ProviderBuilder::new() - .on_reqwest_http( + .on_http( "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" .parse() .unwrap(), - ) - .unwrap(); + ); let client = Arc::new(client); - let mut cache_db = CacheDB::new(AlloyDB::new(client, None)); + let mut cache_db = CacheDB::new(AlloyDB::new(client, BlockId::default())); // Random empty account let account = address!("18B06aaF27d44B756FCF16Ca20C1f183EB49111f"); From 57b8d2940a888dc6ac69a3c841c251109042c0f2 Mon Sep 17 00:00:00 2001 From: halo3mic <46010359+halo3mic@users.noreply.github.com> Date: Sat, 4 May 2024 17:55:30 +0100 Subject: [PATCH 2/2] satisfy fmt check --- crates/revm/src/db/alloydb.rs | 22 +++++++--------------- examples/uniswap_v2_usdc_swap.rs | 13 ++++++------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/crates/revm/src/db/alloydb.rs b/crates/revm/src/db/alloydb.rs index a5690aa1da..932fc32dbe 100644 --- a/crates/revm/src/db/alloydb.rs +++ b/crates/revm/src/db/alloydb.rs @@ -77,9 +77,7 @@ impl> DatabaseRef for AlloyD .provider .get_transaction_count(address, self.block_number); let balance = self.provider.get_balance(address, self.block_number); - let code = self - .provider - .get_code_at(address, self.block_number); + let code = self.provider.get_code_at(address, self.block_number); tokio::join!(nonce, balance, code) }; @@ -90,12 +88,7 @@ impl> DatabaseRef for AlloyD let code_hash = code.hash_slow(); let nonce = nonce?; - Ok(Some(AccountInfo::new( - balance, - nonce, - code_hash, - code, - ))) + Ok(Some(AccountInfo::new(balance, nonce, code_hash, code))) } fn block_hash_ref(&self, number: U256) -> Result { @@ -160,12 +153,11 @@ mod tests { #[test] fn can_get_basic() { - let client = ProviderBuilder::new() - .on_http( - "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" - .parse() - .unwrap(), - ); + let client = ProviderBuilder::new().on_http( + "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" + .parse() + .unwrap(), + ); let alloydb = AlloyDB::new(client, BlockId::from(16148323)); // ETH/USDT pair on Uniswap V2 diff --git a/examples/uniswap_v2_usdc_swap.rs b/examples/uniswap_v2_usdc_swap.rs index 0729256133..a57a982642 100644 --- a/examples/uniswap_v2_usdc_swap.rs +++ b/examples/uniswap_v2_usdc_swap.rs @@ -1,6 +1,6 @@ use alloy_provider::{network::Ethereum, ProviderBuilder, RootProvider}; -use alloy_sol_types::{sol, SolCall, SolValue}; use alloy_rpc_types::BlockId; +use alloy_sol_types::{sol, SolCall, SolValue}; use alloy_transport_http::Http; use anyhow::{anyhow, Result}; use reqwest::Client; @@ -18,12 +18,11 @@ type AlloyCacheDB = CacheDB, Ethereum, Arc Result<()> { - let client = ProviderBuilder::new() - .on_http( - "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" - .parse() - .unwrap(), - ); + let client = ProviderBuilder::new().on_http( + "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" + .parse() + .unwrap(), + ); let client = Arc::new(client); let mut cache_db = CacheDB::new(AlloyDB::new(client, BlockId::default()));