Skip to content

Commit 0112207

Browse files
committed
Use new SlotNumber type in mithril-aggregator
1 parent 0bdf04d commit 0112207

11 files changed

+115
-53
lines changed

mithril-aggregator/benches/cardano_transactions_get.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
44
use sqlite::ConnectionThreadSafe;
55

66
use mithril_aggregator::services::TransactionStore;
7-
use mithril_common::entities::{BlockNumber, CardanoTransaction};
7+
use mithril_common::entities::{BlockNumber, CardanoTransaction, SlotNumber};
88
use mithril_common::test_utils::TempDir;
99
use mithril_persistence::database::repository::CardanoTransactionRepository;
1010
use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnectionPool};
@@ -34,7 +34,7 @@ fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
3434
CardanoTransaction::new(
3535
format!("tx_hash-{}", i),
3636
BlockNumber(i as u64),
37-
i as u64 * 100,
37+
SlotNumber(i as u64 * 100),
3838
format!("block_hash-{}", i),
3939
)
4040
})

mithril-aggregator/benches/cardano_transactions_import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
22
use sqlite::ConnectionThreadSafe;
33
use std::sync::Arc;
44

5-
use mithril_common::entities::{BlockNumber, CardanoTransaction};
5+
use mithril_common::entities::{BlockNumber, CardanoTransaction, SlotNumber};
66
use mithril_common::test_utils::TempDir;
77
use mithril_persistence::database::repository::CardanoTransactionRepository;
88
use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnectionPool};
@@ -29,7 +29,7 @@ fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
2929
CardanoTransaction::new(
3030
format!("tx_hash-{}", i),
3131
BlockNumber(i as u64),
32-
i as u64 + 1,
32+
SlotNumber(i as u64 + 1),
3333
format!("block_hash-{}", i),
3434
)
3535
})

mithril-aggregator/src/services/cardano_transactions_importer.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod tests {
197197
BlockStreamer, DumbBlockScanner, DumbBlockStreamer, ScannedBlock,
198198
};
199199
use mithril_common::crypto_helper::MKTree;
200-
use mithril_common::entities::{BlockNumber, BlockRangesSequence};
200+
use mithril_common::entities::{BlockNumber, BlockRangesSequence, SlotNumber};
201201
use mithril_persistence::database::repository::CardanoTransactionRepository;
202202
use mithril_persistence::sqlite::SqliteConnectionPool;
203203

@@ -237,7 +237,7 @@ mod tests {
237237
ScannedBlock::new(
238238
format!("block_hash-{}", block_number),
239239
BlockNumber(block_number),
240-
block_number * 100,
240+
SlotNumber(block_number * 100),
241241
vec![format!("tx_hash-{}", block_number)],
242242
)
243243
})
@@ -270,13 +270,13 @@ mod tests {
270270
ScannedBlock::new(
271271
"block_hash-1",
272272
BlockNumber(10),
273-
15,
273+
SlotNumber(15),
274274
vec!["tx_hash-1", "tx_hash-2"],
275275
),
276276
ScannedBlock::new(
277277
"block_hash-2",
278278
BlockNumber(20),
279-
25,
279+
SlotNumber(25),
280280
vec!["tx_hash-3", "tx_hash-4"],
281281
),
282282
];
@@ -416,18 +416,19 @@ mod tests {
416416
ScannedBlock::new(
417417
"block_hash-1",
418418
BlockNumber(10),
419-
15,
419+
SlotNumber(15),
420420
vec!["tx_hash-1", "tx_hash-2"],
421421
),
422422
ScannedBlock::new(
423423
"block_hash-2",
424424
BlockNumber(20),
425-
25,
425+
SlotNumber(25),
426426
vec!["tx_hash-3", "tx_hash-4"],
427427
),
428428
]]);
429429

430-
let last_tx = CardanoTransaction::new("tx-20", BlockNumber(30), 35, "block_hash-3");
430+
let last_tx =
431+
CardanoTransaction::new("tx-20", BlockNumber(30), SlotNumber(35), "block_hash-3");
431432
repository
432433
.store_transactions(vec![last_tx.clone()])
433434
.await
@@ -452,7 +453,8 @@ mod tests {
452453
SqliteConnectionPool::build_from_connection(connection),
453454
)));
454455

