From 711d1f073501f871011c1f595b40c31f783e8c2e Mon Sep 17 00:00:00 2001 From: tgmichel Date: Thu, 3 Feb 2022 17:40:59 +0100 Subject: [PATCH] Fresh runtime api instance per call estimation --- client/rpc/src/eth.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/rpc/src/eth.rs b/client/rpc/src/eth.rs index fb1fb83f09..e65a253d58 100644 --- a/client/rpc/src/eth.rs +++ b/client/rpc/src/eth.rs @@ -1391,13 +1391,11 @@ where } }; - let api = self.client.runtime_api(); - // Recap the highest gas allowance with account's balance. if let Some(from) = request.from { let gas_price = gas_price.unwrap_or_default(); if gas_price > U256::zero() { - let balance = api + let balance = self.client.runtime_api() .account_basic(&BlockId::Hash(best_hash), from) .map_err(|err| internal_err(format!("runtime error: {:?}", err)))? .balance; @@ -1429,6 +1427,8 @@ where used_gas: U256, } + let client = self.client.clone(); + // Create a helper to check if a gas allowance results in an executable transaction let executable = move |request: CallRequest, gas_limit, api_version| -> Result { @@ -1443,6 +1443,9 @@ where .. } = request; + // Fresh instance per execution + let api = client.runtime_api(); + // Use request gas limit only if it less than gas_limit parameter let gas_limit = core::cmp::min(gas.unwrap_or(gas_limit), gas_limit);