Skip to content

Commit 3abeead

Browse files
authored
Merge pull request #2266 from input-output-hk/dlachaume/2246/implement-incremental-cardano-db-client-cli
Feat: Implement `cardano-db-v2` command in client CLI (`list` and `show`)
2 parents 3266e77 + 25a9fde commit 3abeead

File tree

19 files changed

+595
-64
lines changed

19 files changed

+595
-64
lines changed

.github/workflows/test-client.yml

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,25 @@ jobs:
9898
if: runner.os != 'Windows'
9999
shell: bash
100100
run: |
101-
CTX_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])')
102-
CSD_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])')
103-
echo "ctx_enabled=$CTX_CAPABILITY" >> $GITHUB_OUTPUT
104-
echo "csd_enabled=$CSD_CAPABILITY" >> $GITHUB_OUTPUT
101+
CARDANO_TRANSACTIONS_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])')
102+
CARDANO_STAKE_DISTRIBUTION_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])')
103+
CARDANO_DATABASE_V2_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoDatabase"])')
104+
echo "cardano_transactions_enabled=$CARDANO_TRANSACTIONS_CAPABILITY" >> $GITHUB_OUTPUT
105+
echo "cardano_stake_distribution_enabled=$CARDANO_STAKE_DISTRIBUTION_CAPABILITY" >> $GITHUB_OUTPUT
106+
echo "cardano_database_v2_enabled=$CARDANO_DATABASE_V2_CAPABILITY" >> $GITHUB_OUTPUT
105107
106108
- name: Assessing aggregator capabilities (Windows)
107109
id: aggregator_capability_windows
108110
if: runner.os == 'Windows'
109111
shell: bash
110112
run: |
111113
aria2c -o aggregator_capabilities.json $AGGREGATOR_ENDPOINT
112-
CTX_CAPABILITY=$(jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])' aggregator_capabilities.json)
113-
CSD_CAPABILITY=$(jq '.capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])' aggregator_capabilities.json)
114-
echo "ctx_enabled=$CTX_CAPABILITY" >> $GITHUB_OUTPUT
115-
echo "csd_enabled=$CSD_CAPABILITY" >> $GITHUB_OUTPUT
114+
CARDANO_TRANSACTIONS_CAPABILITY=$(jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])' aggregator_capabilities.json)
115+
CARDANO_STAKE_DISTRIBUTION_CAPABILITY=$(jq '.capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])' aggregator_capabilities.json)
116+
CARDANO_DATABASE_V2_CAPABILITY=$(jq '.capabilities.signed_entity_types | contains(["CardanoDatabase"])' aggregator_capabilities.json)
117+
echo "cardano_transactions_enabled=$CARDANO_TRANSACTIONS_CAPABILITY" >> $GITHUB_OUTPUT
118+
echo "cardano_stake_distribution_enabled=$CARDANO_STAKE_DISTRIBUTION_CAPABILITY" >> $GITHUB_OUTPUT
119+
echo "cardano_database_v2_enabled=$CARDANO_DATABASE_V2_CAPABILITY" >> $GITHUB_OUTPUT
116120
117121
- name: Checkout binary
118122
uses: dawidd6/action-download-artifact@v6
@@ -134,14 +138,14 @@ jobs:
134138
working-directory: ./bin
135139
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} --version
136140

137-
- name: Cardano-db / list and get last digest
141+
- name: Cardano Database Snapshot / list and get last digest
138142
shell: bash
139143
working-directory: ./bin
140144
run: |
141145
./mithril-client ${{ steps.prepare.outputs.debug_level }} cardano-db snapshot list
142146
echo "CDB_SNAPSHOT_DIGEST=$(./mithril-client cardano-db snapshot list --json | jq -r '.[0].digest')" >> $GITHUB_ENV
143147
144-
- name: Cardano-db / download & restore latest
148+
- name: Cardano Database Snapshot / download & restore latest
145149
shell: bash
146150
working-directory: ./bin
147151
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} cardano-db download $CDB_SNAPSHOT_DIGEST
@@ -159,27 +163,27 @@ jobs:
159163
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} mithril-stake-distribution download $MITHRIL_STAKE_DISTRIBUTION_HASH
160164

