From d7546e2bf1ca0383b6be059ac13ee6c05d2cc496 Mon Sep 17 00:00:00 2001 From: Turner Date: Wed, 21 Feb 2024 14:47:17 -0800 Subject: [PATCH] Remove `gas_price` from predicate execution functions --- fuel-vm/src/checked_transaction.rs | 72 ++++++----------------- fuel-vm/src/interpreter/executors/main.rs | 31 +++------- 2 files changed, 27 insertions(+), 76 deletions(-) diff --git a/fuel-vm/src/checked_transaction.rs b/fuel-vm/src/checked_transaction.rs index bfa321c935..338ea1c1b5 100644 --- a/fuel-vm/src/checked_transaction.rs +++ b/fuel-vm/src/checked_transaction.rs @@ -136,13 +136,7 @@ where { fn default() -> Self { let gas_price = 0; - Tx::default() - .into_checked( - Default::default(), - &ConsensusParameters::standard(), - gas_price, - ) - .expect("default tx should produce a valid fully checked transaction") + Self::default_with_gas_price(gas_price) } } @@ -222,7 +216,7 @@ pub trait IntoChecked: FormatValidityChecks + Sized { let check_predicate_params = consensus_params.into(); self.into_checked_basic(block_height, consensus_params, gas_price)? .check_signatures(&consensus_params.chain_id)? - .check_predicates(gas_price, &check_predicate_params) + .check_predicates(&check_predicate_params) } /// Returns transaction that passed only `Checks::Basic`. @@ -292,16 +286,11 @@ impl From<&ConsensusParameters> for CheckPredicateParams { #[async_trait::async_trait] pub trait CheckPredicates: Sized { /// Performs predicates verification of the transaction. - fn check_predicates( - self, - gas_price: Word, - params: &CheckPredicateParams, - ) -> Result; + fn check_predicates(self, params: &CheckPredicateParams) -> Result; /// Performs predicates verification of the transaction in parallel. async fn check_predicates_async( self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result; } @@ -312,14 +301,12 @@ pub trait EstimatePredicates: Sized { /// Estimates predicates of the transaction. fn estimate_predicates( &mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result<(), CheckError>; /// Estimates predicates of the transaction in parallel. async fn estimate_predicates_async( &mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result<(), CheckError>; } @@ -351,13 +338,10 @@ where { fn check_predicates( mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result { if !self.checks_bitmask.contains(Checks::Predicates) { - Interpreter::::check_predicates( - &self, gas_price, params, - )?; + Interpreter::::check_predicates(&self, params)?; self.checks_bitmask.insert(Checks::Predicates); } Ok(self) @@ -365,7 +349,6 @@ where async fn check_predicates_async( mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result where @@ -373,7 +356,7 @@ where { if !self.checks_bitmask.contains(Checks::Predicates) { Interpreter::::check_predicates_async::( - &self, gas_price, params, + &self, params, ) .await?; @@ -390,25 +373,21 @@ where impl EstimatePredicates for Tx { fn estimate_predicates( &mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result<(), CheckError> { - Interpreter::::estimate_predicates(self, gas_price, params)?; + Interpreter::::estimate_predicates(self, params)?; Ok(()) } async fn estimate_predicates_async( &mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result<(), CheckError> where E: ParallelExecutor, { - Interpreter::::estimate_predicates_async::( - self, gas_price, params, - ) - .await?; + Interpreter::::estimate_predicates_async::(self, params) + .await?; Ok(()) } @@ -418,31 +397,25 @@ impl EstimatePredicates for T impl EstimatePredicates for Transaction { fn estimate_predicates( &mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result<(), CheckError> { match self { - Transaction::Script(script) => script.estimate_predicates(gas_price, params), - Transaction::Create(create) => create.estimate_predicates(gas_price, params), + Transaction::Script(script) => script.estimate_predicates(params), + Transaction::Create(create) => create.estimate_predicates(params), Transaction::Mint(_) => Ok(()), } } async fn estimate_predicates_async( &mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result<(), CheckError> { match self { Transaction::Script(script) => { - script - .estimate_predicates_async::(gas_price, params) - .await + script.estimate_predicates_async::(params).await } Transaction::Create(create) => { - create - .estimate_predicates_async::(gas_price, params) - .await + create.estimate_predicates_async::(params).await } Transaction::Mint(_) => Ok(()), } @@ -453,7 +426,6 @@ impl EstimatePredicates for Transaction { impl CheckPredicates for Checked { fn check_predicates( mut self, - _gas_price: Word, _params: &CheckPredicateParams, ) -> Result { self.checks_bitmask.insert(Checks::Predicates); @@ -462,7 +434,6 @@ impl CheckPredicates for Checked { async fn check_predicates_async( mut self, - _gas_price: Word, _params: &CheckPredicateParams, ) -> Result { self.checks_bitmask.insert(Checks::Predicates); @@ -472,21 +443,17 @@ impl CheckPredicates for Checked { #[async_trait::async_trait] impl CheckPredicates for Checked { - fn check_predicates( - self, - gas_price: Word, - params: &CheckPredicateParams, - ) -> Result { + fn check_predicates(self, params: &CheckPredicateParams) -> Result { let checked_transaction: CheckedTransaction = self.into(); let checked_transaction: CheckedTransaction = match checked_transaction { CheckedTransaction::Script(tx) => { - CheckPredicates::check_predicates(tx, gas_price, params)?.into() + CheckPredicates::check_predicates(tx, params)?.into() } CheckedTransaction::Create(tx) => { - CheckPredicates::check_predicates(tx, gas_price, params)?.into() + CheckPredicates::check_predicates(tx, params)?.into() } CheckedTransaction::Mint(tx) => { - CheckPredicates::check_predicates(tx, gas_price, params)?.into() + CheckPredicates::check_predicates(tx, params)?.into() } }; Ok(checked_transaction.into()) @@ -494,7 +461,6 @@ impl CheckPredicates for Checked { async fn check_predicates_async( mut self, - gas_price: Word, params: &CheckPredicateParams, ) -> Result where @@ -504,17 +470,17 @@ impl CheckPredicates for Checked { let checked_transaction: CheckedTransaction = match checked_transaction { CheckedTransaction::Script(tx) => { - CheckPredicates::check_predicates_async::(tx, gas_price, params) + CheckPredicates::check_predicates_async::(tx, params) .await? .into() } CheckedTransaction::Create(tx) => { - CheckPredicates::check_predicates_async::(tx, gas_price, params) + CheckPredicates::check_predicates_async::(tx, params) .await? .into() } CheckedTransaction::Mint(tx) => { - CheckPredicates::check_predicates_async::(tx, gas_price, params) + CheckPredicates::check_predicates_async::(tx, params) .await? .into() } diff --git a/fuel-vm/src/interpreter/executors/main.rs b/fuel-vm/src/interpreter/executors/main.rs index 7d88321f34..e0b2fa011e 100644 --- a/fuel-vm/src/interpreter/executors/main.rs +++ b/fuel-vm/src/interpreter/executors/main.rs @@ -131,14 +131,13 @@ where /// predicates. pub fn check_predicates( checked: &Checked, - gas_price: Word, params: &CheckPredicateParams, ) -> Result where ::Metadata: CheckedMetadata, { let tx = checked.transaction(); - Self::run_predicate(PredicateRunKind::Verifying(tx), gas_price, params) + Self::run_predicate(PredicateRunKind::Verifying(tx), params) } /// Initialize the VM with the provided transaction and check all predicates defined @@ -148,7 +147,6 @@ where /// predicates. pub async fn check_predicates_async( checked: &Checked, - gas_price: Word, params: &CheckPredicateParams, ) -> Result where @@ -158,12 +156,9 @@ where { let tx = checked.transaction(); - let predicates_checked = Self::run_predicate_async::( - PredicateRunKind::Verifying(tx), - gas_price, - params, - ) - .await?; + let predicates_checked = + Self::run_predicate_async::(PredicateRunKind::Verifying(tx), params) + .await?; Ok(predicates_checked) } @@ -176,14 +171,10 @@ where /// predicates. pub fn estimate_predicates( transaction: &mut Tx, - gas_price: Word, params: &CheckPredicateParams, ) -> Result { - let predicates_checked = Self::run_predicate( - PredicateRunKind::Estimating(transaction), - gas_price, - params, - )?; + let predicates_checked = + Self::run_predicate(PredicateRunKind::Estimating(transaction), params)?; Ok(predicates_checked) } @@ -195,7 +186,6 @@ where /// predicates. pub async fn estimate_predicates_async( transaction: &mut Tx, - gas_price: Word, params: &CheckPredicateParams, ) -> Result where @@ -204,7 +194,6 @@ where { let predicates_checked = Self::run_predicate_async::( PredicateRunKind::Estimating(transaction), - gas_price, params, ) .await?; @@ -214,7 +203,6 @@ where async fn run_predicate_async( kind: PredicateRunKind<'_, Tx>, - gas_price: Word, params: &CheckPredicateParams, ) -> Result where @@ -238,7 +226,6 @@ where index, predicate_action, predicate, - gas_price, my_params, ) }); @@ -254,7 +241,6 @@ where fn run_predicate( kind: PredicateRunKind<'_, Tx>, - gas_price: Word, params: &CheckPredicateParams, ) -> Result { let predicate_action = PredicateAction::from(&kind); @@ -271,7 +257,6 @@ where index, predicate_action, predicate, - gas_price, params.clone(), )); } @@ -285,7 +270,6 @@ where index: usize, predicate_action: PredicateAction, predicate: RuntimePredicate, - gas_price: Word, params: CheckPredicateParams, ) -> Result<(Word, usize), PredicateVerificationFailed> { match &tx.inputs()[index] { @@ -313,7 +297,8 @@ where let max_gas_per_tx = params.max_gas_per_tx; let max_gas_per_predicate = params.max_gas_per_predicate; - let interpreter_params = InterpreterParams::new(gas_price, params); + let zero_gas_price = 0; + let interpreter_params = InterpreterParams::new(zero_gas_price, params); let mut vm = Self::with_storage(PredicateStorage {}, interpreter_params);