radix_engine/blueprints/transaction_processor/
blueprint.rs

1use crate::blueprints::transaction_processor::{IntentProcessor, ResumeResult};
2use crate::errors::RuntimeError;
3use crate::internal_prelude::Sbor;
4use crate::kernel::kernel_api::{KernelNodeApi, KernelSubstateApi};
5use radix_common::crypto::Hash;
6use radix_common::prelude::{GlobalAddressReservation, Reference};
7use radix_engine_interface::api::SystemApi;
8use radix_engine_interface::blueprints::transaction_processor::InstructionOutput;
9use radix_rust::prelude::IndexMap;
10use radix_rust::prelude::*;
11use radix_transactions::model::InstructionV1;
12
13#[cfg(not(feature = "coverage"))]
14pub const MAX_TOTAL_BLOB_SIZE_PER_INVOCATION: usize = 1024 * 1024;
15#[cfg(feature = "coverage")]
16pub const MAX_TOTAL_BLOB_SIZE_PER_INVOCATION: usize = 64 * 1024 * 1024;
17
18/// The minor version of the TransactionProcessor V1 package
19#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Sbor)]
20pub enum TransactionProcessorV1MinorVersion {
21    Zero,
22    One,
23}
24
25pub struct TransactionProcessorBlueprint;
26
27impl TransactionProcessorBlueprint {
28    pub(crate) fn run<
29        Y: SystemApi<RuntimeError> + KernelNodeApi + KernelSubstateApi<L>,
30        L: Default,
31    >(
32        manifest_encoded_instructions: Vec<u8>,
33        global_address_reservations: Vec<GlobalAddressReservation>,
34        _references: Vec<Reference>, // Required so that the kernel passes the references to the processor frame
35        blobs: IndexMap<Hash, Vec<u8>>,
36        version: TransactionProcessorV1MinorVersion,
37        api: &mut Y,
38    ) -> Result<Vec<InstructionOutput>, RuntimeError> {
39        let max_total_size_of_blobs = match version {
40            TransactionProcessorV1MinorVersion::Zero => usize::MAX,
41            TransactionProcessorV1MinorVersion::One => MAX_TOTAL_BLOB_SIZE_PER_INVOCATION,
42        };
43        let mut txn_processor_single_thread = IntentProcessor::<InstructionV1>::init(
44            manifest_encoded_instructions.as_slice(),
45            &global_address_reservations,
46            &blobs,
47            max_total_size_of_blobs,
48            api,
49        )?;
50        let resume_result = txn_processor_single_thread.resume(None, api)?;
51        if !matches!(resume_result, ResumeResult::Done) {
52            panic!("Unexpected yield occurred in v1 transaction processing");
53        }
54        Ok(txn_processor_single_thread.outputs)
55    }
56}