161165
- name: Cardano transaction / list and get last snapshot
162-
if: steps.aggregator_capability_unix.outputs.ctx_enabled == 'true' || steps.aggregator_capability_windows.outputs.ctx_enabled == 'true'
166+
if: steps.aggregator_capability_unix.outputs.cardano_transactions_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_transactions_enabled == 'true'
163167
shell: bash
164168
working-directory: ./bin
165169
run: |
166170
./mithril-client ${{ steps.prepare.outputs.debug_level }} cardano-transaction snapshot list
167171
echo "CTX_SNAPSHOT_HASH=$(./mithril-client cardano-transaction snapshot list --json | jq -r '.[0].hash')" >> $GITHUB_ENV
168172
169173
- name: Cardano transaction / show snapshot
170-
if: steps.aggregator_capability_unix.outputs.ctx_enabled == 'true' || steps.aggregator_capability_windows.outputs.ctx_enabled == 'true'
174+
if: steps.aggregator_capability_unix.outputs.cardano_transactions_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_transactions_enabled == 'true'
171175
shell: bash
172176
working-directory: ./bin
173177
run: ./mithril-client cardano-transaction snapshot show $CTX_SNAPSHOT_HASH
174178

175179
- name: Cardano transaction certify
176-
if: steps.aggregator_capability_unix.outputs.ctx_enabled == 'true' || steps.aggregator_capability_windows.outputs.ctx_enabled == 'true'
180+
if: steps.aggregator_capability_unix.outputs.cardano_transactions_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_transactions_enabled == 'true'
177181
shell: bash
178182
working-directory: ./bin
179183
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} cardano-transaction certify $TRANSACTIONS_HASHES_TO_CERTIFY
180184

181185
- name: Cardano Stake Distribution / list and get last epoch and hash
182-
if: steps.aggregator_capability_unix.outputs.csd_enabled == 'true' || steps.aggregator_capability_windows.outputs.csd_enabled == 'true'
186+
if: steps.aggregator_capability_unix.outputs.cardano_stake_distribution_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_stake_distribution_enabled == 'true'
183187
shell: bash
184188
working-directory: ./bin
185189
run: |
@@ -189,17 +193,31 @@ jobs:
189193
echo "CARDANO_STAKE_DISTRIBUTION_HASH=$(echo "$CMD_OUTPUT" | jq -r '.[0].hash')" >> $GITHUB_ENV
190194
191195
- name: Cardano Stake Distribution / download & restore latest by epoch
192-
if: steps.aggregator_capability_unix.outputs.csd_enabled == 'true' || steps.aggregator_capability_windows.outputs.csd_enabled == 'true'
196+
if: steps.aggregator_capability_unix.outputs.cardano_stake_distribution_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_stake_distribution_enabled == 'true'
193197
shell: bash
194198
working-directory: ./bin
195199
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} cardano-stake-distribution download $CARDANO_STAKE_DISTRIBUTION_EPOCH
196200

197201
- name: Cardano Stake Distribution / download & restore latest by hash
198-
if: steps.aggregator_capability_unix.outputs.csd_enabled == 'true' || steps.aggregator_capability_windows.outputs.csd_enabled == 'true'
202+
if: steps.aggregator_capability_unix.outputs.cardano_stake_distribution_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_stake_distribution_enabled == 'true'
199203
shell: bash
200204
working-directory: ./bin
201205
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} cardano-stake-distribution download $CARDANO_STAKE_DISTRIBUTION_HASH
202206

