Skip to content

Commit 66103dd

Browse files
committed
feat(cli): prevent snapshot converter execution and hide post-download commands on Linux ARM
1 parent 204fc08 commit 66103dd

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

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

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ pub fn log_download_information(
134134
json_output: bool,
135135
include_ancillary: bool,
136136
) -> MithrilResult<()> {
137+
fn is_linux_arm() -> bool {
138+
cfg!(target_os = "linux") && cfg!(target_arch = "aarch64")
139+
}
140+
137141
let canonical_filepath = &db_dir
138142
.canonicalize()
139143
.with_context(|| format!("Could not get canonical filepath of '{}'", db_dir.display()))?;
@@ -155,53 +159,56 @@ pub fn log_download_information(
155159
};
156160

157161
if json_output {
158-
let json = if include_ancillary {
159-
serde_json::json!({
160-
"timestamp": Utc::now().to_rfc3339(),
161-
"db_directory": canonical_filepath,
162-
"run_docker_cmd": docker_cmd,
163-
"snapshot_converter_cmd_to_lmdb": snapshot_converter_cmd("LMDB"),
164-
"snapshot_converter_cmd_to_legacy": snapshot_converter_cmd("Legacy")
165-
})
166-
} else {
167-
serde_json::json!({
168-
"timestamp": Utc::now().to_rfc3339(),
169-
"db_directory": canonical_filepath,
170-
"run_docker_cmd": docker_cmd
171-
})
172-
};
162+
let mut json = serde_json::json!({
163+
"timestamp": Utc::now().to_rfc3339(),
164+
"db_directory": canonical_filepath,
165+
});
166+
167+
if !is_linux_arm() {
168+
json["run_docker_cmd"] = serde_json::Value::String(docker_cmd);
169+
170+
if include_ancillary {
171+
json["snapshot_converter_cmd_to_lmdb"] =
172+
serde_json::Value::String(snapshot_converter_cmd("LMDB"));
173+
json["snapshot_converter_cmd_to_legacy"] =
174+
serde_json::Value::String(snapshot_converter_cmd("Legacy"));
175+
}
176+
}
173177

174178
println!("{json}");
175179
} else {
176180
println!(
177181
r###"Cardano database snapshot '{}' archives have been successfully unpacked. Immutable files have been successfully verified with Mithril.
178182
179183
Files in the directory '{}' can be used to run a Cardano node with version >= {cardano_node_version}.
180-
181-
If you are using Cardano Docker image, you can restore a Cardano Node with:
182-
183-
{}
184-
185184
"###,
186185
snapshot_hash,
187-
db_dir.display(),
188-
docker_cmd
186+
db_dir.display()
189187
);
190188

191-
if include_ancillary {
189+
if !is_linux_arm() {
192190
println!(
193-
r###"Upgrade and replace the restored ledger state snapshot to 'LMDB' flavor by running the command:
191+
r###"If you are using the Cardano Docker image, you can restore a Cardano node with:
192+
193+
{docker_cmd}
194+
195+
"###
196+
);
197+
198+
if include_ancillary {
199+
println!(
200+
r###"Upgrade and replace the restored ledger state snapshot to 'LMDB' flavor by running the command:
194201
195202
{}
196203
197204
Or to 'Legacy' flavor by running the command:
198205
199206
{}
200-
201207
"###,
202-
snapshot_converter_cmd("LMDB"),
203-
snapshot_converter_cmd("Legacy"),
204-
);
208+
snapshot_converter_cmd("LMDB"),
209+
snapshot_converter_cmd("Legacy"),
210+
);
211+
}
205212
}
206213
}
207214

mithril-client-cli/src/commands/tools/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod snapshot_converter;
77

88
pub use snapshot_converter::*;
99

10+
use anyhow::anyhow;
1011
use clap::Subcommand;
1112
use mithril_client::MithrilResult;
1213

@@ -40,7 +41,14 @@ impl UTxOHDCommands {
4041
/// Execute UTxO-HD command
4142
pub async fn execute(&self) -> MithrilResult<()> {
4243
match self {
43-
Self::SnapshotConverter(cmd) => cmd.execute().await,
44+
Self::SnapshotConverter(cmd) => {
45+
if cfg!(target_os = "linux") && cfg!(target_arch = "aarch64") {
46+
return Err(anyhow!(
47+
"'snapshot-converter' command is not supported on Linux ARM"
48+
));
49+
}
50+
cmd.execute().await
51+
}
4452
}
4553
}
4654
}

0 commit comments

Comments
 (0)