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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add join
  • Loading branch information
talekhinezh committed Aug 9, 2024
commit 1c5fba7b8b02e39d9c712132adfd2b81a1114724
2 changes: 2 additions & 0 deletions radix-engine-interface/src/api/thread_api.rs
Original file line number Diff line number Diff line change
@@ -4,4 +4,6 @@ pub trait SystemThreadApi<E> {
fn send(&mut self, thread: usize, value: IndexedScryptoValue) -> Result<(), E>;

fn switch_context(&mut self, thread: usize) -> Result<(), E>;

fn join(&mut self, thread: usize) -> Result<(), E>;
}
6 changes: 5 additions & 1 deletion radix-engine-tests/tests/kernel/panics.rs
Original file line number Diff line number Diff line change
@@ -48,9 +48,13 @@ impl<'g> KernelThreadApi<System<Vm<'g, DefaultWasmEngine, NoExtension>>> for Moc
panic!()
}

fn kernel_switch_context(&mut self, _: usize, _: Option<Actor>) -> Result<(), RuntimeError> {
fn kernel_switch_context(&mut self, _: usize) -> Result<(), RuntimeError> {
panic1!()
}

fn kernel_update_call_frame_data(&mut self, _: Actor) -> Result<(), RuntimeError> {
panic!()
}
}

