Skip to content

Commit

Permalink
tweak: SystemVersion is generic
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Sep 23, 2024
1 parent edc5781 commit 2e6b850
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 148 deletions.
3 changes: 1 addition & 2 deletions radix-engine-tests/tests/kernel/kernel_open_substate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ pub fn test_open_substate_of_invisible_package_address() {
.commit_each_protocol_update(&mut database);

// Create kernel
let mut system = System::new(
SystemVersion::latest(),
let mut system = LatestSystem::new(
Vm {
scrypto_vm: &scrypto_vm,
native_vm,
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/tests/kernel/panics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use scrypto_test::prelude::*;
#[test]
fn panics_at_the_system_layer_or_below_can_be_caught() {
// Arrange
let mut kernel = MockKernel(PhantomData::<System<Vm<DefaultWasmEngine, NoExtension>>>);
let mut kernel = MockKernel(PhantomData::<LatestSystem<Vm<DefaultWasmEngine, NoExtension>>>);
let mut system_service = SystemService::new(&mut kernel);

// Act
Expand Down
6 changes: 2 additions & 4 deletions radix-engine-tests/tests/vm/native_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ fn panics_can_be_caught_in_the_native_vm_and_converted_into_results() {
let native_vm = NativeVm::new_with_extension(Extension);

let intent_hash = Hash([0; 32]);
let mut system = System::new(
SystemVersion::latest(),
let mut system = LatestSystem::new(
Vm {
scrypto_vm: &scrypto_vm,
native_vm,
Expand Down Expand Up @@ -133,8 +132,7 @@ fn any_panics_can_be_caught_in_the_native_vm_and_converted_into_results() {
let native_vm = NativeVm::new_with_extension(NonStringPanicExtension);

let intent_hash = Hash([0; 32]);
let mut system = System::new(
SystemVersion::latest(),
let mut system = LatestSystem::new(
Vm {
scrypto_vm: &scrypto_vm,
native_vm,
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 SystemVersionLogic: SystemVersionLogic;
type SystemCallback: SystemCallbackObject;

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

fn system_state(&mut self) -> SystemState<'_, System<Self::SystemCallback>>;
fn system_state(
&mut self,
) -> SystemState<'_, System<Self::SystemVersionLogic, 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: SystemVersionLogic,
V: SystemCallbackObject,
K: KernelInternalApi<System = System<L, V>> + ?Sized,
> SystemModuleApi for SystemModuleApiImpl<'a, K>
{
type SystemVersionLogic = 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: SystemVersionLogic,
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::SystemVersionLogic, 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::SystemVersionLogic::should_consume_cost_units(self.api) {
return Ok(());
}

Expand Down
Loading

0 comments on commit 2e6b850

Please sign in to comment.