Skip to content

Commit ef079c4

Browse files
committed
Remove immutable_file_number from CardanoTransactionRecord
1 parent 7059534 commit ef079c4

File tree

5 files changed

+41
-116
lines changed

5 files changed

+41
-116
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ mod tests {
6767

6868
fn test_transaction_set() -> Vec<CardanoTransactionRecord> {
6969
vec![
70-
CardanoTransactionRecord::new("tx-hash-0", 10, 50, "block-hash-10", 1),
71-
CardanoTransactionRecord::new("tx-hash-1", 10, 51, "block-hash-10", 1),
72-
CardanoTransactionRecord::new("tx-hash-2", 11, 52, "block-hash-11", 1),
73-
CardanoTransactionRecord::new("tx-hash-3", 11, 53, "block-hash-11", 1),
74-
CardanoTransactionRecord::new("tx-hash-4", 12, 54, "block-hash-12", 1),
75-
CardanoTransactionRecord::new("tx-hash-5", 12, 55, "block-hash-12", 1),
70+
CardanoTransactionRecord::new("tx-hash-0", 10, 50, "block-hash-10"),
71+
CardanoTransactionRecord::new("tx-hash-1", 10, 51, "block-hash-10"),
72+
CardanoTransactionRecord::new("tx-hash-2", 11, 52, "block-hash-11"),
73+
CardanoTransactionRecord::new("tx-hash-3", 11, 53, "block-hash-11"),
74+
CardanoTransactionRecord::new("tx-hash-4", 12, 54, "block-hash-12"),
75+
CardanoTransactionRecord::new("tx-hash-5", 12, 55, "block-hash-12"),
7676
]
7777
}
7878

internal/mithril-persistence/src/database/query/cardano_transaction/get_cardano_transaction.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ mod tests {
132132
insert_transactions(
133133
&connection,
134134
vec![
135-
CardanoTransactionRecord::new("tx-hash-0", 10, 50, "block-hash-10", 1),
136-
CardanoTransactionRecord::new("tx-hash-1", 10, 51, "block-hash-10", 1),
137-
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11", 1),
138-
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11", 1),
135+
CardanoTransactionRecord::new("tx-hash-0", 10, 50, "block-hash-10"),
136+
CardanoTransactionRecord::new("tx-hash-1", 10, 51, "block-hash-10"),
137+
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11"),
138+
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11"),
139139
],
140140
);
141141

@@ -144,8 +144,8 @@ mod tests {
144144
.unwrap();
145145
assert_eq!(
146146
vec![
147-
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11", 1),
148-
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11", 1),
147+
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11"),
148+
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11"),
149149
],
150150
records
151151
);

internal/mithril-persistence/src/database/query/cardano_transaction/insert_cardano_transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl InsertCardanoTransactionQuery {
3535
Value::Integer(record.block_number.try_into()?),
3636
Value::Integer(record.slot_number.try_into()?),
3737
Value::String(record.block_hash.clone()),
38-
Value::Integer(record.immutable_file_number.try_into()?),
38+
Value::Integer(0),
3939
]);
4040
Ok(vec)
4141
});

internal/mithril-persistence/src/database/record/cardano_transaction.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use sqlite::Row;
22

33
use mithril_common::entities::{
4-
BlockHash, BlockNumber, CardanoTransaction, ImmutableFileNumber, SlotNumber, TransactionHash,
4+
BlockHash, BlockNumber, CardanoTransaction, SlotNumber, TransactionHash,
55
};
66

77
use crate::database::Hydrator;
@@ -21,9 +21,6 @@ pub struct CardanoTransactionRecord {
2121

2222
/// Block hash of the transaction
2323
pub block_hash: BlockHash,
24-
25-
/// Immutable file number of the transaction
26-
pub immutable_file_number: ImmutableFileNumber,
2724
}
2825

