Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/transaction threads #1872

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1d0a27b
Add KernelStack
talekhinezh Aug 7, 2024
cd6d11b
Add threads abstraction
talekhinezh Aug 7, 2024
aaf2dd0
Add notion of threads in AuthZoneParams
talekhinezh Aug 7, 2024
0bc0507
Merge remote-tracking branch 'origin/develop' into feature/separate-s…
talekhinezh Aug 7, 2024
1f339c9
Add ExecutableThread
talekhinezh Aug 7, 2024
2d1ced8
Add RootCallFrameInitRefs
talekhinezh Aug 7, 2024
221cd8b
Merge remote-tracking branch 'origin/develop' into feature/transactio…
talekhinezh Aug 7, 2024
f6c5784
Some cleanup
talekhinezh Aug 7, 2024
b9c73e0
Add multiple threads
talekhinezh Aug 7, 2024
e0deaa0
Add SendToSubTransactionAndAwait
talekhinezh Aug 8, 2024
29a010d
Add InvokeResult
talekhinezh Aug 8, 2024
7d83a2b
Add initial resume action
talekhinezh Aug 8, 2024
f1d0fe8
Remove lifetime from Executable
talekhinezh Aug 8, 2024
b9cc742
Add initial async loop
talekhinezh Aug 8, 2024
f0e7536
Refactor TransactionProcessorRunInputEfficientEncodable
talekhinezh Aug 9, 2024
eb97cef
More cleanup
talekhinezh Aug 9, 2024
8b66d69
Cleanup threads
talekhinezh Aug 9, 2024
647dd57
Initial test
talekhinezh Aug 9, 2024
c942938
Expand system callback
talekhinezh Aug 9, 2024
dbe6717
Add VmInvokeResult
talekhinezh Aug 9, 2024
c217d4c
Add NativeVmInvokeResult
talekhinezh Aug 9, 2024
9c3d12a
Revert VmInvokeResult
talekhinezh Aug 9, 2024
a20f923
Update transaction processor input
talekhinezh Aug 9, 2024
81a346f
Add switch stack call
talekhinezh Aug 9, 2024
37f71e5
Add kernel send
talekhinezh Aug 9, 2024
2118491
Add yield instruction
talekhinezh Aug 9, 2024
9e9166c
Add ability to update CallFrameData
talekhinezh Aug 9, 2024
1c5fba7
Add join
talekhinezh Aug 9, 2024
093b6d8
Add value send
talekhinezh Aug 9, 2024
fc36e1a
Implement sending resources between threads
talekhinezh Aug 10, 2024
f070417
Add swap test
talekhinezh Aug 10, 2024
ffd8bd8
Add ids to threads
talekhinezh Aug 10, 2024
b8e6a3e
Some cleanup
talekhinezh Aug 10, 2024
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
1 change: 1 addition & 0 deletions examples/everything/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/hello-world/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/no-std/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions radix-clis/src/replay/ledger_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::rc::Rc;
use radix_common::prelude::*;
use radix_engine_interface::blueprints::consensus_manager::*;
use radix_engine_interface::prelude::system_execution;
Expand Down Expand Up @@ -97,28 +98,28 @@ impl TransactionFullChildPreparable for PreparedRoundUpdateTransactionV1 {
}

impl PreparedRoundUpdateTransactionV1 {
pub fn get_executable(&self) -> Executable<'_> {
pub fn get_executable(&self) -> Executable {
Executable::new(
&self.encoded_instructions,
Rc::new(self.encoded_instructions.clone()),
&self.references,
&self.blobs,
Rc::new(self.blobs.clone()),
vec![],
ExecutionContext {
intent_hash: TransactionIntentHash::NotToCheck {
intent_hash: self.summary.hash,
},
epoch_range: None,
payload_size: 0,
num_of_signature_validations: 0,
auth_zone_params: AuthZoneParams {
initial_proofs: btreeset!(system_execution(SystemExecution::Validator)),
virtual_resources: BTreeSet::new(),
},
auth_zone_params: AuthZoneParams::single_thread(
btreeset!(system_execution(SystemExecution::Validator)),
BTreeSet::new(),
),
costing_parameters: TransactionCostingParameters {
tip_percentage: 0,
free_credit_in_xrd: Decimal::ZERO,
abort_when_loan_repaid: false,
},
pre_allocated_addresses: vec![],
},
true,
)
Expand Down Expand Up @@ -459,7 +460,7 @@ impl ValidatedLedgerTransaction {
}
}

pub fn get_executable(&self) -> Executable<'_> {
pub fn get_executable(&self) -> Executable {
match &self.inner {
ValidatedLedgerTransactionInner::Genesis(genesis) => match genesis.as_ref() {
PreparedGenesisTransaction::Flash(_) => {
Expand Down
8 changes: 4 additions & 4 deletions radix-clis/src/replay/ledger_transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
&ExecutionConfig::for_genesis_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
&tx.get_executable(btreeset!(system_execution(SystemExecution::Protocol))),
Rc::new(tx.get_executable(btreeset!(system_execution(SystemExecution::Protocol)))),
);
LedgerTransactionReceipt::Standard(receipt)
}
Expand All @@ -98,10 +98,10 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
&ExecutionConfig::for_notarized_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
&NotarizedTransactionValidator::new(ValidationConfig::default(network.id))
Rc::new(NotarizedTransactionValidator::new(ValidationConfig::default(network.id))
.validate(tx.as_ref().clone())
.expect("Transaction validation failure")
.get_executable(),
.get_executable()),
);
LedgerTransactionReceipt::Standard(receipt)
}
Expand All @@ -115,7 +115,7 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
&ExecutionConfig::for_system_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
&tx.get_executable(),
Rc::new(tx.get_executable()),
);
LedgerTransactionReceipt::Standard(receipt)
}
Expand Down
8 changes: 4 additions & 4 deletions radix-clis/src/resim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ pub fn handle_system_transaction<O: std::io::Write>(
vm_init,
&ExecutionConfig::for_system_transaction(NetworkDefinition::simulator())
.with_kernel_trace(trace),
&transaction
Rc::new(transaction
.prepare()
.map_err(Error::TransactionPrepareError)?
.get_executable(initial_proofs),
.get_executable(initial_proofs)),
);

