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/owned subintent processor #1876

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::data::manifest::*;
use crate::*;

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ScryptoSbor)]
#[must_use]
pub struct ManifestAddressReservation(pub u32);

Expand Down
2 changes: 1 addition & 1 deletion radix-common/src/data/manifest/model/manifest_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::data::manifest::*;
use crate::*;

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ScryptoSbor)]
#[must_use]
pub struct ManifestBucket(pub u32);

Expand Down
2 changes: 1 addition & 1 deletion radix-common/src/data/manifest/model/manifest_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::data::manifest::*;
use crate::*;

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, ScryptoSbor)]
#[must_use]
pub struct ManifestProof(pub u32);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub const TRANSACTION_PROCESSOR_BLUEPRINT: &str = "TransactionProcessor";

pub const TRANSACTION_PROCESSOR_RUN_IDENT: &str = "run";

pub const TRANSACTION_PROCESSOR_NEW_IDENT: &str = "new";

pub const TRANSACTION_PROCESSOR_EXECUTE_IDENT: &str = "execute";

// TransactionProcessorInput in the engine

pub type TransactionProcessorRunOutput = Vec<InstructionOutput>;
Expand Down
14 changes: 14 additions & 0 deletions radix-engine-interface/src/types/node_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ blueprint_partition_offset!(
}
);


//===========
// Blueprints
//===========
Expand Down Expand Up @@ -201,6 +202,19 @@ blueprint_partition_offset!(
}
);

blueprint_partition_offset!(
pub enum SubTransactionProcessorPartitionOffset {
Field,
}
);

#[repr(u8)]
#[derive(Debug, Copy, Clone, Sbor, PartialEq, Eq, Hash, PartialOrd, Ord, FromRepr)]
pub enum SubTransactionProcessorField {
ExecutionState,
}


