Skip to content

Commit

Permalink
merge 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
falcucci committed Jan 26, 2024
2 parents 14437d1 + 5945700 commit bf066cd
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.2.154"
version = "0.2.155"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down Expand Up @@ -87,6 +87,7 @@ criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
mockall = "0.12.0"
# pallas-crypto = "0.21.0"
pallas-crypto = { git = "https://github.com/falcucci/pallas.git", branch = "fix/legacy-transaction-utxo-by-address" }
rand_core = { version = "0.6.4", features = ["getrandom"] }
reqwest = { version = "0.11.22", features = ["json"] }
slog-async = "2.8.0"
slog-scope = "4.4.0"
Expand All @@ -105,16 +106,16 @@ default = []
# Full feature set
full = ["random", "database", "fs", "test_tools"]
random = ["rand_core/getrandom"]
database = ["sqlite"]
database = ["dep:sqlite"]
fs = [
"tokio/fs",
"tokio/process",
"minicbor",
"pallas-addresses",
"pallas-codec",
"pallas-network",
"pallas-primitives",
"pallas-traverse",
"dep:minicbor",
"dep:pallas-addresses",
"dep:pallas-codec",
"dep:pallas-network",
"dep:pallas-primitives",
"dep:pallas-traverse",
]

# Portable feature avoids SIGILL crashes on CPUs not supporting Intel ADX instruction set when built on CPUs that support it
Expand All @@ -123,10 +124,10 @@ portable = ["mithril-stm/portable"]
# Disable signer certification, to be used only for tests
allow_skip_signer_certification = []
# Enable all tests tools
test_tools = ["apispec", "test_http_server"]
test_tools = ["apispec", "test_http_server", "random"]
# Enable tools to helps validate conformity to an OpenAPI specification
apispec = ["glob", "http", "jsonschema", "warp"]
test_http_server = ["warp"]
apispec = ["dep:glob", "dep:http", "dep:jsonschema", "dep:warp"]
test_http_server = ["dep:warp"]

[package.metadata.docs.rs]
all-features = true
Expand Down
21 changes: 20 additions & 1 deletion mithril-common/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.PHONY: all build test check debug run help doc
.PHONY: all build test check doc check-all-features-set

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

all: test build

Expand All @@ -18,3 +23,17 @@ check:

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

# Compute the powerset of all the given features and save it to a file
.feature-sets:
powerset() { [ $$# -eq 0 ] && echo || (shift; powerset "$$@") | while read r ; do echo "$$1 $$r"; echo "$$r"; done };\
powerset $$(echo "$(FEATURES)") > .features-sets

check-all-features-set: .feature-sets
# Read the file to run cargo clippy on all those features sets
cat .features-sets | while read features_set; do \
echo "Clippy common with feature '$$features_set''"; \
${CARGO} clippy -p mithril-common --features "$$features_set"; \
done

rm .features-sets
9 changes: 6 additions & 3 deletions mithril-common/src/chain_observer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use thiserror::Error;

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

use super::{CardanoCliChainObserver, CardanoCliRunner, FakeObserver, PallasChainObserver};
#[cfg(any(test, feature = "test_tools"))]
use super::FakeObserver;
use super::{CardanoCliChainObserver, CardanoCliRunner, PallasChainObserver};

/// Type of chain observers available
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
Expand All @@ -16,7 +18,7 @@ pub enum ChainObserverType {
/// Pallas chain observer.
Pallas,
/// Fake chain observer.
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
Fake,
}

Expand All @@ -25,6 +27,7 @@ impl Display for ChainObserverType {
match self {
Self::CardanoCli => write!(f, "cardano-cli"),
Self::Pallas => write!(f, "pallas"),
#[cfg(any(test, feature = "test_tools"))]
Self::Fake => write!(f, "fake"),
}
}
Expand Down Expand Up @@ -85,7 +88,7 @@ impl ChainObserverBuilder {
);
Ok(Arc::new(observer))
}
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
ChainObserverType::Fake => Ok(Arc::new(FakeObserver::default())),
}
}
Expand Down
14 changes: 7 additions & 7 deletions mithril-common/src/chain_observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
mod builder;
#[cfg(all(feature = "fs", feature = "random"))]
mod cli_observer;
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
mod fake_observer;
mod interface;
mod model;
#[cfg(all(feature = "fs", feature = "random"))]
mod pallas_observer;

#[cfg(test)]
#[cfg(all(test, feature = "fs", feature = "random"))]
mod test_cli_runner;

#[cfg(test)]
pub use cli_observer::CliRunner;

