Skip to main content

sui_types/
transaction_executor.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::base_types::ObjectID;
5use crate::effects::TransactionEffects;
6use crate::effects::TransactionEvents;
7use crate::error::ExecutionError;
8use crate::error::SuiError;
9use crate::execution::ExecutionResult;
10use crate::full_checkpoint_content::ObjectSet;
11use crate::storage::ObjectKey;
12use crate::transaction::AllowedProposers;
13use crate::transaction::TransactionData;
14use crate::transaction_driver_types::ExecuteTransactionRequestV3;
15use crate::transaction_driver_types::ExecuteTransactionResponseV3;
16use crate::transaction_driver_types::TransactionSubmissionError;
17
18/// Trait to define the interface for how the gRPC service interacts with a  QuorumDriver or a
19/// simulated transaction executor.
20#[async_trait::async_trait]
21pub trait TransactionExecutor: Send + Sync {
22    async fn execute_transaction(
23        &self,
24        request: ExecuteTransactionRequestV3,
25        client_addr: Option<std::net::SocketAddr>,
26    ) -> Result<ExecuteTransactionResponseV3, TransactionSubmissionError>;
27
28    fn simulate_transaction(
29        &self,
30        transaction: TransactionData,
31        checks: TransactionChecks,
32        allow_mock_gas_coin: bool,
33    ) -> Result<SimulateTransactionResult, SuiError>;
34}
35
36/// Trait to let the gRPC service name the validators a transaction should be submitted to,
37/// without depending on the transaction driver that tracks them.
38pub trait ProposerSelector: Send + Sync {
39    /// Up to `max` validators this node would prefer to submit to, as committee indices for the
40    /// current epoch. `None` when no preference can be formed, in which case the transaction is
41    /// left unrestricted rather than pinned to an arbitrary set.
42    ///
43    /// The returned indices are strictly increasing, as `TransactionExpiration::Validity`
44    /// requires.
45    fn preferred_proposers(&self, max: usize) -> Option<AllowedProposers>;
46}
47
48pub struct SimulateTransactionResult {
49    pub effects: TransactionEffects,
50    pub events: Option<TransactionEvents>,
51    pub objects: ObjectSet,
52    pub execution_result: Result<Vec<ExecutionResult>, ExecutionError>,
53    pub mock_gas_id: Option<ObjectID>,
54    pub unchanged_loaded_runtime_objects: Vec<ObjectKey>,
55    pub suggested_gas_price: Option<u64>,
56}
57
58#[derive(Default, Debug, Copy, Clone)]
59pub enum TransactionChecks {
60    #[default]
61    Enabled,
62    Disabled,
63}
64
65impl TransactionChecks {
66    pub fn disabled(self) -> bool {
67        matches!(self, Self::Disabled)
68    }
69
70    pub fn enabled(self) -> bool {
71        matches!(self, Self::Enabled)
72    }
73}