Skip to content

Commit 2c55cf5

Browse files
committed
feat(client-cli): display guidance message for UTxO-HD snapshot conversion after restoration with --include-ancillary
1 parent f6a42d6 commit 2c55cf5

File tree

2 files changed

+110
-16
lines changed

2 files changed

+110
-16
lines changed

mithril-client-cli/src/commands/cardano_db/download.rs

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ impl PreparedCardanoDbDownload {
185185
&db_dir,
186186
&cardano_db_message,
187187
self.is_json_output_enabled(),
188+
self.include_ancillary,
188189
)?;
189190

190191
Ok(())
@@ -328,6 +329,7 @@ impl PreparedCardanoDbDownload {
328329
db_dir: &Path,
329330
cardano_db: &Snapshot,
330331
json_output: bool,
332+
include_ancillary: bool,
331333
) -> MithrilResult<()> {
332334
let canonicalized_filepath = &db_dir.canonicalize().with_context(|| {
333335
format!(
@@ -336,12 +338,41 @@ impl PreparedCardanoDbDownload {
336338
)
337339
})?;
338340

341+
let docker_cmd = format!(
342+
"docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind,source=\"{}\",target=/data/db/ -e NETWORK={} ghcr.io/intersectmbo/cardano-node:{}",
343+
canonicalized_filepath.display(),
344+
cardano_db.network,
345+
cardano_db.cardano_node_version
346+
);
347+
348+
let snapshot_converter_cmd = |flavor| {
349+
format!(
350+
"mithril-client --unstable tools utxo-hd snapshot-converter --db-directory {} --cardano-node-version {} --utxo-hd-flavor {} --cardano-network {} --commit",
351+
db_dir.display(),
352+
cardano_db.cardano_node_version,
353+
flavor,
354+
cardano_db.network
355+
)
356+
};
357+
339358
if json_output {
340-
println!(
341-
r#"{{"timestamp": "{}", "db_directory": "{}"}}"#,
342-
Utc::now().to_rfc3339(),
343-
canonicalized_filepath.display()
344-
);
359+
let json = if include_ancillary {
360+
serde_json::json!({
361+
"timestamp": Utc::now().to_rfc3339(),
362+
"db_directory": canonicalized_filepath,
363+
"run_docker_cmd": docker_cmd,
364+
"snapshot_converter_cmd_to_lmdb": snapshot_converter_cmd("LMDB"),
365+
"snapshot_converter_cmd_to_legacy": snapshot_converter_cmd("Legacy")
366+
})
367+
} else {
368+
serde_json::json!({
369+
"timestamp": Utc::now().to_rfc3339(),
370+
"db_directory": canonicalized_filepath,
371+
"run_docker_cmd": docker_cmd,
372+
})
373+
};
374+
375+
println!("{}", json);
345376
} else {
346377
let cardano_node_version = &cardano_db.cardano_node_version;
347378
println!(
@@ -351,14 +382,29 @@ impl PreparedCardanoDbDownload {
351382
352383
If you are using Cardano Docker image, you can restore a Cardano Node with:
353384
354-
docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind,source="{}",target=/data/db/ -e NETWORK={} ghcr.io/intersectmbo/cardano-node:{cardano_node_version}
385+
{}
355386
356387
"###,
357388
cardano_db.digest,
358389
db_dir.display(),
359-
canonicalized_filepath.display(),
360-
cardano_db.network,
390+
docker_cmd,
361391
);
392+
393+
if include_ancillary {
394+
println!(
395+
r###"Upgrade and replace the restored ledger state snapshot to 'LMDB' flavor by running the command:
396+
397+
{}
398+
399+
Or to 'Legacy' flavor by running the command:
400+
401+
{}
402+
403+
"###,
404+
snapshot_converter_cmd("LMDB"),
405+
snapshot_converter_cmd("Legacy"),
406+
);
407+
}
362408
}
363409

364410
Ok(())

mithril-client-cli/src/commands/cardano_db_v2/download.rs

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ impl PreparedCardanoDbV2Download {
245245
&restoration_options.db_dir,
246246
&cardano_db_message,
247247
self.is_json_output_enabled(),
248+
restoration_options
249+
.download_unpack_options
250+
.include_ancillary,
248251
)?;
249252

250253
Ok(())
@@ -488,6 +491,7 @@ impl PreparedCardanoDbV2Download {
488491
db_dir: &Path,
489492
cardano_db_snapshot: &CardanoDatabaseSnapshot,
490493
json_output: bool,
494+
include_ancillary: bool,
491495
) -> MithrilResult<()> {
492496
let canonicalized_filepath = &db_dir.canonicalize().with_context(|| {
493497
format!(
@@ -496,12 +500,41 @@ impl PreparedCardanoDbV2Download {
496500
)
497501
})?;
498502

503+
let docker_cmd = format!(
504+
"docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind,source=\"{}\",target=/data/db/ -e NETWORK={} ghcr.io/intersectmbo/cardano-node:{}",
505+
canonicalized_filepath.display(),
506+
cardano_db_snapshot.network,
507+
cardano_db_snapshot.cardano_node_version
508+
);
509+
510+
let snapshot_converter_cmd = |flavor| {
511+
format!(
512+
"mithril-client --unstable tools utxo-hd snapshot-converter --db-directory {} --cardano-node-version {} --utxo-hd-flavor {} --cardano-network {} --commit",
513+
db_dir.display(),
514+
cardano_db_snapshot.cardano_node_version,
515+
flavor,
516+
cardano_db_snapshot.network
517+
)
518+
};
519+
499520
if json_output {
500-
println!(
501-
r#"{{"timestamp": "{}", "db_directory": "{}"}}"#,
502-
Utc::now().to_rfc3339(),
503-
canonicalized_filepath.display()
504-
);
521+
let json = if include_ancillary {
522+
serde_json::json!({
523+
"timestamp": Utc::now().to_rfc3339(),
524+
"db_directory": canonicalized_filepath,
525+
"run_docker_cmd": docker_cmd,
526+
"snapshot_converter_cmd_to_lmdb": snapshot_converter_cmd("LMDB"),
527+
"snapshot_converter_cmd_to_legacy": snapshot_converter_cmd("Legacy")
528+
})
529+
} else {
530+
serde_json::json!({
531+
"timestamp": Utc::now().to_rfc3339(),
532+
"db_directory": canonicalized_filepath,
533+
"run_docker_cmd": docker_cmd
534+
})
535+
};
536+
537+
println!("{}", json);
505538
} else {
506539
let cardano_node_version = &cardano_db_snapshot.cardano_node_version;
507540
println!(
@@ -511,14 +544,29 @@ impl PreparedCardanoDbV2Download {
511544
512545
If you are using Cardano Docker image, you can restore a Cardano Node with:
513546
514-
docker run -v cardano-node-ipc:/ipc -v cardano-node-data:/data --mount type=bind,source="{}",target=/data/db/ -e NETWORK={} ghcr.io/intersectmbo/cardano-node:{cardano_node_version}
547+
{}
515548
516549
"###,
517550
cardano_db_snapshot.hash,
518551
db_dir.display(),
519-
canonicalized_filepath.display(),
520-
cardano_db_snapshot.network,
552+
docker_cmd
521553
);
554+
555+
if include_ancillary {
556+
println!(
557+
r###"Upgrade and replace the restored ledger state snapshot to 'LMDB' flavor by running the command:
558+
559+
{}
560+
561+
Or to 'Legacy' flavor by running the command:
562+
563+
{}
564+
565+
"###,
566+
snapshot_converter_cmd("LMDB"),
567+
snapshot_converter_cmd("Legacy"),
568+
);
569+
}
522570
}
523571

524572
Ok(())

0 commit comments

Comments
 (0)