Skip to content

Commit

Permalink
fix: estimate predicates during max fee estimation (#1434)
Browse files Browse the repository at this point in the history
### Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have updated the documentation.
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added necessary labels.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
  • Loading branch information
MujkicA authored Jun 15, 2024
1 parent 7da40f7 commit d3e80aa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/fuels-core/src/types/transaction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use fuel_tx::{
};
pub use fuel_tx::{UpgradePurpose, UploadSubsection};
use fuel_types::{bytes::padded_len_usize, Bytes32, Salt};
use fuel_vm::{checked_transaction::EstimatePredicates, interpreter::MemoryInstance};
use itertools::Itertools;
use script_dry_runner::ScriptDryRunner;

Expand Down Expand Up @@ -324,14 +325,19 @@ macro_rules! impl_tx_trait {
Ok(padded_len as u64)
}

async fn set_max_fee_policy<T: PoliciesField + Chargeable>(
async fn set_max_fee_policy<T: PoliciesField + Chargeable + EstimatePredicates>(
tx: &mut T,
provider: impl DryRunner,
block_horizon: u32,
) -> Result<()> {
let gas_price = provider.estimate_gas_price(block_horizon).await?;
let consensus_parameters = provider.consensus_parameters();

tx.estimate_predicates(
&provider.consensus_parameters().into(),
MemoryInstance::new(),
)?;

let tx_fee = TransactionFee::checked_from_tx(
&consensus_parameters.gas_costs(),
consensus_parameters.fee_params(),
Expand All @@ -343,8 +349,9 @@ macro_rules! impl_tx_trait {
"error calculating `TransactionFee` in `TransactionBuilder`"
))?;

tx.policies_mut()
.set(PolicyType::MaxFee, Some(tx_fee.max_fee()));
let max_fee = tx_fee.max_fee();
let new_max_fee = max_fee + max_fee / 10; // 10% buffer
tx.policies_mut().set(PolicyType::MaxFee, Some(new_max_fee));

Ok(())
}
Expand Down

0 comments on commit d3e80aa

Please sign in to comment.