Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions applications/tari_app_utilities/src/transaction_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tari_engine::{
state_store::{memory::ReadOnlyMemoryStateStore, StateStoreError},
template::LoadedTemplate,
traits::ClaimProofVerifier,
transaction::{TransactionError, TransactionProcessor, TransactionProcessorConfig},
transaction::{TransactionError, TransactionProcessor},
};
use tari_engine_types::{commit_result::ExecuteResult, substate::Substate, virtual_substate::VirtualSubstates};
use tari_ootle_common_types::{
Expand Down Expand Up @@ -87,21 +87,18 @@ impl ExecutionOutput {
pub struct TariTransactionProcessor<TTemplateProvider> {
template_provider: Arc<TTemplateProvider>,
fee_table: FeeTable,
config: TransactionProcessorConfig,
claim_burn_proof_verifier: Arc<dyn ClaimProofVerifier + Send + Sync + 'static>,
}

impl<TTemplateProvider> TariTransactionProcessor<TTemplateProvider> {
pub fn new(
config: TransactionProcessorConfig,
template_provider: TTemplateProvider,
fee_table: FeeTable,
claim_burn_proof_verifier: Arc<dyn ClaimProofVerifier + Send + Sync + 'static>,
) -> Self {
Self {
template_provider: Arc::new(template_provider),
fee_table,
config,
claim_burn_proof_verifier,
}
}
Expand Down Expand Up @@ -132,7 +129,6 @@ where TTemplateProvider: TemplateProvider<Template = LoadedTemplate>
let modules: Vec<Arc<dyn RuntimeModule>> = vec![Arc::new(FeeModule::new(initial_cost, self.fee_table.clone()))];

let processor = TransactionProcessor::new(
self.config.clone(),
self.template_provider.clone(),
state_store,
auth_params,
Expand Down
6 changes: 3 additions & 3 deletions applications/tari_indexer/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use tari_base_node_client::grpc::GrpcBaseNodeClient;
use tari_common::configuration::bootstrap::{grpc_default_port, ApplicationType};
use tari_consensus::consensus_constants::ConsensusConstants;
use tari_crypto::tari_utilities::ByteArray;
use tari_engine::transaction::TransactionProcessorConfig;
use tari_engine_types::ToByteType;
use tari_epoch_manager::service::{EpochManagerConfig, EpochManagerHandle};
use tari_epoch_oracles::{
Expand All @@ -47,6 +46,7 @@ use tari_ootle_app_utilities::{
common::verify_correct_network,
configuration::convert_network_to_l1_network,
epoch_oracle_config::EpochOracleType,
fee_tables::get_fee_table_by_network,
keypair::RistrettoKeypair,
seed_peer::SeedPeer,
shared_consts::TXTR_FAUCET_INITIAL_SUPPLY,
Expand Down Expand Up @@ -237,9 +237,9 @@ pub async fn spawn_services(
let transaction_manager = TransactionManager::new(network_client.clone(), store.clone());

// dry run
let fee_table = get_fee_table_by_network(config.network);
let dry_run_transaction_processor = DryRunTransactionProcessor::new(
TransactionProcessorConfig::new(config.network)
.with_template_binary_max_size_bytes(consensus_constants.template_binary_max_size_bytes),
fee_table.clone(),
epoch_manager.clone(),
validator_node_client_factory.clone(),
template_manager.clone(),
Expand Down
30 changes: 8 additions & 22 deletions applications/tari_indexer/src/dry_run/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
use std::{collections::HashMap, sync::Arc};

use log::{debug, info};
use tari_engine::{state_store::new_memory_store, traits::ClaimProofVerifier, transaction::TransactionProcessorConfig};
use tari_engine::{fees::FeeTable, state_store::new_memory_store, traits::ClaimProofVerifier};
use tari_engine_types::{
commit_result::ExecuteResult,
substate::{Substate, SubstateId},
virtual_substate::{VirtualSubstate, VirtualSubstateId, VirtualSubstates},
};
use tari_epoch_manager::{service::EpochManagerHandle, EpochManagerReader};
use tari_ootle_app_utilities::{
fee_tables::get_fee_table_by_network,
transaction_executor::{TariTransactionProcessor, TransactionExecutor as _},
};
use tari_ootle_app_utilities::transaction_executor::{TariTransactionProcessor, TransactionExecutor as _};
use tari_ootle_common_types::{Epoch, PeerAddress, SubstateRequirement};
use tari_template_manager::implementation::TemplateManager;
use tari_transaction::Transaction;
Expand All @@ -51,27 +48,24 @@ const LOG_TARGET: &str = "tari::indexer::dry_run_transaction_processor";

#[derive(Clone)]
pub struct DryRunTransactionProcessor {
config: TransactionProcessorConfig,
processor: TariTransactionProcessor<TemplateManager<PeerAddress>>,
epoch_manager: EpochManagerHandle<PeerAddress>,
client_provider: TariValidatorNodeRpcClientFactory,
template_manager: TemplateManager<PeerAddress>,
claim_burn_proof_verifier: Arc<dyn ClaimProofVerifier + Send + Sync + 'static>,
}

impl DryRunTransactionProcessor {
pub fn new(
config: TransactionProcessorConfig,
fee_table: FeeTable,
epoch_manager: EpochManagerHandle<PeerAddress>,
client_provider: TariValidatorNodeRpcClientFactory,
template_manager: TemplateManager<PeerAddress>,
claim_burn_proof_verifier: impl ClaimProofVerifier + Send + Sync + 'static,
) -> Self {
let processor = TariTransactionProcessor::new(template_manager, fee_table, Arc::new(claim_burn_proof_verifier));
Self {
config,
processor,
epoch_manager,
client_provider,
template_manager,
claim_burn_proof_verifier: Arc::new(claim_burn_proof_verifier),
}
}

Expand All @@ -88,23 +82,15 @@ impl DryRunTransactionProcessor {
let epoch = self.epoch_manager.current_epoch().await?;
let found_substates = self.fetch_input_substates(&transaction, epoch).await?;

let fee_table = get_fee_table_by_network(self.config.network);

let payload_processor = TariTransactionProcessor::new(
self.config.clone(),
self.template_manager.clone(),
fee_table.clone(),
self.claim_burn_proof_verifier.clone(),
);

let virtual_substates = self.get_virtual_substates(&transaction, epoch).await?;

let mut state_store = new_memory_store();
state_store.set_many(found_substates)?;

// execute the payload in the WASM engine and return the result
let exec_output = task::block_in_place(|| {
payload_processor.execute(&transaction, state_store.into_read_only(), virtual_substates)
self.processor
.execute(&transaction, state_store.into_read_only(), virtual_substates)
})?;

Ok(exec_output.result)
Expand Down
3 changes: 0 additions & 3 deletions applications/tari_validator_node/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use tari_consensus::consensus_constants::ConsensusConstants;
#[cfg(not(feature = "metrics"))]
use tari_consensus::traits::hooks::NoopHooks;
use tari_crypto::tari_utilities::ByteArray;
use tari_engine::transaction::TransactionProcessorConfig;
use tari_engine_types::ToByteType;
use tari_epoch_manager::{
service::{EpochManagerConfig, EpochManagerHandle},
Expand Down Expand Up @@ -301,8 +300,6 @@ pub async fn spawn_services(
// Transaction executor
let fee_table = get_fee_table_by_network(config.network);
let payload_processor = TariTransactionProcessor::new(
TransactionProcessorConfig::new(config.network)
.with_template_binary_max_size_bytes(consensus_constants.template_binary_max_size_bytes),
template_manager.clone(),
fee_table.clone(),
Arc::new(TariClaimBurnProofVerifier::new(config.network, global_db.clone())),
Expand Down
4 changes: 4 additions & 0 deletions applications/tari_walletd/src/handlers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ pub async fn handle_publish_template(
},
};

let wasm_binary = wasm_binary
.try_into()
.map_err(|_| invalid_params("binary", Some("WASM binary too large".to_string())))?;

let transaction = context
.transaction_builder()
.fee_transaction_pay_from_component(*fee_account.component_address(), req.max_fee)
Expand Down
3 changes: 0 additions & 3 deletions crates/consensus/src/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub struct ConsensusConstants {
/// The value that fees are divided by to determine the amount of fees to burn. 0 means no fees are burned.
pub fee_exhaust_divisor: u64,
pub epochs_per_era: Epoch,
/// Maximum size in bytes for a template WASM binary.
pub template_binary_max_size_bytes: usize,
}

impl ConsensusConstants {
Expand All @@ -64,7 +62,6 @@ impl ConsensusConstants {
max_number_commands_in_block: 500,
fee_exhaust_divisor: 20, // 5%
epochs_per_era: Epoch(10),
template_binary_max_size_bytes: 1000 * 1000 * 5, // 5 MB
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus_tests/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,17 +1359,17 @@ async fn multishard_publish_template() {
let inputs = test.create_substates_on_vns(TestVnDestination::All, 1);
let (sk, pk) = create_key_pair();
let wasm = load_binary_fixture("state.wasm");
let expected_binary_hash = hash_template_code(&wasm);
let tx = Transaction::builder()
.publish_template(wasm.clone())
.publish_template(wasm.try_into().unwrap())
.with_inputs(inputs.iter().cloned().map(Into::into))
.build_and_seal(&sk);
let tx = TransactionRecord::new(tx);

test.send_transaction_to_destination(TestVnDestination::All, tx.clone())
.await;

let binary_hash = hash_template_code(&wasm);
let template_id = PublishedTemplateAddress::from_author_and_binary_hash(&pk.to_byte_type(), &binary_hash);
let template_id = PublishedTemplateAddress::from_author_and_binary_hash(&pk.to_byte_type(), &expected_binary_hash);
test.add_execution_at_destination(TestVnDestination::All, ExecuteSpec {
transaction: tx.transaction().clone(),
decision: Decision::Commit,
Expand Down Expand Up @@ -1412,7 +1412,7 @@ async fn multishard_publish_template() {
.into_template()
.expect("Expected template substate")
.binary_hash;
assert_eq!(binary_hash, hash_template_code(&wasm), "Template binary does not match");
assert_eq!(binary_hash, expected_binary_hash, "Template binary does not match");
}

test.assert_clean_shutdown().await;
Expand Down
1 change: 0 additions & 1 deletion crates/consensus_tests/src/support/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ impl TestBuilder {
max_number_commands_in_block: 500,
fee_exhaust_divisor: 20,
epochs_per_era: Epoch(10),
template_binary_max_size_bytes: 1000 * 1000 * 5,
},
state_tree_cleanup_interval: Duration::from_secs(60),
epoch_gc_interval: Duration::from_secs(60),
Expand Down
24 changes: 0 additions & 24 deletions crates/engine/src/transaction/config.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/engine/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub enum TransactionError {
InvariantError { details: String },
#[error("Load template error: {0}")]
LoadTemplate(#[from] TemplateLoaderError),
#[error("WASM binary too big! {0} bytes are greater than allowed maximum {1} bytes.")]
WasmBinaryTooBig(usize, usize),
#[error("Template provider error: {0}")]
TemplateProvider(String),
#[error("Converting to hash error: {0}")]
Expand Down
3 changes: 0 additions & 3 deletions crates/engine/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
mod error;
pub use error::TransactionError;

mod config;
pub use config::*;

mod processor;

pub use processor::*;
32 changes: 8 additions & 24 deletions crates/engine/src/transaction/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use tari_transaction::{
ComponentCall,
Instruction,
ResourceAddressRef,
TemplateBlob,
};

use crate::{
Expand All @@ -69,7 +70,7 @@ use crate::{
state_store::memory::ReadOnlyMemoryStateStore,
template::LoadedTemplate,
traits::{ClaimProofVerifier, Invokable},
transaction::{TransactionError, TransactionProcessorConfig},
transaction::TransactionError,
wasm::{WasmModule, WasmProcess},
};

Expand All @@ -78,7 +79,6 @@ pub const MAX_CALL_DEPTH: usize = 10;
const ACCOUNT_CONSTRUCTOR_FUNCTION: &str = "create";

pub struct TransactionProcessor<TTemplateProvider> {
config: TransactionProcessorConfig,
template_provider: Arc<TTemplateProvider>,
state_db: ReadOnlyMemoryStateStore,
auth_params: AuthParams,
Expand All @@ -89,7 +89,6 @@ pub struct TransactionProcessor<TTemplateProvider> {

impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> TransactionProcessor<TTemplateProvider> {
pub fn new(
config: TransactionProcessorConfig,
template_provider: Arc<TTemplateProvider>,
state_db: ReadOnlyMemoryStateStore,
auth_params: AuthParams,
Expand All @@ -98,7 +97,6 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
claim_burn_proof_verifier: Arc<dyn ClaimProofVerifier + Send + Sync + 'static>,
) -> Self {
Self {
config,
template_provider,
state_db,
auth_params,
Expand All @@ -114,7 +112,6 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
let timer = Instant::now();
let entity_id_provider = EntityIdProvider::new(id.as_hash(), 1000);
let Self {
config,
template_provider,
state_db,
auth_params,
Expand Down Expand Up @@ -169,7 +166,7 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T

let instructions = executable.into_instructions();

let fee_exec_results = Self::process_instructions(&config, &template_provider, &runtime, instructions.fee);
let fee_exec_results = Self::process_instructions(&template_provider, &runtime, instructions.fee);

let fee_exec_result = match fee_exec_results {
Ok(execution_results) => {
Expand All @@ -196,7 +193,7 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
},
};

let instruction_result = Self::process_instructions(&config, &*template_provider, &runtime, instructions.main);
let instruction_result = Self::process_instructions(&*template_provider, &runtime, instructions.main);

match instruction_result {
Ok(execution_results) => {
Expand Down Expand Up @@ -236,14 +233,13 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
}

fn process_instructions(
config: &TransactionProcessorConfig,
template_provider: &TTemplateProvider,
runtime: &Runtime,
instructions: Vec<Instruction>,
) -> Result<Vec<InstructionResult>, TransactionError> {
let result: Result<_, _> = instructions
.into_iter()
.map(|instruction| Self::process_instruction(config, template_provider, runtime, instruction))
.map(|instruction| Self::process_instruction(template_provider, runtime, instruction))
.collect();

// check that the finalized state is valid
Expand All @@ -255,7 +251,6 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
}

fn process_instruction(
config: &TransactionProcessorConfig,
template_provider: &TTemplateProvider,
runtime: &Runtime,
instruction: Instruction,
Expand Down Expand Up @@ -350,7 +345,7 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
.put_on_workspace(output_bucket, IndexedValue::from_value(bucket.into_value()?)?)?;
Ok(InstructionResult::empty())
},
Instruction::PublishTemplate { binary } => Self::publish_template(config, runtime, binary),
Instruction::PublishTemplate { binary } => Self::publish_template(runtime, binary),
Instruction::AllocateAddress {
allocatable_type: substate_type,
workspace_id,
Expand Down Expand Up @@ -453,22 +448,11 @@ impl<TTemplateProvider: TemplateProvider<Template = LoadedTemplate> + 'static> T
}

/// Load, validate template binary and adds it to TemplateProvider.
fn publish_template(
config: &TransactionProcessorConfig,
runtime: &Runtime,
binary: Vec<u8>,
) -> Result<InstructionResult, TransactionError> {
if binary.len() > config.template_binary_max_size_bytes {
return Err(TransactionError::WasmBinaryTooBig(
binary.len(),
config.template_binary_max_size_bytes,
));
}

fn publish_template(runtime: &Runtime, binary: TemplateBlob) -> Result<InstructionResult, TransactionError> {
// validate binary
WasmModule::load_template_from_code(&binary)?;
// creating new substate
runtime.interface().publish_template(binary)?;
runtime.interface().publish_template(binary.into_vec())?;

Ok(InstructionResult::empty())
}
Expand Down
Loading
Loading