Skip to content

Commit 16a54fe

Browse files
committed
Remove TransactionStore::get_up_to from signer & aggregator
As the `CardanoTransactionsImporter` doesn't need it anymore since In test it's replaced with a call to `get_all`.
1 parent 14a995e commit 16a54fe

File tree

5 files changed

+9
-90
lines changed

5 files changed

+9
-90
lines changed

mithril-aggregator/src/database/repository/cardano_transaction_repository.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,6 @@ impl TransactionStore for CardanoTransactionRepository {
233233
}
234234
}
235235

236-
async fn get_up_to(&self, beacon: ImmutableFileNumber) -> StdResult<Vec<CardanoTransaction>> {
237-
self.get_transactions_up_to(beacon).await.map(|v| {
238-
v.into_iter()
239-
.map(|record| record.into())
240-
.collect::<Vec<CardanoTransaction>>()
241-
})
242-
}
243-
244236
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
245237
const DB_TRANSACTION_SIZE: usize = 100000;
246238
for transactions_in_db_transaction_chunk in transactions.chunks(DB_TRANSACTION_SIZE) {

mithril-aggregator/src/services/cardano_transactions_importer.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ pub trait TransactionStore: Send + Sync {
1919
/// Get the highest known transaction beacon
2020
async fn get_highest_beacon(&self) -> StdResult<Option<ImmutableFileNumber>>;
2121

22-
/// Get stored transactions up to the given beacon
23-
async fn get_up_to(
24-
&self,
25-
immutable_file_number: ImmutableFileNumber,
26-
) -> StdResult<Vec<CardanoTransaction>>;
27-
2822
/// Store list of transactions
2923
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()>;
3024

mithril-signer/src/cardano_transactions_importer.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ pub trait TransactionStore: Send + Sync {
1919
/// Get the highest known transaction beacon
2020
async fn get_highest_beacon(&self) -> StdResult<Option<ImmutableFileNumber>>;
2121

22-
/// Get stored transactions up to the given beacon
23-
async fn get_up_to(
24-
&self,
25-
immutable_file_number: ImmutableFileNumber,
26-
) -> StdResult<Vec<CardanoTransaction>>;
27-
2822
/// Store list of transactions
2923
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()>;
3024

@@ -282,7 +276,7 @@ mod tests {
282276
.await
283277
.expect("Transactions Importer should succeed");
284278

285-
let stored_transactions = repository.get_up_to(10000).await.unwrap();
279+
let stored_transactions = repository.get_all().await.unwrap();
286280
assert_eq!(expected_transactions, stored_transactions);
287281
}
288282

@@ -404,7 +398,7 @@ mod tests {
404398
.await
405399
.expect("Transactions Importer should succeed");
406400

407-
let transactions = repository.get_up_to(10000).await.unwrap();
401+
let transactions = repository.get_all().await.unwrap();
408402
assert_eq!(vec![last_tx], transactions);
409403
}
410404

@@ -442,15 +436,15 @@ mod tests {
442436
CardanoTransactionsImporter::new_for_test(Arc::new(scanner_mock), repository.clone())
443437
};
444438

445-
let stored_transactions = repository.get_up_to(10000).await.unwrap();
439+
let stored_transactions = repository.get_all().await.unwrap();
446440
assert_eq!(stored_block.into_transactions(), stored_transactions);
447441

448442
importer
449443
.import_transactions(up_to_beacon)
450444
.await
451445
.expect("Transactions Importer should succeed");
452446

453-
let stored_transactions = repository.get_up_to(10000).await.unwrap();
447+
let stored_transactions = repository.get_all().await.unwrap();
454448
assert_eq!(expected_transactions, stored_transactions);
455449
}
456450

mithril-signer/src/database/provider/cardano_transaction/get_cardano_transaction.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use sqlite::Value;
21
use std::ops::Range;
32

4-
use mithril_common::entities::{BlockNumber, ImmutableFileNumber, TransactionHash};
3+
use sqlite::Value;
4+
5+
use mithril_common::entities::{BlockNumber, TransactionHash};
6+
#[cfg(test)]
7+
use mithril_persistence::sqlite::GetAllCondition;
58
use mithril_persistence::sqlite::{
69
Provider, SourceAlias, SqLiteEntity, SqliteConnection, WhereCondition,
710
};
811

912
use crate::database::record::CardanoTransactionRecord;
1013

11-
#[cfg(test)]
12-
use mithril_persistence::sqlite::GetAllCondition;
13-
1414
/// Simple queries to retrieve [CardanoTransaction] from the sqlite database.
1515
pub struct GetCardanoTransactionProvider<'client> {
1616
connection: &'client SqliteConnection,
@@ -33,16 +33,6 @@ impl<'client> GetCardanoTransactionProvider<'client> {
3333
)
3434
}
3535

36-
pub fn get_transaction_up_to_beacon_condition(
37-
&self,
38-
beacon: ImmutableFileNumber,
39-
) -> WhereCondition {
40-
WhereCondition::new(
41-
"immutable_file_number <= ?*",
42-
vec![Value::Integer(beacon as i64)],
43-
)
44-
}
45-
4636
pub fn get_transaction_between_blocks_condition(
4737
&self,
4838
range: Range<BlockNumber>,

mithril-signer/src/database/repository/cardano_transaction_repository.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ impl CardanoTransactionRepository {
6060
Ok(transactions.collect())
6161
}
6262

63-
/// Return all the [CardanoTransactionRecord]s in the database up to the given beacon using
64-
/// order of insertion.
65-
/// Note: until we rely on block number based beacons, this function needs to compute the highest block number for the given immutable file number.
66-
pub async fn get_transactions_up_to(
67-
&self,
68-
beacon: ImmutableFileNumber,
69-
) -> StdResult<Vec<CardanoTransactionRecord>> {
70-
let provider = GetCardanoTransactionProvider::new(&self.connection);
71-
let filters = provider.get_transaction_up_to_beacon_condition(beacon);
72-
let transactions = provider.find(filters)?;
73-
74-
Ok(transactions.collect())
75-
}
76-
7763
/// Return the [CardanoTransactionRecord] for the given transaction hash.
7864
pub async fn get_transaction<T: Into<TransactionHash>>(
7965
&self,
@@ -227,14 +213,6 @@ impl TransactionStore for CardanoTransactionRepository {
227213
}
228214
}
229215

230-
async fn get_up_to(&self, beacon: ImmutableFileNumber) -> StdResult<Vec<CardanoTransaction>> {
231-
self.get_transactions_up_to(beacon).await.map(|v| {
232-
v.into_iter()
233-
.map(|record| record.into())
234-
.collect::<Vec<CardanoTransaction>>()
235-
})
236-
}
237-
238216
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
239217
const DB_TRANSACTION_SIZE: usize = 100000;
240218
for transactions_in_db_transaction_chunk in transactions.chunks(DB_TRANSACTION_SIZE) {
@@ -419,35 +397,6 @@ mod tests {
419397
);
420398
}
421399

422-
#[tokio::test]
423-
async fn repository_get_up_to_beacon_transactions() {
424-
let connection = Arc::new(cardano_tx_db_connection().unwrap());
425-
let repository = CardanoTransactionRepository::new(connection);
426-
427-
let cardano_transactions: Vec<CardanoTransactionRecord> = (20..=40)
428-
.map(|i| CardanoTransactionRecord {
429-
transaction_hash: format!("tx-hash-{i}"),
430-
block_number: i % 10,
431-
slot_number: i * 100,
432-
block_hash: format!("block-hash-{i}"),
433-
immutable_file_number: i,
434-
})
435-
.collect();
436-
repository
437-
.create_transactions(cardano_transactions.clone())
438-
.await
439-
.unwrap();
440-
441-
let transaction_result = repository.get_transactions_up_to(34).await.unwrap();
442-
assert_eq!(cardano_transactions[0..=14].to_vec(), transaction_result);
443-
444-
let transaction_result = repository.get_transactions_up_to(300).await.unwrap();
445-
assert_eq!(cardano_transactions.clone(), transaction_result);
446-
447-
let transaction_result = repository.get_transactions_up_to(19).await.unwrap();
448-
assert_eq!(Vec::<CardanoTransactionRecord>::new(), transaction_result);
449-
}
450-
451400
#[tokio::test]
452401
async fn repository_get_all_stored_transactions() {
453402
let connection = Arc::new(cardano_tx_db_connection().unwrap());

0 commit comments

Comments
 (0)