-
Notifications
You must be signed in to change notification settings - Fork 296
estimate fee for bulk transactions #1240
estimate fee for bulk transactions #1240
Conversation
let _: Result<_, DispatchError> = storage::transactional::with_transaction(|| { | ||
execution_result = tx.execute(state, block_context, true, disable_nonce_validation); | ||
for tx in txs { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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()); | ||
} | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Pull Request type
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