Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fresh runtime api instance per call estimation #35

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions client/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ExecutableResult> {
Expand All @@ -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);

Expand Down