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 notion of threads in AuthZoneParams
talekhinezh committed Aug 7, 2024
commit aaf2dd0f6407967d351172664fc960f5033c294a
8 changes: 4 additions & 4 deletions radix-clis/src/replay/ledger_transaction.rs
Original file line number Diff line number Diff line change
@@ -109,10 +109,10 @@ impl PreparedRoundUpdateTransactionV1 {
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,
5 changes: 4 additions & 1 deletion radix-engine-tests/tests/kernel/kernel_open_substate.rs
Original file line number Diff line number Diff line change
@@ -51,6 +51,9 @@ pub fn test_open_substate_of_invisible_package_address() {
false,
);

let tx_num_of_signature_validations =
executable.auth_zone_params().thread_params.iter().map(|param| param.initial_proofs.len()).sum();

// Create kernel
let mut system = System {
blueprint_cache: NonIterMap::new(),
@@ -75,7 +78,7 @@ pub fn test_open_substate_of_invisible_package_address() {
fee_reserve: SystemLoanFeeReserve::default(),
fee_table: FeeTable::new(),
tx_payload_len: executable.payload_size(),
tx_num_of_signature_validations: executable.auth_zone_params().initial_proofs.len(),
tx_num_of_signature_validations,
config: CostingModuleConfig::babylon_genesis(),
cost_breakdown: None,
detailed_cost_breakdown: None,
4 changes: 4 additions & 0 deletions radix-engine-tests/tests/kernel/panics.rs
Original file line number Diff line number Diff line change
@@ -181,6 +181,10 @@ impl<'g> KernelInternalApi<System<Vm<'g, DefaultWasmEngine, NoExtension>>> for M
panic1!()
}

fn kernel_get_current_thread(&self) -> usize {
panic1!()
}

fn kernel_get_node_visibility(&self, _: &NodeId) -> NodeVisibility {
panic1!()
}
16 changes: 8 additions & 8 deletions radix-engine-tests/tests/vm/native_vm.rs
Original file line number Diff line number Diff line change
@@ -85,10 +85,10 @@ fn panics_can_be_caught_in_the_native_vm_and_converted_into_results() {
EnabledModules::for_notarized_transaction(),
KernelTraceModule,
TransactionRuntimeModule::new(NetworkDefinition::simulator(), intent_hash),
AuthModule::new(AuthZoneParams {
initial_proofs: Default::default(),
virtual_resources: Default::default(),
}),
AuthModule::new(AuthZoneParams::single_thread(
Default::default(),
Default::default(),
)),
LimitsModule::babylon_genesis(),
CostingModule {
current_depth: 0,
@@ -166,10 +166,10 @@ fn any_panics_can_be_caught_in_the_native_vm_and_converted_into_results() {
EnabledModules::for_notarized_transaction(),
KernelTraceModule,
TransactionRuntimeModule::new(NetworkDefinition::simulator(), intent_hash),
AuthModule::new(AuthZoneParams {
initial_proofs: Default::default(),
virtual_resources: Default::default(),
}),
AuthModule::new(AuthZoneParams::single_thread(
Default::default(),
Default::default(),
)),
LimitsModule::babylon_genesis(),
CostingModule {
current_depth: 0,
26 changes: 26 additions & 0 deletions radix-engine/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
@@ -290,6 +290,7 @@ struct KernelHandler<
M: KernelCallbackObject,
F: FnMut(&mut KernelReadOnly<M>, IOAccess) -> Result<(), RuntimeError>,
> {
current_thread: usize,
callback: &'a mut M,
prev_frame: Option<&'a CallFrame<M::CallFrameData, M::LockData>>,
on_io_access: F,
@@ -308,6 +309,7 @@ impl<
io_access: IOAccess,
) -> Result<(), RuntimeError> {
let mut read_only = KernelReadOnly {
current_thread: self.current_thread,
current_frame,
prev_frame: self.prev_frame,
heap,
@@ -333,6 +335,7 @@ impl<
device: SubstateDevice,
) -> Result<(), Self::Error> {
let mut read_only = KernelReadOnly {
current_thread: self.current_thread,
current_frame,
prev_frame: self.prev_frame,
heap,
@@ -354,6 +357,7 @@ macro_rules! as_read_only {
($kernel:expr) => {{
let thread = $kernel.threads.get($kernel.cur_thread).unwrap();
KernelReadOnly {
current_thread: $kernel.cur_thread,
current_frame: &thread.current_frame,
prev_frame: thread.prev_frames.last(),
heap: &$kernel.substate_io.heap,
@@ -405,6 +409,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -445,6 +450,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -475,6 +481,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -515,6 +522,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -559,6 +567,10 @@ where
self.threads.get(self.cur_thread).unwrap().current_frame.depth()
}

fn kernel_get_current_thread(&self) -> usize {
self.cur_thread
}

fn kernel_get_system_state(&mut self) -> SystemState<'_, M> {
let thread = self.threads.get_mut(self.cur_thread).unwrap();
let caller_actor = match thread.prev_frames.last() {
@@ -590,6 +602,7 @@ struct KernelReadOnly<'g, M>
where
M: KernelCallbackObject,
{
current_thread: usize,
current_frame: &'g CallFrame<M::CallFrameData, M::LockData>,
prev_frame: Option<&'g CallFrame<M::CallFrameData, M::LockData>>,
heap: &'g Heap,
@@ -608,6 +621,10 @@ where
self.current_frame.depth()
}

fn kernel_get_current_thread(&self) -> usize {
self.current_thread
}

fn kernel_get_system_state(&mut self) -> SystemState<'_, M> {
let caller_call_frame = match self.prev_frame {
Some(call_frame) => call_frame.data(),
@@ -823,6 +840,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -852,6 +870,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -935,6 +954,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -973,6 +993,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -1034,6 +1055,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -1079,6 +1101,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -1118,6 +1141,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -1158,6 +1182,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
@@ -1198,6 +1223,7 @@ where
let thread = self.threads.get_mut(self.cur_thread).unwrap();

let mut handler = KernelHandler {
current_thread: self.cur_thread,
callback: self.callback,
prev_frame: thread.prev_frames.last(),
on_io_access: |api, io_access| {
2 changes: 2 additions & 0 deletions radix-engine/src/kernel/kernel_api.rs
Original file line number Diff line number Diff line change
@@ -191,6 +191,8 @@ pub trait KernelInternalApi<M: KernelCallbackObject> {
/// Gets the number of call frames that are currently in the call frame stack
fn kernel_get_current_depth(&self) -> usize;

fn kernel_get_current_thread(&self) -> usize;

/// Returns the visibility of a node
fn kernel_get_node_visibility(&self, node_id: &NodeId) -> NodeVisibility;

4 changes: 4 additions & 0 deletions radix-engine/src/system/system.rs
Original file line number Diff line number Diff line change
@@ -3018,6 +3018,10 @@ impl<'a, Y: KernelApi<System<V>>, V: SystemCallbackObject> KernelInternalApi<Sys
self.api.kernel_get_current_depth()
}

fn kernel_get_current_thread(&self) -> usize {
self.api.kernel_get_current_thread()
}

fn kernel_get_node_visibility(&self, node_id: &NodeId) -> NodeVisibility {
self.api.kernel_get_node_visibility(node_id)
}
5 changes: 3 additions & 2 deletions radix-engine/src/system/system_modules/auth/auth_module.rs
Original file line number Diff line number Diff line change
@@ -92,10 +92,11 @@ impl AuthModule {
let is_at_root = api.kernel_get_current_depth() == 0;
let (virtual_resources, virtual_non_fungibles) =
if is_transaction_processor_blueprint && is_at_root {
let thread_id = api.kernel_get_current_thread();
let auth_module = &api.kernel_get_system().modules.auth;
(
auth_module.params.virtual_resources.clone(),
auth_module.params.initial_proofs.clone(),
auth_module.params.thread_params[thread_id].virtual_resources.clone(),
auth_module.params.thread_params[thread_id].initial_proofs.clone(),
)
} else {
(BTreeSet::new(), BTreeSet::new())
39 changes: 33 additions & 6 deletions radix-transactions/src/model/executable.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
use crate::internal_prelude::*;

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor, Default)]
pub struct AuthZoneParams {
pub struct AuthZoneThreadParams {
pub initial_proofs: BTreeSet<NonFungibleGlobalId>,
pub virtual_resources: BTreeSet<ResourceAddress>,
}

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
pub struct AuthZoneParams {
pub thread_params: Vec<AuthZoneThreadParams>,
}

impl Default for AuthZoneParams {
fn default() -> Self {
Self {
thread_params: vec![AuthZoneThreadParams::default()]
}
}
}

impl AuthZoneParams {
pub fn single_thread(initial_proofs: BTreeSet<NonFungibleGlobalId>, virtual_resources: BTreeSet<ResourceAddress>) -> Self {
Self {
thread_params: vec![AuthZoneThreadParams {
initial_proofs,
virtual_resources,
}]
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
pub struct EpochRange {
pub start_epoch_inclusive: Epoch,
@@ -131,12 +155,15 @@ impl<'a> Executable<'a> {
) -> Self {
let mut references = references.clone();

for proof in &context.auth_zone_params.initial_proofs {
references.insert(proof.resource_address().clone().into());
}
for resource in &context.auth_zone_params.virtual_resources {
references.insert(resource.clone().into());
for auth_zone_params in &context.auth_zone_params.thread_params {
for proof in &auth_zone_params.initial_proofs {
references.insert(proof.resource_address().clone().into());
}
for resource in &auth_zone_params.virtual_resources {
references.insert(resource.clone().into());
}
}

for preallocated_address in &context.pre_allocated_addresses {
references.insert(
preallocated_address
8 changes: 4 additions & 4 deletions radix-transactions/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -213,13 +213,13 @@ Enum<3u8>(
// * Enum variant header: should be 1 + 1 + len(LEB128(size)), instead of fixed 2
payload_size: payload.len() - 3,
num_of_signature_validations: 3,
auth_zone_params: AuthZoneParams {
initial_proofs: btreeset!(
auth_zone_params: AuthZoneParams::single_thread(
btreeset!(
NonFungibleGlobalId::from_public_key(&sig_1_private_key.public_key()),
NonFungibleGlobalId::from_public_key(&sig_2_private_key.public_key())
),
virtual_resources: btreeset!()
},
btreeset!()
),
costing_parameters: TransactionCostingParameters {
tip_percentage: 4,
free_credit_in_xrd: dec!(0),
5 changes: 1 addition & 4 deletions radix-transactions/src/model/v1/preview_transaction.rs
Original file line number Diff line number Diff line change
@@ -79,10 +79,7 @@ impl ValidatedPreviewIntent {
},
payload_size: self.intent.summary.effective_length,
num_of_signature_validations: 0, // Accounted for by tests in `common_transformation_costs.rs`.
auth_zone_params: AuthZoneParams {
initial_proofs,
virtual_resources,
},
auth_zone_params: AuthZoneParams::single_thread(initial_proofs, virtual_resources),
costing_parameters: fee_payment,
pre_allocated_addresses: vec![],
},
5 changes: 1 addition & 4 deletions radix-transactions/src/model/v1/system_transaction.rs
Original file line number Diff line number Diff line change
@@ -111,10 +111,7 @@ impl PreparedSystemTransactionV1 {
epoch_range: None,
payload_size: 0,
num_of_signature_validations: 0,
auth_zone_params: AuthZoneParams {
initial_proofs,
virtual_resources: BTreeSet::new(),
},
auth_zone_params: AuthZoneParams::single_thread(initial_proofs, BTreeSet::new()),
costing_parameters: TransactionCostingParameters {
tip_percentage: 0,
free_credit_in_xrd: Decimal::ZERO,
5 changes: 1 addition & 4 deletions radix-transactions/src/model/v1/test_transaction.rs
Original file line number Diff line number Diff line change
@@ -64,10 +64,7 @@ impl PreparedTestTransaction {
+ self.blobs.values().map(|x| x.len()).sum::<usize>(),
// For testing purpose, assume `num_of_signature_validations = num_of_initial_proofs + 1`
num_of_signature_validations: initial_proofs.len() + 1,
auth_zone_params: AuthZoneParams {
initial_proofs,
virtual_resources: BTreeSet::new(),
},
auth_zone_params: AuthZoneParams::single_thread(initial_proofs, BTreeSet::new()),
costing_parameters: TransactionCostingParameters {
tip_percentage: DEFAULT_TIP_PERCENTAGE,
free_credit_in_xrd: Decimal::ZERO,
Original file line number Diff line number Diff line change
@@ -49,10 +49,7 @@ impl ValidatedNotarizedTransactionV1 {
}),
payload_size: summary.effective_length,
num_of_signature_validations: self.num_of_signature_validations,
auth_zone_params: AuthZoneParams {
initial_proofs: AuthAddresses::signer_set(&self.signer_keys),
virtual_resources: BTreeSet::new(),
},
auth_zone_params: AuthZoneParams::single_thread(AuthAddresses::signer_set(&self.signer_keys), BTreeSet::new()),
costing_parameters: TransactionCostingParameters {
tip_percentage: intent.header.inner.tip_percentage,
free_credit_in_xrd: Decimal::ZERO,
5 changes: 1 addition & 4 deletions scrypto-test/src/environment/builder.rs
Original file line number Diff line number Diff line change
@@ -250,10 +250,7 @@ where
Self::DEFAULT_INTENT_HASH,
);

let auth_module = AuthModule::new(AuthZoneParams {
initial_proofs: Default::default(),
virtual_resources: Default::default(),
});
let auth_module = AuthModule::new(AuthZoneParams::single_thread(Default::default(), Default::default()));

let limits_module = LimitsModule::from_params(LimitParameters::babylon_genesis());

8 changes: 8 additions & 0 deletions scrypto-test/src/ledger_simulator/inject_costing_err.rs
Original file line number Diff line number Diff line change
@@ -505,6 +505,10 @@ impl<'a, M: SystemCallbackObject, K: KernelApi<InjectCostingError<M>>> KernelInt
self.api.kernel_get_current_depth()
}

fn kernel_get_current_thread(&self) -> usize {
self.api.kernel_get_current_thread()
}

fn kernel_get_node_visibility(&self, node_id: &NodeId) -> NodeVisibility {
self.api.kernel_get_node_visibility(node_id)
}
@@ -548,6 +552,10 @@ impl<'a, M: SystemCallbackObject, K: KernelInternalApi<InjectCostingError<M>>>
self.api.kernel_get_current_depth()
}

fn kernel_get_current_thread(&self) -> usize {
self.api.kernel_get_current_thread()
}

fn kernel_get_node_visibility(&self, node_id: &NodeId) -> NodeVisibility {
self.api.kernel_get_node_visibility(node_id)
}