Skip to content

Commit ffc7943

Browse files
authored
Merge pull request #1884 from input-output-hk/fix/lgpl-licence
feat: Make `rug-backend` optional for `mithril-client` crate
2 parents 7b39690 + d5933d2 commit ffc7943

File tree

7 files changed

+52
-32
lines changed

7 files changed

+52
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ As a minor extension, we have adopted a slightly different versioning convention
1919

2020
- **UNSTABLE** Cardano stake distribution certification:
2121

22+
- Add feature options `num-integer-backend` and `rug-backend` for `mithril-common` and `mithril-client` crates. Allows to disable `rug-backend` and avoid `LGPL` licence usage.
2223
- Implement the signable and artifact builders for the signed entity type `CardanoStakeDistribution`.
2324
- Implement the HTTP routes related to the signed entity type `CardanoStakeDistribution` on the aggregator REST API.
2425
- Added support in the `mithril-client` library for retrieving `CardanoStakeDistribution` by epoch or by hash, and for listing all available `CardanoStakeDistribution`.

Cargo.lock

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

mithril-client/Cargo.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client"
3-
version = "0.8.15"
3+
version = "0.8.16"
44
description = "Mithril client library"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -50,13 +50,13 @@ uuid = { version = "1.7.0", features = ["v4"] }
5050
zstd = { version = "0.13.0", optional = true }
5151

