Repository: gakonst/ethers-rs
Pull request #1062 (2022-03-19 06:11:58)

fix(core/TypedTransaction): eip1559 gas price should be max_fee_per_gas
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.

Contributors guide: https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md

The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

Gas price is `max_fee_per_gas`, not `max_fee_per_gas + max_priority_fee_per_gas`. 




Patch:
diff --git a/Cargo.lock b/Cargo.lock
index c38bd39e..5173bfd1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -330,6 +330,12 @@ dependencies = [
  "serde",
 ]
 
+[[package]]
+name = "build_const"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7"
+
 [[package]]
 name = "bumpalo"
 version = "3.9.1"
@@ -1405,6 +1411,7 @@ dependencies = [
  "sha2 0.9.9",
  "solang-parser",
  "svm-rs",
+ "svm-rs-builds",
  "tempfile",
  "thiserror",
  "tiny-keccak",
@@ -3312,9 +3319,9 @@ dependencies = [
 
 [[package]]
 name = "serde_json"
-version = "1.0.78"
+version = "1.0.79"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085"
+checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
 dependencies = [
  "itoa 1.0.1",
  "ryu",
@@ -3576,7 +3583,7 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
 [[package]]
 name = "svm-rs"
 version = "0.2.9"
-source = "git+https://github.com/roynalnaruto/svm-rs#37d0095eeac73546c507b706c51e8f901541a7c1"
+source = "git+https://github.com/roynalnaruto/svm-rs#496888fdcd9d2316a52020a09e281414755de3f8"
 dependencies = [
  "anyhow",
  "cfg-if 1.0.0",
@@ -3601,6 +3608,18 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "svm-rs-builds"
+version = "0.1.0"
+source = "git+https://github.com/roynalnaruto/svm-rs#496888fdcd9d2316a52020a09e281414755de3f8"
+dependencies = [
+ "build_const",
+ "hex",
+ "semver",
+ "serde_json",
+ "svm-rs",
+]
+
 [[package]]
 name = "syn"
 version = "1.0.89"
diff --git a/ethers-core/src/types/transaction/eip2718.rs b/ethers-core/src/types/transaction/eip2718.rs
index fe211df7..8fffc6ba 100644
--- a/ethers-core/src/types/transaction/eip2718.rs
+++ b/ethers-core/src/types/transaction/eip2718.rs
@@ -141,10 +141,10 @@ impl TypedTransaction {
             Eip2930(inner) => inner.tx.gas_price,
             Eip1559(inner) => {
                 match (inner.max_fee_per_gas, inner.max_priority_fee_per_gas) {
-                    (Some(basefee), Some(prio_fee)) => Some(basefee + prio_fee),
+                    (Some(max_fee), Some(_)) => Some(max_fee),
                     // this also covers the None, None case
                     (None, prio_fee) => prio_fee,
-                    (basefee, None) => basefee,
+                    (max_fee, None) => max_fee,
                 }
             }
         }
diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs
index 6f6c7ea8..722b96ba 100644
--- a/ethers-providers/src/provider.rs
+++ b/ethers-providers/src/provider.rs
@@ -1718,7 +1718,7 @@ mod tests {
         provider.from = Some("0x6fC21092DA55B392b045eD78F4732bff3C580e2c".parse().unwrap());
 
         let gas = U256::from(21000_usize);
-        let basefee = U256::from(25_usize);
+        let max_fee = U256::from(25_usize);
         let prio_fee = U256::from(25_usize);
         let access_list: AccessList = vec![Default::default()].into();
 
@@ -1729,7 +1729,7 @@ mod tests {
             .from(from)
             .to(to)
             .gas(gas)
-            .max_fee_per_gas(basefee)
+            .max_fee_per_gas(max_fee)
             .max_priority_fee_per_gas(prio_fee)
             .access_list(access_list.clone())
             .into();
@@ -1738,7 +1738,7 @@ mod tests {
         assert_eq!(tx.from(), Some(&from));
         assert_eq!(tx.to(), Some(&to.into()));
         assert_eq!(tx.gas(), Some(&gas));
-        assert_eq!(tx.gas_price(), Some(basefee + prio_fee));
+        assert_eq!(tx.gas_price(), Some(max_fee));
         assert_eq!(tx.access_list(), Some(&access_list));
 
         // --- fills a 1559 transaction, leaving the existing gas limit unchanged, but including
@@ -1746,7 +1746,7 @@ mod tests {
         let gas_with_al = gas - 1;
         let mut tx = Eip1559TransactionRequest::new()
             .gas(gas)
-            .max_fee_per_gas(basefee)
+            .max_fee_per_gas(max_fee)
             .max_priority_fee_per_gas(prio_fee)
             .into();
 
@@ -1766,7 +1766,7 @@ mod tests {
         // --- fills a 1559 transaction, ignoring access list if more expensive
         let gas_with_al = gas + 1;
         let mut tx = Eip1559TransactionRequest::new()
-            .max_fee_per_gas(basefee)
+            .max_fee_per_gas(max_fee)
             .max_priority_fee_per_gas(prio_fee)
             .into();
 
@@ -1786,7 +1786,7 @@ mod tests {
 
         // --- fills a 1559 transaction, using estimated gas if create_access_list() errors
         let mut tx = Eip1559TransactionRequest::new()
-            .max_fee_per_gas(basefee)
+            .max_fee_per_gas(max_fee)
             .max_priority_fee_per_gas(prio_fee)
             .into();
 
@@ -1803,7 +1803,7 @@ mod tests {
 
         // --- propogates estimate_gas() error
         let mut tx = Eip1559TransactionRequest::new()
-            .max_fee_per_gas(basefee)
+            .max_fee_per_gas(max_fee)
             .max_priority_fee_per_gas(prio_fee)
             .into();
 
diff --git a/ethers-solc/Cargo.toml b/ethers-solc/Cargo.toml
index 26e03d0f..c902b24f 100644
--- a/ethers-solc/Cargo.toml
+++ b/ethers-solc/Cargo.toml
@@ -44,6 +44,7 @@ home = "0.5.3"
 # SVM is not WASM compatible yet.
 # svm = { package = "svm-rs", default-features = false, version = "0.2.7", optional = true }
 svm = { package = "svm-rs", default-features = false, git = "https://github.com/roynalnaruto/svm-rs", optional = true, features = ["blocking"] }
+svm-builds = { package = "svm-rs-builds", git = "https://github.com/roynalnaruto/svm-rs", optional = true}
 
 [target.'cfg(target_arch = "wasm32")'.dependencies]
 # NOTE: this enables wasm compatibility for getrandom indirectly
@@ -69,17 +70,17 @@ harness = false
 [[test]]
 name = "project"
 path = "tests/project.rs"
-required-features = ["async", "svm", "project-util"]
+required-features = ["async", "svm", "svm-builds", "project-util"]
 
 [[test]]
 name = "mocked"
 path = "tests/mocked.rs"
-required-features = ["async", "svm", "project-util"]
+required-features = ["async", "svm", "svm-builds", "project-util"]
 
 [features]
 default = ["rustls"]
 async = ["tokio", "futures-util"]
-full = ["async", "svm", "svm/blocking"]
+full = ["async", "svm", "svm/blocking", "svm-builds"]
 # Utilities for creating and testing project workspaces
 project-util = ["tempfile", "fs_extra", "rand"]
 tests = []
diff --git a/ethers-solc/src/compile/mod.rs b/ethers-solc/src/compile/mod.rs
index c7c4d136..46a36131 100644
--- a/ethers-solc/src/compile/mod.rs
+++ b/ethers-solc/src/compile/mod.rs
@@ -63,17 +63,19 @@ pub(crate) fn take_solc_installer_lock() -> std::sync::MutexGuard<'static, ()> {
 
 /// A list of upstream Solc releases, used to check which version
 /// we should download.
-/// The boolean value marks whether there was an error.
-#[cfg(all(feature = "svm"))]
+/// The boolean value marks whether there was an error accessing the release list
+#[cfg(all(feature = "svm", feature = "svm-builds"))]
 pub static RELEASES: once_cell::sync::Lazy<(svm::Releases, Vec<Version>, bool)> =
-    once_cell::sync::Lazy::new(|| match svm::blocking_all_releases(svm::platform()) {
-        Ok(releases) => {
-            let sorted_versions = releases.clone().into_versions();
-            (releases, sorted_versions, true)
-        }
-        Err(err) => {
-            tracing::error!("{:?}", err);
-            (svm::Releases::default(), Vec::new(), false)
+    once_cell::sync::Lazy::new(|| {
+        match serde_json::from_str::<svm::Releases>(svm_builds::RELEASE_LIST_JSON) {
+            Ok(releases) => {
+                let sorted_versions = releases.clone().into_versions();
+                (releases, sorted_versions, true)
+            }
+            Err(err) => {
+                tracing::error!("{:?}", err);
+                (svm::Releases::default(), Vec::new(), false)
+            }
         }
     });
 


Test patch:
diff --git a/ethers-middleware/tests/nonce_manager.rs b/ethers-middleware/tests/nonce_manager.rs
index 63331037..31e36909 100644
--- a/ethers-middleware/tests/nonce_manager.rs
+++ b/ethers-middleware/tests/nonce_manager.rs
@@ -30,7 +30,7 @@ async fn nonce_manager() {
         .unwrap()
         .as_u64();
 
-    let num_tx = 5;
+    let num_tx = 3;
     let mut tx_hashes = Vec::with_capacity(num_tx);
     for _ in 0..num_tx {
         let tx = provider
@@ -44,7 +44,7 @@ async fn nonce_manager() {
     }
 
     // sleep a bit to ensure there's no flakiness in the test
-    std::thread::sleep(std::time::Duration::new(3, 0));
+    std::thread::sleep(std::time::Duration::new(5, 0));
 
     let mut nonces = Vec::with_capacity(num_tx);
     for tx_hash in tx_hashes {