2926
impl CardanoTransactionRecord {
@@ -33,14 +30,12 @@ impl CardanoTransactionRecord {
3330
block_number: BlockNumber,
3431
slot_number: SlotNumber,
3532
block_hash: U,
36-
immutable_file_number: ImmutableFileNumber,
3733
) -> Self {
3834
Self {
3935
transaction_hash: hash.into(),
4036
block_number,
4137
slot_number,
4238
block_hash: block_hash.into(),
43-
immutable_file_number,
4439
}
4540
}
4641
}
@@ -52,7 +47,6 @@ impl From<CardanoTransaction> for CardanoTransactionRecord {
5247
block_number: transaction.block_number,
5348
slot_number: transaction.slot_number,
5449
block_hash: transaction.block_hash,
55-
immutable_file_number: 0,
5650
}
5751
}
5852
}
@@ -77,15 +71,12 @@ impl SqLiteEntity for CardanoTransactionRecord {
7771
let block_number = Hydrator::try_to_u64("cardano_tx.block_number", row.read::<i64, _>(1))?;
7872
let slot_number = Hydrator::try_to_u64("cardano_tx.slot_number", row.read::<i64, _>(2))?;
7973
let block_hash = row.read::<&str, _>(3);
80-
let immutable_file_number =
81-
Hydrator::try_to_u64("cardano_tx.immutable_file_number", row.read::<i64, _>(4))?;
8274

8375
Ok(Self {
8476
transaction_hash: transaction_hash.to_string(),
8577
block_number,
8678
slot_number,
8779
block_hash: block_hash.to_string(),
88-
immutable_file_number,
8980
})
9081
}
9182

@@ -99,11 +90,6 @@ impl SqLiteEntity for CardanoTransactionRecord {
9990
("block_number", "{:cardano_tx:}.block_number", "int"),
10091
("slot_number", "{:cardano_tx:}.slot_number", "int"),
10192
("block_hash", "{:cardano_tx:}.block_hash", "text"),
102-
(
103-
"immutable_file_number",
104-
"{:cardano_tx:}.immutable_file_number",
105-
"int",
106-
),
10793
])
10894
}
10995
}

internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs

Lines changed: 27 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use async_trait::async_trait;
66

