Skip to content

Commit

Permalink
Merge pull request #1955 from radixdlt/chore/fixes-for-node-integration
Browse files Browse the repository at this point in the history
Chore/fixes for node integration
  • Loading branch information
dhedey authored Oct 14, 2024
2 parents c3227e5 + dbf3ce9 commit bf6ec87
Show file tree
Hide file tree
Showing 74 changed files with 1,152 additions and 854 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions radix-clis/src/replay/cmd_alloc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl TxnAllocDump {
INFO_ALLOC.set_enable(true);
INFO_ALLOC.reset_counters();

let (validated, receipt) = execute_ledger_transaction(
let (kinded_hash, receipt) = execute_ledger_transaction(
&database,
&vm_modules,
&network,
Expand All @@ -140,15 +140,13 @@ impl TxnAllocDump {
.map(|x| x.total_execution_cost_units_consumed.clone());
let database_updates = receipt.into_state_updates().create_database_updates();
database.commit(&database_updates);
match validated.inner {
ValidatedLedgerTransactionInner::User(tx) => {
match kinded_hash {
LedgerTransactionKindedHash::User(hash) => {
if dump_user {
writeln!(
output,
"user,{},{},{},{},{}",
address_encoder
.encode(&tx.transaction_intent_hash())
.unwrap(),
address_encoder.encode(&hash).unwrap(),
execution_cost_units.unwrap(),
heap_allocations_sum,
heap_current_level,
Expand All @@ -157,12 +155,12 @@ impl TxnAllocDump {
.map_err(Error::IOError)?
}
}
ValidatedLedgerTransactionInner::Genesis(tx) => {
LedgerTransactionKindedHash::Genesis(hash) => {
if dump_genesis {
writeln!(
output,
"genesis,{},{},{},{},{}",
tx.system_transaction_hash().0,
hash.0,
execution_cost_units.unwrap_or_default(),
heap_allocations_sum,
heap_current_level,
Expand All @@ -171,12 +169,12 @@ impl TxnAllocDump {
.map_err(Error::IOError)?
}
}
ValidatedLedgerTransactionInner::Validator(tx) => {
LedgerTransactionKindedHash::Validator(hash) => {
if dump_round {
writeln!(
output,
"round_update,{},{},{},{},{}",
tx.summary.hash,
"validator,{},{},{},{},{}",
hash,
execution_cost_units.unwrap_or_default(),
heap_allocations_sum,
heap_current_level,
Expand All @@ -185,12 +183,12 @@ impl TxnAllocDump {
.map_err(Error::IOError)?
}
}
ValidatedLedgerTransactionInner::ProtocolUpdate(tx) => {
LedgerTransactionKindedHash::ProtocolUpdate(hash) => {
if dump_round {
writeln!(
output,
"flash,{},{},{},{},{}",
tx.summary.hash,
"protocol_update,{},{},{},{},{}",
hash,
execution_cost_units.unwrap_or_default(),
heap_allocations_sum,
heap_current_level,
Expand Down
2 changes: 1 addition & 1 deletion radix-clis/src/replay/cmd_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TxnExecute {
let vm_modules = VmModules::default();
let iter = rx.iter();
for tx_payload in iter {
let (_validated, receipt) = execute_ledger_transaction(
let (_hash, receipt) = execute_ledger_transaction(
&database,
&vm_modules,
&network,
Expand Down
2 changes: 1 addition & 1 deletion radix-clis/src/replay/cmd_execute_in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl TxnExecuteInMemory {
let vm_modules = VmModules::default();
let iter = rx.iter();
for tx_payload in iter {
let (_validated, receipt) = execute_ledger_transaction(
let (_hash, receipt) = execute_ledger_transaction(
&database,
&vm_modules,
&network,
Expand Down
6 changes: 3 additions & 3 deletions radix-clis/src/replay/cmd_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TxnMeasure {
let iter = rx.iter();
for tx_payload in iter {
let tx_start_time = std::time::Instant::now();
let (validated, receipt) = execute_ledger_transaction(
let (kinded_hash, receipt) = execute_ledger_transaction(
&database,
&vm_modules,
&network,
Expand All @@ -112,12 +112,12 @@ impl TxnMeasure {
let database_updates = receipt.into_state_updates().create_database_updates();
database.commit(&database_updates);
let tx_processing_time = tx_start_time.elapsed();
if let ValidatedLedgerTransactionInner::User(tx) = validated.inner {
if let LedgerTransactionKindedHash::User(hash) = kinded_hash {
writeln!(
output,
"{},{},{},{}",
TransactionHashBech32Encoder::new(&network)
.encode(&tx.transaction_intent_hash())
.encode(&hash)
.unwrap(),
tx_processing_time.as_micros(),
execution_cost_units.unwrap(),
Expand Down
25 changes: 2 additions & 23 deletions radix-clis/src/replay/cmd_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl TxnSync {
let vm_modules = VmModules::default();
let iter = rx.iter();
for (tx_payload, expected_state_root_hash) in iter {
let (_validated, receipt) = execute_ledger_transaction(
let (_hash, receipt) = execute_ledger_transaction(
&database,
&vm_modules,
&network,
Expand Down Expand Up @@ -210,32 +210,11 @@ define_single_versioned! {

#[derive(Debug, Clone, Sbor)]
pub struct CommittedTransactionIdentifiersV1 {
pub payload: PayloadIdentifiers,
pub payload: LedgerTransactionHashes,
pub resultant_ledger_hashes: LedgerHashes,
pub proposer_timestamp_ms: i64,
}

#[derive(Debug, Clone, PartialEq, Eq, Sbor)]
pub struct PayloadIdentifiers {
pub ledger_transaction_hash: LedgerTransactionHash,
pub typed: TypedTransactionIdentifiers,
}

#[derive(Debug, Clone, PartialEq, Eq, Sbor)]
pub enum TypedTransactionIdentifiers {
Genesis {
system_transaction_hash: SystemTransactionHash,
},
User {
intent_hash: TransactionIntentHash,
signed_intent_hash: SignedTransactionIntentHash,
notarized_transaction_hash: NotarizedTransactionHash,
},
RoundUpdateV1 {
round_update_hash: RoundUpdateTransactionHash,
},
}

#[derive(PartialEq, Eq, Hash, Clone, Copy, PartialOrd, Ord, Debug, Sbor)]
pub struct LedgerHashes {
pub state_root: StateHash,
Expand Down
38 changes: 31 additions & 7 deletions radix-clis/src/replay/ledger_transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,41 @@ impl LedgerTransactionReceipt {
}
}

pub enum LedgerTransactionKindedHash {
Genesis(SystemTransactionHash),
User(NotarizedTransactionHash),
Validator(Hash),
ProtocolUpdate(Hash),
}

pub fn execute_ledger_transaction<S: SubstateDatabase>(
database: &S,
vm_modules: &impl VmInitialize,
network: &NetworkDefinition,
raw: &RawLedgerTransaction,
trace: bool,
) -> (ValidatedLedgerTransaction, LedgerTransactionReceipt) {
) -> (LedgerTransactionKindedHash, LedgerTransactionReceipt) {
let validator = TransactionValidator::new(database, network);
let validated = raw
.validate(&validator, AcceptedLedgerTransactionKind::Any)
.expect("Ledger transaction should be valid");

let receipt = match &validated.inner {
let kinded_hash = match &validated.inner {
ValidatedLedgerTransactionInner::Genesis(tx) => {
LedgerTransactionKindedHash::Genesis(tx.system_transaction_hash())
}
ValidatedLedgerTransactionInner::User(tx) => {
LedgerTransactionKindedHash::User(tx.notarized_transaction_hash())
}
ValidatedLedgerTransactionInner::Validator(tx) => {
LedgerTransactionKindedHash::Validator(tx.summary.hash)
}
ValidatedLedgerTransactionInner::ProtocolUpdate(tx) => {
LedgerTransactionKindedHash::ProtocolUpdate(tx.flash_transaction_hash().into_hash())
}
};

let receipt = match validated.inner {
ValidatedLedgerTransactionInner::Genesis(prepared_genesis_tx) => {
match prepared_genesis_tx {
PreparedGenesisTransaction::Flash(_) => {
Expand All @@ -61,7 +83,9 @@ pub fn execute_ledger_transaction<S: SubstateDatabase>(
&ExecutionConfig::for_genesis_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
tx.get_executable(btreeset!(system_execution(SystemExecution::Protocol))),
tx.create_executable(btreeset!(system_execution(
SystemExecution::Protocol
))),
);
LedgerTransactionReceipt::Standard(receipt)
}
Expand All @@ -74,7 +98,7 @@ pub fn execute_ledger_transaction<S: SubstateDatabase>(
&ExecutionConfig::for_notarized_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
tx.clone().create_executable(),
tx.create_executable(),
);
LedgerTransactionReceipt::Standard(receipt)
}
Expand All @@ -85,14 +109,14 @@ pub fn execute_ledger_transaction<S: SubstateDatabase>(
&ExecutionConfig::for_system_transaction(network.clone())
.with_kernel_trace(trace)
.with_cost_breakdown(trace),
tx.get_executable(),
tx.create_executable(),
);
LedgerTransactionReceipt::Standard(receipt)
}
ValidatedLedgerTransactionInner::ProtocolUpdate(tx) => {
LedgerTransactionReceipt::ProtocolUpdateFlash(tx.state_updates.clone())
LedgerTransactionReceipt::ProtocolUpdateFlash(tx.state_updates)
}
};

(validated, receipt)
(kinded_hash, receipt)
}
Loading

0 comments on commit bf6ec87

Please sign in to comment.