Skip to content

Commit 017d0dd

Browse files
authored
Merge pull request #2547 from input-output-hk/djo/2493/merge-cdb-v1-v2-in-client-cli
client-cli: merge cardano-database-v2 command into 'v1' command
2 parents 475051c + 135710c commit 017d0dd

File tree

22 files changed

+2118
-1869
lines changed

22 files changed

+2118
-1869
lines changed

.github/workflows/test-client.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ jobs:
167167
shell: bash
168168
run: .github/workflows/scripts/verify-cardano-db-restoration.sh ./bin/cdb-download-output.txt "${{ matrix.extra_args }}"
169169

170+
- name: Remove downloaded artifacts to free up disk space (Linux, Windows)
171+
if: runner.os != 'macOS'
172+
shell: bash
173+
working-directory: ./bin
174+
run: rm --force db/immutable/*.{chunk,primary,secondary}
175+
176+
- name: Remove downloaded artifacts to free up disk space (macOs)
177+
if: runner.os == 'macOS'
178+
shell: bash
179+
working-directory: ./bin
180+
run: sudo rm -rf db/
181+
170182
- name: Mithril Stake Distribution / list and get last hash
171183
shell: bash
172184
working-directory: ./bin
@@ -226,20 +238,20 @@ jobs:
226238
shell: bash
227239
working-directory: ./bin
228240
run: |
229-
./mithril-client ${{ steps.prepare.outputs.debug_level }} --unstable --origin-tag CI cardano-db-v2 snapshot list
230-
echo "CARDANO_DATABASE_V2_SNAPSHOT_HASH=$(./mithril-client --unstable --origin-tag CI cardano-db-v2 snapshot list --json | jq -r '.[0].hash')" >> $GITHUB_ENV
241+
./mithril-client ${{ steps.prepare.outputs.debug_level }} --unstable --origin-tag CI cardano-db snapshot list --backend v2
242+
echo "CARDANO_DATABASE_V2_SNAPSHOT_HASH=$(./mithril-client --unstable --origin-tag CI cardano-db snapshot list --backend v2 --json | jq -r '.[0].hash')" >> $GITHUB_ENV
231243
232244
- name: Cardano Database V2 Snapshot / show snapshot
233245
if: steps.aggregator_capability_unix.outputs.cardano_database_v2_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_database_v2_enabled == 'true'
234246
shell: bash
235247
working-directory: ./bin
236-
run: ./mithril-client --unstable --origin-tag CI cardano-db-v2 snapshot show $CARDANO_DATABASE_V2_SNAPSHOT_HASH
248+
run: ./mithril-client --unstable --origin-tag CI cardano-db snapshot show --backend v2 $CARDANO_DATABASE_V2_SNAPSHOT_HASH
237249

238250
- name: Cardano Database V2 Snapshot / download & restore latest (Full restoration)
239251
if: steps.aggregator_capability_unix.outputs.cardano_database_v2_enabled == 'true' || steps.aggregator_capability_windows.outputs.cardano_database_v2_enabled == 'true'
240252
shell: bash
241253
working-directory: ./bin
242-
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} --unstable --origin-tag CI cardano-db-v2 download $CARDANO_DATABASE_V2_SNAPSHOT_HASH ${{ matrix.extra_args }} 2>&1 | tee cdb-v2-download-output.txt
254+
run: ./mithril-client ${{ steps.prepare.outputs.debug_level }} --unstable --origin-tag CI cardano-db download --backend v2 $CARDANO_DATABASE_V2_SNAPSHOT_HASH ${{ matrix.extra_args }} 2>&1 | tee cdb-v2-download-output.txt
243255

244256
- name: Cardano Database V2 Snapshot / verify Cardano node starts successfully
245257
if: runner.os == 'Linux' && steps.aggregator_capability_unix.outputs.cardano_database_v2_enabled == 'true'
@@ -301,6 +313,10 @@ jobs:
301313
shell: bash
302314
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} --origin-tag CI cardano-db download $CDB_SNAPSHOT_DIGEST --download-dir /app ${{ matrix.extra_args }}
303315

316+
- name: Remove downloaded artifacts to free up disk space
317+
shell: bash
318+
run: rm --force /app/db/immutable/*.{chunk,primary,secondary}
319+
304320
- name: Mithril Stake Distribution / list and get last hash
305321
shell: bash
306322
run: |
@@ -351,18 +367,18 @@ jobs:
351367
if: steps.aggregator_capability.outputs.cardano_database_v2_enabled == 'true'
352368
shell: bash
353369
run: |
354-
${{ steps.command.outputs.mithril_client }} --unstable --origin-tag CI cardano-db-v2 snapshot list
355-
echo "CARDANO_DATABASE_V2_SNAPSHOT_HASH=$(${{ steps.command.outputs.mithril_client }} --unstable --origin-tag CI cardano-db-v2 snapshot list --json | jq -r '.[0].hash')" >> $GITHUB_ENV
370+
${{ steps.command.outputs.mithril_client }} --unstable --origin-tag CI cardano-db snapshot list --backend v2
371+
echo "CARDANO_DATABASE_V2_SNAPSHOT_HASH=$(${{ steps.command.outputs.mithril_client }} --unstable --origin-tag CI cardano-db snapshot list --backend v2 --json | jq -r '.[0].hash')" >> $GITHUB_ENV
356372
357373
- name: Cardano Database V2 Snapshot / show snapshot
358374
if: steps.aggregator_capability.outputs.cardano_database_v2_enabled == 'true'
359375
shell: bash
360-
run: ${{ steps.command.outputs.mithril_client }} --unstable --origin-tag CI cardano-db-v2 snapshot show $CARDANO_DATABASE_V2_SNAPSHOT_HASH
376+
run: ${{ steps.command.outputs.mithril_client }} --unstable --origin-tag CI cardano-db snapshot show --backend v2 $CARDANO_DATABASE_V2_SNAPSHOT_HASH
361377

362378
- name: Cardano Database V2 Snapshot / download & restore latest (Full restoration)
363379
if: steps.aggregator_capability.outputs.cardano_database_v2_enabled == 'true'
364380
shell: bash
365-
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} --origin-tag CI --unstable cardano-db-v2 download $CARDANO_DATABASE_V2_SNAPSHOT_HASH --download-dir /app ${{ matrix.extra_args }}
381+
run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} --origin-tag CI --unstable cardano-db download --backend v2 $CARDANO_DATABASE_V2_SNAPSHOT_HASH --download-dir /app ${{ matrix.extra_args }}
366382

367383
test-mithril-client-wasm:
368384
strategy:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ As a minor extension, we have adopted a slightly different versioning convention
1515

1616
- Support for recording client types in Mithril client library, CLI and WASM in the aggregator metrics.
1717

18+
- **UNSTABLE** New api for client-cli partial cardano database restoration:
19+
20+
- Allow switching of backend with parameter `--backend [v1,v2]` to `cardano-database` snapshot list, snapshot show and download subcommands
21+
- backend `v1` (default): support full database restoration only
22+
- backend `v2` (require `--unstable`): support full and partial database restoration
23+
- Add `--start`, `--end`, `--allow-override` to `cardano-database download` subcommand, supported only with `--backend v2`
24+
- Deprecated `cardano-database-v2` subcommand
25+
1826
- Crates versions:
1927

2028
| Crate | Version |

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/website/root/manual/develop/nodes/mithril-client.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Commands:
222222
mithril-stake-distribution Mithril stake distribution management (alias: msd)
223223
cardano-transaction Cardano transactions management (alias: ctx)
224224
cardano-stake-distribution Cardano stake distribution management (alias: csd)
225-
cardano-db-v2 [unstable] Cardano db v2 management (alias: cdbv2)
225+
cardano-db-v2 Deprecated, use `cardano-db` instead
226226
help Print this message or the help of the given subcommand(s)
227227

228228
Options:
@@ -514,7 +514,7 @@ Here are the subcommands available:
514514
| **help** | Prints this message or the help for the given subcommand(s) |
515515
| **list** | Lists available Cardano stake distributions |
516516

517-
### Cardano DB V2 (`unstable`, will replace `Cardano DB` in the future)
517+
### Cardano DB V2 (Deprecated, use `cardano-db` with option `--backend v2` instead)
518518

519519
| Subcommand | Performed action |
520520
| ----------------- | ----------------------------------------------------------- |
@@ -547,27 +547,33 @@ Here is a list of the available parameters:
547547

548548
`cardano-db snapshot show` command:
549549

550-
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
551-
| --------- | ------------------- | :------------------: | -------------------- | ----------------------------------------------------------------------------- | ------------- | ------- | :----------------: |
552-
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
553-
| `digest` | - | - | - | Digest of the Cardano db snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: |
550+
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
551+
| --------- | ------------------- | :------------------: | -------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: |
552+
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
553+
| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (unstable, full or partial database restoration) | `v1` | - | - |
554+
| `digest` | - | - | - | Digest of the Cardano db snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: |
554555

555556
`cardano-db snapshot list` command:
556557

557-
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
558-
| --------- | ------------------- | :------------------: | -------------------- | -------------------------------------- | ------------- | ------- | :-------: |
559-
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
558+
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
559+
| --------- | ------------------- | :------------------: | -------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :-------: |
560+
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
561+
| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (unstable, full or partial database restoration) | `v1` | - | - |
560562

561563
`cardano-db download` command:
562564

563565
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
564566
| ---------------------------- | ------------------------------ | :------------------: | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: |
565567
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
568+
| `backend` | `--backend` | `-b` | - | Backend to use, either: `v1` (default, full database restoration only) or `v2` (unstable, full or partial database restoration) | `v1` | - | - |
566569
| `digest` | - | - | - | Digest of the Cardano db snapshot to download or `latest` for the latest artifact | - | - | :heavy_check_mark: |
567570
| `download_dir` | `--download-dir` | - | - | Directory where the immutable and ancillary files will be downloaded | - | - | - |
568571
| `genesis_verification_key` | `--genesis-verification-key` | - | `GENESIS_VERIFICATION_KEY` | Genesis verification key to check the certificate chain | - | - | :heavy_check_mark: |
569572
| `include_ancillary` | `--include-ancillary` | - | - | Include ancillary files in the download, if set the `ancillary_verification_key` is required in order to verify the ancillary files | `false` | - | - |
570573
| `ancillary_verification_key` | `--ancillary-verification-key` | - | `ANCILLARY_VERIFICATION_KEY` | Ancillary verification key to verify the ancillary files | - | - | - |
574+
| `start` | `--start` | - | - | [backend `v2` only] The first immutable file number to download | - | - | - |
575+
| `end` | `--end` | - | - | [backend `v2` only] The last immutable file number to download | - | - | - |
576+
| `allow_override` | `--allow-override` | - | - | [backend `v2` only] Allow existing files in the download directory to be overridden | `false` | - | - |
571577

572578
`mithril-stake-distribution list` command:
573579

@@ -622,19 +628,37 @@ Here is a list of the available parameters:
622628

623629
`cardano-db-v2 snapshot show` command:
624630

631+
:::warning
632+
633+
Deprecated, use `cardano-db snapshot show` with option `--backend v2` instead
634+
635+
:::
636+
625637
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
626638
| --------- | ------------------- | :------------------: | -------------------- | --------------------------------------------------------------------------- | ------------- | ------- | :----------------: |
627639
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
628640
| `hash` | - | - | - | Hash of the Cardano db snapshot to show or `latest` for the latest artifact | - | - | :heavy_check_mark: |
629641

630642
`cardano-db-v2 snapshot list` command:
631643

644+
:::warning
645+
646+
Deprecated, use `cardano-db snapshot list` with option `--backend v2` instead
647+
648+
:::
649+
632650
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
633651
| --------- | ------------------- | :------------------: | -------------------- | -------------------------------------- | ------------- | ------- | :-------: |
634652
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |
635653

636654
`cardano-db-v2 download` command:
637655

656+
:::warning
657+
658+
Deprecated, use `cardano-db download` with option `--backend v2` instead
659+
660+
:::
661+
638662
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
639663
| ---------------------------- | ------------------------------ | :------------------: | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------- | :----------------: |
640664
| `json` | `--json` | - | - | Enable JSON output for command results | `false` | - | - |

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.12.8"
3+
version = "0.12.9"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-cli/src/command_context.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::anyhow;
12
use config::builder::DefaultState;
23
use config::ConfigBuilder;
34
use slog::Logger;
@@ -33,6 +34,23 @@ impl CommandContext {
3334
self.unstable_enabled
3435
}
3536

37+
/// Ensure that unstable commands are enabled
38+
pub fn require_unstable(
39+
&self,
40+
sub_command: &str,
41+
command_example: Option<&str>,
42+
) -> MithrilResult<()> {
43+
if self.is_unstable_enabled() {
44+
Ok(())
45+
} else {
46+
let example = command_example.map(|e| format!(" {e}")).unwrap_or_default();
47+
Err(anyhow!(
48+
"The \"{sub_command}\" subcommand is only accepted using the --unstable flag.\n\n\
49+
ie: \"mithril-client --unstable {sub_command}{example}\""
50+
))
51+
}
52+
}
53+
3654
/// Get the configured parameters
3755
pub fn config_parameters(&self) -> MithrilResult<ConfigParameters> {
3856
let config = self.config_builder.clone().build()?;
@@ -45,3 +63,36 @@ impl CommandContext {
4563
&self.logger
4664
}
4765
}
66+
67+
#[cfg(test)]
68+
mod tests {
69+
use slog::o;
70+
71+
use super::*;
72+
73+
#[test]
74+
fn require_unstable_return_ok_if_unstable_enabled() {
75+
let unstable_enabled = true;
76+
let context = CommandContext::new(
77+
ConfigBuilder::default(),
78+
unstable_enabled,
79+
Logger::root(slog::Discard, o!()),
80+
);
81+
82+
let result = context.require_unstable("test", None);
83+
assert!(result.is_ok(), "Expected Ok, got {result:?}");
84+
}
85+
86+
#[test]
87+
fn require_unstable_return_err_if_unstable_disabled() {
88+
let unstable_enabled = false;
89+
let context = CommandContext::new(
90+
ConfigBuilder::default(),
91+
unstable_enabled,
92+
Logger::root(slog::Discard, o!()),
93+
);
94+
95+
let result = context.require_unstable("test", None);
96+
assert!(result.is_err(), "Expected Err, got {result:?}");
97+
}
98+
}

0 commit comments

Comments
 (0)