Skip to content

Commit

Permalink
feat: Separate out VmInit creation to VmInitialize trait
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Aug 20, 2024
1 parent c4d6037 commit c9f1f38
Show file tree
Hide file tree
Showing 18 changed files with 312 additions and 587 deletions.
11 changes: 4 additions & 7 deletions radix-engine-tests/benches/resources_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use radix_engine::kernel::vm::ScryptoInterpreter;
use radix_engine::ledger::*;
use radix_engine::transaction::execute_and_commit_transaction;
use radix_engine::transaction::{CostingParameters, ExecutionConfig, ResourcesUsage};
use radix_engine::updates::ProtocolBuilder;
use radix_engine::wasm::{DefaultWasmEngine, WasmValidatorConfig};
use radix_engine_interface::blueprints::resource::*;
use radix_engine_interface::dec;
Expand Down Expand Up @@ -125,14 +126,10 @@ fn transfer_test(c: &mut Criterion) {
// Set up environment.
let mut fwk = ResourceInfoFramework::new();

let mut scrypto_interpreter = ScryptoInterpreter {
wasm_engine: DefaultWasmEngine::default(),
wasm_validator_config: WasmValidatorConfig::new(),
};
let mut substate_db = InMemorySubstateDatabase::standard();
let _ = Bootstrapper::new(&mut substate_db, &scrypto_interpreter)
.bootstrap_test_default()
.unwrap();
ProtocolBuilder::for_simulator()
.from_bootstrap_to_latest()
.commit_each_protocol_update(&mut substate_db);

// Create a key pair
let private_key = Secp256k1PrivateKey::from_u64(1).unwrap();
Expand Down
28 changes: 9 additions & 19 deletions radix-engine-tests/benches/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use criterion::{criterion_group, criterion_main, Criterion};
use radix_common::prelude::*;
use radix_engine::system::bootstrap::Bootstrapper;
use radix_engine::transaction::execute_and_commit_transaction;
use radix_engine::transaction::ExecutionConfig;
use radix_engine::vm::wasm::{DefaultWasmEngine, WasmValidatorConfigV1};
use radix_engine::vm::{NoExtension, ScryptoVm, VmInit};
use radix_engine::updates::ProtocolBuilder;
use radix_engine::vm::*;
use radix_engine_interface::prelude::*;
use radix_engine_interface::rule;
use radix_substate_store_impls::memory_db::InMemorySubstateDatabase;
Expand All @@ -13,20 +12,11 @@ use radix_transactions::prelude::*;

fn bench_transfer(c: &mut Criterion) {
// Set up environment.
let scrypto_vm = ScryptoVm {
wasm_engine: DefaultWasmEngine::default(),
wasm_validator_config: WasmValidatorConfigV1::new(),
};
let vm_init = VmInit::new(&scrypto_vm, NoExtension);
let mut substate_db = InMemorySubstateDatabase::standard();
Bootstrapper::new(
NetworkDefinition::simulator(),
&mut substate_db,
vm_init.clone(),
false,
)
.bootstrap_test_default()
.unwrap();
let vm_modules = VmModules::default();
ProtocolBuilder::for_simulator()
.from_bootstrap_to_latest()
.commit_each_protocol_update(&mut substate_db);

// Create a key pair
let private_key = Secp256k1PrivateKey::from_u64(1).unwrap();
Expand All @@ -44,7 +34,7 @@ fn bench_transfer(c: &mut Criterion) {
.build();
let account = execute_and_commit_transaction(
&mut substate_db,
vm_init.clone(),
vm_modules.create_vm_init(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
TestTransaction::new_from_nonce(manifest, 1)
.prepare()
Expand All @@ -70,7 +60,7 @@ fn bench_transfer(c: &mut Criterion) {
for nonce in 0..1000 {
execute_and_commit_transaction(
&mut substate_db,
vm_init.clone(),
vm_modules.create_vm_init(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
TestTransaction::new_from_nonce(manifest.clone(), nonce)
.prepare()
Expand All @@ -93,7 +83,7 @@ fn bench_transfer(c: &mut Criterion) {
b.iter(|| {
let receipt = execute_and_commit_transaction(
&mut substate_db,
vm_init.clone(),
vm_modules.create_vm_init(),
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
TestTransaction::new_from_nonce(manifest.clone(), nonce)
.prepare()
Expand Down
7 changes: 2 additions & 5 deletions radix-engine-tests/tests/application/fuzz_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use radix_common::prelude::*;
use radix_engine::system::bootstrap::Bootstrapper;
use radix_engine::transaction::{
execute_and_commit_transaction, ExecutionConfig,
};
use radix_engine::updates::ProtocolBuilder;
use radix_engine::vm::wasm::{DefaultWasmEngine, WasmValidatorConfigV1};
use radix_engine::vm::{NoExtension, ScryptoVm, VmInit};
use radix_engine_interface::blueprints::resource::AccessRule;
Expand Down Expand Up @@ -32,12 +32,9 @@ impl TransactionFuzzer {
wasm_engine: DefaultWasmEngine::default(),
wasm_validator_config: WasmValidatorConfigV1::new(),
};
let vms = VmInit::new(&scrypto_vm, NoExtension);

let mut substate_db = InMemorySubstateDatabase::standard();
Bootstrapper::new(NetworkDefinition::simulator(), &mut substate_db, vms, false)
.bootstrap_test_default()
.unwrap();
ProtocolBuilder::for_simulator().from_bootstrap_to_latest().commit_each_protocol_update(&mut substate_db);

Self {
rng,
Expand Down
11 changes: 2 additions & 9 deletions radix-engine-tests/tests/db/substate_database_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use radix_engine::system::system_db_reader::*;
use radix_engine::transaction::*;
use radix_engine::updates::*;
use radix_engine::vm::NoExtension;
use radix_engine::vm::VmModules;
use radix_substate_store_impls::memory_db::*;
use radix_substate_store_impls::substate_database_overlay::*;
use radix_substate_store_interface::db_key_mapper::*;
Expand All @@ -10,7 +11,6 @@ use radix_transaction_scenarios::executor::*;
use radix_transactions::builder::*;
use scrypto::prelude::*;
use scrypto_test::ledger_simulator::*;
use scrypto_test::prelude::DefaultWasmEngine;

#[test]
fn substates_written_to_root_database_can_be_read() {
Expand Down Expand Up @@ -472,14 +472,6 @@ fn run_scenarios(
}

impl<'a> ProtocolUpdateExecutionHooks for ProtocolUpdateHooks<'a> {
const IS_ENABLED: bool = true;
type WasmEngine = DefaultWasmEngine;
type NativeVmExtension = NoExtension;

fn get_vm_extension(&mut self) -> NoExtension {
NoExtension
}

fn on_transaction_executed(
&mut self,
_protocol_version: ProtocolVersion,
Expand Down Expand Up @@ -523,6 +515,7 @@ fn run_scenarios(
&mut ProtocolUpdateHooks {
ledger_with_overlay: ledger_with_overlay.clone(),
},
&VmModules::default(),
)
.expect("Must succeed!");
}
15 changes: 3 additions & 12 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,6 @@ 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::bootstrap::Bootstrapper;
use radix_engine::system::system_callback::{System, SystemLockData};
use radix_engine::system::system_modules::auth::AuthModule;
use radix_engine::system::system_modules::costing::{
Expand All @@ -16,8 +15,9 @@ use radix_engine::system::system_modules::limits::LimitsModule;
use radix_engine::system::system_modules::transaction_runtime::TransactionRuntimeModule;
use radix_engine::system::system_modules::{EnabledModules, SystemModuleMixer};
use radix_engine::track::Track;
use radix_engine::updates::ProtocolBuilder;
use radix_engine::vm::wasm::DefaultWasmEngine;
use radix_engine::vm::{DefaultNativeVm, NoExtension, ScryptoVm, Vm, VmBoot, VmInit};
use radix_engine::vm::*;
use radix_engine_interface::api::LockFlags;
use radix_engine_interface::prelude::*;
use radix_substate_store_impls::memory_db::InMemorySubstateDatabase;
Expand All @@ -40,16 +40,7 @@ pub fn test_open_substate_of_invisible_package_address() {
let mut database = InMemorySubstateDatabase::standard();
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let native_vm = DefaultNativeVm::new();
let vm_init = VmInit {
scrypto_vm: &scrypto_vm,
native_vm_extension: NoExtension,
};
Bootstrapper::new(
NetworkDefinition::simulator(),
&mut database,
vm_init,
false,
);
ProtocolBuilder::for_simulator().from_bootstrap_to_latest().commit_each_protocol_update(&mut database);

// Create kernel
let mut system = System {
Expand Down
11 changes: 2 additions & 9 deletions radix-engine-tests/tests/kernel/transaction_executor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use radix_common::prelude::*;
use radix_engine::errors::RejectionReason;
use radix_engine::system::bootstrap::Bootstrapper;
use radix_engine::transaction::execute_and_commit_transaction;
use radix_engine::transaction::ExecutionConfig;
use radix_engine::updates::ProtocolBuilder;
use radix_engine::vm::wasm::{DefaultWasmEngine, WasmValidatorConfigV1};
use radix_engine::vm::ScryptoVm;
use radix_substate_store_impls::memory_db::InMemorySubstateDatabase;
Expand Down Expand Up @@ -99,14 +99,7 @@ fn test_normal_transaction_flow() {
let vm_init = VmInit::new(&scrypto_vm, NoExtension);

let mut substate_db = InMemorySubstateDatabase::standard();
Bootstrapper::new(
NetworkDefinition::simulator(),
&mut substate_db,
vm_init.clone(),
true,
)
.bootstrap_test_default()
.unwrap();
ProtocolBuilder::for_simulator().from_bootstrap_to_latest().commit_each_protocol_update(&mut substate_db);

let execution_config = ExecutionConfig::for_test_transaction().with_kernel_trace(true);
let raw_transaction = create_notarized_transaction(
Expand Down
11 changes: 2 additions & 9 deletions radix-engine-tests/tests/kernel/transaction_multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#[cfg(not(feature = "resource_tracker"))]
mod multi_threaded_test {
use radix_common::prelude::*;
use radix_engine::system::bootstrap::Bootstrapper;
use radix_engine::transaction::ExecutionConfig;
use radix_engine::transaction::{execute_and_commit_transaction, execute_transaction};
use radix_engine::updates::ProtocolBuilder;
use radix_engine::vm::wasm::{DefaultWasmEngine, WasmValidatorConfigV1};
use radix_engine_interface::prelude::*;
use radix_engine_interface::rule;
Expand All @@ -30,14 +30,7 @@ mod multi_threaded_test {
native_vm_extension: NoExtension,
};
let mut substate_db = InMemorySubstateDatabase::standard();
Bootstrapper::new(
NetworkDefinition::simulator(),
&mut substate_db,
vm_init.clone(),
false,
)
.bootstrap_test_default()
.unwrap();
ProtocolBuilder::for_simulator().from_bootstrap_to_latest().commit_each_protocol_update(&mut substate_db);

// Create a key pair
let private_key = Secp256k1PrivateKey::from_u64(1).unwrap();
Expand Down
Loading

0 comments on commit c9f1f38

Please sign in to comment.