207+
- name: Cardano Database V2 Snapshot / list and get last hash
208+
if: steps.aggregator_capability_unix.outputs.cardano_database_v2_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_database_v2_enabled == 'true'
209+
shell: bash
210+
working-directory: ./bin
211+
run: |
212+
./mithril-client ${{ steps.prepare.outputs.debug_level }} --unstable cardano-db-v2 snapshot list
213+
echo "CARDANO_DATABASE_V2_SNAPSHOT_HASH=$(./mithril-client --unstable cardano-db-v2 snapshot list --json | jq -r '.[0].hash')" >> $GITHUB_ENV
214+
215+
- name: Cardano Database V2 Snapshot / show snapshot
216+
if: steps.aggregator_capability_unix.outputs.cardano_database_v2_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_database_v2_enabled == 'true'
217+
shell: bash
218+
working-directory: ./bin
219+
run: ./mithril-client --unstable cardano-db-v2 snapshot show $CARDANO_DATABASE_V2_SNAPSHOT_HASH
220+
203221
test-docker:
204222
strategy:
205223
fail-fast: false
@@ -225,10 +243,12 @@ jobs:
225243
id: aggregator_capability
226244
shell: bash
227245
run: |
228-
CTX_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])')
229-
CSD_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])')
230-
echo "ctx_enabled=$CTX_CAPABILITY" >> $GITHUB_OUTPUT
231-
echo "csd_enabled=$CSD_CAPABILITY" >> $GITHUB_OUTPUT
246+
CARDANO_TRANSACTIONS_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoTransactions"])')
247+
CARDANO_STAKE_DISTRIBUTION_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoStakeDistribution"])')
248+
CARDANO_DATABASE_V2_CAPABILITY=$(wget -q -O - $AGGREGATOR_ENDPOINT | jq '.capabilities.signed_entity_types | contains(["CardanoDatabase"])')
249+
echo "cardano_transactions_enabled=$CARDANO_TRANSACTIONS_CAPABILITY" >> $GITHUB_OUTPUT
250+
echo "cardano_stake_distribution_enabled=$CARDANO_STAKE_DISTRIBUTION_CAPABILITY" >> $GITHUB_OUTPUT
251+
echo "cardano_database_v2_enabled=$CARDANO_DATABASE_V2_CAPABILITY" >> $GITHUB_OUTPUT
232252
233253
- name: Prepare Mithril client command
234254
id: command
@@ -240,13 +260,13 @@ jobs:
240260
shell: bash
241261
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} --version
242262

243-
- name: Cardano-db / list and get last digest
263+
- name: Cardano Database Snapshot / list and get last digest
244264
shell: bash
245265
run: |
246266
${{ steps.command.outputs.mithril_client }} cardano-db snapshot list
247267
echo "CDB_SNAPSHOT_DIGEST=$(${{ steps.command.outputs.mithril_client }} cardano-db snapshot list --json | jq -r '.[0].digest')" >> $GITHUB_ENV
248268
249-
- name: Cardano-db / download & restore latest
269+
- name: Cardano Database Snapshot / download & restore latest
250270
shell: bash
251271
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} cardano-db download $CDB_SNAPSHOT_DIGEST --download-dir /app
252272

@@ -261,24 +281,24 @@ jobs:
261281
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} mithril-stake-distribution download $MITHRIL_STAKE_DISTRIBUTION_HASH --download-dir /app
262282

263283
- name: Cardano transaction / list and get last snapshot
264-
if: steps.aggregator_capability.outputs.ctx_enabled == 'true'
284+
if: steps.aggregator_capability.outputs.cardano_transactions_enabled == 'true'
265285
shell: bash
266286
run: |
267287
${{ steps.command.outputs.mithril_client }} cardano-transaction snapshot list
268288
echo "CTX_SNAPSHOT_HASH=$(${{ steps.command.outputs.mithril_client }} cardano-transaction snapshot list --json | jq -r '.[0].hash')" >> $GITHUB_ENV
269289
270290
- name: Cardano transaction / show snapshot
271-
if: steps.aggregator_capability.outputs.ctx_enabled == 'true'
291+
if: steps.aggregator_capability.outputs.cardano_transactions_enabled == 'true'
272292
shell: bash
273293
run: ${{ steps.command.outputs.mithril_client }} cardano-transaction snapshot show $CTX_SNAPSHOT_HASH
274294

275295
- name: Cardano transaction certify
276-
if: steps.aggregator_capability.outputs.ctx_enabled == 'true'
296+
if: steps.aggregator_capability.outputs.cardano_transactions_enabled == 'true'
277297
shell: bash
278298
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} cardano-transaction certify $TRANSACTIONS_HASHES_TO_CERTIFY
279299

