Skip to content

Commit

Permalink
tweak: Make SystemLogicVersion a generic for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Sep 15, 2024
1 parent 769c596 commit a3ef568
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 180 deletions.
6 changes: 3 additions & 3 deletions radix-engine-tests/tests/kernel/kernel_open_substate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use radix_engine::kernel::call_frame::OpenSubstateError;
use radix_engine::kernel::id_allocator::IdAllocator;
use radix_engine::kernel::kernel::Kernel;
use radix_engine::kernel::kernel_api::KernelSubstateApi;
use radix_engine::system::system_callback::{System, SystemLockData, VersionedSystemLogic};
use radix_engine::system::system_callback::{System, SystemLockData};
use radix_engine::system::system_modules::auth::AuthModule;
use radix_engine::system::system_modules::costing::{
CostingModule, CostingModuleConfig, FeeTable, SystemLoanFeeReserve,
Expand All @@ -26,7 +26,7 @@ use radix_substate_store_queries::typed_substate_layout::{
BlueprintVersionKey, PACKAGE_AUTH_TEMPLATE_PARTITION_OFFSET,
};
use radix_transactions::prelude::*;
use scrypto_test::prelude::UniqueTransaction;
use scrypto_test::prelude::{LatestSystemLogicVersion, UniqueTransaction};

#[test]
pub fn test_open_substate_of_invisible_package_address() {
Expand All @@ -48,7 +48,7 @@ pub fn test_open_substate_of_invisible_package_address() {

// Create kernel
let mut system = System {
versioned_system_logic: VersionedSystemLogic::V1,
versioned_system_logic: LatestSystemLogicVersion::default(),
blueprint_cache: NonIterMap::new(),
auth_cache: NonIterMap::new(),
schema_cache: NonIterMap::new(),
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-tests/tests/kernel/panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ macro_rules! panic1 {
pub struct MockKernel<M: SystemCallbackObject>(PhantomData<M>);

impl<M: SystemCallbackObject> KernelApi for MockKernel<M> {
type CallbackObject = System<M>;
type CallbackObject = System<LatestSystemLogicVersion, M>;
}

impl<M: SystemCallbackObject> KernelStackApi for MockKernel<M> {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<M: SystemCallbackObject> KernelInvokeApi<Actor> for MockKernel<M> {
}

impl<M: SystemCallbackObject> KernelInternalApi for MockKernel<M> {
type System = System<M>;
type System = System<LatestSystemLogicVersion, M>;

fn kernel_get_system_state(&mut self) -> SystemState<'_, Self::System> {
panic1!()
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-tests/tests/vm/native_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn panics_can_be_caught_in_the_native_vm_and_converted_into_results() {

let intent_hash = Hash([0; 32]);
let mut system = System {
versioned_system_logic: VersionedSystemLogic::V1,
versioned_system_logic: LatestSystemLogicVersion::default(),
blueprint_cache: NonIterMap::new(),
auth_cache: NonIterMap::new(),
schema_cache: NonIterMap::new(),
Expand Down Expand Up @@ -138,7 +138,7 @@ fn any_panics_can_be_caught_in_the_native_vm_and_converted_into_results() {

let intent_hash = Hash([0; 32]);
let mut system = System {
versioned_system_logic: VersionedSystemLogic::V1,
versioned_system_logic: LatestSystemLogicVersion::default(),
blueprint_cache: NonIterMap::new(),
auth_cache: NonIterMap::new(),
schema_cache: NonIterMap::new(),
Expand Down
2 changes: 1 addition & 1 deletion radix-engine/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'h, M: KernelTransactionCallbackObject, S: SubstateDatabase> BootLoader<'h,
.unwrap_or(KernelBoot::babylon());

// Upper Layer Initialization
let system_init_result = M::init(&mut self.track, &executable, self.init.clone());
let system_init_result = M::init(&mut self.track, &executable, self.init);

let (mut system, call_frame_inits) = match system_init_result {
Ok(success) => success,
Expand Down
2 changes: 1 addition & 1 deletion radix-engine/src/kernel/kernel_callback_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub trait ExecutionReceipt {

pub trait KernelTransactionCallbackObject: KernelCallbackObject {
/// Initialization object
type Init: Clone;
type Init;
/// The transaction object
type Executable;
/// Output to be returned at the end of execution
Expand Down
19 changes: 14 additions & 5 deletions radix-engine/src/system/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@ impl<'a, K: KernelInternalApi + ?Sized> SystemModuleApiImpl<'a, K> {
}

pub trait SystemModuleApi {
type SystemLogicVersion: SystemLogicVersion;
type SystemCallback: SystemCallbackObject;

fn system(&mut self) -> &mut System<Self::SystemCallback>;
fn system(&mut self) -> &mut System<Self::SystemLogicVersion, Self::SystemCallback>;

fn system_state(&mut self) -> SystemState<'_, System<Self::SystemCallback>>;
fn system_state(
&mut self,
) -> SystemState<'_, System<Self::SystemLogicVersion, Self::SystemCallback>>;

/// Gets the number of call frames that are currently in the call frame stack
fn current_stack_depth(&self) -> usize;
}

impl<'a, V: SystemCallbackObject, K: KernelInternalApi<System = System<V>> + ?Sized> SystemModuleApi
for SystemModuleApiImpl<'a, K>
impl<
'a,
L: SystemLogicVersion,
V: SystemCallbackObject,
K: KernelInternalApi<System = System<L, V>> + ?Sized,
> SystemModuleApi for SystemModuleApiImpl<'a, K>
{
type SystemLogicVersion = L;
type SystemCallback = V;

fn system(&mut self) -> &mut K::System {
Expand Down Expand Up @@ -76,8 +84,9 @@ pub trait SystemModuleApiFor<M: ResolvableSystemModule + ?Sized>: SystemModuleAp

impl<
'a,
L: SystemLogicVersion,
V: SystemCallbackObject,
K: KernelInternalApi<System = System<V>> + ?Sized,
K: KernelInternalApi<System = System<L, V>> + ?Sized,
M: ResolvableSystemModule + ?Sized,
> SystemModuleApiFor<M> for SystemModuleApiImpl<'a, K>
{
Expand Down
9 changes: 2 additions & 7 deletions radix-engine/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'a, Y: SystemBasedKernelApi + ?Sized> SystemService<'a, Y> {
self.api
}

pub fn system(&mut self) -> &mut System<Y::SystemCallback> {
pub fn system(&mut self) -> &mut System<Y::SystemLogicVersion, Y::SystemCallback> {
self.api.kernel_get_system()
}

Expand Down Expand Up @@ -2168,12 +2168,7 @@ impl<'a, Y: SystemBasedKernelApi> SystemCostingApi<RuntimeError> for SystemServi
&mut self,
costing_entry: ClientCostingEntry,
) -> Result<(), RuntimeError> {
let system_logic = self
.api
.kernel_get_system_state()
.system
.versioned_system_logic;
if !system_logic.should_consume_cost_units(self.api) {
if !Y::SystemLogicVersion::should_consume_cost_units(self.api) {
return Ok(());
}

Expand Down
Loading

0 comments on commit a3ef568

Please sign in to comment.