Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mithril common circular dependencies and random feature #2269

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.6.25"
version = "0.6.26"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
5 changes: 2 additions & 3 deletions mithril-aggregator/src/database/record/signed_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use serde::{Deserialize, Serialize};

use mithril_common::crypto_helper::ProtocolParameters;
use mithril_common::entities::{
BlockNumber, CardanoDatabaseSnapshot, Epoch, SignedEntity, SignedEntityType, Snapshot,
StakeDistribution,
BlockNumber, CardanoDatabaseSnapshot, Epoch, SignedEntityType, Snapshot, StakeDistribution,
};
#[cfg(test)]
use mithril_common::entities::{CardanoStakeDistribution, MithrilStakeDistribution};
Expand All @@ -15,7 +14,7 @@ use mithril_common::messages::{
MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage,
SignerWithStakeMessagePart, SnapshotListItemMessage, SnapshotMessage,
};
use mithril_common::signable_builder::Artifact;
use mithril_common::signable_builder::{Artifact, SignedEntity};
use mithril_common::StdError;
use mithril_persistence::database::Hydrator;
use mithril_persistence::sqlite::{HydrationError, Projection, SqLiteEntity};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ impl SignedEntityStorer for SignedEntityStore {
#[cfg(test)]
mod tests {
use mithril_common::{
entities::{Epoch, MithrilStakeDistribution, SignedEntity, Snapshot},
entities::{Epoch, MithrilStakeDistribution, Snapshot},
signable_builder::SignedEntity,
test_utils::fake_data,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub mod snapshot;
#[cfg(test)]
pub mod test_utils {
use chrono::{DateTime, Utc};
use mithril_common::entities::{SignedEntity, SignedEntityType};
use mithril_common::signable_builder::Artifact;
use mithril_common::entities::SignedEntityType;
use mithril_common::signable_builder::{Artifact, SignedEntity};

pub fn create_signed_entity<T>(
signed_entity_type: SignedEntityType,
Expand Down
10 changes: 4 additions & 6 deletions mithril-aggregator/src/http_server/routes/proof_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ fn proof_cardano_transaction(

mod handlers {
use mithril_common::{
entities::{CardanoTransactionsSnapshot, SignedEntity},
messages::CardanoTransactionsProofsMessage,
StdResult,
entities::CardanoTransactionsSnapshot, messages::CardanoTransactionsProofsMessage,
signable_builder::SignedEntity, StdResult,
};
use slog::{debug, warn, Logger};
use std::{convert::Infallible, sync::Arc};
Expand Down Expand Up @@ -148,9 +147,8 @@ mod tests {
};

use mithril_common::{
entities::{
BlockNumber, CardanoTransactionsSetProof, CardanoTransactionsSnapshot, SignedEntity,
},
entities::{BlockNumber, CardanoTransactionsSetProof, CardanoTransactionsSnapshot},
signable_builder::SignedEntity,
test_utils::{apispec::APISpec, assert_equivalent, fake_data},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use mithril_common::entities::{CardanoTransactionsSnapshot, SignedEntity};
use mithril_common::messages::CardanoTransactionsSetProofMessagePart;
use mithril_common::{
entities::{CardanoTransactionsSetProof, TransactionHash},
messages::CardanoTransactionsProofsMessage,
entities::{CardanoTransactionsSetProof, CardanoTransactionsSnapshot, TransactionHash},
messages::{CardanoTransactionsProofsMessage, CardanoTransactionsSetProofMessagePart},
signable_builder::SignedEntity,
StdResult,
};

Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/services/signed_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use tokio::task::JoinHandle;
use mithril_common::{
entities::{
BlockNumber, CardanoDatabaseSnapshot, CardanoDbBeacon, CardanoStakeDistribution,
CardanoTransactionsSnapshot, Certificate, Epoch, MithrilStakeDistribution, SignedEntity,
CardanoTransactionsSnapshot, Certificate, Epoch, MithrilStakeDistribution,
SignedEntityType, SignedEntityTypeDiscriminants, Snapshot,
},
logging::LoggerExtensions,
signable_builder::Artifact,
signable_builder::{Artifact, SignedEntity},
signed_entity_type_lock::SignedEntityTypeLock,
StdResult,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use mithril_aggregator::{
entities::OpenMessage,
services::{CertifierService, SignedEntityService},
};
use mithril_common::entities::{CardanoTransactionsSnapshot, Certificate, SignedEntity};
use mithril_common::{
entities::{Epoch, SignedEntityType, SignedEntityTypeDiscriminants, TimePoint},
entities::{
CardanoTransactionsSnapshot, Certificate, Epoch, SignedEntityType,
SignedEntityTypeDiscriminants, TimePoint,
},
signable_builder::SignedEntity,
StdResult, TickerService,
};
use std::sync::Arc;
Expand Down
3 changes: 1 addition & 2 deletions mithril-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client"
version = "0.10.9"
version = "0.10.10"
description = "Mithril client library"
authors = { workspace = true }
edition = { workspace = true }
Expand Down Expand Up @@ -69,7 +69,6 @@ reqwest = { version = "0.12.12", default-features = false, features = [
httpmock = "0.7.0"
indicatif = { version = "0.17.9", features = ["tokio"] }
mithril-common = { path = "../mithril-common", version = "=0.4", default-features = false, features = [
"random",
"test_tools",
] }
mockall = "0.13.1"
Expand Down
10 changes: 4 additions & 6 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.4.111"
version = "0.4.112"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down Expand Up @@ -56,7 +56,7 @@ pallas-network = { version = "0.32.0", optional = true }
pallas-primitives = { version = "0.32.0", optional = true }
pallas-traverse = { version = "0.32.0", optional = true }
rand_chacha = "0.3.1"
rand_core = "0.6.4"
rand_core = { version = "0.6.4", features = ["getrandom"] }
rayon = "1.10.0"
reqwest = { version = "0.12.12", optional = true }
semver = "1.0.24"
Expand All @@ -81,7 +81,6 @@ wasm-bindgen = "0.2.99"
criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
mockall = "0.13.1"
pallas-crypto = "0.32.0"
rand_core = { version = "0.6.4", features = ["getrandom"] }
reqwest = { version = "0.12.12", features = ["json"] }
slog-async = "2.8.0"
slog-term = "2.9.1"
Expand All @@ -94,8 +93,7 @@ mithril-build-script = { path = "../internal/mithril-build-script", version = "=
default = ["rug-backend"]

# Full feature set
full = ["random", "fs", "test_tools"]
random = ["rand_core/getrandom"]
full = ["fs", "test_tools"]
fs = [
"tokio/fs",
"tokio/process",
Expand All @@ -116,7 +114,7 @@ num-integer-backend = ["mithril-stm/num-integer-backend"]
# Disable signer certification, to be used only for tests
allow_skip_signer_certification = []
# Enable all tests tools
test_tools = ["apispec", "test_http_server", "random"]
test_tools = ["apispec", "test_http_server"]
# Enable tools to helps validate conformity to an OpenAPI specification
apispec = ["dep:glob", "dep:jsonschema", "dep:warp", "dep:reqwest"]
test_http_server = ["dep:warp"]
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/chain_observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use model::{
ChainAddress, TxDatum, TxDatumBuilder, TxDatumError, TxDatumFieldTypeName, TxDatumFieldValue,
};

cfg_fs_random! {
cfg_fs! {
mod builder;
mod cli_observer;
mod pallas_observer;
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/chain_observer/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thiserror::Error;

use crate::{StdError, StdResult};

cfg_fs_random! {
cfg_fs! {
use serde::Deserialize;
use anyhow::Context;
use pallas_codec::minicbor::{Decode, Decoder, decode};
Expand Down
7 changes: 2 additions & 5 deletions mithril-common/src/crypto_helper/cardano/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
mod codec;
mod cold_key;
mod key_certification;
mod opcert;

pub use codec::*;
pub use key_certification::*;
pub use opcert::*;

cfg_random! {
mod cold_key;

pub use cold_key::*;
}
pub use cold_key::*;
48 changes: 22 additions & 26 deletions mithril-common/src/crypto_helper/era.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use ed25519_dalek::{Signer, SigningKey};
#[cfg(feature = "random")]
use rand_chacha::rand_core;
use rand_chacha::rand_core::{CryptoRng, RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -49,8 +47,7 @@ impl EraMarkersSigner {
Self::create_test_signer(rng)
}

#[cfg(any(test, feature = "random"))]
#[cfg_attr(docsrs, doc(cfg(feature = "random")))]
#[cfg(test)]
/// [EraMarkersSigner] non deterministic
pub fn create_non_deterministic_signer() -> Self {
let rng = rand_core::OsRng;
Expand Down Expand Up @@ -118,29 +115,28 @@ mod tests {
.expect("Decoding golden secret key should not fail");
}

cfg_random! {
#[test]
fn test_generate_test_deterministic_keypair() {
let signer = EraMarkersSigner::create_deterministic_signer();
let verifier = signer.create_verifier();
let signer_2 = EraMarkersSigner::create_deterministic_signer();
let verifier_2 = signer.create_verifier();
assert_eq!(signer.secret_key.to_bytes(), signer_2.secret_key.to_bytes());
assert_eq!(
verifier.verification_key.as_bytes(),
verifier_2.verification_key.as_bytes()
);

println!(
"Deterministic Verification Key={}",
verifier.verification_key.to_json_hex().unwrap()
);
println!(
"Deterministic Secret Key=={}",
signer.secret_key.to_json_hex().unwrap()
);
}
#[test]
fn test_generate_test_deterministic_keypair() {
let signer = EraMarkersSigner::create_deterministic_signer();
let verifier = signer.create_verifier();
let signer_2 = EraMarkersSigner::create_deterministic_signer();
let verifier_2 = signer.create_verifier();
assert_eq!(signer.secret_key.to_bytes(), signer_2.secret_key.to_bytes());
assert_eq!(
verifier.verification_key.as_bytes(),
verifier_2.verification_key.as_bytes()
);

println!(
"Deterministic Verification Key={}",
verifier.verification_key.to_json_hex().unwrap()
);
println!(
"Deterministic Secret Key=={}",
signer.secret_key.to_json_hex().unwrap()
);
}

#[test]
fn test_generate_test_non_deterministic_keypair() {
let signer = EraMarkersSigner::create_non_deterministic_signer();
Expand Down
40 changes: 17 additions & 23 deletions mithril-common/src/crypto_helper/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{StdError, StdResult};
use anyhow::anyhow;
use ed25519_dalek::{Signer, SigningKey};
#[cfg(feature = "random")]
use rand_chacha::rand_core;
use rand_chacha::rand_core::{CryptoRng, RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -39,12 +37,10 @@ impl ProtocolGenesisSigner {
Self::create_test_genesis_signer(rng)
}

cfg_random! {
/// [ProtocolGenesisSigner] non deterministic
pub fn create_non_deterministic_genesis_signer() -> Self {
let rng = rand_core::OsRng;
Self::create_test_genesis_signer(rng)
}
/// [ProtocolGenesisSigner] non deterministic
pub fn create_non_deterministic_genesis_signer() -> Self {
let rng = rand_core::OsRng;
Self::create_test_genesis_signer(rng)
}

/// Get the [ProtocolGenesisSecretKey]
Expand Down Expand Up @@ -135,21 +131,19 @@ mod tests {
);
}

cfg_random! {
#[test]
fn test_generate_test_non_deterministic_genesis_keypair() {
let genesis_signer = ProtocolGenesisSigner::create_non_deterministic_genesis_signer();
let genesis_verifier = genesis_signer.create_genesis_verifier();

println!(
"Non Deterministic Genesis Verification Key={}",
genesis_verifier.verification_key.to_json_hex().unwrap()
);
println!(
"Non Deterministic Genesis Secret Key=={}",
genesis_signer.secret_key.to_json_hex().unwrap()
);
}
#[test]
fn test_generate_test_non_deterministic_genesis_keypair() {
let genesis_signer = ProtocolGenesisSigner::create_non_deterministic_genesis_signer();
let genesis_verifier = genesis_signer.create_genesis_verifier();

println!(
"Non Deterministic Genesis Verification Key={}",
genesis_verifier.verification_key.to_json_hex().unwrap()
);
println!(
"Non Deterministic Genesis Secret Key=={}",
genesis_signer.secret_key.to_json_hex().unwrap()
);
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions mithril-common/src/crypto_helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ cfg_test_tools! {
pub mod tests_setup;
}

cfg_random! {
pub use cardano::ColdKeyGenerator;
}
pub use cardano::ColdKeyGenerator;

pub use cardano::{
KESPeriod, OpCert, ProtocolInitializerErrorWrapper, ProtocolRegistrationErrorWrapper,
Expand Down
3 changes: 0 additions & 3 deletions mithril-common/src/entities/block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::entities::arithmetic_operation_wrapper::{
impl_add_to_wrapper, impl_div_to_wrapper, impl_mul_to_wrapper, impl_partial_eq_to_wrapper,
impl_rem_to_wrapper, impl_sub_to_wrapper,
};
use crate::signable_builder::Beacon;

#[cfg(target_family = "wasm")]
use wasm_bindgen::prelude::*;
Expand All @@ -20,8 +19,6 @@ use wasm_bindgen::prelude::*;
#[cfg_attr(target_family = "wasm", wasm_bindgen)]
pub struct BlockNumber(pub u64);

impl Beacon for BlockNumber {}

impl Display for BlockNumber {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
Expand Down
Loading