Skip to content

Commit ba0c09a

Browse files
committed
merge 'main'
2 parents 14437d1 + 5945700 commit ba0c09a

File tree

16 files changed

+72
-38
lines changed

16 files changed

+72
-38
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-common/Cargo.toml

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.2.154"
3+
version = "0.2.155"
44
description = "Common types, interfaces, and utilities for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -87,6 +87,7 @@ criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
8787
mockall = "0.12.0"
8888
# pallas-crypto = "0.21.0"
8989
pallas-crypto = { git = "https://github.com/falcucci/pallas.git", branch = "fix/legacy-transaction-utxo-by-address" }
90+
rand_core = { version = "0.6.4", features = ["getrandom"] }
9091
reqwest = { version = "0.11.22", features = ["json"] }
9192
slog-async = "2.8.0"
9293
slog-scope = "4.4.0"
@@ -105,6 +106,7 @@ default = []
105106
# Full feature set
106107
full = ["random", "database", "fs", "test_tools"]
107108
random = ["rand_core/getrandom"]
109+
<<<<<<< HEAD
108110
database = ["sqlite"]
109111
fs = [
110112
"tokio/fs",
@@ -116,17 +118,21 @@ fs = [
116118
"pallas-primitives",
117119
"pallas-traverse",
118120
]
121+
=======
122+
database = ["dep:sqlite"]
123+
fs = ["tokio/fs", "tokio/process", "dep:pallas-network", "dep:pallas-traverse"]
124+
>>>>>>> main
119125

120126
# Portable feature avoids SIGILL crashes on CPUs not supporting Intel ADX instruction set when built on CPUs that support it
121127
portable = ["mithril-stm/portable"]
122128

123129
# Disable signer certification, to be used only for tests
124130
allow_skip_signer_certification = []
125131
# Enable all tests tools
126-
test_tools = ["apispec", "test_http_server"]
132+
test_tools = ["apispec", "test_http_server", "random"]
127133
# Enable tools to helps validate conformity to an OpenAPI specification
128-
apispec = ["glob", "http", "jsonschema", "warp"]
129-
test_http_server = ["warp"]
134+
apispec = ["dep:glob", "dep:http", "dep:jsonschema", "dep:warp"]
135+
test_http_server = ["dep:warp"]
130136

131137
[package.metadata.docs.rs]
132138
all-features = true

mithril-common/Makefile

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
.PHONY: all build test check debug run help doc
1+
.PHONY: all build test check doc check-all-features-set
22

33
CARGO = cargo
4+
# All the crates features excluding the two that have little to no impact to the code
5+
FEATURES := $(shell ${CARGO} metadata --quiet --no-deps \
6+
| jq -r '.packages[] | select(.name=="mithril-common") | .features \
7+
| del(.allow_skip_signer_certification) | del(.portable) \
8+
| keys | join(" ")')
49

510
all: test build
611

@@ -18,3 +23,17 @@ check:
1823

1924
doc:
2025
${CARGO} doc --no-deps --open --features full
26+
27+
# Compute the powerset of all the given features and save it to a file
28+
.feature-sets:
29+
powerset() { [ $$# -eq 0 ] && echo || (shift; powerset "$$@") | while read r ; do echo "$$1 $$r"; echo "$$r"; done };\
30+
powerset $$(echo "$(FEATURES)") > .features-sets
31+
32+
check-all-features-set: .feature-sets
33+
# Read the file to run cargo clippy on all those features sets
34+
cat .features-sets | while read features_set; do \
35+
echo "Clippy common with feature '$$features_set''"; \
36+
${CARGO} clippy -p mithril-common --features "$$features_set"; \
37+
done
38+
39+
rm .features-sets

mithril-common/src/chain_observer/builder.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use thiserror::Error;
44

55
use crate::{chain_observer::ChainObserver, CardanoNetwork, StdResult};
66

7-
use super::{CardanoCliChainObserver, CardanoCliRunner, FakeObserver, PallasChainObserver};
7+
#[cfg(any(test, feature = "test_tools"))]
8+
use super::FakeObserver;
9+
use super::{CardanoCliChainObserver, CardanoCliRunner, PallasChainObserver};
810

911
/// Type of chain observers available
1012
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
@@ -16,7 +18,7 @@ pub enum ChainObserverType {
1618
/// Pallas chain observer.
1719
Pallas,
1820
/// Fake chain observer.
19-
#[cfg(feature = "test_tools")]
21+
#[cfg(any(test, feature = "test_tools"))]
2022
Fake,
2123
}
2224

@@ -25,6 +27,7 @@ impl Display for ChainObserverType {
2527
match self {
2628
Self::CardanoCli => write!(f, "cardano-cli"),
2729
Self::Pallas => write!(f, "pallas"),
30+
#[cfg(any(test, feature = "test_tools"))]
2831
Self::Fake => write!(f, "fake"),
2932
}
3033
}
@@ -85,7 +88,7 @@ impl ChainObserverBuilder {
8588
);
8689
Ok(Arc::new(observer))
8790
}
88-
#[cfg(feature = "test_tools")]
91+
#[cfg(any(test, feature = "test_tools"))]
8992
ChainObserverType::Fake => Ok(Arc::new(FakeObserver::default())),
9093
}
9194
}

mithril-common/src/chain_observer/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
mod builder;
55
#[cfg(all(feature = "fs", feature = "random"))]
66
mod cli_observer;
7-
#[cfg(feature = "test_tools")]
7+
#[cfg(any(test, feature = "test_tools"))]
88
mod fake_observer;
99
mod interface;
1010
mod model;
1111
#[cfg(all(feature = "fs", feature = "random"))]
1212
mod pallas_observer;
1313

14-
#[cfg(test)]
14+
#[cfg(all(test, feature = "fs", feature = "random"))]
1515
mod test_cli_runner;
1616

17-
#[cfg(test)]
18-
pub use cli_observer::CliRunner;
19-
2017
#[cfg(all(feature = "fs", feature = "random"))]
2118
pub use builder::{ChainObserverBuilder, ChainObserverType};
2219
#[cfg(all(feature = "fs", feature = "random"))]
20+
pub use cli_observer::CliRunner;
21+
#[cfg(all(feature = "fs", feature = "random"))]
2322
pub use cli_observer::{CardanoCliChainObserver, CardanoCliRunner};
24-
#[cfg(feature = "test_tools")]
25-
pub use fake_observer::FakeObserver;
23+
cfg_test_tools! {
24+
pub use fake_observer::FakeObserver;
25+
}
2626
#[cfg(test)]
2727
pub use interface::MockChainObserver;
2828
pub use interface::{ChainObserver, ChainObserverError};

mithril-common/src/crypto_helper/cardano/cold_key.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ use rand_chacha::ChaCha20Rng;
33
use rand_core::SeedableRng;
44

55
/// A cold key generator / test only
6+
#[doc(hidden)]
67
#[derive(Debug)]
78
pub struct ColdKeyGenerator();
89

910
impl ColdKeyGenerator {
10-
pub(crate) fn create_deterministic_keypair(seed: [u8; 32]) -> ColdSecretKey {
11+
#[doc(hidden)]
12+
/// Create a deterministic secret key using the given seed. (test only)
13+
pub fn create_deterministic_keypair(seed: [u8; 32]) -> ColdSecretKey {
1114
let mut rng = ChaCha20Rng::from_seed(seed);
1215
ColdSecretKey::generate(&mut rng)
1316
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
mod codec;
2-
#[cfg(feature = "random")]
2+
#[cfg(any(test, feature = "random"))]
33
mod cold_key;
44
mod key_certification;
55
mod opcert;
66

77
pub use codec::*;
8-
#[cfg(feature = "random")]
8+
#[cfg(any(test, feature = "random"))]
99
pub use cold_key::*;
1010
pub use key_certification::*;
1111
pub use opcert::*;

mithril-common/src/crypto_helper/era.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ impl EraMarkersSigner {
4949
Self::create_test_signer(rng)
5050
}
5151

52-
cfg_random! {
53-
/// [EraMarkersSigner] non deterministic
54-
pub fn create_non_deterministic_signer() -> Self {
55-
let rng = rand_core::OsRng;
56-
Self::create_test_signer(rng)
57-
}
52+
#[cfg(any(test, feature = "random"))]
53+
#[cfg_attr(docsrs, doc(cfg(feature = "random")))]
54+
/// [EraMarkersSigner] non deterministic
55+
pub fn create_non_deterministic_signer() -> Self {
56+
let rng = rand_core::OsRng;
57+
Self::create_test_signer(rng)
5858
}
5959

6060
/// [EraMarkersSigner] from [EraMarkersVerifierSecretKey]

mithril-common/src/crypto_helper/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ mod conversions;
66
mod era;
77
mod genesis;
88
mod merkle_tree;
9-
#[cfg(feature = "test_tools")]
9+
#[cfg(any(test, feature = "test_tools"))]
1010
pub mod tests_setup;
1111
mod types;
1212

13-
#[cfg(feature = "random")]
13+
#[cfg(any(test, feature = "random"))]
1414
pub use cardano::ColdKeyGenerator;
1515

1616
pub use cardano::{

mithril-common/src/entities/signed_entity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#[cfg(feature = "test_tools")]
1+
#[cfg(any(test, feature = "test_tools"))]
22
use super::{Beacon, Epoch};
33
use super::{CardanoTransactionsCommitment, MithrilStakeDistribution, SignedEntityType, Snapshot};
44
use crate::signable_builder::Artifact;
5-
#[cfg(feature = "test_tools")]
5+
#[cfg(any(test, feature = "test_tools"))]
66
use crate::test_utils::fake_data;
77
use chrono::{DateTime, Utc};
88

mithril-common/src/lib.rs

+5-3
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
//! Shared datatypes and traits used by Mithril rust projects
45
//!
@@ -43,7 +44,7 @@ macro_rules! cfg_random {
4344
macro_rules! cfg_test_tools {
4445
($($item:item)*) => {
4546
$(
46-
#[cfg(feature = "test_tools")]
47+
#[cfg(any(test, feature = "test_tools"))]
4748
#[cfg_attr(docsrs, doc(cfg(feature = "test_tools")))]
4849
$item
4950
)*
@@ -76,8 +77,9 @@ pub mod sqlite;
7677
#[cfg(feature = "database")]
7778
pub mod store;
7879

79-
#[cfg(feature = "test_tools")]
80-
pub mod test_utils;
80+
cfg_test_tools! {
81+
pub mod test_utils;
82+
}
8183

8284
#[cfg(feature = "fs")]
8385
pub use beacon_provider::{BeaconProvider, BeaconProviderImpl};

mithril-common/src/messages/certificate.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use anyhow::Context;
22
use serde::{Deserialize, Serialize};
33
use std::fmt::{Debug, Formatter};
44

5-
#[cfg(feature = "test_tools")]
5+
#[cfg(any(test, feature = "test_tools"))]
66
use crate::entities::ProtocolMessagePartKey;
77
use crate::entities::{
88
Beacon, Certificate, CertificateMetadata, CertificateSignature, ProtocolMessage,
99
};
1010
use crate::messages::CertificateMetadataMessagePart;
11-
#[cfg(feature = "test_tools")]
11+
12+
#[cfg(any(test, feature = "test_tools"))]
1213
use crate::test_utils::fake_keys;
1314
use crate::StdError;
1415

mithril-common/src/messages/message_parts/signer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "test_tools")]
1+
#[cfg(any(test, feature = "test_tools"))]
22
use crate::test_utils::fake_keys;
33
use crate::{
44
crypto_helper::{KESPeriod, ProtocolOpCert, ProtocolSignerVerificationKeySignature},

mithril-common/src/messages/mithril_stake_distribution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44

55
use crate::entities::Epoch;
66
use crate::entities::ProtocolParameters;
7-
#[cfg(feature = "test_tools")]
7+
#[cfg(any(test, feature = "test_tools"))]
88
use crate::test_utils::fake_data;
99

1010
use super::SignerWithStakeMessagePart;

mithril-common/src/messages/register_signature.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
22
use std::fmt::{Debug, Formatter};
33

44
use crate::entities::{HexEncodedSingleSignature, LotteryIndex, PartyId, SignedEntityType};
5-
#[cfg(feature = "test_tools")]
5+
#[cfg(any(test, feature = "test_tools"))]
66
use crate::test_utils::fake_keys;
77

88
era_deprecate!("make signed_entity_type of RegisterSignatureMessage not optional");

mithril-common/src/messages/register_signer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use std::fmt::{Debug, Formatter};
33

4-
#[cfg(feature = "test_tools")]
4+
#[cfg(any(test, feature = "test_tools"))]
55
use crate::test_utils::fake_keys;
66
use crate::{
77
crypto_helper::KESPeriod,

0 commit comments

Comments
 (0)