Skip to content

Commit

Permalink
Merge pull request #35 from PureStake/tgm-fix-runtime-api-reuse
Browse files Browse the repository at this point in the history
Fresh runtime api instance per call estimation
  • Loading branch information
librelois authored Feb 3, 2022
2 parents 3aa4b0f + 711d1f0 commit 3bb9f72
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions client/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,13 +1413,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;
Expand Down Expand Up @@ -1451,6 +1449,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<ExecutableResult> {
Expand All @@ -1465,6 +1465,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);

Expand Down

0 comments on commit 3bb9f72

Please sign in to comment.