77
use mithril_common::crypto_helper::MKTreeNode;
88
use mithril_common::entities::{
9-
BlockHash, BlockNumber, BlockRange, CardanoTransaction, ChainPoint, ImmutableFileNumber,
10-
SlotNumber, TransactionHash,
9+
BlockHash, BlockNumber, BlockRange, CardanoTransaction, ChainPoint, SlotNumber, TransactionHash,
1110
};
1211
use mithril_common::signable_builder::BlockRangeRootRetriever;
1312
use mithril_common::StdResult;
@@ -68,14 +67,12 @@ impl CardanoTransactionRepository {
6867
block_number: BlockNumber,
6968
slot_number: SlotNumber,
7069
block_hash: U,
71-
immutable_file_number: ImmutableFileNumber,
7270
) -> StdResult<Option<CardanoTransactionRecord>> {
7371
let query = InsertCardanoTransactionQuery::insert_one(&CardanoTransactionRecord {
7472
transaction_hash: transaction_hash.into(),
7573
block_number,
7674
slot_number,
7775
block_hash: block_hash.into(),
78-
immutable_file_number,
7976
})?;
8077

8178
self.connection_pool.connection()?.fetch_first(query)
@@ -190,22 +187,6 @@ impl CardanoTransactionRepository {
190187
.fetch_collect(GetBlockRangeRootQuery::all())
191188
}
192189

193-
/// Get the highest [ImmutableFileNumber] of the cardano transactions stored in the database.
194-
pub async fn get_transaction_highest_immutable_file_number(
195-
&self,
196-
) -> StdResult<Option<ImmutableFileNumber>> {
197-
let highest: Option<i64> = self.connection_pool.connection()?.query_single_cell(
198-
"select max(immutable_file_number) as highest from cardano_tx;",
199-
&[],
200-
)?;
201-
highest
202-
.map(u64::try_from)
203-
.transpose()
204-
.with_context(||
205-
format!("Integer field max(immutable_file_number) (value={highest:?}) is incompatible with u64 representation.")
206-
)
207-
}
208-
209190
/// Store the given transactions in the database.
210191
///
211192
/// The storage is done in chunks to avoid exceeding sqlite binding limitations.
@@ -354,7 +335,6 @@ mod tests {
354335
block_number: 10,
355336
slot_number: 50,
356337
block_hash: "block_hash-123".to_string(),
357-
immutable_file_number: 0
358338
}),
359339
transaction_result
360340
);
@@ -373,10 +353,10 @@ mod tests {
373353

374354
repository
375355
.create_transactions(vec![
376-
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123", 1234),
377-
CardanoTransactionRecord::new("tx_hash-456", 11, 51, "block_hash-456", 1234),
378-
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789", 1234),
379-
CardanoTransactionRecord::new("tx_hash-000", 101, 100, "block_hash-000", 1234),
356+
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123"),
357+
CardanoTransactionRecord::new("tx_hash-456", 11, 51, "block_hash-456"),
358+
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789"),
359+
CardanoTransactionRecord::new("tx_hash-000", 101, 100, "block_hash-000"),
380360
])
381361
.await
382362
.unwrap();
@@ -389,8 +369,8 @@ mod tests {
389369

390370
assert_eq!(
391371
vec![
392-
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123", 1234),
393-
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789", 1234),
372+
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123"),
373+
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789"),
394374
],
395375
transactions
396376
);
@@ -403,8 +383,8 @@ mod tests {
403383

404384
assert_eq!(
405385
vec![
406-
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123", 1234),
407-
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789", 1234),
386+
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123"),
387+
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789"),
408388
],
409389
transactions
410390
);
@@ -417,9 +397,9 @@ mod tests {
417397

418398
assert_eq!(
419399
vec![
420-
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123", 1234),
421-
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789", 1234),
422-
CardanoTransactionRecord::new("tx_hash-000", 101, 100, "block_hash-000", 1234),
400+
CardanoTransactionRecord::new("tx_hash-123", 10, 50, "block_hash-123"),
401+
CardanoTransactionRecord::new("tx_hash-789", 12, 52, "block_hash-789"),
402+
CardanoTransactionRecord::new("tx_hash-000", 101, 100, "block_hash-000"),
423403
],
424404
transactions
425405
);
@@ -442,11 +422,11 @@ mod tests {
442422
));
443423

444424
repository
445-
.create_transaction("tx-hash-123", 10, 50, "block_hash-123", 99)
425+
.create_transaction("tx-hash-123", 10, 50, "block_hash-123")
446426
.await
447427
.unwrap();
448428
repository
449-
.create_transaction("tx-hash-123", 11, 51, "block_hash-123-bis", 100)
429+
.create_transaction("tx-hash-123", 11, 51, "block_hash-123-bis")
450430
.await
451431
.unwrap();
452432
let transaction_result = repository.get_transaction("tx-hash-123").await.unwrap();
@@ -457,7 +437,6 @@ mod tests {
457437
block_number: 10,
458438
slot_number: 50,
459439
block_hash: "block_hash-123".to_string(),
460-
immutable_file_number: 99
461440
}),
462441
transaction_result
463442
);
@@ -487,7 +466,6 @@ mod tests {
487466
block_number: 10,
488467
slot_number: 50,
489468
block_hash: "block-hash-123".to_string(),
490-
immutable_file_number: 0
491469
}),
492470
transaction_result
493471
);
@@ -500,7 +478,6 @@ mod tests {
500478
block_number: 11,
501479
slot_number: 51,
502480
block_hash: "block-hash-456".to_string(),
503-
immutable_file_number: 0,
504481
}),
505482
transaction_result
506483
);
@@ -539,7 +516,7 @@ mod tests {
539516
));
540517

541518
repository
542-
.create_transaction("tx-hash-000", 1, 5, "block-hash", 9)
519+
.create_transaction("tx-hash-000", 1, 5, "block-hash")
543520
.await
544521
.unwrap();
545522

@@ -562,7 +539,6 @@ mod tests {
562539
block_number: 1,
563540
slot_number: 5,
564541
block_hash: "block-hash".to_string(),
565-
immutable_file_number: 9
566542
}),
567543
transaction_result
568544
);
@@ -644,43 +620,6 @@ mod tests {
644620
);
645621
}
646622