#[cfg(all(feature = "fs", feature = "random"))]
pub use builder::{ChainObserverBuilder, ChainObserverType};
#[cfg(all(feature = "fs", feature = "random"))]
pub use cli_observer::CliRunner;
#[cfg(all(feature = "fs", feature = "random"))]
pub use cli_observer::{CardanoCliChainObserver, CardanoCliRunner};
#[cfg(feature = "test_tools")]
pub use fake_observer::FakeObserver;
cfg_test_tools! {
pub use fake_observer::FakeObserver;
}
#[cfg(test)]
pub use interface::MockChainObserver;
pub use interface::{ChainObserver, ChainObserverError};
Expand Down
5 changes: 4 additions & 1 deletion mithril-common/src/crypto_helper/cardano/cold_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;

/// A cold key generator / test only
#[doc(hidden)]
#[derive(Debug)]
pub struct ColdKeyGenerator();

impl ColdKeyGenerator {
pub(crate) fn create_deterministic_keypair(seed: [u8; 32]) -> ColdSecretKey {
#[doc(hidden)]
/// Create a deterministic secret key using the given seed. (test only)
pub fn create_deterministic_keypair(seed: [u8; 32]) -> ColdSecretKey {
let mut rng = ChaCha20Rng::from_seed(seed);
ColdSecretKey::generate(&mut rng)
}
Expand Down
4 changes: 2 additions & 2 deletions mithril-common/src/crypto_helper/cardano/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mod codec;
#[cfg(feature = "random")]
#[cfg(any(test, feature = "random"))]
mod cold_key;
mod key_certification;
mod opcert;

pub use codec::*;
#[cfg(feature = "random")]
#[cfg(any(test, feature = "random"))]
pub use cold_key::*;
pub use key_certification::*;
pub use opcert::*;
12 changes: 6 additions & 6 deletions mithril-common/src/crypto_helper/era.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ impl EraMarkersSigner {
Self::create_test_signer(rng)
}

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

/// [EraMarkersSigner] from [EraMarkersVerifierSecretKey]
Expand Down
4 changes: 2 additions & 2 deletions mithril-common/src/crypto_helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ mod conversions;
mod era;
mod genesis;
mod merkle_tree;
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
pub mod tests_setup;
mod types;

#[cfg(feature = "random")]
#[cfg(any(test, feature = "random"))]
pub use cardano::ColdKeyGenerator;

pub use cardano::{
Expand Down
4 changes: 2 additions & 2 deletions mithril-common/src/entities/signed_entity.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
use super::{Beacon, Epoch};
use super::{CardanoTransactionsCommitment, MithrilStakeDistribution, SignedEntityType, Snapshot};
use crate::signable_builder::Artifact;
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
use crate::test_utils::fake_data;
use chrono::{DateTime, Utc};

Expand Down
8 changes: 5 additions & 3 deletions mithril-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]

//! Shared datatypes and traits used by Mithril rust projects
//!
Expand Down Expand Up @@ -43,7 +44,7 @@ macro_rules! cfg_random {
macro_rules! cfg_test_tools {
($($item:item)*) => {
$(
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
#[cfg_attr(docsrs, doc(cfg(feature = "test_tools")))]
$item
)*
Expand Down Expand Up @@ -76,8 +77,9 @@ pub mod sqlite;
#[cfg(feature = "database")]
pub mod store;

#[cfg(feature = "test_tools")]
pub mod test_utils;
cfg_test_tools! {
pub mod test_utils;
}

#[cfg(feature = "fs")]
pub use beacon_provider::{BeaconProvider, BeaconProviderImpl};
Expand Down
5 changes: 3 additions & 2 deletions mithril-common/src/messages/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use anyhow::Context;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};

#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
use crate::entities::ProtocolMessagePartKey;
use crate::entities::{
Beacon, Certificate, CertificateMetadata, CertificateSignature, ProtocolMessage,
};
use crate::messages::CertificateMetadataMessagePart;
#[cfg(feature = "test_tools")]

#[cfg(any(test, feature = "test_tools"))]
use crate::test_utils::fake_keys;
use crate::StdError;

Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/messages/message_parts/signer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
use crate::test_utils::fake_keys;
use crate::{
crypto_helper::{KESPeriod, ProtocolOpCert, ProtocolSignerVerificationKeySignature},
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/messages/mithril_stake_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

use crate::entities::Epoch;
use crate::entities::ProtocolParameters;
#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
use crate::test_utils::fake_data;

use super::SignerWithStakeMessagePart;
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/messages/register_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};

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

era_deprecate!("make signed_entity_type of RegisterSignatureMessage not optional");
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/messages/register_signer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};

#[cfg(feature = "test_tools")]
#[cfg(any(test, feature = "test_tools"))]
use crate::test_utils::fake_keys;
use crate::{
crypto_helper::KESPeriod,
Expand Down

0 comments on commit bf066cd

Please sign in to comment.