280300
- name: Cardano Stake Distribution / list and get last epoch and hash
281-
if: steps.aggregator_capability.outputs.csd_enabled == 'true'
301+
if: steps.aggregator_capability.outputs.cardano_stake_distribution_enabled == 'true'
282302
shell: bash
283303
run: |
284304
${{ steps.command.outputs.mithril_client }} cardano-stake-distribution list
@@ -287,15 +307,27 @@ jobs:
287307
echo "CARDANO_STAKE_DISTRIBUTION_HASH=$(echo "$CMD_OUTPUT" | jq -r '.[0].hash')" >> $GITHUB_ENV
288308
289309
- name: Cardano Stake Distribution / download & restore latest by epoch
290-
if: steps.aggregator_capability.outputs.csd_enabled == 'true'
310+
if: steps.aggregator_capability.outputs.cardano_stake_distribution_enabled == 'true'
291311
shell: bash
292312
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} cardano-stake-distribution download $CARDANO_STAKE_DISTRIBUTION_EPOCH --download-dir /app
293313

294314
- name: Cardano Stake Distribution / download & restore latest by hash
295-
if: steps.aggregator_capability.outputs.csd_enabled == 'true'
315+
if: steps.aggregator_capability.outputs.cardano_stake_distribution_enabled == 'true'
296316
shell: bash
297317
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} cardano-stake-distribution download $CARDANO_STAKE_DISTRIBUTION_HASH --download-dir /app
298318

319+
- name: Cardano Database V2 Snapshot / list and get last digest
320+
if: steps.aggregator_capability.outputs.cardano_database_v2_enabled == 'true'
321+
shell: bash
322+
run: |
323+
${{ steps.command.outputs.mithril_client }} --unstable cardano-db-v2 snapshot list
324+
echo "CARDANO_DATABASE_V2_SNAPSHOT_HASH=$(${{ steps.command.outputs.mithril_client }} --unstable cardano-db-v2 snapshot list --json | jq -r '.[0].hash')" >> $GITHUB_ENV
325+
326+
- name: Cardano Database V2 Snapshot / show snapshot
327+
if: steps.aggregator_capability.outputs.cardano_database_v2_enabled == 'true'
328+
shell: bash
329+
run: ${{ steps.command.outputs.mithril_client }} --unstable cardano-db-v2 snapshot show $CARDANO_DATABASE_V2_SNAPSHOT_HASH
330+
299331
test-mithril-client-wasm:
300332
strategy:
301333
fail-fast: false

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-client-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client-cli"
3-
version = "0.10.8"
3+
version = "0.10.9"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use cli_table::{format::Justify, print_stdout, Cell, Table};
33

