Skip to content

Commit

Permalink
tweak: Remove BootStore abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Sep 23, 2024
1 parent 0a4810e commit 25299b4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 60 deletions.
9 changes: 3 additions & 6 deletions radix-engine/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,8 @@ pub struct Kernel<
callback: &'g mut M,
}

impl<
'g,
M: KernelCallbackObject<CallFrameData: Default>,
S: CommitableSubstateStore + BootStore,
> Kernel<'g, M, S>
impl<'g, M: KernelCallbackObject<CallFrameData: Default>, S: CommitableSubstateStore>
Kernel<'g, M, S>
{
pub fn new_no_refs(
store: &'g mut S,
Expand All @@ -331,7 +328,7 @@ impl<
}
}

impl<'g, M: KernelCallbackObject, S: CommitableSubstateStore + BootStore> Kernel<'g, M, S> {
impl<'g, M: KernelCallbackObject, S: CommitableSubstateStore> Kernel<'g, M, S> {
pub fn new(
store: &'g mut S,
id_allocator: &'g mut IdAllocator,
Expand Down
4 changes: 2 additions & 2 deletions radix-engine/src/kernel/kernel_callback_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ pub trait KernelTransactionExecutor: KernelCallbackObject {
type Receipt: ExecutionReceipt;

/// Create the callback object (system layer) and the initial call frame configuration for each intent
fn init<S: BootStore + CommitableSubstateStore>(
store: &mut S,
fn init(
store: &mut impl CommitableSubstateStore,
executable: &Self::Executable,
init: Self::Init,
) -> Result<(Self, Vec<CallFrameInit<Self::CallFrameData>>), Self::Receipt>;
Expand Down
10 changes: 5 additions & 5 deletions radix-engine/src/system/system_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ impl<L: SystemVersionLogic, V: SystemCallbackObject> System<L, V> {
fn reference_check(
references: &IndexSet<Reference>,
modules: &mut SystemModuleMixer,
store: &mut (impl BootStore + CommitableSubstateStore),
store: &mut impl CommitableSubstateStore,
) -> Result<(IndexSet<GlobalAddress>, IndexSet<InternalAddress>), BootloadingError> {
let mut global_addresses = indexset!();
let mut direct_accesses = indexset!();
Expand Down Expand Up @@ -1197,7 +1197,7 @@ impl<L: SystemVersionLogic, V: SystemCallbackObject> System<L, V> {
fn build_call_frame_inits_with_reference_check(
intents: &Vec<ExecutableIntent>,
modules: &mut SystemModuleMixer,
store: &mut (impl BootStore + CommitableSubstateStore),
store: &mut impl CommitableSubstateStore,
) -> Result<Vec<CallFrameInit<Actor>>, BootloadingError> {
let mut init_call_frames = vec![];
for intent in intents {
Expand Down Expand Up @@ -1568,8 +1568,8 @@ impl<L: SystemVersionLogic, V: SystemCallbackObject> KernelTransactionExecutor f
type ExecutionOutput = Vec<InstructionOutput>;
type Receipt = TransactionReceipt;

fn init<S: BootStore + CommitableSubstateStore>(
store: &mut S,
fn init(
store: &mut impl CommitableSubstateStore,
executable: &ExecutableTransaction,
init_input: Self::Init,
) -> Result<(Self, Vec<CallFrameInit<Actor>>), Self::Receipt> {
Expand All @@ -1582,7 +1582,7 @@ impl<L: SystemVersionLogic, V: SystemCallbackObject> KernelTransactionExecutor f
let mut modules = Self::resolve_modules(executable, init_input.self_init)?;

// NOTE: Have to use match pattern rather than map_err to appease the borrow checker
let callback = match V::init(store, init_input.callback_init) {
let callback = match V::init(init_input.callback_init) {
Ok(callback) => callback,
Err(error) => return Err(Self::create_rejection_receipt(error, modules)),
};
Expand Down
3 changes: 1 addition & 2 deletions radix-engine/src/system/system_callback_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::errors::RuntimeError;
use crate::internal_prelude::*;
use crate::kernel::kernel_api::{KernelNodeApi, KernelSubstateApi};
use crate::system::system_callback::*;
use crate::track::BootStore;
use radix_engine_interface::api::SystemApi;
use radix_engine_interface::blueprints::package::PackageExport;

Expand All @@ -12,7 +11,7 @@ pub trait SystemCallbackObject: Sized {
type Init: InitializationParameters<For = Self>;

/// Initialize and create the callback object above the system
fn init<S: BootStore>(store: &S, init_input: Self::Init) -> Result<Self, BootloadingError>;
fn init(init_input: Self::Init) -> Result<Self, BootloadingError>;

/// Invoke a function
fn invoke<
Expand Down
14 changes: 0 additions & 14 deletions radix-engine/src/track/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ pub enum TrackedSubstateInfo {
Unmodified,
}

/// The interface to be used during boot loading
/// This interface is different from the CommitableSubstateStore in
/// that these reads should not be tracked / costed since it will
/// cause a protocol break.
pub trait BootStore {
/// Read a substate from the store
fn read_boot_substate(
&self,
node_id: &NodeId,
partition_num: PartitionNumber,
substate_key: &SubstateKey,
) -> Option<IndexedScryptoValue>;
}

/// Represents the interface between Radix Engine and Track.
///
/// In practice, we will likely end up with only one implementation.
Expand Down
17 changes: 0 additions & 17 deletions radix-engine/src/track/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::track::interface::{
CommitableSubstateStore, IOAccess, NodeSubstates, TrackedSubstateInfo,
};
use crate::track::state_updates::*;
use crate::track::BootStore;
use radix_engine_interface::types::*;
use radix_substate_store_interface::db_key_mapper::{SpreadPrefixKeyMapper, SubstateKeyContent};
use radix_substate_store_interface::interface::DbPartitionKey;
Expand Down Expand Up @@ -40,22 +39,6 @@ pub struct MappedTrack<'s, S: SubstateDatabase, M: DatabaseKeyMapper + 'static>
phantom_data: PhantomData<M>,
}

impl<'s, S: SubstateDatabase, M: DatabaseKeyMapper + 'static> BootStore for MappedTrack<'s, S, M> {
fn read_boot_substate(
&self,
node_id: &NodeId,
partition_num: PartitionNumber,
substate_key: &SubstateKey,
) -> Option<IndexedScryptoValue> {
let db_partition_key = M::to_db_partition_key(node_id, partition_num);
let db_sort_key = M::to_db_sort_key(&substate_key);

self.substate_db
.get_raw_substate_by_db_key(&db_partition_key, &db_sort_key)
.map(|e| IndexedScryptoValue::from_vec(e).expect("Failed to decode substate"))
}
}

/// Records all the substates that have been read or written into, and all the partitions to delete.
///
/// `NodeId` in this struct isn't always valid.
Expand Down
14 changes: 2 additions & 12 deletions radix-engine/src/vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::kernel::kernel_api::{KernelNodeApi, KernelSubstateApi};
use crate::system::system_callback::*;
use crate::system::system_callback_api::SystemCallbackObject;
use crate::system::system_substates::KeyValueEntrySubstate;
use crate::track::BootStore;
use crate::vm::wasm::{ScryptoV1WasmValidator, WasmEngine};
use crate::vm::{NativeVm, NativeVmExtension, ScryptoVm};
use radix_engine_interface::api::field_api::LockFlags;
Expand Down Expand Up @@ -162,20 +161,11 @@ pub struct Vm<'g, W: WasmEngine, E: NativeVmExtension> {
impl<'g, W: WasmEngine + 'g, E: NativeVmExtension> SystemCallbackObject for Vm<'g, W, E> {
type Init = VmInit<'g, W, E>;

fn init<S: BootStore>(store: &S, vm_init: VmInit<'g, W, E>) -> Result<Self, BootloadingError> {
let vm_boot = store
.read_boot_substate(
TRANSACTION_TRACKER.as_node_id(),
BOOT_LOADER_PARTITION,
&SubstateKey::Field(BOOT_LOADER_VM_BOOT_FIELD_KEY),
)
.map(|v| scrypto_decode(v.as_slice()).unwrap())
.unwrap_or(VmBoot::babylon_genesis());

fn init(vm_init: VmInit<'g, W, E>) -> Result<Self, BootloadingError> {
Ok(Self {
scrypto_vm: vm_init.scrypto_vm,
native_vm: NativeVm::new_with_extension(vm_init.native_vm_extension),
vm_boot,
vm_boot: vm_init.vm_boot,
})
}

Expand Down
4 changes: 2 additions & 2 deletions scrypto-test/src/ledger_simulator/inject_costing_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ impl<
type ExecutionOutput = Vec<InstructionOutput>;
type Receipt = TransactionReceipt;

fn init<S: BootStore + CommitableSubstateStore>(
store: &mut S,
fn init(
store: &mut impl CommitableSubstateStore,
executable: &ExecutableTransaction,
init_input: Self::Init,
) -> Result<(Self, Vec<CallFrameInit<Self::CallFrameData>>), Self::Receipt> {
Expand Down

0 comments on commit 25299b4

Please sign in to comment.