Skip to content

Commit

Permalink
removing clone constraint, trying to reason through the async issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Voxelot committed Oct 5, 2024
1 parent 2da51b1 commit 3073daa
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 55 deletions.
32 changes: 16 additions & 16 deletions fuel-vm/src/checked_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ pub trait IntoChecked: FormatValidityChecks + Sized {
) -> Result<Checked<Self>, CheckError>
where
Checked<Self>: CheckPredicates,
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
self.into_checked_reusable_memory(
block_height,
Expand All @@ -324,7 +324,7 @@ pub trait IntoChecked: FormatValidityChecks + Sized {
) -> Result<Checked<Self>, CheckError>
where
Checked<Self>: CheckPredicates,
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
let check_predicate_params = consensus_params.into();
self.into_checked_basic(block_height, consensus_params)?
Expand Down Expand Up @@ -406,7 +406,7 @@ pub trait CheckPredicates: Sized {
storage: S,
) -> Result<Self, CheckError>
where
S: StorageRead<BlobData> + Clone;
S: StorageRead<BlobData>;

/// Performs predicates verification of the transaction in parallel.
async fn check_predicates_async<E: ParallelExecutor, S>(
Expand All @@ -416,7 +416,7 @@ pub trait CheckPredicates: Sized {
storage: S,
) -> Result<Self, CheckError>
where
S: StorageRead<BlobData> + Clone + Send + 'static;
S: StorageRead<BlobData> + Send + 'static;
}

/// Provides predicate estimation functionality for the transaction.
Expand All @@ -430,7 +430,7 @@ pub trait EstimatePredicates: Sized {
storage: S,
) -> Result<(), CheckError>
where
S: StorageRead<BlobData> + Clone;
S: StorageRead<BlobData>;

/// Estimates predicates of the transaction in parallel.
async fn estimate_predicates_async<E: ParallelExecutor, S>(
Expand All @@ -440,7 +440,7 @@ pub trait EstimatePredicates: Sized {
storage: S,
) -> Result<(), CheckError>
where
S: StorageRead<BlobData> + Clone + Send + 'static;
S: StorageRead<BlobData> + Send + 'static;
}

/// Executes CPU-heavy tasks in parallel.
Expand Down Expand Up @@ -475,7 +475,7 @@ where
storage: S,
) -> Result<Self, CheckError>
where
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
if !self.checks_bitmask.contains(Checks::Predicates) {
Interpreter::<&mut MemoryInstance, PredicateStorage<S>, Tx>::check_predicates(&self, params, memory, storage)?;
Expand All @@ -492,7 +492,7 @@ where
) -> Result<Self, CheckError>
where
E: ParallelExecutor,
S: StorageRead<BlobData> + Clone + Send + 'static,
S: StorageRead<BlobData> + Send + 'static,
{
if !self.checks_bitmask.contains(Checks::Predicates) {
Interpreter::check_predicates_async::<E>(&self, params, pool, storage)
Expand All @@ -516,7 +516,7 @@ impl<Tx: ExecutableTransaction + Send + Sync + 'static> EstimatePredicates for T
storage: S,
) -> Result<(), CheckError>
where
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
Interpreter::estimate_predicates(self, params, memory, storage)?;
Ok(())
Expand All @@ -530,7 +530,7 @@ impl<Tx: ExecutableTransaction + Send + Sync + 'static> EstimatePredicates for T
) -> Result<(), CheckError>
where
E: ParallelExecutor,
S: StorageRead<BlobData> + Clone + Send + 'static,
S: StorageRead<BlobData> + Send + 'static,
{
Interpreter::estimate_predicates_async::<E>(self, params, pool, storage).await?;

Expand All @@ -547,7 +547,7 @@ impl EstimatePredicates for Transaction {
storage: S,
) -> Result<(), CheckError>
where
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
match self {
Self::Script(tx) => tx.estimate_predicates(params, memory, storage),
Expand All @@ -566,7 +566,7 @@ impl EstimatePredicates for Transaction {
storage: S,
) -> Result<(), CheckError>
where
S: StorageRead<BlobData> + Clone + Send + 'static,
S: StorageRead<BlobData> + Send + 'static,
{
match self {
Self::Script(tx) => {
Expand Down Expand Up @@ -603,7 +603,7 @@ impl CheckPredicates for Checked<Mint> {
_storage: S,
) -> Result<Self, CheckError>
where
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
self.checks_bitmask.insert(Checks::Predicates);
Ok(self)
Expand All @@ -616,7 +616,7 @@ impl CheckPredicates for Checked<Mint> {
_storage: S,
) -> Result<Self, CheckError>
where
S: StorageRead<BlobData> + Clone + Send + 'static,
S: StorageRead<BlobData> + Send + 'static,
{
self.checks_bitmask.insert(Checks::Predicates);
Ok(self)
Expand All @@ -632,7 +632,7 @@ impl CheckPredicates for Checked<Transaction> {
storage: S,
) -> Result<Self, CheckError>
where
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
let checked_transaction: CheckedTransaction = self.into();
let checked_transaction: CheckedTransaction = match checked_transaction {
Expand Down Expand Up @@ -666,7 +666,7 @@ impl CheckPredicates for Checked<Transaction> {
) -> Result<Self, CheckError>
where
E: ParallelExecutor,
S: StorageRead<BlobData> + Clone + Send + 'static,
S: StorageRead<BlobData> + Send + 'static,
{
let checked_transaction: CheckedTransaction = self.into();

Expand Down
4 changes: 2 additions & 2 deletions fuel-vm/src/checked_transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
fn finalize_checked(
&self,
height: BlockHeight,
storage: impl StorageRead<BlobData> + Clone,
storage: impl StorageRead<BlobData>,
) -> Checked<Tx>;

/// Finalize the builder into a [`Checked<Tx>`] of the correct type, with basic checks
Expand All @@ -41,7 +41,7 @@ where
fn finalize_checked(
&self,
height: BlockHeight,
storage: impl StorageRead<BlobData> + Clone,
storage: impl StorageRead<BlobData>,
) -> Checked<Tx> {
self.finalize()
.into_checked(height, self.get_params(), storage)
Expand Down
7 changes: 3 additions & 4 deletions fuel-vm/src/interpreter/executors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ enum PredicateAction {
impl<Tx, S> Interpreter<&mut MemoryInstance, PredicateStorage<S>, Tx>
where
Tx: ExecutableTransaction,
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
/// Initialize the VM with the provided transaction and check all predicates defined
/// in the inputs.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion fuel-vm/src/interpreter/executors/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
M: Memory,
Tx: ExecutableTransaction,
Ecal: EcalHandler,
S: StorageRead<BlobData> + Clone,
S: StorageRead<BlobData>,
{
/// Verify a predicate that has been initialized already
pub(crate) fn verify_predicate(
Expand Down
38 changes: 16 additions & 22 deletions fuel-vm/src/storage/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use core::fmt::Debug;
use fuel_asm::Word;
use fuel_storage::{
Mappable,
StorageAsMut,
StorageInspect,
StorageMutate,
StorageRead,
Expand Down Expand Up @@ -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<D: StorageRead<BlobData> + Clone> {
#[derive(Debug, Default)]
pub struct PredicateStorage<D: StorageRead<BlobData>> {
storage: D,
}

impl<D: StorageRead<BlobData> + Clone> PredicateStorage<D> {
impl<D: StorageRead<BlobData>> PredicateStorage<D> {
pub fn new(storage: D) -> Self {
Self { storage }
}
}

// pub trait StorageRead<BlobData> + Clone: StorageRead<BlobData> + Clone {}

#[derive(Debug, Clone, Copy)]
pub enum PredicateStorageError {
/// Storage operation is unavailable in predicate context.
Expand Down Expand Up @@ -96,7 +93,7 @@ impl From<StorageUnavailable> for RuntimeError<StorageUnavailable> {
impl<Type, D> StorageInspect<Type> for PredicateStorage<D>
where
Type: Mappable,
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
type Error = PredicateStorageError;

Expand All @@ -115,7 +112,7 @@ where
impl<Type, D> StorageMutate<Type> for PredicateStorage<D>
where
Type: Mappable,
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn replace(
&mut self,
Expand All @@ -135,7 +132,7 @@ where

impl<D> StorageSize<ContractsRawCode> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn size_of_value(&self, _key: &ContractId) -> Result<Option<usize>, Self::Error> {
Err(Self::Error::UnsupportedStorageOperation)
Expand All @@ -144,7 +141,7 @@ where

impl<D> StorageRead<ContractsRawCode> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn read(
&self,
Expand All @@ -164,7 +161,7 @@ where

impl<D> StorageWrite<ContractsRawCode> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn write_bytes(
&mut self,
Expand Down Expand Up @@ -192,7 +189,7 @@ where

impl<D> StorageSize<ContractsState> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn size_of_value(
&self,
Expand All @@ -204,7 +201,7 @@ where

impl<D> StorageRead<ContractsState> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn read(
&self,
Expand All @@ -224,7 +221,7 @@ where

impl<D> StorageWrite<ContractsState> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn write_bytes(
&mut self,
Expand Down Expand Up @@ -252,7 +249,7 @@ where

impl<D> StorageSize<BlobData> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn size_of_value(
&self,
Expand All @@ -265,7 +262,7 @@ where

impl<D> StorageRead<BlobData> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn read(
&self,
Expand All @@ -287,7 +284,7 @@ where

impl<D> StorageWrite<BlobData> for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
fn write_bytes(
&mut self,
Expand All @@ -313,14 +310,11 @@ where
}
}

impl<D> ContractsAssetsStorage for PredicateStorage<D> where
D: StorageRead<BlobData> + Clone
{
}
impl<D> ContractsAssetsStorage for PredicateStorage<D> where D: StorageRead<BlobData> {}

impl<D> InterpreterStorage for PredicateStorage<D>
where
D: StorageRead<BlobData> + Clone,
D: StorageRead<BlobData>,
{
type DataError = PredicateStorageError;

Expand Down
Loading

0 comments on commit 3073daa

Please sign in to comment.