From 50fbf051fda39b56d5a3c6088c11f0f1f3b3aad3 Mon Sep 17 00:00:00 2001 From: Richard Bertok Date: Fri, 6 Dec 2024 05:43:32 +0100 Subject: [PATCH] feat: new PublishTemplate instruction (#1208) Description --- As part of https://github.com/tari-project/tari-dan/issues/1207 , this PR contains the basic instruction and skeleton for instruction processing. There is a validation implemented for the new PublishTemplate instruction (where also we validate size of wasm binary). Please note that in this PR there is no new substates or anything generated yet. Motivation and Context --- https://github.com/tari-project/tari-dan/issues/1207 How Has This Been Tested? --- Send a new transaction to VN: ```rust let AccountGetResponse { account, public_key, } = client .accounts_get(ComponentAddressOrName::Name("acc")) .await?; let account_component_address = account.address .as_component_address() .expect("Failed to get component address"); // publish wasm template let wasm_binary = fs::read("./templates/counter/target/wasm32-unknown-unknown/release/counter.wasm")?; let tx = Transaction::builder() .fee_transaction_pay_from_component(account_component_address, Amount(1000)) .publish_template(wasm_binary) .build_unsigned_transaction(); let transaction_submit_req = TransactionSubmitRequest { transaction: tx, signing_key_index: Some(account.key_index), detect_inputs: true, detect_inputs_use_unversioned: true, proof_ids: vec![], autofill_inputs: vec![], }; let resp = client.submit_transaction(transaction_submit_req).await?; println!("Submit RESP: {resp:?}"); let wait_req = TransactionWaitResultRequest { transaction_id: resp.transaction_id, timeout_secs: Some(120), }; let wait_resp = client.wait_transaction_result(wait_req).await?; println!("TX RESP: {wait_resp:?}"); ``` Check printed out result and transaction result on UIs. Examples: - Invalid wasm template binary ![image](https://github.com/user-attachments/assets/de090251-5dae-4b21-a72b-f3c4f4939db6) - Size exceeding wasm template (manually set a lower limit to check error) ![image](https://github.com/user-attachments/assets/49b588c2-5008-4d70-b831-ab2f0400f647) - Success ![image](https://github.com/user-attachments/assets/ca86cd58-0ae9-4719-a3c8-132ca7fe8a51) What process can a PR reviewer use to test or verify this change? --- Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify --- Cargo.lock | 2 +- .../src/transaction_executor.rs | 11 +- .../tari_indexer/src/dry_run/processor.rs | 11 +- applications/tari_indexer/src/lib.rs | 9 +- .../tari_validator_node/src/bootstrap.rs | 11 +- bindings/dist/index.d.ts | 42 +++--- bindings/dist/index.js | 42 +++--- bindings/dist/tari-indexer-client.d.ts | 50 +++--- bindings/dist/tari-indexer-client.js | 50 +++--- bindings/dist/types/Instruction.d.ts | 4 + bindings/dist/types/PublishedTemplate.d.ts | 3 + bindings/dist/types/PublishedTemplate.js | 2 + .../dist/types/PublishedTemplateAddress.d.ts | 1 + .../dist/types/PublishedTemplateAddress.js | 2 + .../TransactionSubmitRequest.d.ts | 1 + bindings/dist/validator-node-client.d.ts | 88 +++++------ bindings/dist/validator-node-client.js | 88 +++++------ bindings/dist/wallet-daemon-client.d.ts | 142 +++++++++--------- bindings/dist/wallet-daemon-client.js | 142 +++++++++--------- bindings/src/index.ts | 42 +++--- bindings/src/tari-indexer-client.ts | 50 +++--- bindings/src/types/Instruction.ts | 3 +- .../TransactionSubmitRequest.ts | 1 + bindings/src/validator-node-client.ts | 88 +++++------ bindings/src/wallet-daemon-client.ts | 142 +++++++++--------- .../consensus/src/consensus_constants.rs | 3 + .../consensus_tests/src/support/harness.rs | 3 +- dan_layer/engine/src/transaction/error.rs | 6 +- dan_layer/engine/src/transaction/mod.rs | 7 +- dan_layer/engine/src/transaction/processor.rs | 87 +++++++++-- dan_layer/engine_types/src/instruction.rs | 6 + dan_layer/p2p/proto/transaction.proto | 4 + dan_layer/p2p/src/conversions/transaction.rs | 13 ++ .../src/template_test.rs | 6 +- dan_layer/transaction/src/builder.rs | 7 + 35 files changed, 653 insertions(+), 516 deletions(-) create mode 100644 bindings/dist/types/PublishedTemplate.d.ts create mode 100644 bindings/dist/types/PublishedTemplate.js create mode 100644 bindings/dist/types/PublishedTemplateAddress.d.ts create mode 100644 bindings/dist/types/PublishedTemplateAddress.js diff --git a/Cargo.lock b/Cargo.lock index 454e7f25f..3a4d83746 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" diff --git a/applications/tari_dan_app_utilities/src/transaction_executor.rs b/applications/tari_dan_app_utilities/src/transaction_executor.rs index f634ea63d..b3e257e7b 100644 --- a/applications/tari_dan_app_utilities/src/transaction_executor.rs +++ b/applications/tari_dan_app_utilities/src/transaction_executor.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use log::*; -use tari_common::configuration::Network; use tari_common_types::types::PublicKey; use tari_crypto::tari_utilities::ByteArray; use tari_dan_common_types::{ @@ -18,7 +17,7 @@ use tari_dan_engine::{ runtime::{AuthParams, RuntimeModule}, state_store::{memory::ReadOnlyMemoryStateStore, StateStoreError}, template::LoadedTemplate, - transaction::{TransactionError, TransactionProcessor}, + transaction::{TransactionError, TransactionProcessor, TransactionProcessorConfig}, }; use tari_dan_storage::consensus_models::VersionedSubstateIdLockIntent; use tari_engine_types::{commit_result::ExecuteResult, substate::Substate, virtual_substate::VirtualSubstates}; @@ -89,15 +88,15 @@ impl ExecutionOutput { pub struct TariDanTransactionProcessor { template_provider: Arc, fee_table: FeeTable, - network: Network, + config: TransactionProcessorConfig, } impl TariDanTransactionProcessor { - pub fn new(network: Network, template_provider: TTemplateProvider, fee_table: FeeTable) -> Self { + pub fn new(config: TransactionProcessorConfig, template_provider: TTemplateProvider, fee_table: FeeTable) -> Self { Self { template_provider: Arc::new(template_provider), fee_table, - network, + config, } } } @@ -128,12 +127,12 @@ where TTemplateProvider: TemplateProvider