Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

estimate fee for bulk transactions #1240

Conversation

lana-shanghai
Copy link
Contributor

Pull Request type

  • Feature
    Allow to pass a vector of transactions for fee estimation. Needed for instance for compatibility with the Argent wallet.

What is the current behavior?

Currently we accept only 1 transaction to estimate the fee and the state rolls back to initial state after each estimation.
Resolves: issue

What is the new behavior?

We pass a vector of transaction to the estimate_fee function

@EvolveArt EvolveArt marked this pull request as ready for review November 3, 2023 22:45
@EvolveArt EvolveArt merged commit 79b1e71 into keep-starknet-strange:main Nov 4, 2023
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2023
crates/client/rpc/src/lib.rs Show resolved Hide resolved
let _: Result<_, DispatchError> = storage::transactional::with_transaction(|| {
execution_result = tx.execute(state, block_context, true, disable_nonce_validation);
for tx in txs {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use an iterator and map, and stop iterating at the first error encountered.
collect::<Result<Value, E>> allows you to do this.

Here you keep executing every transaction, even after a previous one failed. This is a waste of computation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you just do exectuction_results = txs.into_iter().map(|tx| {...}) to bring the result outside the closure

Comment on lines +1151 to +1161
let mut results = vec![];
for res in execution_results {
match res {
Ok(tx_exec_info) => {
log!(info, "Successfully estimated fee: {:?}", tx_exec_info);
if let Some(l1_gas_usage) = tx_exec_info.actual_resources.0.get("l1_gas_usage") {
results.push((tx_exec_info.actual_fee.0 as u64, *l1_gas_usage as u64));
} else {
return Err(Error::<T>::TransactionExecutionFailed.into());
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed anymore if you stop executing the tx after the first that failed

@@ -46,7 +46,7 @@ sp_api::decl_runtime_apis! {
/// Returns the chain id.
fn chain_id() -> Felt252Wrapper;
/// Returns fee estimate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add in the doc, which u64 is the overall_fee and which is the gas_consumed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But even better would be creating a dedicated struct so the API users are less prone to commit mistakes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: estimate_fee should keep state changes between two tx when doing bulk estimate
3 participants