Skip to content

Commit

Permalink
Create a mithril-resource-pool module
Browse files Browse the repository at this point in the history
  • Loading branch information
sfauvel committed Feb 12, 2025
1 parent f9b2d69 commit 751a371
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 21 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"internal/mithril-doc-derive",
"internal/mithril-metric",
"internal/mithril-persistence",
"internal/mithril-resource-pool",
"mithril-aggregator",
"mithril-client",
"mithril-client-cli",
Expand Down
1 change: 1 addition & 0 deletions internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async-trait = "0.1.86"
chrono = { version = "0.4.39", features = ["serde"] }
hex = "0.4.3"
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::{Reset, StdResult};
use mithril_resource_pool::resource_pool::{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 = "Common types, interfaces, and utilities to persist data for Mithril nodes."
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
5 changes: 5 additions & 0 deletions internal/mithril-resource-pool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Mithril-resource-pool

**This is a work in progress** 🛠

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

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

use crate::StdResult;
use mithril_common::{Reset, StdResult};

/// [ResourcePool] related errors.
#[derive(Error, Debug)]
Expand Down Expand Up @@ -207,19 +207,19 @@ impl<T: Reset + Send + Sync> Drop for ResourcePoolItem<'_, T> {
}
}

/// Reset trait which is implemented by pooled resource items.
/// As pool resource items are mutable, this will guarantee that the pool stays consistent
/// and that acquired resource items do not depend from previous computations.
pub trait Reset {
/// Reset the resource
fn reset(&mut self) -> StdResult<()> {
Ok(())
}
}

cfg_test_tools! {
impl Reset for String {}
}
// /// Reset trait which is implemented by pooled resource items.
// /// As pool resource items are mutable, this will guarantee that the pool stays consistent
// /// and that acquired resource items do not depend from previous computations.
// pub trait Reset {
// /// Reset the resource
// fn reset(&mut self) -> StdResult<()> {
// Ok(())
// }
// }

// cfg_test_tools! {
// impl Reset for String {}
// }

#[cfg(test)]
mod tests {
Expand Down
1 change: 1 addition & 0 deletions mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mithril-common = { path = "../mithril-common", features = ["full"] }
mithril-doc = { path = "../internal/mithril-doc" }
mithril-metric = { path = "../internal/mithril-metric" }
mithril-persistence = { path = "../internal/mithril-persistence" }
mithril-resource-pool = { path = "../internal/mithril-resource-pool" }
paste = "1.0.15"
prometheus = "0.13.4"
rayon = "1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/services/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use mithril_common::{
BlockNumber, BlockRange, CardanoTransaction, CardanoTransactionsSetProof, TransactionHash,
},
logging::LoggerExtensions,
resource_pool::ResourcePool,
signable_builder::BlockRangeRootRetriever,
StdResult,
};
use mithril_resource_pool::resource_pool::ResourcePool;

/// Prover service is the cryptographic engine in charge of producing cryptographic proofs for transactions
#[cfg_attr(test, mockall::automock)]
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/src/crypto_helper/merkle_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
sync::Arc,
};

use crate::{resource_pool::Reset, StdError, StdResult};
use crate::{Reset, StdError, StdResult};

use super::{MKProof, MKTree, MKTreeNode, MKTreeStorer};

Expand Down
14 changes: 13 additions & 1 deletion mithril-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub mod era;
pub mod logging;
pub mod messages;
pub mod protocol;
pub mod resource_pool;
pub mod signable_builder;
pub mod signed_entity_type_lock;

Expand Down Expand Up @@ -72,6 +71,19 @@ pub const MITHRIL_API_VERSION_HEADER: &str = "mithril-api-version";
/// Mithril Signer node version header name
pub const MITHRIL_SIGNER_VERSION_HEADER: &str = "signer-node-version";

/// Reset trait which is implemented by pooled resource items.
/// As pool resource items are mutable, this will guarantee that the pool stays consistent
/// and that acquired resource items do not depend from previous computations.
pub trait Reset {
/// Reset the resource
fn reset(&mut self) -> StdResult<()> {
Ok(())
}
}

cfg_test_tools! {
impl Reset for String {}
}
#[cfg(test)]
mod tests {
#[cfg(feature = "apispec")]
Expand Down

0 comments on commit 751a371

Please sign in to comment.