647-
#[tokio::test]
648-
async fn repository_get_transaction_highest_immutable_file_number_without_transactions_in_db() {
649-
let connection = cardano_tx_db_connection().unwrap();
650-
let repository = CardanoTransactionRepository::new(Arc::new(
651-
SqliteConnectionPool::build_from_connection(connection),
652-
));
653-
654-
let highest_beacon = repository
655-
.get_transaction_highest_immutable_file_number()
656-
.await
657-
.unwrap();
658-
assert_eq!(None, highest_beacon);
659-
}
660-
661-
#[tokio::test]
662-
async fn repository_get_transaction_highest_immutable_file_number_with_transactions_in_db() {
663-
let connection = cardano_tx_db_connection().unwrap();
664-
let repository = CardanoTransactionRepository::new(Arc::new(
665-
SqliteConnectionPool::build_from_connection(connection),
666-
));
667-
668-
let cardano_transactions = vec![
669-
CardanoTransactionRecord::new("tx-hash-123".to_string(), 10, 50, "block-hash-123", 50),
670-
CardanoTransactionRecord::new("tx-hash-456".to_string(), 11, 51, "block-hash-456", 100),
671-
];
672-
repository
673-
.create_transactions(cardano_transactions)
674-
.await
675-
.unwrap();
676-
677-
let highest_beacon = repository
678-
.get_transaction_highest_immutable_file_number()
679-
.await
680-
.unwrap();
681-
assert_eq!(Some(100), highest_beacon);
682-
}
683-
684623
#[tokio::test]
685624
async fn repository_get_transactions_in_range_blocks() {
686625
let connection = cardano_tx_db_connection().unwrap();
@@ -689,9 +628,9 @@ mod tests {
689628
));
690629

691630
let transactions = vec![
692-
CardanoTransactionRecord::new("tx-hash-1", 10, 50, "block-hash-1", 99),
693-
CardanoTransactionRecord::new("tx-hash-2", 11, 51, "block-hash-2", 100),
694-
CardanoTransactionRecord::new("tx-hash-3", 12, 52, "block-hash-3", 101),
631+
CardanoTransactionRecord::new("tx-hash-1", 10, 50, "block-hash-1"),
632+
CardanoTransactionRecord::new("tx-hash-2", 11, 51, "block-hash-2"),
633+
CardanoTransactionRecord::new("tx-hash-3", 12, 52, "block-hash-3"),
695634
];
696635
repository
697636
.create_transactions(transactions.clone())
@@ -743,12 +682,12 @@ mod tests {
743682
));
744683

745684
let transactions = vec![
746-
CardanoTransactionRecord::new("tx-hash-1", 10, 50, "block-hash-1", 99),
747-
CardanoTransactionRecord::new("tx-hash-2", 11, 51, "block-hash-2", 100),
748-
CardanoTransactionRecord::new("tx-hash-3", 20, 52, "block-hash-3", 101),
749-
CardanoTransactionRecord::new("tx-hash-4", 31, 53, "block-hash-4", 102),
750-
CardanoTransactionRecord::new("tx-hash-5", 35, 54, "block-hash-5", 103),
751-
CardanoTransactionRecord::new("tx-hash-6", 46, 55, "block-hash-6", 104),
685+
CardanoTransactionRecord::new("tx-hash-1", 10, 50, "block-hash-1"),
686+
CardanoTransactionRecord::new("tx-hash-2", 11, 51, "block-hash-2"),
687+
CardanoTransactionRecord::new("tx-hash-3", 20, 52, "block-hash-3"),
688+
CardanoTransactionRecord::new("tx-hash-4", 31, 53, "block-hash-4"),
689+
CardanoTransactionRecord::new("tx-hash-5", 35, 54, "block-hash-5"),
690+
CardanoTransactionRecord::new("tx-hash-6", 46, 55, "block-hash-6"),
752691
];
753692
repository
754693
.create_transactions(transactions.clone())
@@ -802,9 +741,9 @@ mod tests {
802741
));
803742

804743
let transactions = vec![
805-
CardanoTransactionRecord::new("tx-1", 100, 500, "block-1", 99),
806-
CardanoTransactionRecord::new("tx-2", 100, 500, "block-1", 99),
807-
CardanoTransactionRecord::new("tx-3", 101, 501, "block-1", 99),
744+
CardanoTransactionRecord::new("tx-1", 100, 500, "block-1"),
745+
CardanoTransactionRecord::new("tx-2", 100, 500, "block-1"),
746+
CardanoTransactionRecord::new("tx-3", 101, 501, "block-1"),
808747
];
809748
repository
810749
.create_transactions(transactions.clone())

0 commit comments

Comments
 (0)