Skip to content

Commit

Permalink
fix: pull max gas from provider (#1115)
Browse files Browse the repository at this point in the history
Retrieve gas limit for dry run dx dynamically

---------

Co-authored-by: Ahmed Sagdati <[email protected]>
Co-authored-by: segfault_magnet <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent 9595252 commit c4ed431
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ mod tests {
assert_eq!(signature, tx_signature);

// Check if the signature is what we expect it to be
assert_eq!(signature, Signature::from_str("df91e8ae723165f9a28b70910e3da41300da413607065618522f3084c9f051114acb1b51a836bd63c3d84a1ac904bf37b82ef03973c19026b266d04872f170a6")?);
assert_eq!(signature, Signature::from_str("d7027be16db0aada625ac8cd438f9b6187bd74465495ba39511c1ad72b7bb10af4ef582c94cc33433f7a1eb4f2ad21c471473947f5f645e90924ba273e2cee7f")?);

// Recover the address that signed the transaction
let recovered_address = signature.recover(&message)?;
Expand Down
11 changes: 6 additions & 5 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fuel_tx::{AssetId, ConsensusParameters, Receipt, ScriptExecutionResult, TxId
use fuel_types::{Address, Bytes32, ChainId, MessageId, Nonce};
use fuel_vm::state::ProgramState;
use fuels_core::{
constants::{BASE_ASSET_ID, DEFAULT_GAS_ESTIMATION_TOLERANCE, MAX_GAS_PER_TX},
constants::{BASE_ASSET_ID, DEFAULT_GAS_ESTIMATION_TOLERANCE},
types::{
bech32::{Bech32Address, Bech32ContractId},
block::Block,
Expand Down Expand Up @@ -527,7 +527,7 @@ impl Provider {
let tolerance = tolerance.unwrap_or(DEFAULT_GAS_ESTIMATION_TOLERANCE);

// Remove limits from an existing Transaction for accurate gas estimation
let dry_run_tx = Self::generate_dry_run_tx(tx.clone());
let dry_run_tx = self.generate_dry_run_tx(tx.clone());
let gas_used = self
.get_gas_used_with_tolerance(dry_run_tx.clone(), tolerance)
.await?;
Expand All @@ -551,9 +551,10 @@ impl Provider {
}

// Remove limits from an existing Transaction to get an accurate gas estimation
fn generate_dry_run_tx<T: Transaction>(tx: T) -> T {
// Simulate the contract call with MAX_GAS_PER_TX to get the complete gas_used
tx.clone().with_gas_limit(MAX_GAS_PER_TX).with_gas_price(0)
fn generate_dry_run_tx<T: Transaction>(&self, tx: T) -> T {
// Simulate the contract call with max gas to get the complete gas_used
let max_gas_per_tx = self.consensus_parameters.max_gas_per_tx;
tx.clone().with_gas_limit(max_gas_per_tx).with_gas_price(0)
}

// Increase estimated gas by the provided tolerance
Expand Down
4 changes: 1 addition & 3 deletions packages/fuels-core/src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const WORD_SIZE: usize = core::mem::size_of::<Word>();

// ANCHOR: default_tx_parameters
pub const DEFAULT_GAS_PRICE: u64 = 0;
pub const DEFAULT_GAS_LIMIT: u64 = 100_000_000;
pub const DEFAULT_GAS_LIMIT: u64 = 10_000_000;
pub const DEFAULT_MATURITY: u32 = 0;
// ANCHOR_END: default_tx_parameters

Expand All @@ -17,5 +17,3 @@ pub const BASE_ASSET_ID: AssetId = AssetId::BASE;
// ANCHOR_END: default_call_parameters

pub const DEFAULT_GAS_ESTIMATION_TOLERANCE: f64 = 0.2;
pub const GAS_PRICE_FACTOR: u64 = 1_000_000_000;
pub const MAX_GAS_PER_TX: u64 = 100_000_000;

0 comments on commit c4ed431

Please sign in to comment.