if print_receipt {
Expand Down Expand Up @@ -254,10 +254,10 @@ pub fn handle_manifest<O: std::io::Write>(
&mut db,
vm_init,
&ExecutionConfig::for_test_transaction().with_kernel_trace(trace),
&transaction
Rc::new(transaction
.prepare()
.map_err(Error::TransactionPrepareError)?
.get_executable(initial_proofs),
.get_executable(initial_proofs)),
);

if print_receipt {
Expand Down
3 changes: 3 additions & 0 deletions radix-engine-interface/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod key_value_entry_api;
pub mod key_value_store_api;
pub mod object_api;
pub mod transaction_runtime_api;
pub mod thread_api;

// Re-exports
pub use actor_api::*;
Expand Down Expand Up @@ -41,6 +42,7 @@ pub type FieldIndex = u8;
pub type CollectionIndex = u8;

use radix_common::prelude::*;
use crate::api::thread_api::SystemThreadApi;

pub trait SystemApiError: fmt::Debug + ScryptoCategorize + ScryptoDecode {}

Expand All @@ -58,6 +60,7 @@ pub trait SystemApi<E: SystemApiError>:
+ SystemFieldApi<E>
+ SystemBlueprintApi<E>
+ SystemCostingApi<E>
+ SystemThreadApi<E>
+ SystemTransactionRuntimeApi<E>
+ SystemExecutionTraceApi<E>
{
Expand Down
10 changes: 10 additions & 0 deletions radix-engine-interface/src/api/thread_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::types::IndexedScryptoValue;

pub trait SystemThreadApi<E> {

fn free_stack(&mut self, stack_id: usize) -> Result<(), E>;

fn move_to_stack(&mut self, stack_id: usize, value: IndexedScryptoValue) -> Result<(), E>;

fn switch_stack(&mut self, stack_id: usize) -> Result<(), E>;
}
42 changes: 13 additions & 29 deletions radix-engine-monkey-tests/tests/fuzz_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ use radix_common::prelude::*;
use radix_engine::errors::{
BootloadingError, RejectionReason, RuntimeError, TransactionExecutionError,
};
use radix_engine::kernel::call_frame::{CallFrameMessage, StableReferenceType};
use radix_engine::kernel::call_frame::{CallFrameMessage, RootCallFrameInitRefs, StableReferenceType};
use radix_engine::kernel::id_allocator::IdAllocator;
use radix_engine::kernel::kernel::Kernel;
use radix_engine::kernel::kernel_api::{
KernelApi, KernelInternalApi, KernelInvocation, KernelInvokeApi, KernelNodeApi,
KernelSubstateApi,
};
use radix_engine::kernel::kernel_callback_api::{
CallFrameReferences, CloseSubstateEvent, CreateNodeEvent, DrainSubstatesEvent, DropNodeEvent,
ExecutionReceipt, KernelCallbackObject, MoveModuleEvent, OpenSubstateEvent, ReadSubstateEvent,
RemoveSubstateEvent, ScanKeysEvent, ScanSortedSubstatesEvent, SetSubstateEvent,
WriteSubstateEvent,
};
use radix_engine::kernel::kernel_callback_api::{CallFrameReferences, CloseSubstateEvent, CreateNodeEvent, DrainSubstatesEvent, DropNodeEvent, ExecutionReceipt, InvokeResult, KernelCallbackObject, MoveModuleEvent, OpenSubstateEvent, ReadSubstateEvent, RemoveSubstateEvent, ResumeResult, ScanKeysEvent, ScanSortedSubstatesEvent, SetSubstateEvent, WriteSubstateEvent};
use radix_engine::system::checkers::KernelDatabaseChecker;
use radix_engine::track::{
to_state_updates, BootStore, CommitableSubstateStore, StoreCommitInfo, Track,
Expand All @@ -24,7 +19,7 @@ use radix_engine_interface::prelude::*;
use radix_substate_store_impls::memory_db::InMemorySubstateDatabase;
use radix_substate_store_interface::db_key_mapper::SpreadPrefixKeyMapper;
use radix_substate_store_interface::interface::{CommittableSubstateDatabase, SubstateDatabase};
use radix_transactions::model::{Executable, PreAllocatedAddress};
use radix_transactions::model::{Executable, ExecutableThread};
use rand::Rng;
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::ChaCha8Rng;
Expand Down Expand Up @@ -75,19 +70,13 @@ impl KernelCallbackObject for TestCallbackObject {

fn init<S: BootStore + CommitableSubstateStore>(
_store: &mut S,
_executable: &Executable,
_executable: Rc<Executable>,
_init_input: Self::Init,
) -> Result<Self, RejectionReason> {
Ok(Self)
) -> Result<(Self, Vec<RootCallFrameInitRefs>), RejectionReason> {
Ok((Self, vec![]))
}

fn start<Y: KernelApi<Self>>(
_: &mut Y,
_: &[u8],
_: &Vec<PreAllocatedAddress>,
_: &IndexSet<Reference>,
_: &IndexMap<Hash, Vec<u8>>,
) -> Result<(), RuntimeError> {
fn start<Y: KernelApi<Self>>(_: &mut Y) -> Result<(), RuntimeError> {
unreachable!()
}

Expand All @@ -98,20 +87,11 @@ impl KernelCallbackObject for TestCallbackObject {
fn create_receipt<S: SubstateDatabase>(
self,
_track: Track<S, SpreadPrefixKeyMapper>,
_executable: &Executable,
_result: Result<(), TransactionExecutionError>,
) -> Self::Receipt {
TestReceipt
}

fn verify_boot_ref_value(
&mut self,
_node_id: &NodeId,
_value: &IndexedScryptoValue,
) -> Result<StableReferenceType, BootloadingError> {
Ok(StableReferenceType::Global)
}

fn on_pin_node(&mut self, _node_id: &NodeId) -> Result<(), RuntimeError> {
Ok(())
}
Expand Down Expand Up @@ -223,8 +203,12 @@ impl KernelCallbackObject for TestCallbackObject {
fn invoke_upstream<Y: KernelApi<Self>>(
args: &IndexedScryptoValue,
_api: &mut Y,
) -> Result<IndexedScryptoValue, RuntimeError> {
Ok(args.clone())
) -> Result<InvokeResult, RuntimeError> {
Ok(InvokeResult::Done(args.clone()))
}

fn resume_thread<Y: KernelApi<Self>>(args: &IndexedScryptoValue, api: &mut Y) -> Result<ResumeResult, RuntimeError> {
Ok(ResumeResult::Done(0, args.clone()))
}

fn auto_drop<Y: KernelApi<Self>>(
Expand Down
12 changes: 6 additions & 6 deletions radix-engine-tests/benches/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ fn bench_transfer(c: &mut Criterion) {
&mut substate_db,
vm_init.clone(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
&TestTransaction::new_from_nonce(manifest, 1)
Rc::new(TestTransaction::new_from_nonce(manifest, 1)
.prepare()
.unwrap()
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)]),
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)])),
)
.expect_commit(true)
.new_component_addresses()[0];
Expand All @@ -72,10 +72,10 @@ fn bench_transfer(c: &mut Criterion) {
&mut substate_db,
vm_init.clone(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
&TestTransaction::new_from_nonce(manifest.clone(), nonce)
Rc::new(TestTransaction::new_from_nonce(manifest.clone(), nonce)
.prepare()
.unwrap()
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)]),
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)])),
)
.expect_commit(true);
}
Expand All @@ -95,10 +95,10 @@ fn bench_transfer(c: &mut Criterion) {
&mut substate_db,
vm_init.clone(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
&TestTransaction::new_from_nonce(manifest.clone(), nonce)
Rc::new(TestTransaction::new_from_nonce(manifest.clone(), nonce)
.prepare()
.unwrap()
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)]),
.get_executable(btreeset![NonFungibleGlobalId::from_public_key(&public_key)])),
);
receipt.expect_commit_success();
nonce += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl TransactionFuzzer {
&mut self.substate_db,
vm_init,
&execution_config,
&validated.get_executable(),
Rc::new(validated.get_executable()),
);
}

Expand Down
6 changes: 3 additions & 3 deletions radix-engine-tests/tests/application/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ fn transaction_processor_produces_expected_error_for_undecodable_instructions()
let blobs = Default::default();

let executable = Executable::new(
&invalid_encoded_instructions,
Rc::new(invalid_encoded_instructions.to_vec()),
&references,
&blobs,
Rc::new(blobs),
Default::default(),
ExecutionContext {
intent_hash: TransactionIntentHash::NotToCheck {
intent_hash: Hash([0; 32]),
},
epoch_range: Default::default(),
pre_allocated_addresses: Default::default(),
payload_size: 4,
num_of_signature_validations: 0,
auth_zone_params: Default::default(),
Expand Down
Loading
Loading