Skip to content

Commit

Permalink
refactor: Moves all transaction models into radix-transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Aug 10, 2024
1 parent 1ab370e commit 472ece9
Show file tree
Hide file tree
Showing 77 changed files with 1,443 additions and 1,330 deletions.
22 changes: 16 additions & 6 deletions radix-clis/src/replay/cmd_alloc_dump.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
use super::ledger_transaction_execution::*;
use super::txn_reader::TxnReader;
use super::Error;
use crate::replay::ledger_transaction::PreparedLedgerTransactionInner;
use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
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;
use radix_substate_store_interface::interface::CommittableSubstateDatabase;
use radix_transactions::prelude::HasSystemTransactionHash;
use radix_transactions::prelude::IntentHash;
use radix_transactions::prelude::TransactionHashBech32Encoder;
use radix_substate_store_interface::interface::*;
use radix_transactions::prelude::*;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::prelude::*;
Expand Down Expand Up @@ -194,6 +190,20 @@ impl TxnAllocDump {
.map_err(Error::IOError)?
}
}
PreparedLedgerTransactionInner::FlashV1(tx) => {
if dump_round {
writeln!(
output,
"flash,{},{},{},{},{}",
tx.summary.hash,
execution_cost_units.unwrap_or_default(),
heap_allocations_sum,
heap_current_level,
heap_peak_memory
)
.map_err(Error::IOError)?
}
}
}

let new_version = database.get_current_version();
Expand Down
3 changes: 1 addition & 2 deletions radix-clis/src/replay/cmd_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use super::Error;
use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
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::CommittableSubstateDatabase;
use radix_substate_store_interface::interface::*;
use std::fs::File;
use std::path::PathBuf;
use std::thread;
Expand Down
3 changes: 1 addition & 2 deletions radix-clis/src/replay/cmd_execute_in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use super::Error;
use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
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;
use radix_substate_store_interface::interface::CommittableSubstateDatabase;
use radix_substate_store_interface::interface::*;
use std::fs::File;
use std::path::PathBuf;
use std::thread;
Expand Down
7 changes: 2 additions & 5 deletions radix-clis/src/replay/cmd_measure.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use super::ledger_transaction_execution::*;
use super::txn_reader::TxnReader;
use super::Error;
use crate::replay::ledger_transaction::PreparedLedgerTransactionInner;
use clap::Parser;
use flate2::read::GzDecoder;
use flume;
use radix_common::prelude::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
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::CommittableSubstateDatabase;
use radix_transactions::prelude::IntentHash;
use radix_transactions::prelude::TransactionHashBech32Encoder;
use radix_substate_store_interface::interface::*;
use radix_transactions::prelude::*;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::prelude::*;
Expand Down
8 changes: 2 additions & 6 deletions radix-clis/src/replay/cmd_sync.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use super::ledger_transaction::*;
use super::ledger_transaction_execution::execute_ledger_transaction;
use super::Error;
use clap::Parser;
use flume;
use flume::Sender;
use radix_common::prelude::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::vm::wasm::*;
use radix_engine::vm::ScryptoVm;
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::CommittableSubstateDatabase;
use radix_transactions::prelude::{
IntentHash, NotarizedTransactionHash, SignedIntentHash, SystemTransactionHash,
};
use radix_substate_store_interface::interface::*;
use radix_transactions::prelude::*;
use rocksdb::{Direction, IteratorMode, Options, DB};
use std::path::PathBuf;
use std::thread;
Expand Down
10 changes: 7 additions & 3 deletions radix-clis/src/replay/ledger_transaction_execution.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use super::ledger_transaction::*;
use radix_common::prelude::NetworkDefinition;
use radix_common::prelude::*;
use radix_engine::system::bootstrap::*;
use radix_engine::track::StateUpdates;
use radix_engine::transaction::{
execute_transaction, ExecutionConfig, TransactionFeeSummary, TransactionReceipt,
};
use radix_engine::vm::wasm::*;
use radix_engine::vm::{NoExtension, ScryptoVm, VmInit};
use radix_engine_interface::prelude::system_execution;
use radix_substate_store_interface::interface::SubstateDatabase;
use radix_transactions::prelude::*;
use radix_transactions::validation::{
NotarizedTransactionValidator, TransactionValidator, ValidationConfig,
};