#[repr(u8)]
#[derive(Debug, Copy, Clone, Sbor, PartialEq, Eq, Hash, PartialOrd, Ord, FromRepr)]
pub enum FungibleBucketField {
Expand Down
4 changes: 4 additions & 0 deletions radix-engine-tests/tests/intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ fn swap_with_intents_should_work() {

let execution_config = {
let mut execution_config = ExecutionConfig::for_test_transaction();
execution_config.system_overrides = Some(SystemOverrides {
disable_auth: true,
..Default::default()
});
execution_config.enable_kernel_trace = false;
execution_config
};
Expand Down
2 changes: 2 additions & 0 deletions radix-engine/assets/native_function_base_costs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
0d906318c6318c61e603c64c6318c6318cf7be913d63aafbc6318c6318c6,update_non_fungible_data,1805510
0d906318c6318c659963ed8c6318c6318cf7be85a17d48bca6318c6318c6,create,3072615
0d906318c6318c659a6130cc6318c6318cf7a8ba5295eabf46318c6318c6,run,2056162
0d906318c6318c659a6130cc6318c6318cf7a8ba5295eabf46318c6318c6,new,2056162
0d906318c6318c659a6130cc6318c6318cf7a8ba5295eabf46318c6318c6,execute,2056162
0d906318c6318c66cd64318c6318c6318cf79e9a7f8f179ca6318c6318c6,create,2237763
0d906318c6318c66cd64318c6318c6318cf79e9a7f8f179ca6318c6318c6,create_advanced,1709496
0d906318c6318c66cd64318c6318c6318cf79e9a7f8f179ca6318c6318c6,on_virtualize,1298374
Expand Down
28 changes: 28 additions & 0 deletions radix-engine/src/blueprints/transaction_processor/blueprint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::blueprints::account::AccountSubstate;
use crate::blueprints::transaction_processor::TransactionProcessor;
use crate::internal_prelude::declare_native_blueprint_state;
use crate::internal_prelude::*;
use radix_engine_interface::types::*;



declare_native_blueprint_state! {
blueprint_ident: SubTransactionProcessor,
blueprint_snake_case: sub_transaction_processor,
features: {
},
fields: {
execution_state: {
ident: ExecutionState,
field_type: {
kind: StaticSingleVersioned,
},
condition: Condition::Always,
}
},
collections: {
}
}


pub type SubTransactionProcessorExecutionStateV1 = TransactionProcessor;
2 changes: 2 additions & 0 deletions radix-engine/src/blueprints/transaction_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod package;
mod tx_processor;
mod blueprint;

pub use blueprint::*;
pub use package::*;
pub use tx_processor::*;
65 changes: 58 additions & 7 deletions radix-engine/src/blueprints/transaction_processor/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use radix_engine_interface::blueprints::package::{
PackageDefinition,
};
use radix_engine_interface::blueprints::transaction_processor::*;
use crate::blueprints::resource::FungibleResourceManagerStateSchemaInit;

use super::TransactionProcessorBlueprint;
use super::{SubTransactionProcessorStateSchemaInit, TransactionProcessorBlueprint, TransactionProcessorExecuteInput, TransactionProcessorExecuteOutput, TransactionProcessorNewInput, TransactionProcessorNewOutput};
use super::TransactionProcessorRunInput;
use super::TransactionProcessorV1MinorVersion;

Expand All @@ -24,7 +25,8 @@ impl TransactionProcessorNativePackage {
pub fn definition() -> PackageDefinition {
let mut aggregator = TypeAggregator::<ScryptoCustomTypeKind>::new();

let fields = Vec::new();

let state = SubTransactionProcessorStateSchemaInit::create_schema_init(&mut aggregator);

let mut functions = index_map_new();
functions.insert(
Expand All @@ -40,6 +42,32 @@ impl TransactionProcessorNativePackage {
export: TRANSACTION_PROCESSOR_RUN_IDENT.to_string(),
},
);
functions.insert(
TRANSACTION_PROCESSOR_NEW_IDENT.to_string(),
FunctionSchemaInit {
receiver: None,
input: TypeRef::Static(
aggregator.add_child_type_and_descendents::<TransactionProcessorNewInput>(),
),
output: TypeRef::Static(
aggregator.add_child_type_and_descendents::<TransactionProcessorNewOutput>(),
),
export: TRANSACTION_PROCESSOR_NEW_IDENT.to_string(),
},
);
functions.insert(
TRANSACTION_PROCESSOR_EXECUTE_IDENT.to_string(),
FunctionSchemaInit {
receiver: Some(ReceiverInfo::normal_ref_mut()),
input: TypeRef::Static(
aggregator.add_child_type_and_descendents::<TransactionProcessorExecuteInput>(),
),
output: TypeRef::Static(
aggregator.add_child_type_and_descendents::<TransactionProcessorExecuteOutput>(),
),
export: TRANSACTION_PROCESSOR_EXECUTE_IDENT.to_string(),
},
);

let schema = generate_full_schema(aggregator);
let blueprints = indexmap!(
Expand All @@ -51,10 +79,7 @@ impl TransactionProcessorNativePackage {
schema: BlueprintSchemaInit {
generics: vec![],
schema,
state: BlueprintStateSchemaInit {
fields,
collections: vec![],
},
state,
functions: BlueprintFunctionsSchemaInit {
functions,
},
Expand All @@ -67,7 +92,7 @@ impl TransactionProcessorNativePackage {
// Only allow the root call frame to call any function in transaction processor.
// This is a safety precaution to reduce surface area of attack. This may be removed
// if/when the transaction processor is verified to be safe.
function_auth: FunctionAuth::RootOnly,
function_auth: FunctionAuth::AllowAll,
method_auth: MethodAuthTemplate::AllowAll,
},
}
Expand Down Expand Up @@ -100,6 +125,32 @@ impl TransactionProcessorNativePackage {

Ok(IndexedScryptoValue::from_typed(&rtn))
}
TRANSACTION_PROCESSOR_NEW_IDENT => {
let input: TransactionProcessorNewInput = input.as_typed().map_err(|e| {
RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
})?;

let rtn = TransactionProcessorBlueprint::new(
input.manifest,
input.global_address_reservations,
input.references,
api,
)?;

Ok(IndexedScryptoValue::from_typed(&rtn))
}
TRANSACTION_PROCESSOR_EXECUTE_IDENT => {
let input: TransactionProcessorExecuteInput = input.as_typed().map_err(|e| {
RuntimeError::ApplicationError(ApplicationError::InputDecodeError(e))
})?;

let rtn = TransactionProcessorBlueprint::execute(
input,
api,
)?;

Ok(IndexedScryptoValue::from_typed(&rtn))
}
_ => Err(RuntimeError::ApplicationError(
ApplicationError::ExportDoesNotExist(export_name.to_string()),
)),
Expand Down
Loading
Loading