Skip to content

Commit 73cffbc

Browse files
committed
tweak: Add new debug! logs before commit batches and user transaction executions
1 parent 2c138a0 commit 73cffbc

File tree

9 files changed

+120
-9
lines changed

9 files changed

+120
-9
lines changed

core-rust/state-manager/src/committer.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub struct Committer {
7474
execution_cache_manager: Arc<ExecutionCacheManager>,
7575
protocol_manager: Arc<ProtocolManager>,
7676
ledger_metrics: Arc<LedgerMetrics>,
77+
formatter: Arc<Formatter>,
7778
}
7879

7980
impl Committer {
@@ -86,6 +87,7 @@ impl Committer {
8687
execution_cache_manager: Arc<ExecutionCacheManager>,
8788
protocol_manager: Arc<ProtocolManager>,
8889
ledger_metrics: Arc<LedgerMetrics>,
90+
formatter: Arc<Formatter>,
8991
) -> Self {
9092
Self {
9193
database,
@@ -95,6 +97,7 @@ impl Committer {
9597
execution_cache_manager,
9698
protocol_manager,
9799
ledger_metrics,
100+
formatter,
98101
}
99102
}
100103
}
@@ -171,6 +174,12 @@ impl Committer {
171174
.start_series_execution(database.deref());
172175
self.verify_pre_commit_invariants(&series_executor, transactions.len(), &proof);
173176

177+
debug!(
178+
"Starting commit of normal transaction batch on top of existing state version {} until state version {}",
179+
series_executor.latest_state_version(),
180+
commit_state_version,
181+
);
182+
174183
// Naively, the below could be a part of pre-commit invariants (see above); however, we do
175184
// not want to panic, but rather return an `Err` for the consensus layer, since a
176185
// transaction root mismatch may mean a malicious peer (and not our inconsistent state).
@@ -221,6 +230,16 @@ impl Committer {
221230
let hashes = validated.create_hashes();
222231
let executable = validated.create_ledger_executable();
223232

233+
if let Some(user_hashes) = hashes.as_user() {
234+
debug!(
235+
"Starting commit execution of {} for {:?}",
236+
user_hashes
237+
.transaction_intent_hash
238+
.display(&*self.formatter),
239+
series_executor.latest_state_version().next().unwrap(),
240+
);
241+
}
242+
224243
let commit = series_executor
225244
.execute_and_update_state(&executable, &hashes, "prepared")
226245
.expect("cannot execute transaction to be committed");
@@ -304,6 +323,12 @@ impl Committer {
304323
.start_series_execution(database.deref());
305324
self.verify_pre_commit_invariants(&series_executor, transactions.len(), &proof);
306325

326+
debug!(
327+
"Starting commit of system transaction batch on top of existing state version {} until state version {}",
328+
series_executor.latest_state_version(),
329+
proof.ledger_header.state_version,
330+
);
331+
307332
let mut commit_bundle_builder = series_executor.start_commit_builder();
308333
let mut transactions_metrics_data = Vec::new();
309334
for ProcessedLedgerTransaction {
@@ -312,6 +337,15 @@ impl Committer {
312337
hashes,
313338
} in transactions
314339
{
340+
if let Some(user_hashes) = hashes.as_user() {
341+
debug!(
342+
"Starting commit execution of {} for {:?}",
343+
user_hashes
344+
.transaction_intent_hash
345+
.display(&*self.formatter),
346+
series_executor.latest_state_version().next().unwrap(),
347+
);
348+
}
315349
let mut commit = series_executor
316350
.execute_and_update_state(&executable, &hashes, "system transaction")
317351
.expect("cannot execute system transaction");
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use crate::prelude::*;
2+
3+
pub struct Formatter {
4+
address_encoder: AddressBech32Encoder,
5+
transaction_hash_encoder: TransactionHashBech32Encoder,
6+
}
7+
8+
impl Formatter {
9+
pub fn new(network_definition: &NetworkDefinition) -> Self {
10+
let address_encoder = AddressBech32Encoder::new(network_definition);
11+
let hash_encoder = TransactionHashBech32Encoder::new(network_definition);
12+
13+
Self {
14+
address_encoder,
15+
transaction_hash_encoder: hash_encoder,
16+
}
17+
}
18+
19+
pub fn address_encoder(&self) -> &AddressBech32Encoder {
20+
&self.address_encoder
21+
}
22+
}
23+
24+
impl<'a> From<&'a Formatter> for ScryptoValueDisplayContext<'a> {
25+
fn from(formatter: &'a Formatter) -> Self {
26+
ScryptoValueDisplayContext {
27+
address_bech32_encoder: Some(&formatter.address_encoder),
28+
}
29+
}
30+
}
31+
32+
impl<'a> From<&'a Formatter> for AddressDisplayContext<'a> {
33+
fn from(formatter: &'a Formatter) -> Self {
34+
AddressDisplayContext {
35+
encoder: Some(&formatter.address_encoder),
36+
}
37+
}
38+
}
39+
40+
impl<'a> From<&'a Formatter> for TransactionHashDisplayContext<'a> {
41+
fn from(formatter: &'a Formatter) -> Self {
42+
TransactionHashDisplayContext {
43+
encoder: Some(&formatter.transaction_hash_encoder),
44+
}
45+
}
46+
}

core-rust/state-manager/src/jni/mempool.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ extern "system" fn Java_com_radixdlt_mempool_RustMempool_add(
8484
JNINodeRustEnvironment::get_mempool_manager(&env, j_node_rust_env)
8585
.add_if_committable(MempoolAddSource::MempoolSync, transaction, false)
8686
.map_err(|err| {
87-
let encoder =
88-
JNINodeRustEnvironment::get_address_encoder(&env, j_node_rust_env);
89-
MempoolAddErrorJava::new_from(err, (&encoder).into())
87+
let formatter = JNINodeRustEnvironment::get_formatter(&env, j_node_rust_env);
88+
MempoolAddErrorJava::new_from(err, &formatter)
9089
})?;
9190
Ok(())
9291
},
@@ -203,7 +202,7 @@ enum MempoolAddErrorJava {
203202
}
204203

205204
impl MempoolAddErrorJava {
206-
fn new_from(err: MempoolAddError, display_context: ScryptoValueDisplayContext) -> Self {
205+
fn new_from(err: MempoolAddError, formatter: &Formatter) -> Self {
207206
match err {
208207
MempoolAddError::PriorityThresholdNotMet {
209208
min_tip_basis_points_required: min_tip_percentage_required,
@@ -214,7 +213,7 @@ impl MempoolAddErrorJava {
214213
},
215214
MempoolAddError::Duplicate(hash) => MempoolAddErrorJava::Duplicate(hash),
216215
MempoolAddError::Rejected(rejection, _) => {
217-
MempoolAddErrorJava::Rejected(rejection.reason.to_string(display_context))
216+
MempoolAddErrorJava::Rejected(rejection.reason.to_string(formatter))
218217
}
219218
}
220219
}

core-rust/state-manager/src/jni/node_rust_environment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ impl JNINodeRustEnvironment {
214214
.clone()
215215
}
216216

217-
pub fn get_address_encoder(env: &JNIEnv, j_node_rust_env: JObject) -> AddressBech32Encoder {
217+
pub fn get_formatter(env: &JNIEnv, j_node_rust_env: JObject) -> Arc<Formatter> {
218218
let env = Self::get(env, j_node_rust_env);
219-
AddressBech32Encoder::new(&env.state_manager.network_definition)
219+
env.state_manager.formatter.clone()
220220
}
221221

222222
pub fn get_database(

core-rust/state-manager/src/jni/test_state_reader.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_getTransactionAtSt
117117
let local_transaction_execution =
118118
database.get_committed_local_transaction_execution(state_version)?;
119119

120-
let encoder = JNINodeRustEnvironment::get_address_encoder(&env, j_rust_global_context);
120+
let formatter = JNINodeRustEnvironment::get_formatter(&env, j_rust_global_context);
121121

122122
Some(ExecutedTransaction {
123123
ledger_transaction_hash: committed_identifiers
@@ -129,7 +129,9 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_getTransactionAtSt
129129
},
130130
error_message: match local_transaction_execution.outcome {
131131
DetailedTransactionOutcome::Success(_) => None,
132-
DetailedTransactionOutcome::Failure(error) => Some(error.to_string(&encoder)),
132+
DetailedTransactionOutcome::Failure(error) => {
133+
Some(error.to_string(&*formatter))
134+
}
133135
},
134136
consensus_receipt_bytes: scrypto_encode(
135137
&committed_ledger_transaction_receipt.get_consensus_receipt(),

core-rust/state-manager/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ extern crate core;
6767
mod accumulator_tree;
6868
mod commit_bundle;
6969
mod committer;
70+
mod formatter;
7071
pub mod jni;
7172
mod limits;
7273
mod mempool;
@@ -91,6 +92,7 @@ pub mod prelude {
9192
pub(crate) use node_common::prelude::*;
9293

9394
// Public prelude
95+
pub use crate::formatter::*;
9496
pub use crate::mempool::*;
9597
pub use crate::protocol::*;
9698
pub use crate::query::*;

core-rust/state-manager/src/state_manager.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub struct StateManager {
180180
pub protocol_manager: Arc<ProtocolManager>,
181181
pub protocol_update_executor: Arc<NodeProtocolUpdateExecutor>,
182182
pub ledger_metrics: Arc<LedgerMetrics>,
183+
pub formatter: Arc<Formatter>,
183184
}
184185

185186
impl StateManager {
@@ -222,6 +223,8 @@ impl StateManager {
222223

223224
let database = Arc::new(lock_factory.named("database").new_db_lock(raw_db));
224225

226+
let formatter = Arc::new(Formatter::new(&network_definition));
227+
225228
let transaction_validator = Arc::new(lock_factory.named("validator").new_rwlock(
226229
TransactionValidator::new(database.access_direct().deref(), &network_definition),
227230
));
@@ -266,6 +269,7 @@ impl StateManager {
266269
database.clone(),
267270
execution_configurator.clone(),
268271
transaction_validator.clone(),
272+
formatter.clone(),
269273
),
270274
));
271275
let cached_committability_validator = CachedCommittabilityValidator::new(
@@ -307,6 +311,7 @@ impl StateManager {
307311
transaction_validator.clone(),
308312
vertex_limits_config.unwrap_or_default(),
309313
metrics_registry,
314+
formatter.clone(),
310315
));
311316

312317
let ledger_metrics = Arc::new(LedgerMetrics::new(
@@ -325,6 +330,7 @@ impl StateManager {
325330
execution_cache_manager.clone(),
326331
protocol_manager.clone(),
327332
ledger_metrics.clone(),
333+
formatter.clone(),
328334
));
329335

330336
let system_executor = Arc::new(SystemExecutor::new(
@@ -387,6 +393,7 @@ impl StateManager {
387393
protocol_manager,
388394
protocol_update_executor,
389395
ledger_metrics,
396+
formatter,
390397
};
391398

392399
state_manager.resume_protocol_updates_if_any();

core-rust/state-manager/src/transaction/preparation.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub struct Preparator {
7171
transaction_validator: Arc<RwLock<TransactionValidator>>,
7272
vertex_prepare_metrics: VertexPrepareMetrics,
7373
vertex_limits_config: VertexLimitsConfig,
74+
formatter: Arc<Formatter>,
7475
}
7576

7677
impl Preparator {
@@ -81,6 +82,7 @@ impl Preparator {
8182
transaction_validator: Arc<RwLock<TransactionValidator>>,
8283
vertex_limits_config: VertexLimitsConfig,
8384
metrics_registry: &MetricRegistry,
85+
formatter: Arc<Formatter>,
8486
) -> Self {
8587
Self {
8688
database,
@@ -89,6 +91,7 @@ impl Preparator {
8991
transaction_validator,
9092
vertex_prepare_metrics: VertexPrepareMetrics::new(metrics_registry),
9193
vertex_limits_config,
94+
formatter,
9295
}
9396
}
9497

@@ -454,6 +457,14 @@ impl Preparator {
454457
let ledger_transaction_hash = prepared_details.hashes.ledger_transaction_hash;
455458
let invalid_at_epoch = prepared_details.end_epoch_exclusive;
456459

460+
debug!(
461+
"Starting prepare execution of {} for {:?}",
462+
user_hashes
463+
.transaction_intent_hash
464+
.display(&*self.formatter),
465+
series_executor.latest_state_version().next().unwrap(),
466+
);
467+
457468
// Note that we're using a "_no_state_update" variant here, because
458469
// we may still reject some *committable* transactions if they exceed
459470
// the limit, which would otherwise spoil the internal StateTracker.

core-rust/state-manager/src/transaction/validation.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ pub struct CommittabilityValidator {
2626
database: Arc<DbLock<ActualStateManagerDatabase>>,
2727
execution_configurator: Arc<ExecutionConfigurator>,
2828
transaction_validator: Arc<RwLock<TransactionValidator>>,
29+
formatter: Arc<Formatter>,
2930
}
3031

3132
impl CommittabilityValidator {
3233
pub fn new(
3334
database: Arc<DbLock<ActualStateManagerDatabase>>,
3435
execution_configurator: Arc<ExecutionConfigurator>,
3536
transaction_validator: Arc<RwLock<TransactionValidator>>,
37+
formatter: Arc<Formatter>,
3638
) -> Self {
3739
Self {
3840
database,
3941
execution_configurator,
4042
transaction_validator,
43+
formatter,
4144
}
4245
}
4346

@@ -93,6 +96,13 @@ impl CommittabilityValidator {
9396
};
9497
}
9598

99+
trace!(
100+
"Starting mempool execution of {}",
101+
user_hashes
102+
.transaction_intent_hash
103+
.display(&*self.formatter),
104+
);
105+
96106
let receipt = self
97107
.execution_configurator
98108
.wrap_pending_transaction(executable, user_hashes)

0 commit comments

Comments
 (0)