From 8493451917c400e3feec3b1dfc41e259b067c3e5 Mon Sep 17 00:00:00 2001 From: Eduard S Date: Thu, 18 Nov 2021 10:59:29 +0100 Subject: [PATCH] Fix/providers (#590) * ethers-providers: Fix http Provider request id data race * ethers-providers: Remove Serialize from JsonRpcClient Response * Update changelog --- CHANGELOG.md | 2 ++ ethers-providers/src/lib.rs | 2 +- ethers-providers/src/transports/http.rs | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8f8609..d7ec7dc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ - add the missing constructor for `Timelag` middleware via [#568](https://github.com/gakonst/ethers-rs/pull/568) - re-export error types for `Http` and `Ws` providers in [#570](https://github.com/gakonst/ethers-rs/pull/570) - add a method on the `Middleware` to broadcast a tx with a series of escalating gas prices via [#566](https://github.com/gakonst/ethers-rs/pull/566) +- Remove unnecessary `Serialize` constraint to `R` (the Response type) in the `request` method of `JsonRpcClient`. +- Fix `http Provider` data race when generating new request `id`s. ### 0.5.3 diff --git a/ethers-providers/src/lib.rs b/ethers-providers/src/lib.rs index 3d735a8f..4ae61897 100644 --- a/ethers-providers/src/lib.rs +++ b/ethers-providers/src/lib.rs @@ -116,7 +116,7 @@ pub trait JsonRpcClient: Debug + Send + Sync { async fn request(&self, method: &str, params: T) -> Result where T: Debug + Serialize + Send + Sync, - R: Serialize + DeserializeOwned; + R: DeserializeOwned; } use ethers_core::types::*; diff --git a/ethers-providers/src/transports/http.rs b/ethers-providers/src/transports/http.rs index a0e70439..3db8d2f2 100644 --- a/ethers-providers/src/transports/http.rs +++ b/ethers-providers/src/transports/http.rs @@ -68,8 +68,7 @@ impl JsonRpcClient for Provider { method: &str, params: T, ) -> Result { - let next_id = self.id.load(Ordering::SeqCst) + 1; - self.id.store(next_id, Ordering::SeqCst); + let next_id = self.id.fetch_add(1, Ordering::SeqCst); let payload = Request::new(next_id, method, params);