From 3073daa19edaf745c4d67860ca79e9245b03b0ca Mon Sep 17 00:00:00 2001 From: Voxelot Date: Fri, 4 Oct 2024 18:46:19 -0700 Subject: [PATCH] removing clone constraint, trying to reason through the async issues --- fuel-vm/src/checked_transaction.rs | 32 ++++++++-------- fuel-vm/src/checked_transaction/builder.rs | 4 +- fuel-vm/src/interpreter/executors/main.rs | 7 ++-- .../src/interpreter/executors/predicate.rs | 2 +- fuel-vm/src/storage/predicate.rs | 38 ++++++++----------- fuel-vm/src/util.rs | 20 +++++----- 6 files changed, 48 insertions(+), 55 deletions(-) diff --git a/fuel-vm/src/checked_transaction.rs b/fuel-vm/src/checked_transaction.rs index 3beced2f2..0eeceb445 100644 --- a/fuel-vm/src/checked_transaction.rs +++ b/fuel-vm/src/checked_transaction.rs @@ -303,7 +303,7 @@ pub trait IntoChecked: FormatValidityChecks + Sized { ) -> Result, CheckError> where Checked: CheckPredicates, - S: StorageRead + Clone, + S: StorageRead, { self.into_checked_reusable_memory( block_height, @@ -324,7 +324,7 @@ pub trait IntoChecked: FormatValidityChecks + Sized { ) -> Result, CheckError> where Checked: CheckPredicates, - S: StorageRead + Clone, + S: StorageRead, { let check_predicate_params = consensus_params.into(); self.into_checked_basic(block_height, consensus_params)? @@ -406,7 +406,7 @@ pub trait CheckPredicates: Sized { storage: S, ) -> Result where - S: StorageRead + Clone; + S: StorageRead; /// Performs predicates verification of the transaction in parallel. async fn check_predicates_async( @@ -416,7 +416,7 @@ pub trait CheckPredicates: Sized { storage: S, ) -> Result where - S: StorageRead + Clone + Send + 'static; + S: StorageRead + Send + 'static; } /// Provides predicate estimation functionality for the transaction. @@ -430,7 +430,7 @@ pub trait EstimatePredicates: Sized { storage: S, ) -> Result<(), CheckError> where - S: StorageRead + Clone; + S: StorageRead; /// Estimates predicates of the transaction in parallel. async fn estimate_predicates_async( @@ -440,7 +440,7 @@ pub trait EstimatePredicates: Sized { storage: S, ) -> Result<(), CheckError> where - S: StorageRead + Clone + Send + 'static; + S: StorageRead + Send + 'static; } /// Executes CPU-heavy tasks in parallel. @@ -475,7 +475,7 @@ where storage: S, ) -> Result where - S: StorageRead + Clone, + S: StorageRead, { if !self.checks_bitmask.contains(Checks::Predicates) { Interpreter::<&mut MemoryInstance, PredicateStorage, Tx>::check_predicates(&self, params, memory, storage)?; @@ -492,7 +492,7 @@ where ) -> Result where E: ParallelExecutor, - S: StorageRead + Clone + Send + 'static, + S: StorageRead + Send + 'static, { if !self.checks_bitmask.contains(Checks::Predicates) { Interpreter::check_predicates_async::(&self, params, pool, storage) @@ -516,7 +516,7 @@ impl EstimatePredicates for T storage: S, ) -> Result<(), CheckError> where - S: StorageRead + Clone, + S: StorageRead, { Interpreter::estimate_predicates(self, params, memory, storage)?; Ok(()) @@ -530,7 +530,7 @@ impl EstimatePredicates for T ) -> Result<(), CheckError> where E: ParallelExecutor, - S: StorageRead + Clone + Send + 'static, + S: StorageRead + Send + 'static, { Interpreter::estimate_predicates_async::(self, params, pool, storage).await?; @@ -547,7 +547,7 @@ impl EstimatePredicates for Transaction { storage: S, ) -> Result<(), CheckError> where - S: StorageRead + Clone, + S: StorageRead, { match self { Self::Script(tx) => tx.estimate_predicates(params, memory, storage), @@ -566,7 +566,7 @@ impl EstimatePredicates for Transaction { storage: S, ) -> Result<(), CheckError> where - S: StorageRead + Clone + Send + 'static, + S: StorageRead + Send + 'static, { match self { Self::Script(tx) => { @@ -603,7 +603,7 @@ impl CheckPredicates for Checked { _storage: S, ) -> Result where - S: StorageRead + Clone, + S: StorageRead, { self.checks_bitmask.insert(Checks::Predicates); Ok(self) @@ -616,7 +616,7 @@ impl CheckPredicates for Checked { _storage: S, ) -> Result where - S: StorageRead + Clone + Send + 'static, + S: StorageRead + Send + 'static, { self.checks_bitmask.insert(Checks::Predicates); Ok(self) @@ -632,7 +632,7 @@ impl CheckPredicates for Checked { storage: S, ) -> Result where - S: StorageRead + Clone, + S: StorageRead, { let checked_transaction: CheckedTransaction = self.into(); let checked_transaction: CheckedTransaction = match checked_transaction { @@ -666,7 +666,7 @@ impl CheckPredicates for Checked { ) -> Result where E: ParallelExecutor, - S: StorageRead + Clone + Send + 'static, + S: StorageRead + Send + 'static, { let checked_transaction: CheckedTransaction = self.into(); diff --git a/fuel-vm/src/checked_transaction/builder.rs b/fuel-vm/src/checked_transaction/builder.rs index 2c1ff7dd0..223c7df18 100644 --- a/fuel-vm/src/checked_transaction/builder.rs +++ b/fuel-vm/src/checked_transaction/builder.rs @@ -25,7 +25,7 @@ where fn finalize_checked( &self, height: BlockHeight, - storage: impl StorageRead + Clone, + storage: impl StorageRead, ) -> Checked; /// Finalize the builder into a [`Checked`] of the correct type, with basic checks @@ -41,7 +41,7 @@ where fn finalize_checked( &self, height: BlockHeight, - storage: impl StorageRead + Clone, + storage: impl StorageRead, ) -> Checked { self.finalize() .into_checked(height, self.get_params(), storage) diff --git a/fuel-vm/src/interpreter/executors/main.rs b/fuel-vm/src/interpreter/executors/main.rs index 9aad5c383..edde6f927 100644 --- a/fuel-vm/src/interpreter/executors/main.rs +++ b/fuel-vm/src/interpreter/executors/main.rs @@ -143,7 +143,7 @@ enum PredicateAction { impl Interpreter<&mut MemoryInstance, PredicateStorage, Tx> where Tx: ExecutableTransaction, - S: StorageRead + Clone, + S: StorageRead, { /// Initialize the VM with the provided transaction and check all predicates defined /// in the inputs. @@ -278,7 +278,7 @@ where let tx = kind.tx().clone(); let my_params = params.clone(); let mut memory = pool.get_new().await; - let my_storage = storage.clone(); + let my_storage = &storage; let verify_task = E::create_task(move || { let (used_gas, result) = Interpreter::check_predicate( @@ -319,7 +319,6 @@ where for index in 0..kind.tx().inputs().len() { let tx = kind.tx().clone(); - let storage = storage.clone(); if let Some(predicate) = RuntimePredicate::from_tx(&tx, params.tx_offset, index) @@ -337,7 +336,7 @@ where predicate, params.clone(), memory.as_mut(), - storage, + &storage, ); available_gas = available_gas.saturating_sub(gas_used); let result = result.map(|_| (gas_used, index)); diff --git a/fuel-vm/src/interpreter/executors/predicate.rs b/fuel-vm/src/interpreter/executors/predicate.rs index 720680420..829d61da0 100644 --- a/fuel-vm/src/interpreter/executors/predicate.rs +++ b/fuel-vm/src/interpreter/executors/predicate.rs @@ -24,7 +24,7 @@ where M: Memory, Tx: ExecutableTransaction, Ecal: EcalHandler, - S: StorageRead + Clone, + S: StorageRead, { /// Verify a predicate that has been initialized already pub(crate) fn verify_predicate( diff --git a/fuel-vm/src/storage/predicate.rs b/fuel-vm/src/storage/predicate.rs index 657002551..f463823a1 100644 --- a/fuel-vm/src/storage/predicate.rs +++ b/fuel-vm/src/storage/predicate.rs @@ -14,7 +14,6 @@ use core::fmt::Debug; use fuel_asm::Word; use fuel_storage::{ Mappable, - StorageAsMut, StorageInspect, StorageMutate, StorageRead, @@ -42,19 +41,17 @@ use super::{ /// operations. However, predicates, as defined in the protocol, cannot execute contract /// opcodes. This means its storage backend for predicate execution shouldn't provide any /// functionality. Unless the storage access is limited to immutable data and read-only. -#[derive(Debug, Default, Clone, Copy)] -pub struct PredicateStorage + Clone> { +#[derive(Debug, Default)] +pub struct PredicateStorage> { storage: D, } -impl + Clone> PredicateStorage { +impl> PredicateStorage { pub fn new(storage: D) -> Self { Self { storage } } } -// pub trait StorageRead + Clone: StorageRead + Clone {} - #[derive(Debug, Clone, Copy)] pub enum PredicateStorageError { /// Storage operation is unavailable in predicate context. @@ -96,7 +93,7 @@ impl From for RuntimeError { impl StorageInspect for PredicateStorage where Type: Mappable, - D: StorageRead + Clone, + D: StorageRead, { type Error = PredicateStorageError; @@ -115,7 +112,7 @@ where impl StorageMutate for PredicateStorage where Type: Mappable, - D: StorageRead + Clone, + D: StorageRead, { fn replace( &mut self, @@ -135,7 +132,7 @@ where impl StorageSize for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn size_of_value(&self, _key: &ContractId) -> Result, Self::Error> { Err(Self::Error::UnsupportedStorageOperation) @@ -144,7 +141,7 @@ where impl StorageRead for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn read( &self, @@ -164,7 +161,7 @@ where impl StorageWrite for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn write_bytes( &mut self, @@ -192,7 +189,7 @@ where impl StorageSize for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn size_of_value( &self, @@ -204,7 +201,7 @@ where impl StorageRead for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn read( &self, @@ -224,7 +221,7 @@ where impl StorageWrite for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn write_bytes( &mut self, @@ -252,7 +249,7 @@ where impl StorageSize for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn size_of_value( &self, @@ -265,7 +262,7 @@ where impl StorageRead for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn read( &self, @@ -287,7 +284,7 @@ where impl StorageWrite for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { fn write_bytes( &mut self, @@ -313,14 +310,11 @@ where } } -impl ContractsAssetsStorage for PredicateStorage where - D: StorageRead + Clone -{ -} +impl ContractsAssetsStorage for PredicateStorage where D: StorageRead {} impl InterpreterStorage for PredicateStorage where - D: StorageRead + Clone, + D: StorageRead, { type DataError = PredicateStorageError; diff --git a/fuel-vm/src/util.rs b/fuel-vm/src/util.rs index f33279cb6..1cbd2ba01 100644 --- a/fuel-vm/src/util.rs +++ b/fuel-vm/src/util.rs @@ -359,7 +359,7 @@ pub mod test_helpers { pub fn build(&mut self, storage: S) -> Checked