Skip to content

Commit 221a003

Browse files
authored
Merge pull request #1344 from input-output-hk/djo/1311/feature_for_snapshot_download
Mithril-client-lib: Gate snapshot download & message computation behind a feature
2 parents d02447f + c1b9afb commit 221a003

File tree

13 files changed

+263
-171
lines changed

13 files changed

+263
-171
lines changed

.github/workflows/actions/publish-crate-package/action.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
api_token:
1212
description: crates.io API token.
1313
required: false
14+
publish_args:
15+
description: Additional arguments that will be passed to 'cargo publish'
16+
required: false
1417

1518
runs:
1619
using: "composite"
@@ -36,18 +39,18 @@ runs:
3639
- name: Cargo publish dry run
3740
shell: bash
3841
run: |
39-
echo "Cargo publish '${{ inputs.package}}' package (dry run)"
40-
cargo publish -p ${{ inputs.package}} --dry-run --no-verify
42+
echo "Cargo publish '${{ inputs.package }}' package (dry run)"
43+
cargo publish -p ${{ inputs.package }} --dry-run --no-verify ${{ inputs.publish_args }}
4144
4245
- name: Cargo package list
4346
shell: bash
4447
run: |
45-
echo "Cargo package list '${{ inputs.package}}' package"
46-
cargo package -p ${{ inputs.package}} --list
48+
echo "Cargo package list '${{ inputs.package }}' package"
49+
cargo package -p ${{ inputs.package }} --list
4750
4851
- name: Cargo publish
4952
if: inputs.dry_run == 'false' && steps.check_version.outputs.should_deploy == 'true'
5053
shell: bash
5154
run: |
52-
echo "Cargo publish '${{ inputs.package}}' package"
53-
cargo publish -p ${{ inputs.package}} --token ${{ inputs.api_token }} --no-verify
55+
echo "Cargo publish '${{ inputs.package }}' package"
56+
cargo publish -p ${{ inputs.package }} --token ${{ inputs.api_token }} --no-verify ${{ inputs.publish_args }}

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
uses: ./.github/workflows/actions/build-upload-mithril-artifact
4747
with:
4848
binaries-build-args: --bin mithril-aggregator --bin mithril-signer --bin mithril-client --bin mithril-relay --features bundle_openssl
49-
libraries-build-args: --package mithril-stm --package mithril-client
49+
libraries-build-args: --package mithril-stm --package mithril-client --features full
5050

5151
- name: Build Debian packages
5252
shell: bash
@@ -87,12 +87,12 @@ jobs:
8787
# Only build client on windows & mac
8888
- os: macos-12
8989
binaries-build-args: --bin mithril-client --features bundle_openssl
90-
libraries-build-args: --package mithril-stm --package mithril-client
90+
libraries-build-args: --package mithril-stm --package mithril-client --features full
9191
- os: windows-latest
9292
# Use `--bins --package <package>` instead of `--bin <package>`, otherwise the 'windows' compatibility
9393
# hack in mithril common cargo.toml doesn't apply (we have no idea why).
9494
binaries-build-args: --bins --package mithril-client-cli --features bundle_openssl
95-
libraries-build-args: --package mithril-stm --package mithril-client --no-default-features --features num-integer-backend
95+
libraries-build-args: --package mithril-stm --package mithril-client --no-default-features --features num-integer-backend,full
9696
runs-on: ${{ matrix.os }}
9797

9898
steps:
@@ -119,12 +119,12 @@ jobs:
119119

120120
include:
121121
- os: ubuntu-22.04
122-
test-args: --features portable --workspace
122+
test-args: --features portable,full --workspace
123123
# Only test client on windows & mac (since its the only binaries supported for those os for now)
124124
- os: macos-12
125-
test-args: --package mithril-client --package mithril-client-cli
125+
test-args: --package mithril-client --package mithril-client-cli --features full
126126
- os: windows-latest
127-
test-args: --package mithril-client --package mithril-client-cli
127+
test-args: --package mithril-client --package mithril-client-cli --features full
128128

129129
runs-on: ${{ matrix.os }}
130130