44
use crate::{
55
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
6+
utils::CardanoDbUtils,
67
CommandContext,
78
};
89
use mithril_client::MithrilResult;
@@ -39,7 +40,7 @@ impl CardanoDbListCommand {
3940
format!("{}", item.beacon.immutable_file_number).cell(),
4041
item.network.cell(),
4142
item.digest.cell(),
42-
item.size.cell(),
43+
CardanoDbUtils::format_bytes_to_gigabytes(item.size).cell(),
4344
format!("{}", item.locations.len()).cell(),
4445
item.created_at.to_string().cell(),
4546
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use cli_table::{print_stdout, Cell, Table};
44

55
use crate::{
66
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
7-
utils::ExpanderUtils,
7+
utils::{CardanoDbUtils, ExpanderUtils},
88
CommandContext,
99
};
1010
use mithril_client::MithrilResult;
@@ -70,7 +70,7 @@ impl CardanoDbShowCommand {
7070
vec!["Digest".cell(), cardano_db_message.digest.cell()],
7171
vec![
7272
"Size".cell(),
73-
format!("{}", &cardano_db_message.size).cell(),
73+
CardanoDbUtils::format_bytes_to_gigabytes(cardano_db_message.size).cell(),
7474
],
7575
vec![
7676
"Cardano node version".cell(),
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use clap::Parser;
2+
use cli_table::{format::Justify, print_stdout, Cell, Table};
3+
4+
use mithril_client::MithrilResult;
5+
6+
use crate::{
7+
commands::{client_builder_with_fallback_genesis_key, SharedArgs},
8+
utils::CardanoDbUtils,
9+
CommandContext,
10+
};
11+
12+
/// Clap command to list existing cardano db snapshots
13+
#[derive(Parser, Debug, Clone)]
14+
pub struct CardanoDbListCommand {
15+
#[clap(flatten)]
16+
shared_args: SharedArgs,
17+
}
18+
19+
impl CardanoDbListCommand {
20+
/// Is JSON output enabled
21+
pub fn is_json_output_enabled(&self) -> bool {
22+
self.shared_args.json
23+
}
24+
25+
/// Main command execution
26+
pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> {
27+
let params = context.config_parameters()?;
28+
let client = client_builder_with_fallback_genesis_key(&params)?
29+
.with_logger(context.logger().clone())
30+
.build()?;
31+
let items = client.cardano_database().list().await?;
32+
33+
if self.is_json_output_enabled() {
34+
println!("{}", serde_json::to_string(&items)?);
35+
} else {
36+
let items = items
37+
.into_iter()
38+
.map(|item| {
39+
vec![
40+
format!("{}", item.beacon.epoch).cell(),
41+
format!("{}", item.beacon.immutable_file_number).cell(),
42+
item.hash.cell(),
43+
item.merkle_root.cell(),
44+
CardanoDbUtils::format_bytes_to_gigabytes(item.total_db_size_uncompressed)
45+
.cell(),
46+
format!("{}", item.compression_algorithm).cell(),
47+
item.cardano_node_version.cell(),
48+
item.created_at.to_string().cell(),
49+
]
50+
})
51+
.collect::<Vec<_>>()
52+
.table()
53+
.title(vec![
54+
"Epoch".cell(),
55+
"Immutable".cell(),
56+
"Hash".cell(),
57+
"Merkle root".cell(),
58+
"Database size".cell().justify(Justify::Right),
59+
"Compression".cell(),
60+
"Cardano node".cell(),
61+
"Created".cell().justify(Justify::Right),
62+
]);
63+
print_stdout(items)?;
64+
}
65+
66+
Ok(())
67+
}
68+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! Commands for the cardano db v2 artifact
2+
mod list;
3+
mod show;
4+
5+
pub use list::*;
6+
pub use show::*;
7+
8+
use crate::CommandContext;
9+
use clap::Subcommand;
10+
use mithril_client::MithrilResult;
11+
12+
/// Cardano db v2 management (alias: cdbv2)
13+
#[derive(Subcommand, Debug, Clone)]
14+
pub enum CardanoDbV2Commands {
15+
/// Cardano db snapshot v2 commands
16+
#[clap(subcommand)]
17+
Snapshot(CardanoDbV2SnapshotCommands),
18+
}
19+
20+
/// Cardano db v2 snapshots
21+
#[derive(Subcommand, Debug, Clone)]
22+
pub enum CardanoDbV2SnapshotCommands {
23+
/// List available cardano db v2 snapshots
24+
#[clap(arg_required_else_help = false)]
25+
List(CardanoDbListCommand),
26+
27+
/// Show detailed information about a cardano db v2 snapshot
28+
#[clap(arg_required_else_help = true)]
29+
Show(CardanoDbShowCommand),
30+
}
31+
32+
impl CardanoDbV2Commands {
33+
/// Execute Cardano db v2 command
34+
pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> {
35+
match self {
36+
Self::Snapshot(cmd) => cmd.execute(config_builder).await,
37+
}
38+
}
39+
}
40+
41+
impl CardanoDbV2SnapshotCommands {
42+
/// Execute Cardano db v2 snapshot command
43+
pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> {
44+
match self {
45+
Self::List(cmd) => cmd.execute(config_builder).await,
46+
Self::Show(cmd) => cmd.execute(config_builder).await,
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)