pub enum LedgerTransactionReceipt {
Flash(FlashReceipt),
Standard(TransactionReceipt),
ProtocolUpdateFlash(StateUpdates),
}

impl LedgerTransactionReceipt {
Expand All @@ -26,13 +25,15 @@ impl LedgerTransactionReceipt {
LedgerTransactionReceipt::Standard(receipt) => {
receipt.into_commit_ignore_outcome().state_updates
}
LedgerTransactionReceipt::ProtocolUpdateFlash(state_updates) => state_updates,
}
}

pub fn fee_summary(&self) -> Option<&TransactionFeeSummary> {
match self {
LedgerTransactionReceipt::Flash(_) => None,
LedgerTransactionReceipt::Standard(receipt) => Some(&receipt.fee_summary),
LedgerTransactionReceipt::ProtocolUpdateFlash(_) => None,
}
}
}
Expand Down Expand Up @@ -119,5 +120,8 @@ pub fn execute_prepared_ledger_transaction<S: SubstateDatabase>(
);
LedgerTransactionReceipt::Standard(receipt)
}
PreparedLedgerTransactionInner::FlashV1(tx) => {
LedgerTransactionReceipt::ProtocolUpdateFlash(tx.state_updates.clone())
}
}
}
1 change: 0 additions & 1 deletion radix-clis/src/replay/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod ledger_transaction;
pub mod ledger_transaction_execution;
pub mod txn_reader;

Expand Down
1 change: 0 additions & 1 deletion radix-clis/src/resim/addressing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub enum AddressError {
InvalidAddress(String),
}

#[cfg(not(feature = "alloc"))]
impl std::error::Error for AddressError {}

impl fmt::Display for AddressError {
Expand Down
2 changes: 1 addition & 1 deletion radix-clis/src/resim/cmd_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use radix_rust::ContextualDisplay;
use radix_substate_store_interface::interface::DatabaseUpdates;
use radix_substate_store_interface::{
db_key_mapper::{DatabaseKeyMapper, SpreadPrefixKeyMapper},
interface::{CommittableSubstateDatabase, DatabaseUpdate},
interface::*,
};
use radix_substate_store_queries::typed_substate_layout::*;
use std::ffi::OsStr;
Expand Down
1 change: 1 addition & 0 deletions radix-clis/src/rtmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub fn run() -> Result<(), String> {
blobs,
..
}) => (instructions.0, blobs.blobs),
_ => return Err("Transaction type not currently supported".to_string()),
};

let blobs: Vec<Vec<u8>> = blobs.into_iter().map(|item| item.0).collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ manifest_type!(
ManifestCustomValueKind::AddressReservation,
4
);
scrypto_describe_for_manifest_type!(
ManifestAddressReservation,
OWN_GLOBAL_ADDRESS_RESERVATION_TYPE,
own_global_address_reservation_type_data,
);

