Skip to content

Commit

Permalink
tweak: Further neatenings
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Aug 22, 2024
1 parent 78a5bf2 commit 38ff19d
Show file tree
Hide file tree
Showing 57 changed files with 572 additions and 479 deletions.
7 changes: 3 additions & 4 deletions radix-clis/src/replay/cmd_alloc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
use radix_engine::vm::VmModules;
use radix_engine_profiling::info_alloc::*;
use radix_substate_store_impls::rocks_db_with_merkle_tree::RocksDBWithMerkleTreeSubstateStore;
use radix_substate_store_interface::db_key_mapper::SpreadPrefixKeyMapper;
Expand Down Expand Up @@ -118,7 +117,7 @@ impl TxnAllocDump {
);
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let vm_modules = VmModules::default();
let iter = rx.iter();
for tx_payload in iter {
let prepared = prepare_ledger_transaction(&tx_payload);
Expand All @@ -128,7 +127,7 @@ impl TxnAllocDump {

let receipt = execute_prepared_ledger_transaction(
&database,
&scrypto_vm,
&vm_modules,
&network,
&prepared,
trace,
Expand Down
7 changes: 3 additions & 4 deletions radix-clis/src/replay/cmd_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
use radix_engine::vm::VmModules;
use radix_substate_store_impls::rocks_db_with_merkle_tree::RocksDBWithMerkleTreeSubstateStore;
use radix_substate_store_interface::db_key_mapper::SpreadPrefixKeyMapper;
use radix_substate_store_interface::interface::*;
Expand Down Expand Up @@ -74,12 +73,12 @@ impl TxnExecute {
let mut database = RocksDBWithMerkleTreeSubstateStore::standard(self.database_dir.clone());
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let vm_modules = VmModules::default();
let iter = rx.iter();
for tx_payload in iter {
let state_updates = execute_ledger_transaction(
&database,
&scrypto_vm,
&vm_modules,
&network,
&tx_payload,
trace,
Expand Down
7 changes: 3 additions & 4 deletions radix-clis/src/replay/cmd_execute_in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
use radix_engine::vm::VmModules;
use radix_substate_store_impls::memory_db::InMemorySubstateDatabase;
use radix_substate_store_impls::state_tree_support::StateTreeUpdatingDatabase;
use radix_substate_store_interface::db_key_mapper::SpreadPrefixKeyMapper;
Expand Down Expand Up @@ -86,12 +85,12 @@ impl TxnExecuteInMemory {
let mut database = StateTreeUpdatingDatabase::new(substate_database);
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let vm_modules = VmModules::default();
let iter = rx.iter();
for tx_payload in iter {
let state_updates = execute_ledger_transaction(
&database,
&scrypto_vm,
&vm_modules,
&network,
&tx_payload,
trace,
Expand Down
7 changes: 3 additions & 4 deletions radix-clis/src/replay/cmd_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
use radix_engine::vm::*;
use radix_substate_store_impls::rocks_db_with_merkle_tree::RocksDBWithMerkleTreeSubstateStore;
use radix_substate_store_interface::db_key_mapper::SpreadPrefixKeyMapper;
use radix_substate_store_interface::interface::*;
Expand Down Expand Up @@ -94,14 +93,14 @@ impl TxnMeasure {

let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let vm_modules = VmModules::default();
let iter = rx.iter();
for tx_payload in iter {
let tx_start_time = std::time::Instant::now();
let prepared = prepare_ledger_transaction(&tx_payload);
let receipt = execute_prepared_ledger_transaction(
&database,
&scrypto_vm,
&vm_modules,
&network,
&prepared,
trace,
Expand Down
7 changes: 3 additions & 4 deletions radix-clis/src/replay/cmd_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use clap::Parser;
use flume;
use flume::Sender;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
use radix_engine::vm::VmModules;
use radix_substate_store_impls::rocks_db_with_merkle_tree::RocksDBWithMerkleTreeSubstateStore;
use radix_substate_store_interface::db_key_mapper::SpreadPrefixKeyMapper;
use radix_substate_store_interface::interface::*;
Expand Down Expand Up @@ -64,12 +63,12 @@ impl TxnSync {
let mut database = RocksDBWithMerkleTreeSubstateStore::standard(self.database_dir.clone());
let trace = self.trace;
let txn_write_thread_handle = thread::spawn(move || {
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let vm_modules = VmModules::default();
let iter = rx.iter();
for (tx_payload, expected_state_root_hash) in iter {
let state_updates = execute_ledger_transaction(
&database,
&scrypto_vm,
&vm_modules,
&network,
&tx_payload,
trace,
Expand Down
24 changes: 7 additions & 17 deletions radix-clis/src/replay/ledger_transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use radix_engine::system::bootstrap::*;
use radix_engine::transaction::{
execute_transaction, ExecutionConfig, TransactionFeeSummary, TransactionReceipt,
};
use radix_engine::vm::wasm::*;
use radix_engine::vm::{NoExtension, ScryptoVm, VmInit};
use radix_engine::vm::*;
use radix_engine_interface::prelude::system_execution;
use radix_substate_store_interface::interface::SubstateDatabase;
use radix_transactions::prelude::*;
Expand Down Expand Up @@ -40,13 +39,13 @@ impl LedgerTransactionReceipt {

pub fn execute_ledger_transaction<S: SubstateDatabase>(
database: &S,
scrypto_vm: &ScryptoVm<DefaultWasmEngine>,
vm_modules: &impl VmInitialize,
network: &NetworkDefinition,
tx_payload: &[u8],
trace: bool,
) -> StateUpdates {
let prepared = prepare_ledger_transaction(tx_payload);
execute_prepared_ledger_transaction(database, scrypto_vm, network, &prepared, trace)
execute_prepared_ledger_transaction(database, vm_modules, network, &prepared, trace)
.into_state_updates()
}

Expand All @@ -61,7 +60,7 @@ pub fn prepare_ledger_transaction(tx_payload: &[u8]) -> PreparedLedgerTransactio

pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
database: &S,
scrypto_vm: &ScryptoVm<DefaultWasmEngine>,
vm_modules: &impl VmInitialize,
network: &NetworkDefinition,
prepared: &PreparedLedgerTransaction,
trace: bool,
Expand All @@ -76,10 +75,7 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
PreparedGenesisTransaction::Transaction(tx) => {
let receipt = execute_transaction(
database,
VmInit {
scrypto_vm,
native_vm_extension: NoExtension,
},
vm_modules,
&ExecutionConfig::for_genesis_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
Expand All @@ -92,10 +88,7 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
PreparedLedgerTransactionInner::UserV1(tx) => {
let receipt = execute_transaction(
database,
VmInit {
scrypto_vm,
native_vm_extension: NoExtension,
},
vm_modules,
&ExecutionConfig::for_notarized_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
Expand All @@ -109,10 +102,7 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
PreparedLedgerTransactionInner::RoundUpdateV1(tx) => {
let receipt = execute_transaction(
database,
VmInit {
scrypto_vm,
native_vm_extension: NoExtension,
},
vm_modules,
&ExecutionConfig::for_system_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
Expand Down
1 change: 1 addition & 0 deletions radix-clis/src/resim/cmd_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use clap::Parser;
use colored::*;
use radix_common::prelude::*;
use radix_engine::blueprints::models::*;
use radix_engine::vm::wasm::ScryptoV1WasmValidator;
use radix_engine::vm::ScryptoVmVersion;
use radix_engine_interface::blueprints::package::{
BlueprintDefinition, BlueprintDependencies, BlueprintPayloadDef, FunctionSchema,
Expand Down
7 changes: 4 additions & 3 deletions radix-clis/src/resim/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::resim::*;
use radix_common::prelude::*;
use radix_engine::updates::*;
use radix_engine::vm::*;
use std::env;
use std::fs;
use std::path::PathBuf;
Expand All @@ -10,7 +11,7 @@ pub struct SimulatorEnvironment {
// Db
pub db: RocksdbSubstateStore,
// VMs
pub scrypto_vm: ScryptoVm<DefaultWasmEngine>,
pub vm_modules: DefaultVmModules,
pub network_definition: NetworkDefinition,
}

Expand All @@ -20,11 +21,11 @@ impl SimulatorEnvironment {
let db = RocksdbSubstateStore::standard(get_data_dir()?);

// Create the VMs
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();
let vm_modules = VmModules::default();

let mut env = Self {
db,
scrypto_vm,
vm_modules,
network_definition: NetworkDefinition::simulator(),
};
env.bootstrap();
Expand Down
28 changes: 7 additions & 21 deletions radix-clis/src/resim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,16 @@ use clap::{Parser, Subcommand};
use radix_common::crypto::{hash, Secp256k1PrivateKey};
use radix_common::network::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::blueprints::consensus_manager::{
ConsensusManagerSubstate, ProposerMilliTimestampSubstate, ProposerMinuteTimestampSubstate,
};
use radix_engine::blueprints::consensus_manager::*;
use radix_engine::blueprints::models::FieldPayload;
use radix_engine::system::system_db_reader::*;
use radix_engine::transaction::execute_and_commit_transaction;
use radix_engine::transaction::ExecutionConfig;
use radix_engine::transaction::TransactionOutcome;
use radix_engine::transaction::TransactionReceipt;
use radix_engine::transaction::TransactionReceiptDisplayContextBuilder;
use radix_engine::transaction::TransactionResult;
use radix_engine::vm::wasm::*;
use radix_engine::vm::{NoExtension, ScryptoVm, VmInit};
use radix_engine::transaction::*;
use radix_engine_interface::api::ModuleId;
use radix_engine_interface::blueprints::package::{
BlueprintDefinition, BlueprintInterface, BlueprintPayloadDef, BlueprintVersionKey,
};
use radix_engine_interface::blueprints::package::*;
use radix_engine_interface::prelude::*;
use radix_engine_interface::types::FromPublicKey;
use radix_rust::ContextualDisplay;
use radix_substate_store_impls::rocks_db::RocksdbSubstateStore;
use radix_substate_store_queries::typed_substate_layout::*;
use radix_transactions::manifest::decompile;
use radix_transactions::model::TestTransaction;
use radix_transactions::model::{BlobV1, BlobsV1, InstructionV1, InstructionsV1};
Expand Down Expand Up @@ -166,9 +154,8 @@ pub fn handle_system_transaction<O: std::io::Write>(
out: &mut O,
) -> Result<TransactionReceipt, Error> {
let SimulatorEnvironment {
mut db, scrypto_vm, ..
mut db, vm_modules, ..
} = SimulatorEnvironment::new()?;
let vm_init = VmInit::new(&scrypto_vm, NoExtension);

let nonce = get_nonce()?;
let transaction = SystemTransactionV1 {
Expand All @@ -182,7 +169,7 @@ pub fn handle_system_transaction<O: std::io::Write>(

let receipt = execute_and_commit_transaction(
&mut db,
vm_init,
&vm_modules,
&ExecutionConfig::for_system_transaction(NetworkDefinition::simulator())
.with_kernel_trace(trace),
transaction
Expand Down Expand Up @@ -237,9 +224,8 @@ pub fn handle_manifest<O: std::io::Write>(
}
None => {
let SimulatorEnvironment {
mut db, scrypto_vm, ..
mut db, vm_modules, ..
} = SimulatorEnvironment::new()?;
let vm_init = VmInit::new(&scrypto_vm, NoExtension);

let sks = get_signing_keys(signing_keys)?;
let initial_proofs = sks
Expand All @@ -251,7 +237,7 @@ pub fn handle_manifest<O: std::io::Write>(

let receipt = execute_and_commit_transaction(
&mut db,
vm_init,
&vm_modules,
&ExecutionConfig::for_test_transaction().with_kernel_trace(trace),
transaction
.prepare()
Expand Down
2 changes: 0 additions & 2 deletions radix-common/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod native_addresses;
mod native_blueprints;
mod sbor_payload;
mod system_execution;
mod transaction_construction;
mod transaction_execution;
mod transaction_validation;
mod wasm;
Expand All @@ -15,7 +14,6 @@ pub use native_addresses::*;
pub use native_blueprints::*;
pub use sbor_payload::*;
pub use system_execution::*;
pub use transaction_construction::*;
pub use transaction_execution::*;
pub use transaction_validation::*;
pub use wasm::*;
2 changes: 0 additions & 2 deletions radix-common/src/constants/transaction_construction.rs

This file was deleted.

2 changes: 1 addition & 1 deletion radix-engine-interface/src/api/costing_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait SystemCostingApi<E> {
fn max_per_function_royalty_in_xrd(&mut self) -> Result<Decimal, E>;

/// Retrieve the tip percentage of the transaction
fn tip_percentage(&mut self) -> Result<u32, E>;
fn tip_percentage_truncated(&mut self) -> Result<u32, E>;

/// Retrieve the current fee balance in XRD
fn fee_balance(&mut self) -> Result<Decimal, E>;
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-tests/benches/costing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use radix_engine_tests::common::*;
use radix_substate_store_queries::typed_substate_layout::{CodeHash, PackageDefinition};
use radix_transactions::prelude::TransactionCostingParameters;
use sbor::rust::iter;
use scrypto_test::prelude::LedgerSimulatorBuilder;
use scrypto_test::prelude::*;
use wabt::wat2wasm;

fn generate_interesting_bytes_of_length(length: usize) -> Vec<u8> {
Expand Down Expand Up @@ -200,7 +200,7 @@ fn bench_spin_loop(c: &mut Criterion) {
CostingParameters::babylon_genesis(),
TransactionCostingParameters {
free_credit_in_xrd: Decimal::try_from(PREVIEW_CREDIT_IN_XRD).unwrap(),
tip_percentage: DEFAULT_TIP_PERCENTAGE,
tip: Default::default(),
abort_when_loan_repaid: false,
},
);
Expand Down
6 changes: 3 additions & 3 deletions radix-engine-tests/benches/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn bench_transfer(c: &mut Criterion) {
.build();
let account = execute_and_commit_transaction(
&mut substate_db,
vm_modules.create_vm_init(),
&vm_modules,
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
TestTransaction::new_from_nonce(manifest, 1)
.prepare()
Expand All @@ -60,7 +60,7 @@ fn bench_transfer(c: &mut Criterion) {
for nonce in 0..1000 {
execute_and_commit_transaction(
&mut substate_db,
vm_modules.create_vm_init(),
&vm_modules,
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
TestTransaction::new_from_nonce(manifest.clone(), nonce)
.prepare()
Expand All @@ -83,7 +83,7 @@ fn bench_transfer(c: &mut Criterion) {
b.iter(|| {
let receipt = execute_and_commit_transaction(
&mut substate_db,
vm_modules.create_vm_init(),
&vm_modules,
&ExecutionConfig::for_notarized_transaction(NetworkDefinition::simulator()),
TestTransaction::new_from_nonce(manifest.clone(), nonce)
.prepare()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn estimate_notarizing(notary_is_signatory: bool, max: Decimal) {
let receipt1 = ledger.preview_manifest(
manifest.clone(),
vec![], // signed by nobody
DEFAULT_TIP_PERCENTAGE,
0,
PreviewFlags::default(),
);
receipt1.expect_commit_success();
Expand Down
Loading

0 comments on commit 38ff19d

Please sign in to comment.