impl KernelNodeApi for MockKernel {
Original file line number Diff line number Diff line change
@@ -139,6 +139,10 @@ impl TransactionProcessorBlueprint {
match result {
InstructionExecutionResult::Output(output) => outputs.push(output),
InstructionExecutionResult::Done => {
if cur_thread > 0 {
api.join(0)?;
}

let next = threads.iter().enumerate()
.filter(|(thread_id, thread)| !matches!(thread, TransactionProcessorThread::Done))
.next();
13 changes: 7 additions & 6 deletions radix-engine/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
@@ -333,15 +333,16 @@ impl<'g, M, S> KernelThreadApi<M> for Kernel<'g, M, S>
Ok(())
}

fn kernel_switch_context(&mut self, thread: usize, update: Option<M::CallFrameData>) -> Result<(), RuntimeError> {
if let Some(update) = update {
let data = self.threads.get_mut(thread).unwrap().current_frame.data_mut();
*data = update;
}

fn kernel_switch_context(&mut self, thread: usize) -> Result<(), RuntimeError> {
self.cur_thread = thread;
Ok(())
}

fn kernel_update_call_frame_data(&mut self, update: M::CallFrameData) -> Result<(), RuntimeError> {
let data = self.threads.get_mut(self.cur_thread).unwrap().current_frame.data_mut();
*data = update;
Ok(())
}
}

impl<'g, M, S> KernelNodeApi for Kernel<'g, M, S>
4 changes: 3 additions & 1 deletion radix-engine/src/kernel/kernel_api.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,9 @@ pub struct DroppedNode {
pub trait KernelThreadApi<M: KernelCallbackObject> {
fn kernel_send(&mut self, thread: usize, value: IndexedScryptoValue) -> Result<(), RuntimeError>;

fn kernel_switch_context(&mut self, thread: usize, update: Option<M::CallFrameData>) -> Result<(), RuntimeError>;
fn kernel_switch_context(&mut self, thread: usize) -> Result<(), RuntimeError>;

fn kernel_update_call_frame_data(&mut self, update: M::CallFrameData) -> Result<(), RuntimeError>;
}

/// API for managing nodes
52 changes: 50 additions & 2 deletions radix-engine/src/system/system.rs
Original file line number Diff line number Diff line change
@@ -44,10 +44,12 @@ use radix_engine_interface::api::*;
use radix_engine_interface::api::thread_api::SystemThreadApi;
use radix_engine_interface::blueprints::package::*;
use radix_engine_interface::blueprints::resource::*;
use radix_engine_interface::blueprints::transaction_processor::TRANSACTION_PROCESSOR_BLUEPRINT;
use radix_engine_profiling_derive::trace_resources;
use radix_substate_store_interface::db_key_mapper::SubstateKeyContent;
use sbor::rust::string::ToString;
use sbor::rust::vec::Vec;
use crate::system::system_modules::auth::AuthModule;

pub const BOOT_LOADER_SYSTEM_VERSION_FIELD_KEY: FieldKey = 1u8;

@@ -2769,10 +2771,56 @@ for SystemService<'a, Y, V>
}

fn switch_context(&mut self, thread: usize) -> Result<(), RuntimeError> {

//let auth_zone = SystemModuleMixer::on_call_function(self, &blueprint_id, function_name)?;

self.api.kernel_switch_context(thread, None)
self.api.kernel_switch_context(thread)?;

let cur_frame = self.api.kernel_get_system_state().current_call_frame;
match cur_frame {
Actor::Root => {
let (virtual_resources, virtual_non_fungibles) = {
let auth_module = &self.api.kernel_get_system().modules.auth;
let virtual_resources =
auth_module.params.thread_params[thread]
.virtual_resources
.clone();
let virtual_non_fungibles =
auth_module.params.thread_params[thread]
.initial_proofs
.clone();

(virtual_resources, virtual_non_fungibles)
};

let auth_zone = AuthModule::create_auth_zone(self, None, virtual_resources, virtual_non_fungibles)?;

self.api.kernel_update_call_frame_data(Actor::Function(
FunctionActor {
blueprint_id: BlueprintId::new(&TRANSACTION_PROCESSOR_PACKAGE, TRANSACTION_PROCESSOR_BLUEPRINT),
ident: "run".to_string(),
auth_zone,
}
))?;
}
_ => {
}
}

Ok(())
}


fn join(&mut self, thread: usize) -> Result<(), RuntimeError> {
let cur_frame = self.api.kernel_get_system_state().current_call_frame;
match cur_frame {
Actor::Function(FunctionActor { auth_zone, .. }) => {
let auth_zone = auth_zone.clone();
self.api.kernel_drop_node(&auth_zone)?;
}
_ => {}
}

Ok(())
}
}

Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ impl AuthModule {
Ok((auth_zone.into_payload().global_caller, Some(handle)))
}

fn create_auth_zone<Y: KernelApi<System<V>>, V: SystemCallbackObject>(
pub(crate) fn create_auth_zone<Y: KernelApi<System<V>>, V: SystemCallbackObject>(
system: &mut SystemService<Y, V>,
receiver: Option<(&NodeId, bool)>,
virtual_resources: BTreeSet<ResourceAddress>,
2 changes: 1 addition & 1 deletion radix-engine/src/system/system_modules/module_mixer.rs
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ pub struct SystemModuleMixer {
pub(super) kernel_trace: KernelTraceModule,
pub(super) limits: LimitsModule,
pub(super) costing: CostingModule,
pub(super) auth: AuthModule,
pub(crate) auth: AuthModule,
pub(crate) transaction_runtime: TransactionRuntimeModule,
pub(super) execution_trace: ExecutionTraceModule,
}
1 change: 1 addition & 0 deletions scrypto-test/src/environment/system_api.rs
Original file line number Diff line number Diff line change
@@ -106,6 +106,7 @@ implement_system_api! {
SystemThreadApi: {
send: (&mut self, thread: usize, value: IndexedScryptoValue) -> Result<(), RuntimeError>,
switch_context: (&mut self, thread: usize) -> Result<(), RuntimeError>,
join: (&mut self, thread: usize) -> Result<(), RuntimeError>,
},
SystemActorApi: {
actor_get_blueprint_id: (&mut self) -> Result<BlueprintId, RuntimeError>,
8 changes: 6 additions & 2 deletions scrypto-test/src/ledger_simulator/inject_costing_err.rs
Original file line number Diff line number Diff line change
@@ -321,8 +321,12 @@ for WrappedKernelApi<'a, M, K>
self.api.kernel_send(thread, value)
}

fn kernel_switch_context(&mut self, thread: usize, update: Option<Actor>) -> Result<(), RuntimeError> {
self.api.kernel_switch_context(thread, update)
fn kernel_switch_context(&mut self, thread: usize) -> Result<(), RuntimeError> {
self.api.kernel_switch_context(thread)
}

fn kernel_update_call_frame_data(&mut self, update: Actor) -> Result<(), RuntimeError> {
self.api.kernel_update_call_frame_data(update)
}
}