5252
[target.'cfg(not(target_family = "wasm"))'.dependencies]
53-
mithril-common = { path = "../mithril-common", version = "=0.4", features = [
53+
mithril-common = { path = "../mithril-common", version = "=0.4", default-features = false, features = [
5454
"fs",
5555
] }
5656

5757
[target.'cfg(target_family = "wasm")'.dependencies]
5858
getrandom = { version = "0.2.12", features = ["js"] }
59-
mithril-common = { path = "../mithril-common", version = "=0.4" }
59+
mithril-common = { path = "../mithril-common", version = "=0.4", default-features = false }
6060
reqwest = { version = "0.12.4", default-features = false, features = [
6161
"charset",
6262
"http2",
@@ -68,7 +68,7 @@ reqwest = { version = "0.12.4", default-features = false, features = [
6868
[dev-dependencies]
6969
httpmock = "0.7.0"
7070
indicatif = { version = "0.17.7", features = ["tokio"] }
71-
mithril-common = { path = "../mithril-common", version = "=0.4", features = [
71+
mithril-common = { path = "../mithril-common", version = "=0.4", default-features = false, features = [
7272
"random",
7373
"test_tools",
7474
] }
@@ -81,7 +81,7 @@ warp = "0.3.6"
8181

8282
[features]
8383
# Include native-tls in reqwest by default
84-
default = ["native-tls"]
84+
default = ["native-tls", "rug-backend"]
8585

8686
# Full feature set
8787
full = ["fs"]
@@ -102,6 +102,12 @@ rustls-tls-manual-roots = ["reqwest/rustls-tls-manual-roots"]
102102
rustls-tls-webpki-roots = ["reqwest/rustls-tls-webpki-roots"]
103103
rustls-tls-native-roots = ["reqwest/rustls-tls-native-roots"]
104104

105+
# Enables `rug-backend` features for `mithril-common` dependency
106+
rug-backend = ["mithril-common/rug-backend"]
107+
# Enables `num-integer-backend` features for `mithril-common` dependency
108+
# by default it's `rug-backend`
109+
num-integer-backend = ["mithril-common/num-integer-backend"]
110+
105111
[package.metadata.docs.rs]
106112
all-features = true
107113
# enable unstable features in the documentation

mithril-client/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ async fn main() -> mithril_client::MithrilResult<()> {
5151
}
5252
```
5353

54+
## Different arithmetic libraries
55+
56+
Under the hood mithril client could use different arithmetic libraries:
57+
58+
- [rug](https://crates.io/crates/rug)
59+
- [num](https://crates.io/crates/num)
60+
61+
You can switch beetwen them by using `rug-backend` and `num-integer-backend` respectively.
62+
For Windows and WASM target platforms only `num-integer-backend` is available,
63+
for others `rug-backend` is a default option.
64+
5465
## Getting Help
5566

5667
First, check our [Developer documentation](https://mithril.network/doc/manual/developer-docs/nodes/mithril-client-library).

mithril-common/Cargo.toml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ kes-summed-ed25519 = { version = "0.2.1", features = [
4747
"serde_enabled",
4848
"sk_clone_enabled",
4949
] }
50+
mithril-stm = { path = "../mithril-stm", version = "0.3", default-features = false }
5051
nom = "7.1.3"
5152
pallas-addresses = { version = "0.29.0", optional = true }
5253
pallas-codec = { version = "0.29.0", optional = true }
@@ -73,21 +74,7 @@ typetag = "0.2.15"
7374
walkdir = "2.4.0"
7475
warp = { version = "0.3.6", optional = true }
7576

76-
[target.'cfg(target_family = "unix")'.dependencies]
77-
# only unix supports the default rug backend
78-
mithril-stm = { path = "../mithril-stm", version = "0.3" }
79-
80-
[target.'cfg(windows)'.dependencies]
81-
# Windows doesn't support rug backend, fallback to num-integer
82-
mithril-stm = { path = "../mithril-stm", version = "0.3", default-features = false, features = [
83-
"num-integer-backend",
84-
] }
85-
8677
[target.'cfg(target_family = "wasm")'.dependencies]
87-
# WASM doesn't support rug backend, fallback to num-integer
88-
mithril-stm = { path = "../mithril-stm", version = "0.3", default-features = false, features = [
89-
"num-integer-backend",
90-
] }
9178
wasm-bindgen = "0.2.90"
9279

9380
[dev-dependencies]
@@ -105,7 +92,7 @@ tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread", "time"] }
10592
mithril-build-script = { path = "../internal/mithril-build-script", version = "=0.2" }
10693

10794
[features]
108-
default = []
95+
default = ["rug-backend"]
10996

11097
# Full feature set
11198
full = ["random", "fs", "test_tools"]
@@ -121,6 +108,12 @@ fs = [
121108
"dep:pallas-traverse",
122109
]
123110

111+
# Enables `rug-backend` features for `mithril-stm` dependency
112+
rug-backend = ["mithril-stm/rug-backend"]
113+
# Enables `num-integer-backend` features for `mithril-stm` dependency
114+
# by default it's `rug-backend`
115+
num-integer-backend = ["mithril-stm/num-integer-backend"]
116+
124117
# Disable signer certification, to be used only for tests
125118
allow_skip_signer_certification = []
126119
# Enable all tests tools

mithril-stm/Cargo.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-stm"
3-
version = "0.3.27"
3+
version = "0.3.28"
44
edition = { workspace = true }
55
authors = { workspace = true }
66
homepage = { workspace = true }
@@ -18,15 +18,24 @@ blake2 = "0.10.6"
1818
# Enforce blst portable feature for runtime detection of Intel ADX instruction set.
1919
blst = { version = "0.3.11", features = ["portable"] }
2020
digest = { version = "0.10.7", features = ["alloc"] }
21-
num-bigint = { version = "0.4.4", optional = true }
22-
num-rational = { version = "0.4.1", optional = true }
23-
num-traits = { version = "0.2.16", optional = true }
2421
rand_core = "0.6.4"
2522
rayon = "1.8.0"
26-
rug = { version = "1.22.0", optional = true }
2723
serde = { version = "1.0.188", features = ["rc", "derive"] }
2824
thiserror = "1.0.49"
2925

26+
[target.'cfg(not(any(target_family = "wasm", windows)))'.dependencies]
27+
# only unix supports the rug backend
28+
rug = { version = "1.22.0", optional = true }
29+
num-bigint = { version = "0.4.4", optional = true }
30+
num-rational = { version = "0.4.1", optional = true }
31+
num-traits = { version = "0.2.16", optional = true }
32+
33+
[target.'cfg(any(target_family = "wasm", windows))'.dependencies]
34+
# WASM and Windows don't support rug backend, fallback to num-integer only
35+
num-bigint = { version = "0.4.4" }
36+
num-rational = { version = "0.4.1" }
37+
num-traits = { version = "0.2.16" }
38+
3039
[dev-dependencies]
3140
bincode = "1.3.3"
3241
criterion = { version = "0.5.1", features = ["html_reports"] }

mithril-stm/src/eligibility_check.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::stm::Stake;
2-
#[cfg(feature = "num-integer-backend")]
2+
#[cfg(any(feature = "num-integer-backend", target_family = "wasm", windows))]
33
use {
44
num_bigint::{BigInt, Sign},
55
num_rational::Ratio,
66
num_traits::{One, Signed},
77
std::ops::Neg,
88
};
99

10-
#[cfg(feature = "num-integer-backend")]
10+
#[cfg(any(feature = "num-integer-backend", target_family = "wasm", windows))]
1111
/// Checks that ev is successful in the lottery. In particular, it compares the output of `phi`
1212
/// (a real) to the output of `ev` (a hash). It uses the same technique used in the
1313
/// [Cardano ledger](https://github.com/input-output-hk/cardano-ledger/). In particular,
@@ -49,7 +49,7 @@ pub(crate) fn ev_lt_phi(phi_f: f64, ev: [u8; 64], stake: Stake, total_stake: Sta
4949
taylor_comparison(1000, q, x)
5050
}
5151

52-
#[cfg(feature = "num-integer-backend")]
52+
#[cfg(any(feature = "num-integer-backend", target_family = "wasm", windows))]
5353
/// Checks if cmp < exp(x). Uses error approximation for an early stop. Whenever the value being
5454
/// compared, `cmp`, is smaller (or greater) than the current approximation minus an `error_term`
5555
/// (plus an `error_term` respectively), then we stop approximating. The choice of the `error_term`
@@ -82,7 +82,7 @@ fn taylor_comparison(bound: usize, cmp: Ratio<BigInt>, x: Ratio<BigInt>) -> bool
8282
false
8383
}
8484

85-
#[cfg(not(feature = "num-integer-backend"))]
85+
#[cfg(not(any(feature = "num-integer-backend", target_family = "wasm", windows)))]
8686
/// The crate `rug` has sufficient optimizations to not require a taylor approximation with early
8787
/// stop. The difference between the current implementation and the one using the optimization
8888
/// above is around 10% faster. We perform the computations with 117 significant bits of
@@ -146,7 +146,7 @@ mod tests {
146146
assert_eq!(quick_result, result);
147147
}
148148

149-
#[cfg(feature = "num-integer-backend")]
149+
#[cfg(any(feature = "num-integer-backend", target_family = "wasm", windows))]
150150
#[test]
151151
/// Checking the early break of Taylor computation
152152
fn early_break_taylor(

0 commit comments

Comments
 (0)