Skip to content

Commit 8a0f5c7

Browse files
author
Damien LACHAUME / PALO-IT
committed
Readjustments after PR reviews
1 parent 97fcb18 commit 8a0f5c7

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,10 @@ impl DependenciesBuilder {
746746
}
747747

748748
async fn build_transaction_parser(&mut self) -> Result<Arc<dyn TransactionParser>> {
749-
let transaction_parser = CardanoTransactionParser::new(self.get_logger().await?);
749+
// TODO: 'allow_unparsable_block' parameter should be configurable and its default value set to false
750+
let allow_unparsable_block = true;
751+
let transaction_parser =
752+
CardanoTransactionParser::new(self.get_logger().await?, allow_unparsable_block);
750753

751754
Ok(Arc::new(transaction_parser))
752755
}

mithril-common/src/cardano_transaction_parser.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ impl Block {
105105
/// Cardano transaction parser
106106
pub struct CardanoTransactionParser {
107107
logger: Logger,
108+
/// When set to true, no error is returned in case of unparsable block, and an error log is written instead.
109+
/// This can occur when the crate 'pallas-hardano' doesn't support some non final encoding for a Cardano era.
110+
/// This situation should only happen on the test networks and not on the mainnet.
108111
allow_unparsable_block: bool,
109112
}
110113

111114
impl CardanoTransactionParser {
112115
/// Factory
113-
pub fn new(logger: Logger) -> Self {
116+
pub fn new(logger: Logger, allow_unparsable_block: bool) -> Self {
114117
Self {
115118
logger,
116-
// TODO: should be configurable, and should be 'false' by default
117-
allow_unparsable_block: true,
119+
allow_unparsable_block,
118120
}
119121
}
120122

@@ -138,19 +140,12 @@ impl CardanoTransactionParser {
138140
Ok(convert_to_block) => {
139141
blocks.push(convert_to_block);
140142
}
141-
// TODO: no error are returned due to the crate 'pallas-hardano'
142-
// that doesn't support all encoding versions (test networks doesn't work)
143-
Err(e) if self.allow_unparsable_block => {
143+
Err(err) if self.allow_unparsable_block => {
144144
error!(
145145
self.logger,
146-
"pallas-hardano does not support this block format"
146+
"The cbor encoded block could not be parsed";
147+
"error" => ?err, "immutable_file_number" => immutable_file.number
147148
);
148-
error!(self.logger, "error='{e}'.");
149-
let mut potential_source = e.source();
150-
while let Some(error) = potential_source {
151-
error!(self.logger, "cause='{}'.", error);
152-
potential_source = error.source();
153-
}
154149
}
155150
Err(e) => return Err(e),
156151
}
@@ -267,7 +262,7 @@ mod tests {
267262
};
268263
let tx_count: usize = immutable_files.iter().map(|(_, count)| *count).sum();
269264
let cardano_transaction_parser =
270-
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()));
265+
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()), false);
271266

272267
let transactions = cardano_transaction_parser
273268
.parse(db_path, &beacon)
@@ -284,9 +279,8 @@ mod tests {
284279
immutable_file_number: 4831,
285280
..Beacon::default()
286281
};
287-
let mut cardano_transaction_parser =
288-
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()));
289-
cardano_transaction_parser.allow_unparsable_block = false; // TODO should be the default value
282+
let cardano_transaction_parser =
283+
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()), false);
290284

291285
let result = cardano_transaction_parser.parse(db_path, &beacon).await;
292286

@@ -305,17 +299,16 @@ mod tests {
305299
immutable_file_number: 4831,
306300
..Beacon::default()
307301
};
308-
let mut cardano_transaction_parser =
309-
CardanoTransactionParser::new(create_file_logger(&filepath));
310-
cardano_transaction_parser.allow_unparsable_block = true;
302+
let cardano_transaction_parser =
303+
CardanoTransactionParser::new(create_file_logger(&filepath), true);
311304

312305
cardano_transaction_parser
313306
.parse(db_path, &beacon)
314307
.await
315308
.unwrap();
316309

317310
let log_file = std::fs::read_to_string(&filepath).unwrap();
318-
assert!(log_file.contains("pallas-hardano does not support this block format"));
311+
assert!(log_file.contains("The cbor encoded block could not be parsed"));
319312
}
320313

321314
#[tokio::test]
@@ -331,7 +324,7 @@ mod tests {
331324
};
332325
let tx_count: usize = immutable_files.iter().map(|(_, count)| *count).sum();
333326
let cardano_transaction_parser =
334-
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()));
327+
CardanoTransactionParser::new(Logger::root(slog::Discard, slog::o!()), false);
335328

336329
let transactions = cardano_transaction_parser
337330
.parse(db_path, &beacon)

mithril-signer/src/runtime/signer_services.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> {
267267
));
268268
let mithril_stake_distribution_signable_builder =
269269
Arc::new(MithrilStakeDistributionSignableBuilder::default());
270-
let transaction_parser = Arc::new(CardanoTransactionParser::new(slog_scope::logger()));
270+
// TODO: 'allow_unparsable_block' parameter should be configurable and its default value set to false
271+
let allow_unparsable_block = true;
272+
let transaction_parser = Arc::new(CardanoTransactionParser::new(
273+
slog_scope::logger(),
274+
allow_unparsable_block,
275+
));
271276
let transaction_store = Arc::new(CardanoTransactionRepository::new(
272277
transaction_sqlite_connection,
273278
));

mithril-test-lab/test_data/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
> [!NOTE]
88
> The immutable files (`.chunk`, `.primary` and `.secondary`) files are data that are the result of
99
> the `mithril-end-to-end` test command execution.
10-
> The `parsing_error/` directory contains a file `04831.chunk` with unparsable block. It's needed for testing.
10+
> The `parsing_error/` directory contains the `04831` and `04832` immutable files with some unparsable blocks in the first one (`04831` have been produced by the Sanchonet network, and `04832` created manually).
11+
> They are needed for testing of the Cardano transactions parser.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)