#[cfg(test)]
mod tests {
Expand Down
1 change: 1 addition & 0 deletions radix-common/src/data/manifest/model/manifest_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ManifestBucket {
}

manifest_type!(ManifestBucket, ManifestCustomValueKind::Bucket, 4);
scrypto_describe_for_manifest_type!(ManifestBucket, OWN_BUCKET_TYPE, own_bucket_type_data,);

#[cfg(test)]
mod tests {
Expand Down
3 changes: 2 additions & 1 deletion radix-common/src/data/manifest/model/manifest_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ impl ManifestDecimal {
manifest_type!(
ManifestDecimal,
ManifestCustomValueKind::Decimal,
DECIMAL_SIZE
DECIMAL_SIZE,
);
scrypto_describe_for_manifest_type!(ManifestDecimal, DECIMAL_TYPE, decimal_type_data,);

#[cfg(test)]
mod tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ impl ManifestPreciseDecimal {
manifest_type!(
ManifestPreciseDecimal,
ManifestCustomValueKind::PreciseDecimal,
PRECISE_DECIMAL_SIZE
PRECISE_DECIMAL_SIZE,
);
scrypto_describe_for_manifest_type!(
ManifestPreciseDecimal,
PRECISE_DECIMAL_TYPE,
precise_decimal_type_data,
);

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions radix-common/src/data/manifest/model/manifest_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ManifestProof {
}

manifest_type!(ManifestProof, ManifestCustomValueKind::Proof, 4);
scrypto_describe_for_manifest_type!(ManifestProof, OWN_PROOF_TYPE, own_proof_type_data);

#[cfg(test)]
mod tests {
Expand Down
6 changes: 5 additions & 1 deletion radix-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub mod data;
pub mod math;
/// RE network identifier model.
pub mod network;
/// Common models for state changes in RE
pub mod state;
/// RE time library.
pub mod time;
/// RE types.
Expand Down Expand Up @@ -60,7 +62,8 @@ pub mod prelude {
// Exports from upstream libraries
pub use radix_sbor_derive::{
ManifestCategorize, ManifestDecode, ManifestEncode, ManifestSbor, ScryptoCategorize,
ScryptoDecode, ScryptoEncode, ScryptoEvent, ScryptoSbor, ScryptoSborAssertion,
ScryptoDecode, ScryptoDescribe, ScryptoEncode, ScryptoEvent, ScryptoSbor,
ScryptoSborAssertion,
};
pub use sbor::prelude::*;
pub use sbor::*;
Expand All @@ -73,6 +76,7 @@ pub mod prelude {
pub use super::data::scrypto::prelude::*;
pub use super::math::*;
pub use super::network::*;
pub use super::state::*;
pub use super::time::*;
pub use super::traits::*;
pub use super::types::*;
Expand Down
21 changes: 18 additions & 3 deletions radix-common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! i {
#[macro_export]
macro_rules! well_known_scrypto_custom_type {
// with describe
($t:ty, $value_kind:expr, $schema_type:expr, $size:expr, $well_known_type:ident, $well_known_type_data_method:ident) => {
($t:ty, $value_kind:expr, $schema_type:expr, $size:expr, $well_known_type:ident, $well_known_type_data_method:ident$(,)?) => {
impl sbor::Categorize<$crate::data::scrypto::ScryptoCustomValueKind> for $t {
#[inline]
fn value_kind() -> sbor::ValueKind<$crate::data::scrypto::ScryptoCustomValueKind> {
Expand Down Expand Up @@ -62,8 +62,8 @@ macro_rules! well_known_scrypto_custom_type {

#[macro_export]
macro_rules! manifest_type {
// without describe
($t:ty, $value_kind:expr, $size: expr) => {
// Without describe - if you need describe, also use scrypto_describe_for_manifest_type!
($t:ty, $value_kind:expr, $size: expr$(,)?) => {
impl sbor::Categorize<$crate::data::manifest::ManifestCustomValueKind> for $t {
#[inline]
fn value_kind() -> sbor::ValueKind<$crate::data::manifest::ManifestCustomValueKind> {
Expand Down Expand Up @@ -100,6 +100,21 @@ macro_rules! manifest_type {
};
}

#[macro_export]
macro_rules! scrypto_describe_for_manifest_type {
($t:ty, $well_known_type:ident, $well_known_type_data_method:ident$(,)?) => {
impl sbor::Describe<$crate::data::scrypto::ScryptoCustomTypeKind> for $t {
const TYPE_ID: sbor::RustTypeId = sbor::RustTypeId::WellKnown(
$crate::data::scrypto::well_known_scrypto_custom_types::$well_known_type,
);

fn type_data() -> sbor::TypeData<$crate::data::scrypto::ScryptoCustomTypeKind, sbor::RustTypeId> {
$crate::data::scrypto::well_known_scrypto_custom_types::$well_known_type_data_method()
}
}
}
}

#[macro_export]
macro_rules! count {
() => {0usize};
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/math/precise_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,13 @@ well_known_scrypto_custom_type!(
Type::PreciseDecimal,
PreciseDecimal::BITS / 8,
PRECISE_DECIMAL_TYPE,
precise_decimal_type_data
precise_decimal_type_data,
);

manifest_type!(
PreciseDecimal,
ManifestCustomValueKind::PreciseDecimal,
PreciseDecimal::BITS / 8
PreciseDecimal::BITS / 8,
);

//======
Expand Down
3 changes: 3 additions & 0 deletions radix-common/src/state/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod state_updates;

pub use state_updates::*;
Loading

0 comments on commit 472ece9

Please sign in to comment.