Repository: MystenLabs/sui
File: sui-execution/src/executor.rs (Rust)

Code before:
pub fn dev_inspect_transaction_for_simulate(
    executor: &dyn Executor,
    store: &dyn BackingStore,
    protocol_config: &ProtocolConfig,
    metrics: Arc<LimitsMetrics>,
    enable_expensive_checks: bool,
    execution_params: ExecutionOrEarlyError,
    epoch_id: &EpochId,
    epoch_timestamp_ms: u64,
    input_objects: CheckedInputObjects,
    gas: GasData,
    gas_status: SuiGasStatus,
    transaction_kind: TransactionKind,
    transaction_signer: SuiAddress,
    transaction_digest: TransactionDigest,
    skip_all_checks: bool,
    address_funds: &BTreeSet<AccumulatorObjId>,
) -> (
    InnerTemporaryStore,
    SuiGasStatus,
    TransactionEffects,
    Result<Vec<ExecutionResult>, ExecutionError>,
) {
    let cloned_input_objects = input_objects.clone();
    let cloned_gas = gas.clone();
    let cloned_gas_status = gas_status.clone();
    let cloned_kind = transaction_kind.clone();

    let (inner_temp_store, gas_status, effects, result) = executor.dev_inspect_transaction(
        store,
        protocol_config,
        metrics.clone(),
        enable_expensive_checks,
        execution_params,
        epoch_id,
        epoch_timestamp_ms,
        input_objects,
        gas,
        gas_status,
        transaction_kind,
        transaction_signer,
        transaction_digest,
        skip_all_checks,
    );

    if result.is_ok()
        && !inner_temp_store.has_sufficient_object_funds_for_simulate(address_funds, store)
    {
        return executor.dev_inspect_transaction(
            store,
            protocol_config,

Review comment (bug):
I do not like having the ability to close a gas status conceptually, as 99.9999% (maybe some more 9s) of the time, it is the wrong thing to do. I'm not sure if @tzakian has thoughts on alternatives here. 

Since it is for dev inspect, could you just pass in two different gas statuses? 

Code after:
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_trace_format::format::MoveTraceBuilder;
use std::sync::Arc;
use sui_protocol_config::ProtocolConfig;
use sui_types::execution::ExecutionTiming;
use sui_types::execution_params::ExecutionOrEarlyError;
use sui_types::storage::BackingStore;
use sui_types::transaction::GasData;
use sui_types::{
    base_types::SuiAddress,
    committee::EpochId,
    digests::TransactionDigest,
    effects::TransactionEffects,
    error::ExecutionError,
    execution::{ExecutionResult, TypeLayoutStore},
    gas::SuiGasStatus,
    inner_temporary_store::InnerTemporaryStore,
    layout_resolver::LayoutResolver,
    metrics::LimitsMetrics,
    transaction::{CheckedInputObjects, ProgrammableTransaction, TransactionKind},
};

/// Abstracts over access to the VM across versions of the execution layer.
pub trait Executor {
    fn execute_transaction_to_effects(
        &self,
        store: &dyn BackingStore,
        // Configuration
        protocol_config: &ProtocolConfig,
        metrics: Arc<LimitsMetrics>,
        enable_expensive_checks: bool,
        execution_params: ExecutionOrEarlyError,
        // Epoch
        epoch_id: &EpochId,
        epoch_timestamp_ms: u64,
        // Transaction Inputs
        input_objects: CheckedInputObjects,
        // Gas related
        gas: GasData,
        gas_status: SuiGasStatus,
        // Transaction
        transaction_kind: TransactionKind,
        transaction_signer: SuiAddress,
        transaction_digest: TransactionDigest,
        trace_builder_opt: &mut Option<MoveTraceBuilder>,
    ) -> (
        InnerTemporaryStore,
        SuiGasStatus,
        TransactionEffects,
        Vec<ExecutionTiming>,
        Result<(), ExecutionError>,
    );

    fn dev_inspect_transaction(
        &self,
        store: &dyn BackingStore,
        // Configuration
        protocol_config: &ProtocolConfig,
        metrics: Arc<LimitsMetrics>,
        enable_expensive_checks: bool,
        execution_params: ExecutionOrEarlyError,
        // Epoch
        epoch_id: &EpochId,
        epoch_timestamp_ms: u64,
        // Transaction Inputs
        input_objects: CheckedInputObjects,
        // Gas related
        gas: GasData,
        gas_status: SuiGasStatus,
        // Transaction
        transaction_kind: TransactionKind,
        transaction_signer: SuiAddress,
        transaction_digest: TransactionDigest,
        skip_all_checks: bool,
    ) -> (
        InnerTemporaryStore,
        SuiGasStatus,
        TransactionEffects,
        Result<Vec<ExecutionResult>, ExecutionError>,
    );

    fn update_genesis_state(
        &self,
        store: &dyn BackingStore,
        // Configuration
        protocol_config: &ProtocolConfig,
        metrics: Arc<LimitsMetrics>,
        // Epoch
        epoch_id: EpochId,
        epoch_timestamp_ms: u64,
        // Genesis Digest
        transaction_digest: &TransactionDigest,
        // Transaction
        input_objects: CheckedInputObjects,
        pt: ProgrammableTransaction,
    ) -> Result<InnerTemporaryStore, ExecutionError>;

    fn type_layout_resolver<'r, 'vm: 'r, 'store: 'r>(
        &'vm self,
        store: Box<dyn TypeLayoutStore + 'store>,
    ) -> Box<dyn LayoutResolver + 'r>;
}