455-
let highest_stored_chain_point = ChainPoint::new(134, BlockNumber(10), "block_hash-1");
456+
let highest_stored_chain_point =
457+
ChainPoint::new(SlotNumber(134), BlockNumber(10), "block_hash-1");
456458
let stored_block = ScannedBlock::new(
457459
highest_stored_chain_point.block_hash.clone(),
458460
highest_stored_chain_point.block_number,
@@ -462,7 +464,7 @@ mod tests {
462464
let to_store_block = ScannedBlock::new(
463465
"block_hash-2",
464466
BlockNumber(20),
465-
229,
467+
SlotNumber(229),
466468
vec!["tx_hash-3", "tx_hash-4"],
467469
);
468470
let expected_transactions: Vec<CardanoTransaction> = [
@@ -733,13 +735,13 @@ mod tests {
733735
ScannedBlock::new(
734736
"block_hash-1",
735737
BlockNumber(10),
736-
15,
738+
SlotNumber(15),
737739
vec!["tx_hash-1", "tx_hash-2"],
738740
),
739741
ScannedBlock::new(
740742
"block_hash-2",
741743
BlockNumber(20),
742-
25,
744+
SlotNumber(25),
743745
vec!["tx_hash-3", "tx_hash-4"],
744746
),
745747
];
@@ -783,7 +785,7 @@ mod tests {
783785
let expected_remaining_transactions = ScannedBlock::new(
784786
"block_hash-130",
785787
BlockNumber(130),
786-
5,
788+
SlotNumber(5),
787789
vec!["tx_hash-6", "tx_hash-7"],
788790
)
789791
.into_transactions();
@@ -796,15 +798,15 @@ mod tests {
796798
ScannedBlock::new(
797799
"block_hash-131",
798800
BlockNumber(131),
799-
10,
801+
SlotNumber(10),
800802
vec!["tx_hash-8", "tx_hash-9", "tx_hash-10"],
801803
)
802804
.into_transactions(),
803805
)
804806
.await
805807
.unwrap();
806808

807-
let chain_point = ChainPoint::new(5, BlockNumber(130), "block_hash-130");
809+
let chain_point = ChainPoint::new(SlotNumber(5), BlockNumber(130), "block_hash-130");
808810
let scanner = DumbBlockScanner::new().backward(chain_point);
809811

810812
let importer =
@@ -859,7 +861,7 @@ mod tests {
859861
ScannedBlock::new(
860862
"block_hash-131",
861863
BlockRange::from_block_number(BlockRange::LENGTH * 3).start,
862-
1,
864+
SlotNumber(1),
863865
vec!["tx_hash-1", "tx_hash-2", "tx_hash-3"],
864866
)
865867
.into_transactions(),
@@ -870,7 +872,7 @@ mod tests {
870872
let block_range_roots = repository.get_all_block_range_root().unwrap();
871873
assert_eq!(6, block_range_roots.len());
872874

873-
let chain_point = ChainPoint::new(1, BlockRange::LENGTH * 3, "block_hash-131");
875+
let chain_point = ChainPoint::new(SlotNumber(1), BlockRange::LENGTH * 3, "block_hash-131");
874876
let scanner = DumbBlockScanner::new().backward(chain_point);
875877

876878
let importer =

mithril-aggregator/tests/certificate_chain.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use mithril_aggregator::Configuration;
44
use mithril_common::{
55
entities::{
66
BlockNumber, CardanoDbBeacon, ChainPoint, Epoch, ProtocolParameters, SignedEntityType,
7-
SignedEntityTypeDiscriminants, StakeDistribution, StakeDistributionParty, TimePoint,
7+
SignedEntityTypeDiscriminants, SlotNumber, StakeDistribution, StakeDistributionParty,
8+
TimePoint,
89
},
910
test_utils::MithrilFixtureBuilder,
1011
};
@@ -23,7 +24,11 @@ async fn certificate_chain() {
2324
..Configuration::new_sample()
2425
};
2526
let mut tester = RuntimeTester::build(
26-
TimePoint::new(1, 1, ChainPoint::new(10, BlockNumber(1), "block_hash-1")),
27+
TimePoint::new(
28+
1,
29+
1,
30+
ChainPoint::new(SlotNumber(10), BlockNumber(1), "block_hash-1"),
31+
),
2732
configuration,
2833
)
2934
.await;

mithril-aggregator/tests/create_certificate.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use mithril_aggregator::Configuration;
44
use mithril_common::{
55
entities::{
66
BlockNumber, CardanoDbBeacon, CardanoTransactionsSigningConfig, ChainPoint, Epoch,
7-
ProtocolParameters, SignedEntityType, SignedEntityTypeDiscriminants,
7+
ProtocolParameters, SignedEntityType, SignedEntityTypeDiscriminants, SlotNumber,
88
StakeDistributionParty, TimePoint,
99
},
1010
test_utils::MithrilFixtureBuilder,
@@ -33,7 +33,10 @@ async fn create_certificate() {
3333
epoch: Epoch(1),
3434
immutable_file_number: 1,
3535
chain_point: ChainPoint {
36-
slot_number: 10,
36+
// TODO: It's probably not a good idea to have the same slot_number and block_number. Can we change this?
37+
// Note: slot_number and block_number need to be equal
38+
// to check the expected when we increase both with `increase_block_number_and_slot_number`
39+
slot_number: SlotNumber(100),
3740
block_number: BlockNumber(100),
3841
block_hash: "block_hash-100".to_string(),
3942
},
@@ -145,7 +148,10 @@ async fn create_certificate() {
145148
"Increase cardano chain block number to 185,
146149
the state machine should be signing CardanoTransactions for block 179"
147150
);
148-
tester.increase_block_number(85, 185).await.unwrap();
151+
tester
152+
.increase_block_number_and_slot_number(85, 185)
153+
.await
154+
.unwrap();
149155
cycle!(tester, "signing");
150156
let signers_for_transaction = &fixture.signers_fixture()[2..=6];
151157
tester
@@ -181,7 +187,7 @@ async fn create_certificate() {
181187
the state machine should be signing CardanoTransactions for block 120"
182188
);
183189
tester
184-
.cardano_chain_send_rollback(BlockNumber(149))
190+
.cardano_chain_send_rollback(SlotNumber(149))
185191
.await
186192
.unwrap();
187193
cycle!(tester, "signing");

mithril-aggregator/tests/era_checker.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod test_extensions;
22
use mithril_aggregator::{Configuration, RuntimeError};
33
use mithril_common::{
4-
entities::{BlockNumber, ChainPoint, Epoch, ProtocolParameters, TimePoint},
4+
entities::{BlockNumber, ChainPoint, Epoch, ProtocolParameters, SlotNumber, TimePoint},
55
era::{EraMarker, SupportedEra},
66
test_utils::MithrilFixtureBuilder,
77
};
@@ -24,7 +24,11 @@ async fn testing_eras() {
2424
..Configuration::new_sample()
2525
};
2626
let mut tester = RuntimeTester::build(
27-
TimePoint::new(1, 1, ChainPoint::new(10, BlockNumber(1), "block_hash-1")),
27+
TimePoint::new(
28+
1,
29+
1,
30+
ChainPoint::new(SlotNumber(10), BlockNumber(1), "block_hash-1"),
31+
),
2832
configuration,
2933
)
3034
.await;

mithril-aggregator/tests/genesis_to_signing.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ mod test_extensions;
22

33
use mithril_aggregator::Configuration;
44
use mithril_common::{
5-
entities::{BlockNumber, CardanoDbBeacon, ChainPoint, ProtocolParameters, TimePoint},
5+
entities::{
6+
BlockNumber, CardanoDbBeacon, ChainPoint, ProtocolParameters, SlotNumber, TimePoint,
7+
},
68
test_utils::MithrilFixtureBuilder,
79
};
810
use test_extensions::{utilities::get_test_dir, ExpectedCertificate, RuntimeTester};
@@ -20,7 +22,11 @@ async fn genesis_to_signing() {
2022
..Configuration::new_sample()
2123
};
2224
let mut tester = RuntimeTester::build(
23-
TimePoint::new(1, 1, ChainPoint::new(10, BlockNumber(1), "block_hash-1")),
25+
TimePoint::new(
26+
1,
27+
1,
28+
ChainPoint::new(SlotNumber(10), BlockNumber(1), "block_hash-1"),
29+
),
2430
configuration,
2531
)
2632
.await;

mithril-aggregator/tests/open_message_expiration.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use mithril_aggregator::Configuration;
66
use mithril_common::{
77
entities::{
88
BlockNumber, CardanoDbBeacon, ChainPoint, ProtocolParameters, SignedEntityType,
9-
SignedEntityTypeDiscriminants, TimePoint,
9+
SignedEntityTypeDiscriminants, SlotNumber, TimePoint,
1010
},
1111
test_utils::MithrilFixtureBuilder,
1212
};
@@ -25,7 +25,11 @@ async fn open_message_expiration() {
2525
..Configuration::new_sample()
2626
};
2727
let mut tester = RuntimeTester::build(
28-
TimePoint::new(1, 1, ChainPoint::new(10, BlockNumber(1), "block_hash-1")),
28+
TimePoint::new(
29+
1,
30+
1,
31+
ChainPoint::new(SlotNumber(10), BlockNumber(1), "block_hash-1"),
32+
),
2933
configuration,
3034
)
3135
.await;

mithril-aggregator/tests/open_message_newer_exists.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use mithril_aggregator::Configuration;
44
use mithril_common::{
55
entities::{
66
BlockNumber, CardanoDbBeacon, ChainPoint, Epoch, ProtocolParameters, SignedEntityType,
7-
SignedEntityTypeDiscriminants, StakeDistributionParty, TimePoint,
7+
SignedEntityTypeDiscriminants, SlotNumber, StakeDistributionParty, TimePoint,
88
},
99
test_utils::MithrilFixtureBuilder,
1010
};
@@ -23,7 +23,11 @@ async fn open_message_newer_exists() {
2323
..Configuration::new_sample()
2424
};
2525
let mut tester = RuntimeTester::build(
26-
TimePoint::new(1, 1, ChainPoint::new(10, BlockNumber(1), "block_hash-1")),
26+
TimePoint::new(
27+
1,
28+
1,
29+
ChainPoint::new(SlotNumber(10), BlockNumber(1), "block_hash-1"),
30+
),
2731
configuration,
2832
)
2933
.await;

mithril-aggregator/tests/prove_transactions.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use mithril_common::{
33
entities::{
44
BlockNumber, CardanoDbBeacon, CardanoTransactionsSigningConfig, ChainPoint, Epoch,
55
ProtocolMessagePartKey, ProtocolParameters, SignedEntityType,
6-
SignedEntityTypeDiscriminants, TimePoint,
6+
SignedEntityTypeDiscriminants, SlotNumber, TimePoint,
77
},
88
test_utils::MithrilFixtureBuilder,
99
};
@@ -35,7 +35,10 @@ async fn prove_transactions() {
3535
epoch: Epoch(1),
3636
immutable_file_number: 1,
3737
chain_point: ChainPoint {
38-
slot_number: 10,
38+
// TODO: It's probably not a good idea to have the same slot_number and block_number. Can we change this?
39+
// Note: slot_number and block_number need to be equal
40+
// to check the expected when we increase both with `increase_block_number_and_slot_number`
41+
slot_number: SlotNumber(100),
3942
block_number: BlockNumber(100),
4043
block_hash: "block_hash-100".to_string(),
4144
},
@@ -89,7 +92,10 @@ async fn prove_transactions() {
8992
"Increase cardano chain block number to 185,
9093
the state machine should be signing CardanoTransactions up to block 179 included"
9194
);
92-
tester.increase_block_number(85, 185).await.unwrap();
95+
tester
96+
.increase_block_number_and_slot_number(85, 185)
97+
.await
98+
.unwrap();
9399
cycle!(tester, "signing");
94100
tester
95101
.send_single_signatures(SignedEntityTypeDiscriminants::CardanoTransactions, signers)

0 commit comments

Comments
 (0)