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

tweak: Move System version into type system #1919

Open
wants to merge 1 commit into
base: refactor/engine-init-improvements
Choose a base branch
from
Open
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
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
Loading