Skip to content

Split mithril-common crate by extracting some modules #2304

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

Merged
merged 7 commits into from
Feb 17, 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
48 changes: 44 additions & 4 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ members = [
"internal/mithril-doc-derive",
"internal/mithril-metric",
"internal/mithril-persistence",
"internal/mithril-resource-pool",
"internal/signed-entity/mithril-signed-entity-lock",
"internal/signed-entity/mithril-signed-entity-preloader",
"mithril-aggregator",
"mithril-client",
"mithril-client-cli",
Expand Down
3 changes: 2 additions & 1 deletion internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-persistence"
version = "0.2.45"
version = "0.2.46"
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand All @@ -16,6 +16,7 @@ anyhow = "1.0.95"
async-trait = "0.1.86"
chrono = { version = "0.4.39", features = ["serde"] }
mithril-common = { path = "../../mithril-common", features = ["fs"] }
mithril-resource-pool = { path = "../mithril-resource-pool" }
semver = "1.0.25"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.138"
Expand Down
6 changes: 2 additions & 4 deletions internal/mithril-persistence/src/sqlite/connection_pool.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{ops::Deref, time::Duration};

use mithril_common::{
resource_pool::{Reset, ResourcePool, ResourcePoolItem},
StdResult,
};
use mithril_common::StdResult;
use mithril_resource_pool::{Reset, ResourcePool, ResourcePoolItem};

use crate::sqlite::SqliteConnection;

Expand Down
23 changes: 23 additions & 0 deletions internal/mithril-resource-pool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "mithril-resource-pool"
version = "0.0.1"
description = "Provide a resource pool for Mithril."
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[lib]
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
anyhow = "1.0.95"
mithril-common = { path = "../../mithril-common", features = ["fs"] }
thiserror = "2.0.11"
tokio = { version = "1.43.0", features = ["sync"] }

[dev-dependencies]
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
mockall = "0.13.1"
tokio = { version = "1.43.0", features = ["macros", "time"] }
19 changes: 19 additions & 0 deletions internal/mithril-resource-pool/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: all build test check doc

CARGO = cargo

all: test build

build:
${CARGO} build --release

test:
${CARGO} test

check:
${CARGO} check --release --all-features --all-targets
${CARGO} clippy --release --all-features --all-targets
${CARGO} fmt --check

doc:
${CARGO} doc --no-deps --open --features full
3 changes: 3 additions & 0 deletions internal/mithril-resource-pool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mithril-resource-pool

This crate provide a resource pool for Mithril.
7 changes: 7 additions & 0 deletions internal/mithril-resource-pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(missing_docs)]

//! Provide a resource pool for Mithril.

mod resource_pool;

pub use resource_pool::*;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use std::{
};
use thiserror::Error;

use crate::StdResult;
use mithril_common::{
crypto_helper::{MKMap, MKMapKey, MKMapValue, MKTreeStorer},
StdResult,
};

/// [ResourcePool] related errors.
#[derive(Error, Debug)]
Expand Down Expand Up @@ -184,6 +187,12 @@ impl<'a, T: Reset + Send + Sync> ResourcePoolItem<'a, T> {
}
}

impl<K: MKMapKey, V: MKMapValue<K>, S: MKTreeStorer> Reset for MKMap<K, V, S> {
fn reset(&mut self) -> StdResult<()> {
self.compress()
}
}

impl<T: Reset + Send + Sync> Deref for ResourcePoolItem<'_, T> {
type Target = T;

Expand Down Expand Up @@ -217,9 +226,8 @@ pub trait Reset {
}
}

cfg_test_tools! {
impl Reset for String {}
}
#[cfg(test)]
impl Reset for String {}

#[cfg(test)]
mod tests {
Expand Down
19 changes: 19 additions & 0 deletions internal/signed-entity/mithril-signed-entity-lock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "mithril-signed-entity-lock"
version = "0.0.1"
description = "A non-blocking lock mechanism for signed entity type."
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[lib]
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
mithril-common = { path = "../../../mithril-common" }
tokio = { version = "1.43.0" }

[dev-dependencies]
tokio = { version = "1.43.0", features = ["macros"] }
19 changes: 19 additions & 0 deletions internal/signed-entity/mithril-signed-entity-lock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: all build test check doc

CARGO = cargo

all: test build

build:
${CARGO} build --release

test:
${CARGO} test

check:
${CARGO} check --release --all-features --all-targets
${CARGO} clippy --release --all-features --all-targets
${CARGO} fmt --check

doc:
${CARGO} doc --no-deps --open --features full
3 changes: 3 additions & 0 deletions internal/signed-entity/mithril-signed-entity-lock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mithril-signed-entity-lock

This crate provides a non-blocking lock mechanism for signed entity type.
8 changes: 8 additions & 0 deletions internal/signed-entity/mithril-signed-entity-lock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![warn(missing_docs)]

//! This module provides a non-blocking lock mechanism for signed entity types to prevent multiple
//! modification on a same entity type at the same time.

mod signed_entity_type_lock;

pub use signed_entity_type_lock::*;
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! # Signed Entity Type Lock
//!
//! This module provides a non-blocking lock mechanism for signed entity types to prevent multiple
//! modification on a same entity type at the same time.
//! modifications on a same entity type at the same time.

use std::collections::BTreeSet;

use tokio::sync::RwLock;

use crate::entities::SignedEntityTypeDiscriminants;
use mithril_common::entities::SignedEntityTypeDiscriminants;

/// Non-blocking lock mechanism for signed entity types to prevent multiple
/// modification on a same entity type at the same time.
/// modifications on a same entity type at the same time.
pub struct SignedEntityTypeLock {
locked_entities: RwLock<BTreeSet<SignedEntityTypeDiscriminants>>,
}
Expand Down
27 changes: 27 additions & 0 deletions internal/signed-entity/mithril-signed-entity-preloader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "mithril-signed-entity-preloader"
version = "0.0.1"
description = "A preload mechanism for Cardano Transaction signed entity."
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }

[lib]
crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
anyhow = "1.0.95"
async-trait = "0.1.86"
mithril-common = { path = "../../../mithril-common", features = ["fs"] }
mithril-signed-entity-lock = { path = "../mithril-signed-entity-lock" }
slog = "2.7.0"
tokio = { version = "1.43.0", features = ["sync"] }

[dev-dependencies]
mithril-common = { path = "../../../mithril-common", features = ["test_tools"] }
mockall = "0.13.1"
slog-async = "2.8.0"
slog-term = "2.9.1"
tokio = { version = "1.43.0", features = ["macros"] }
19 changes: 19 additions & 0 deletions internal/signed-entity/mithril-signed-entity-preloader/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: all build test check doc

CARGO = cargo

all: test build

build:
${CARGO} build --release

test:
${CARGO} test

check:
${CARGO} check --release --all-features --all-targets
${CARGO} clippy --release --all-features --all-targets
${CARGO} fmt --check

doc:
${CARGO} doc --no-deps --open --features full
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mithril-signed-entity-preloader

This crate provide a preload mechanism for Cardano Transaction signed entity.
Loading
Loading