.github/workflows/docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ jobs:
2727
- name: Generate cargo doc
2828
run: |
2929
cargo doc --no-deps -p mithril-stm -p mithril-common -p mithril-aggregator \
30-
-p mithril-signer -p mithril-client -p mithril-client-cli --message-format=json \
30+
-p mithril-signer -p mithril-client -p mithril-client-cli \
31+
--all-features --message-format=json \
3132
| clippy-sarif | tee rust-cargo-doc-results.sarif | sarif-fmt
3233
3334
# Update tool sarif metadata from "clippy" to "cargo-doc" (since it's set this way by clippy-sarif)

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/developer-docs/nodes/mithril-client-library.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Snapshot download and certificate chain validation can take quite some time even
117117
An example of implementation with the crate [indicatif](https://crates.io/crates/indicatif) is available in the [Mithril repository](https://github.com/input-output-hk/mithril/tree/main/mithril-client/examples/snapshot_list_get_show_download_verify.rs). To run it, execute the following command:
118118

119119
```bash
120-
cargo run --example snapshot_list_get_show_download_verify
120+
cargo run --example snapshot_list_get_show_download_verify --features fs
121121
```
122122

123123
:::

mithril-client/Cargo.toml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client"
3-
version = "0.5.6"
3+
version = "0.5.7"
44
description = "Mithril client library"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -13,25 +13,35 @@ include = ["**/*.rs", "Cargo.toml", "README.md", ".gitignore"]
1313
[lib]
1414
crate-type = ["lib", "cdylib", "staticlib"]
1515

16+
[[example]]
17+
name = "snapshot_list_get_show_download_verify"
18+
path = "examples/snapshot_list_get_show_download_verify.rs"
19+
required-features = ["fs"]
20+
21+
[[test]]
22+
name = "snapshot_list_get_show_download_verify"
23+
path = "tests/snapshot_list_get_show_download_verify.rs"
24+
required-features = ["fs"]
25+
1626
[dependencies]
1727
anyhow = "1.0.75"
1828
async-recursion = "1.0.5"
1929
async-trait = "0.1.73"
2030
chrono = { version = "0.4.31", features = ["serde"] }
21-
flate2 = "1.0.27"
22-
flume = "0.11.0"
31+
flate2 = { version = "1.0.27", optional = true }
32+
flume = { version = "0.11.0", optional = true }
2333
futures = "0.3.28"
2434
mithril-common = { path = "../mithril-common", version = "0.2" }
2535
reqwest = { version = "0.11.22", features = ["json", "stream"] }
2636
semver = "1.0.19"
2737
serde = { version = "1.0.188", features = ["derive"] }
2838
serde_json = "1.0.107"
2939
slog = "2.7.0"
30-
tar = "0.4.40"
40+
tar = { version = "0.4.40", optional = true }
3141
thiserror = "1.0.49"
3242
tokio = { version = "1.32.0", features = ["sync"] }
3343
uuid = { version = "1.5.0", features = ["v4"] }
34-
zstd = "0.13.0"
44+
zstd = { version = "0.13.0", optional = true }
3545

3646
[dev-dependencies]
3747
httpmock = "0.6.8"
@@ -47,4 +57,15 @@ tokio = { version = "1.32.0", features = ["macros", "rt"] }
4757
warp = "0.3"
4858

4959
[features]
60+
# Include nothing by default
61+
# TODO: rollback to default = []
62+
default = ["full"]
63+
full = ["fs"]
64+
# Enable file system releated functionnality, right now that mean ony snapshot download
65+
fs = ["flate2", "flume", "tar", "tokio/rt", "zstd"]
5066
portable = ["mithril-common/portable"]
67+
68+
[package.metadata.docs.rs]
69+
all-features = true
70+
# enable unstable features in the documentation
71+
rustdoc-args = ["--cfg", "docsrs"]

mithril-client/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ all: test build
1111

1212
build:
1313
# We use 'portable' feature to avoid SIGILL crashes
14-
${CARGO} build --release --features portable
14+
${CARGO} build --release --features portable,full
1515

1616
test:
17-
${CARGO} test
17+
${CARGO} test --features full
1818

1919
check:
2020
${CARGO} check --release --all-features --all-targets
@@ -25,4 +25,4 @@ clean:
2525
${CARGO} clean
2626

2727
doc:
28-
${CARGO} doc --no-deps --open
28+
${CARGO} doc --no-deps --open --features full

mithril-client/src/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::certificate_client::{
55
use crate::feedback::{FeedbackReceiver, FeedbackSender};
66
use crate::mithril_stake_distribution_client::MithrilStakeDistributionClient;
77
use crate::snapshot_client::SnapshotClient;
8+
#[cfg(feature = "fs")]
89
use crate::snapshot_downloader::{HttpSnapshotDownloader, SnapshotDownloader};
910
use crate::MithrilResult;
1011
use anyhow::{anyhow, Context};
@@ -45,6 +46,7 @@ pub struct ClientBuilder {
4546
genesis_verification_key: String,
4647
aggregator_client: Option<Arc<dyn AggregatorClient>>,
4748
certificate_verifier: Option<Arc<dyn CertificateVerifier>>,
49+
#[cfg(feature = "fs")]
4850
snapshot_downloader: Option<Arc<dyn SnapshotDownloader>>,
4951
logger: Option<Logger>,
5052
feedback_receivers: Vec<Arc<dyn FeedbackReceiver>>,
@@ -59,6 +61,7 @@ impl ClientBuilder {
5961
genesis_verification_key: genesis_verification_key.to_string(),
6062
aggregator_client: None,
6163
certificate_verifier: None,
64+
#[cfg(feature = "fs")]
6265
snapshot_downloader: None,
6366
logger: None,
6467
feedback_receivers: vec![],
@@ -75,6 +78,7 @@ impl ClientBuilder {
7578
genesis_verification_key: genesis_verification_key.to_string(),
7679
aggregator_client: None,
7780
certificate_verifier: None,
81+
#[cfg(feature = "fs")]
7882
snapshot_downloader: None,
7983
logger: None,
8084
feedback_receivers: vec![],
@@ -115,6 +119,7 @@ impl ClientBuilder {
115119
Some(client) => client,
116120
};
117121

122+
#[cfg(feature = "fs")]
118123
let snapshot_downloader = match self.snapshot_downloader {
119124
None => Arc::new(
120125
HttpSnapshotDownloader::new(feedback_sender.clone(), logger.clone())
@@ -146,8 +151,11 @@ impl ClientBuilder {
146151
));
147152
let snapshot_client = Arc::new(SnapshotClient::new(
148153
aggregator_client,
154+
#[cfg(feature = "fs")]
149155
snapshot_downloader,
156+
#[cfg(feature = "fs")]
150157
feedback_sender,
158+
#[cfg(feature = "fs")]
151159
logger,
152160
));
153161

@@ -176,6 +184,7 @@ impl ClientBuilder {
176184
self
177185
}
178186

187+
cfg_fs! {
179188
/// Set the [SnapshotDownloader] that will be used to download snapshots.
180189
pub fn with_snapshot_downloader(
181190
mut self,
@@ -184,6 +193,7 @@ impl ClientBuilder {
184193
self.snapshot_downloader = Some(snapshot_downloader);
185194
self
186195
}
196+
}
187197

188198
/// Set the [Logger] to use.
189199
pub fn with_logger(mut self, logger: Logger) -> Self {

mithril-client/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(missing_docs)]
2+
#![cfg_attr(docsrs, feature(doc_cfg))]
23

34
//! Define all the tooling necessary to manipulate Mithril certified types from a
45
//! [Mithril Aggregator](https://mithril.network/rust-doc/mithril_aggregator/index.html).
@@ -19,6 +20,8 @@
1920
//!
2021
//! Below is an example describing the usage of most of the library's functions together:
2122
//!
23+
//! **Note:** _Snapshot download and the compute snapshot message functions are available using crate feature_ **fs**.
24+
//!
2225
//! ```no_run
2326
//! # async fn run() -> mithril_client::MithrilResult<()> {
2427
//! use mithril_client::{ClientBuilder, MessageBuilder};
@@ -52,14 +55,26 @@
5255
//! # }
5356
//! ```
5457
58+
macro_rules! cfg_fs {
59+
($($item:item)*) => {
60+
$(
61+
#[cfg(feature = "fs")]
62+
#[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
63+
$item
64+
)*
65+
}
66+
}
67+
5568
pub mod aggregator_client;
5669
pub mod certificate_client;
5770
mod client;
5871
pub mod feedback;
5972
mod message;
6073
pub mod mithril_stake_distribution_client;
6174
pub mod snapshot_client;
62-
pub mod snapshot_downloader;
75+
cfg_fs! {
76+
pub mod snapshot_downloader;
77+
}
6378
mod type_alias;
6479
mod utils;
6580

mithril-client/src/message.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
use anyhow::Context;
2+
#[cfg(feature = "fs")]
23
use mithril_common::digesters::{CardanoImmutableDigester, ImmutableDigester};
34
use mithril_common::entities::{ProtocolMessage, ProtocolMessagePartKey};
45
use mithril_common::messages::SignerWithStakeMessagePart;
56
use mithril_common::protocol::SignerBuilder;
67
use slog::{o, Logger};
8+
#[cfg(feature = "fs")]
79
use std::path::Path;
10+
#[cfg(feature = "fs")]
811
use std::sync::Arc;
912

10-
use crate::{MithrilCertificate, MithrilResult, MithrilStakeDistribution};
13+
#[cfg(feature = "fs")]
14+
use crate::MithrilCertificate;
15+
use crate::{MithrilResult, MithrilStakeDistribution};
1116

1217
/// A [MessageBuilder] can be used to compute the message of Mithril artifacts.
1318
pub struct MessageBuilder {
19+
#[cfg(feature = "fs")]
1420
immutable_digester: Option<Arc<dyn ImmutableDigester>>,
1521
logger: Logger,
1622
}
@@ -20,35 +26,37 @@ impl MessageBuilder {
2026
pub fn new() -> MessageBuilder {
2127
let logger = Logger::root(slog::Discard, o!());
2228
Self {
29+
#[cfg(feature = "fs")]
2330
immutable_digester: None,
2431
logger,
2532
}
2633
}
2734

28-
/// Set the [ImmutableDigester] to be used for the message computation for snapshot.
29-
///
30-
/// If not set a default implementation will be used.
31-
pub fn with_immutable_digester(
32-
mut self,
33-
immutable_digester: Arc<dyn ImmutableDigester>,
34-
) -> Self {
35-
self.immutable_digester = Some(immutable_digester);
36-
self
37-
}
38-
3935
/// Set the [Logger] to use.
4036
pub fn with_logger(mut self, logger: Logger) -> Self {
4137
self.logger = logger;
4238
self
4339
}
4440

41+
cfg_fs! {
4542
fn get_immutable_digester(&self) -> Arc<dyn ImmutableDigester> {
4643
match self.immutable_digester.as_ref() {
4744
None => Arc::new(CardanoImmutableDigester::new(None, self.logger.clone())),
4845
Some(digester) => digester.clone(),
4946
}
5047
}
5148

49+
/// Set the [ImmutableDigester] to be used for the message computation for snapshot.
50+
///
51+
/// If not set a default implementation will be used.
52+
pub fn with_immutable_digester(
53+
mut self,
54+
immutable_digester: Arc<dyn ImmutableDigester>,
55+
) -> Self {
56+
self.immutable_digester = Some(immutable_digester);
57+
self
58+
}
59+
5260
/// Compute message for a snapshot (based on the directory where it was unpacked).
5361
///
5462
/// Warning: this operation can be quite long depending on the snapshot size.
@@ -74,6 +82,7 @@ impl MessageBuilder {
7482

7583
Ok(message)
7684
}
85+
}
7786

7887
/// Compute message for a Mithril stake distribution.
7988
pub fn compute_mithril_stake_distribution_message(

0 commit comments

Comments
 (0)