Skip to content

Commit be3ccc5

Browse files
committed
Review: apply suggestions
* more explicit parameter name for `DeleteCardanoTransactionProvider` method * Simplify `TransactionPruner` doc * Remove 'decorator' from the transaction pruner name * Simplify some generics declaration
1 parent 4164aca commit be3ccc5

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

internal/mithril-persistence/src/database/provider/cardano_transaction/delete_cardano_transaction.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ impl<'conn> DeleteCardanoTransactionProvider<'conn> {
3737
Self { connection }
3838
}
3939

40-
fn get_prune_condition(&self, threshold: BlockNumber) -> StdResult<WhereCondition> {
41-
let threshold = Value::Integer(
42-
threshold
43-
.try_into()
44-
.with_context(|| format!("Failed to convert threshold `{threshold}` to i64"))?,
45-
);
40+
fn get_prune_condition(
41+
&self,
42+
block_number_threshold: BlockNumber,
43+
) -> StdResult<WhereCondition> {
44+
let threshold = Value::Integer(block_number_threshold.try_into().with_context(|| {
45+
format!("Failed to convert threshold `{block_number_threshold}` to i64")
46+
})?);
4647

4748
Ok(WhereCondition::new("block_number < ?*", vec![threshold]))
4849
}
4950

5051
/// Prune the cardano transaction data below the given threshold.
5152
pub fn prune(
5253
&self,
53-
threshold: BlockNumber,
54+
block_number_threshold: BlockNumber,
5455
) -> StdResult<EntityCursor<CardanoTransactionRecord>> {
55-
let filters = self.get_prune_condition(threshold)?;
56+
let filters = self.get_prune_condition(block_number_threshold)?;
5657

5758
self.find(filters)
5859
}

mithril-signer/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod metrics;
1515
mod protocol_initializer_store;
1616
mod runtime;
1717
mod single_signer;
18-
mod transactions_importer_with_prune_decorator;
18+
mod transactions_importer_with_pruner;
1919

2020
#[cfg(test)]
2121
pub use aggregator_client::dumb::DumbAggregatorClient;
@@ -29,7 +29,7 @@ pub use metrics::*;
2929
pub use protocol_initializer_store::{ProtocolInitializerStore, ProtocolInitializerStorer};
3030
pub use runtime::*;
3131
pub use single_signer::*;
32-
pub use transactions_importer_with_prune_decorator::*;
32+
pub use transactions_importer_with_pruner::*;
3333

3434
/// HTTP request timeout duration in milliseconds
3535
const HTTP_REQUEST_TIMEOUT_DURATION: u64 = 30000;

mithril-signer/src/runtime/signer_services.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use mithril_persistence::{
2929
use crate::{
3030
aggregator_client::AggregatorClient, metrics::MetricsService, single_signer::SingleSigner,
3131
AggregatorHTTPClient, CardanoTransactionsImporter, Configuration, MithrilSingleSigner,
32-
ProtocolInitializerStore, ProtocolInitializerStorer, HTTP_REQUEST_TIMEOUT_DURATION,
33-
SQLITE_FILE, SQLITE_FILE_CARDANO_TRANSACTION,
32+
ProtocolInitializerStore, ProtocolInitializerStorer, TransactionsImporterWithPruner,
33+
HTTP_REQUEST_TIMEOUT_DURATION, SQLITE_FILE, SQLITE_FILE_CARDANO_TRANSACTION,
3434
};
3535

3636
type StakeStoreService = Arc<StakeStore>;
@@ -274,7 +274,7 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> {
274274
slog_scope::logger(),
275275
));
276276
// Wrap the transaction importer with decorator to prune the transactions after import
277-
let transactions_importer = Arc::new(crate::TransactionsImporterWithPruneDecorator::new(
277+
let transactions_importer = Arc::new(TransactionsImporterWithPruner::new(
278278
self.config
279279
.enable_transaction_pruning
280280
.then_some(self.config.network_security_parameter),

mithril-signer/src/transactions_importer_with_prune_decorator.rs renamed to mithril-signer/src/transactions_importer_with_pruner.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,22 @@ use mithril_common::StdResult;
1010
#[cfg_attr(test, mockall::automock)]
1111
#[async_trait]
1212
pub trait TransactionPruner: Send + Sync {
13-
/// Prune the transactions older than the given number of blocks (based on the block range root
14-
/// stored).
13+
/// Prune the transactions older than the given number of blocks.
1514
async fn prune(&self, number_of_blocks_to_keep: BlockNumber) -> StdResult<()>;
1615
}
1716

1817
/// A decorator of [TransactionsImporter] that prunes the transactions older than a given number of
1918
/// blocks after running the import.
2019
///
2120
/// If the number of blocks to keep is not provided, no pruning is performed.
22-
pub struct TransactionsImporterWithPruneDecorator {
21+
pub struct TransactionsImporterWithPruner {
2322
number_of_blocks_to_keep: Option<BlockNumber>,
2423
transaction_pruner: Arc<dyn TransactionPruner>,
2524
wrapped_importer: Arc<dyn TransactionsImporter>,
2625
}
2726

28-
impl TransactionsImporterWithPruneDecorator {
29-
/// Create a new instance of [TransactionsImporterWithPruneDecorator].
27+
impl TransactionsImporterWithPruner {
28+
/// Create a new instance of [TransactionsImporterWithPruner].
3029
pub fn new(
3130
number_of_blocks_to_keep: Option<BlockNumber>,
3231
transaction_pruner: Arc<dyn TransactionPruner>,
@@ -41,7 +40,7 @@ impl TransactionsImporterWithPruneDecorator {
4140
}
4241

4342
#[async_trait]
44-
impl TransactionsImporter for TransactionsImporterWithPruneDecorator {
43+
impl TransactionsImporter for TransactionsImporterWithPruner {
4544
async fn import(&self, up_to_beacon: ImmutableFileNumber) -> StdResult<()> {
4645
self.wrapped_importer.import(up_to_beacon).await?;
4746

@@ -71,15 +70,15 @@ mod tests {
7170
}
7271
}
7372

74-
impl TransactionsImporterWithPruneDecorator {
75-
pub fn new_with_mock<Ti, Pr>(
73+
impl TransactionsImporterWithPruner {
74+
pub fn new_with_mock<P, I>(
7675
number_of_blocks_to_keep: Option<BlockNumber>,
77-
transaction_pruner_mock_config: Pr,
78-
importer_mock_config: Ti,
76+
transaction_pruner_mock_config: P,
77+
importer_mock_config: I,
7978
) -> Self
8079
where
81-
Pr: FnOnce(&mut MockTransactionPruner),
82-
Ti: FnOnce(&mut MockTransactionImporterImpl),
80+
P: FnOnce(&mut MockTransactionPruner),
81+
I: FnOnce(&mut MockTransactionImporterImpl),
8382
{
8483
let mut transaction_pruner = MockTransactionPruner::new();
8584
transaction_pruner_mock_config(&mut transaction_pruner);
@@ -96,7 +95,7 @@ mod tests {
9695

9796
#[tokio::test]
9897
async fn test_does_not_prune_if_none_is_configured() {
99-
let importer = TransactionsImporterWithPruneDecorator::new_with_mock(
98+
let importer = TransactionsImporterWithPruner::new_with_mock(
10099
None,
101100
|mock| {
102101
mock.expect_prune().never();
@@ -112,7 +111,7 @@ mod tests {
112111
#[tokio::test]
113112
async fn test_does_prune_if_a_block_number_is_configured() {
114113
let expected_block_number: BlockNumber = 5;
115-
let importer = TransactionsImporterWithPruneDecorator::new_with_mock(
114+
let importer = TransactionsImporterWithPruner::new_with_mock(
116115
Some(expected_block_number),
117116
|mock| {
118117
mock.expect_prune()

0 commit comments

Comments
 (0)