From 1b7ef9279fbd1e56c538f2005518e43c39c3d3fc Mon Sep 17 00:00:00 2001 From: MujkicA Date: Wed, 30 Aug 2023 15:53:11 +0200 Subject: [PATCH 1/4] pull max gas from provider --- packages/fuels-accounts/src/provider.rs | 9 ++++++--- packages/fuels-core/src/utils/constants.rs | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index ab56813277..989d9f48e8 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -154,6 +154,8 @@ impl Provider { .estimate_transaction_cost(tx.clone(), Some(tolerance)) .await?; + dbg!("AHAA"); + if gas_used > tx.gas_limit() { return Err(error!( ProviderError, @@ -527,7 +529,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?; @@ -551,9 +553,10 @@ impl Provider { } // Remove limits from an existing Transaction to get an accurate gas estimation - fn generate_dry_run_tx(tx: T) -> T { + fn generate_dry_run_tx(&self, 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) + 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 diff --git a/packages/fuels-core/src/utils/constants.rs b/packages/fuels-core/src/utils/constants.rs index 8880059863..32521c31a5 100644 --- a/packages/fuels-core/src/utils/constants.rs +++ b/packages/fuels-core/src/utils/constants.rs @@ -18,4 +18,3 @@ pub const BASE_ASSET_ID: AssetId = AssetId::BASE; 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; From bb091f1d8a7322b03116c2fc64ea60837125a87b Mon Sep 17 00:00:00 2001 From: MujkicA <32431923+MujkicA@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:57:19 +0200 Subject: [PATCH 2/4] Update packages/fuels-accounts/src/provider.rs Co-authored-by: Ahmed Sagdati <37515857+segfault-magnet@users.noreply.github.com> --- packages/fuels-accounts/src/provider.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 989d9f48e8..e955e0d82c 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -154,8 +154,6 @@ impl Provider { .estimate_transaction_cost(tx.clone(), Some(tolerance)) .await?; - dbg!("AHAA"); - if gas_used > tx.gas_limit() { return Err(error!( ProviderError, From a452852d98c26323da2b0389b4700136f59e6b76 Mon Sep 17 00:00:00 2001 From: MujkicA Date: Wed, 30 Aug 2023 16:02:48 +0200 Subject: [PATCH 3/4] update tx param default --- packages/fuels-accounts/src/provider.rs | 4 ++-- packages/fuels-core/src/utils/constants.rs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index 989d9f48e8..80dec527af 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -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, @@ -554,7 +554,7 @@ impl Provider { // Remove limits from an existing Transaction to get an accurate gas estimation fn generate_dry_run_tx(&self, tx: T) -> T { - // Simulate the contract call with MAX_GAS_PER_TX to get the complete gas_used + // 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) } diff --git a/packages/fuels-core/src/utils/constants.rs b/packages/fuels-core/src/utils/constants.rs index 32521c31a5..23673d4287 100644 --- a/packages/fuels-core/src/utils/constants.rs +++ b/packages/fuels-core/src/utils/constants.rs @@ -6,7 +6,7 @@ pub const WORD_SIZE: usize = core::mem::size_of::(); // 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 @@ -17,4 +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; From 1ddaf7d9767b79dfd4267ef874ca409dd491b343 Mon Sep 17 00:00:00 2001 From: segfault_magnet Date: Wed, 30 Aug 2023 16:12:24 +0200 Subject: [PATCH 4/4] fix signing test --- packages/fuels-accounts/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fuels-accounts/src/lib.rs b/packages/fuels-accounts/src/lib.rs index 4b85d2b16f..97faf8e878 100644 --- a/packages/fuels-accounts/src/lib.rs +++ b/packages/fuels-accounts/src/lib.rs @@ -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)?;