Skip to content

Commit b664ac7

Browse files
committed
Remove immutable_file_number from ScannedBlock
1 parent 406d7c4 commit b664ac7

File tree

9 files changed

+48
-77
lines changed

9 files changed

+48
-77
lines changed

mithril-aggregator/src/services/cardano_transactions_importer.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ mod tests {
242242
format!("block_hash-{}", block_number),
243243
block_number,
244244
block_number * 100,
245-
block_number * 10,
246245
vec![format!("tx_hash-{}", block_number)],
247246
)
248247
})
@@ -272,8 +271,8 @@ mod tests {
272271
)));
273272

274273
let blocks = vec![
275-
ScannedBlock::new("block_hash-1", 10, 15, 11, vec!["tx_hash-1", "tx_hash-2"]),
276-
ScannedBlock::new("block_hash-2", 20, 25, 12, vec!["tx_hash-3", "tx_hash-4"]),
274+
ScannedBlock::new("block_hash-1", 10, 15, vec!["tx_hash-1", "tx_hash-2"]),
275+
ScannedBlock::new("block_hash-2", 20, 25, vec!["tx_hash-3", "tx_hash-4"]),
277276
];
278277
let expected_transactions = into_transactions(&blocks);
279278
let up_to_block_number = 1000;
@@ -408,8 +407,8 @@ mod tests {
408407
SqliteConnectionPool::build_from_connection(connection),
409408
)));
410409
let scanner = DumbBlockScanner::new().forwards(vec![vec![
411-
ScannedBlock::new("block_hash-1", 10, 15, 10, vec!["tx_hash-1", "tx_hash-2"]),
412-
ScannedBlock::new("block_hash-2", 20, 25, 11, vec!["tx_hash-3", "tx_hash-4"]),
410+
ScannedBlock::new("block_hash-1", 10, 15, vec!["tx_hash-1", "tx_hash-2"]),
411+
ScannedBlock::new("block_hash-2", 20, 25, vec!["tx_hash-3", "tx_hash-4"]),
413412
]]);
414413

415414
let last_tx = CardanoTransaction::new("tx-20", 30, 35, "block_hash-3");
@@ -442,11 +441,10 @@ mod tests {
442441
highest_stored_chain_point.block_hash.clone(),
443442
highest_stored_chain_point.block_number,
444443
highest_stored_chain_point.slot_number,
445-
5,
446444
vec!["tx_hash-1", "tx_hash-2"],
447445
);
448446
let to_store_block =
449-
ScannedBlock::new("block_hash-2", 20, 229, 8, vec!["tx_hash-3", "tx_hash-4"]);
447+
ScannedBlock::new("block_hash-2", 20, 229, vec!["tx_hash-3", "tx_hash-4"]);
450448
let expected_transactions: Vec<CardanoTransaction> = [
451449
stored_block.clone().into_transactions(),
452450
to_store_block.clone().into_transactions(),
@@ -712,8 +710,8 @@ mod tests {
712710
async fn importing_twice_starting_with_nothing_in_a_real_db_should_yield_transactions_in_same_order(
713711
) {
714712
let blocks = vec![
715-
ScannedBlock::new("block_hash-1", 10, 15, 11, vec!["tx_hash-1", "tx_hash-2"]),
716-
ScannedBlock::new("block_hash-2", 20, 25, 12, vec!["tx_hash-3", "tx_hash-4"]),
713+
ScannedBlock::new("block_hash-1", 10, 15, vec!["tx_hash-1", "tx_hash-2"]),
714+
ScannedBlock::new("block_hash-2", 20, 25, vec!["tx_hash-3", "tx_hash-4"]),
717715
];
718716
let up_to_block_number = 1000;
719717
let transactions = into_transactions(&blocks);
@@ -753,7 +751,7 @@ mod tests {
753751
)));
754752

755753
let expected_remaining_transactions =
756-
ScannedBlock::new("block_hash-130", 130, 5, 1, vec!["tx_hash-6", "tx_hash-7"])
754+
ScannedBlock::new("block_hash-130", 130, 5, vec!["tx_hash-6", "tx_hash-7"])
757755
.into_transactions();
758756
repository
759757
.store_transactions(expected_remaining_transactions.clone())
@@ -765,7 +763,6 @@ mod tests {
765763
"block_hash-131",
766764
131,
767765
10,
768-
2,
769766
vec!["tx_hash-8", "tx_hash-9", "tx_hash-10"],
770767
)
771768
.into_transactions(),
@@ -829,7 +826,6 @@ mod tests {
829826
"block_hash-131",
830827
BlockRange::from_block_number(BlockRange::LENGTH * 3).start,
831828
1,
832-
0,
833829
vec!["tx_hash-1", "tx_hash-2", "tx_hash-3"],
834830
)
835831
.into_transactions(),

mithril-aggregator/tests/test_extensions/runtime_tester.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use mithril_common::{
1313
cardano_block_scanner::{DumbBlockScanner, ScannedBlock},
1414
chain_observer::{ChainObserver, FakeObserver},
1515
crypto_helper::ProtocolGenesisSigner,
16-
digesters::{DumbImmutableDigester, DumbImmutableFileObserver, ImmutableFileObserver},
16+
digesters::{DumbImmutableDigester, DumbImmutableFileObserver},
1717
entities::{
1818
BlockNumber, Certificate, CertificateSignature, ChainPoint, Epoch, ImmutableFileNumber,
1919
SignedEntityType, SignedEntityTypeDiscriminants, Snapshot, StakeDistribution, TimePoint,
@@ -270,10 +270,6 @@ impl RuntimeTester {
270270
);
271271

272272
// Make the block scanner return new blocks
273-
let current_immutable = self
274-
.immutable_file_observer
275-
.get_last_immutable_number()
276-
.await?;
277273
let blocks_to_scan: Vec<ScannedBlock> = ((expected - increment + 1)..=expected)
278274
.map(|block_number| {
279275
let block_hash = format!("block_hash-{block_number}");
@@ -282,7 +278,6 @@ impl RuntimeTester {
282278
block_hash,
283279
block_number,
284280
slot_number,
285-
current_immutable,
286281
vec![tx_hash(block_number, 1)],
287282
)
288283
})

mithril-common/src/cardano_block_scanner/chain_reader_block_streamer.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ mod tests {
173173
"hash-1",
174174
until_block_number,
175175
100,
176-
1,
177176
Vec::<&str>::new(),
178177
),
179178
},
@@ -182,7 +181,6 @@ mod tests {
182181
"hash-2",
183182
until_block_number,
184183
100,
185-
1,
186184
Vec::<&str>::new(),
187185
),
188186
},
@@ -216,7 +214,6 @@ mod tests {
216214
"hash-2",
217215
until_block_number,
218216
100,
219-
1,
220217
Vec::<&str>::new(),
221218
)])),
222219
scanned_blocks
@@ -227,10 +224,10 @@ mod tests {
227224
async fn test_parse_expected_multiple_rollforwards_below_block_number_threshold() {
228225
let chain_reader = Arc::new(Mutex::new(FakeChainReader::new(vec![
229226
ChainBlockNextAction::RollForward {
230-
parsed_block: ScannedBlock::new("hash-1", 1, 10, 1, Vec::<&str>::new()),
227+
parsed_block: ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new()),
231228
},
232229
ChainBlockNextAction::RollForward {
233-
parsed_block: ScannedBlock::new("hash-2", 2, 20, 1, Vec::<&str>::new()),
230+
parsed_block: ScannedBlock::new("hash-2", 2, 20, Vec::<&str>::new()),
234231
},
235232
])));
236233
let mut block_streamer = ChainReaderBlockStreamer::try_new(
@@ -247,8 +244,8 @@ mod tests {
247244

248245
assert_eq!(
249246
Some(ChainScannedBlocks::RollForwards(vec![
250-
ScannedBlock::new("hash-1", 1, 10, 1, Vec::<&str>::new()),
251-
ScannedBlock::new("hash-2", 2, 20, 1, Vec::<&str>::new())
247+
ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new()),
248+
ScannedBlock::new("hash-2", 2, 20, Vec::<&str>::new())
252249
])),
253250
scanned_blocks,
254251
);
@@ -258,13 +255,13 @@ mod tests {
258255
async fn test_parse_expected_maximum_rollforwards_retrieved_per_poll() {
259256
let chain_reader = Arc::new(Mutex::new(FakeChainReader::new(vec![
260257
ChainBlockNextAction::RollForward {
261-
parsed_block: ScannedBlock::new("hash-1", 1, 10, 1, Vec::<&str>::new()),
258+
parsed_block: ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new()),
262259
},
263260
ChainBlockNextAction::RollForward {
264-
parsed_block: ScannedBlock::new("hash-2", 2, 20, 1, Vec::<&str>::new()),
261+
parsed_block: ScannedBlock::new("hash-2", 2, 20, Vec::<&str>::new()),
265262
},
266263
ChainBlockNextAction::RollForward {
267-
parsed_block: ScannedBlock::new("hash-3", 3, 30, 1, Vec::<&str>::new()),
264+
parsed_block: ScannedBlock::new("hash-3", 3, 30, Vec::<&str>::new()),
268265
},
269266
])));
270267
let mut block_streamer = ChainReaderBlockStreamer::try_new(
@@ -281,8 +278,8 @@ mod tests {
281278
let scanned_blocks = block_streamer.poll_next().await.expect("poll_next failed");
282279
assert_eq!(
283280
Some(ChainScannedBlocks::RollForwards(vec![
284-
ScannedBlock::new("hash-1", 1, 10, 1, Vec::<&str>::new()),
285-
ScannedBlock::new("hash-2", 2, 20, 1, Vec::<&str>::new())
281+
ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new()),
282+
ScannedBlock::new("hash-2", 2, 20, Vec::<&str>::new())
286283
])),
287284
scanned_blocks,
288285
);
@@ -293,7 +290,6 @@ mod tests {
293290
"hash-3",
294291
3,
295292
30,
296-
1,
297293
Vec::<&str>::new()
298294
),])),
299295
scanned_blocks,
@@ -351,13 +347,13 @@ mod tests {
351347
) {
352348
let chain_reader = Arc::new(Mutex::new(FakeChainReader::new(vec![
353349
ChainBlockNextAction::RollForward {
354-
parsed_block: ScannedBlock::new("hash-8", 80, 8, 1, Vec::<&str>::new()),
350+
parsed_block: ScannedBlock::new("hash-8", 80, 8, Vec::<&str>::new()),
355351
},
356352
ChainBlockNextAction::RollForward {
357-
parsed_block: ScannedBlock::new("hash-9", 90, 9, 1, Vec::<&str>::new()),
353+
parsed_block: ScannedBlock::new("hash-9", 90, 9, Vec::<&str>::new()),
358354
},
359355
ChainBlockNextAction::RollForward {
360-
parsed_block: ScannedBlock::new("hash-10", 100, 10, 1, Vec::<&str>::new()),
356+
parsed_block: ScannedBlock::new("hash-10", 100, 10, Vec::<&str>::new()),
361357
},
362358
ChainBlockNextAction::RollBackward { slot_number: 9 },
363359
])));
@@ -375,8 +371,8 @@ mod tests {
375371

376372
assert_eq!(
377373
Some(ChainScannedBlocks::RollForwards(vec![
378-
ScannedBlock::new("hash-8", 80, 8, 1, Vec::<&str>::new()),
379-
ScannedBlock::new("hash-9", 90, 9, 1, Vec::<&str>::new())
374+
ScannedBlock::new("hash-8", 80, 8, Vec::<&str>::new()),
375+
ScannedBlock::new("hash-9", 90, 9, Vec::<&str>::new())
380376
])),
381377
scanned_blocks,
382378
);
@@ -387,10 +383,10 @@ mod tests {
387383
) {
388384
let chain_reader = Arc::new(Mutex::new(FakeChainReader::new(vec![
389385
ChainBlockNextAction::RollForward {
390-
parsed_block: ScannedBlock::new("hash-8", 80, 8, 1, Vec::<&str>::new()),
386+
parsed_block: ScannedBlock::new("hash-8", 80, 8, Vec::<&str>::new()),
391387
},
392388
ChainBlockNextAction::RollForward {
393-
parsed_block: ScannedBlock::new("hash-9", 90, 9, 1, Vec::<&str>::new()),
389+
parsed_block: ScannedBlock::new("hash-9", 90, 9, Vec::<&str>::new()),
394390
},
395391
ChainBlockNextAction::RollBackward { slot_number: 3 },
396392
])));

mithril-common/src/cardano_block_scanner/dumb_block_scanner.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ mod tests {
131131

132132
#[tokio::test]
133133
async fn polling_with_one_set_of_block_returns_some_once() {
134-
let expected_blocks = vec![ScannedBlock::new("hash-1", 1, 10, 20, Vec::<&str>::new())];
134+
let expected_blocks = vec![ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new())];
135135
let mut streamer = DumbBlockStreamer::new().forwards(vec![expected_blocks.clone()]);
136136

137137
let blocks = streamer.poll_next().await.unwrap();
@@ -147,12 +147,12 @@ mod tests {
147147
#[tokio::test]
148148
async fn polling_with_multiple_sets_of_blocks_returns_some_once() {
149149
let expected_blocks = vec![
150-
vec![ScannedBlock::new("hash-1", 1, 10, 20, Vec::<&str>::new())],
150+
vec![ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new())],
151151
vec![
152-
ScannedBlock::new("hash-2", 2, 11, 21, Vec::<&str>::new()),
153-
ScannedBlock::new("hash-3", 3, 12, 22, Vec::<&str>::new()),
152+
ScannedBlock::new("hash-2", 2, 11, Vec::<&str>::new()),
153+
ScannedBlock::new("hash-3", 3, 12, Vec::<&str>::new()),
154154
],
155-
vec![ScannedBlock::new("hash-4", 4, 13, 23, Vec::<&str>::new())],
155+
vec![ScannedBlock::new("hash-4", 4, 13, Vec::<&str>::new())],
156156
];
157157
let mut streamer = DumbBlockStreamer::new().forwards(expected_blocks.clone());
158158

@@ -180,7 +180,7 @@ mod tests {
180180

181181
#[tokio::test]
182182
async fn dumb_scanned_construct_a_streamer_based_on_its_stored_blocks() {
183-
let expected_blocks = vec![ScannedBlock::new("hash-1", 1, 10, 20, Vec::<&str>::new())];
183+
let expected_blocks = vec![ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new())];
184184

185185
let scanner = DumbBlockScanner::new().forwards(vec![expected_blocks.clone()]);
186186
let mut streamer = scanner.scan(None, 5).await.unwrap();
@@ -191,7 +191,7 @@ mod tests {
191191

192192
#[tokio::test]
193193
async fn dumb_scanned_construct_a_streamer_based_on_its_stored_chain_scanned_blocks() {
194-
let expected_blocks = vec![ScannedBlock::new("hash-1", 1, 10, 20, Vec::<&str>::new())];
194+
let expected_blocks = vec![ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new())];
195195
let expected_chain_point = ChainPoint::new(10, 2, "block-hash");
196196

197197
let scanner = DumbBlockScanner::new()
@@ -217,8 +217,8 @@ mod tests {
217217
#[tokio::test]
218218
async fn polling_with_can_return_roll_backward() {
219219
let expected_blocks = vec![
220-
vec![ScannedBlock::new("hash-1", 1, 10, 20, Vec::<&str>::new())],
221-
vec![ScannedBlock::new("hash-4", 4, 13, 23, Vec::<&str>::new())],
220+
vec![ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new())],
221+
vec![ScannedBlock::new("hash-4", 4, 13, Vec::<&str>::new())],
222222
];
223223

224224
let expected_chain_point = ChainPoint::new(10, 2, "block-hash");

mithril-common/src/cardano_block_scanner/scanned_block.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use pallas_traverse::MultiEraBlock;
22

3-
use crate::entities::{
4-
BlockHash, BlockNumber, CardanoTransaction, ImmutableFileNumber, SlotNumber, TransactionHash,
5-
};
3+
use crate::entities::{BlockHash, BlockNumber, CardanoTransaction, SlotNumber, TransactionHash};
64

75
/// A block scanned from a Cardano database
86
#[derive(Debug, Clone, PartialEq)]
@@ -13,8 +11,6 @@ pub struct ScannedBlock {
1311
pub block_number: BlockNumber,
1412
/// Slot number of the block
1513
pub slot_number: SlotNumber,
16-
/// Number of the immutable file that own the block
17-
pub immutable_file_number: ImmutableFileNumber,
1814
/// Hashes of the transactions in the block
1915
pub transactions_hashes: Vec<TransactionHash>,
2016
}
@@ -25,22 +21,17 @@ impl ScannedBlock {
2521
block_hash: U,
2622
block_number: BlockNumber,
2723
slot_number: SlotNumber,
28-
immutable_file_number: ImmutableFileNumber,
2924
transaction_hashes: Vec<T>,
3025
) -> Self {
3126
Self {
3227
block_hash: block_hash.into(),
3328
block_number,
3429
slot_number,
35-
immutable_file_number,
3630
transactions_hashes: transaction_hashes.into_iter().map(|h| h.into()).collect(),
3731
}
3832
}
3933

40-
pub(crate) fn convert(
41-
multi_era_block: MultiEraBlock,
42-
immutable_file_number: ImmutableFileNumber,
43-
) -> Self {
34+
pub(crate) fn convert(multi_era_block: MultiEraBlock) -> Self {
4435
let mut transactions = Vec::new();
4536
for tx in &multi_era_block.txs() {
4637
transactions.push(tx.hash().to_string());
@@ -50,7 +41,6 @@ impl ScannedBlock {
5041
multi_era_block.hash().to_string(),
5142
multi_era_block.number(),
5243
multi_era_block.slot(),
53-
immutable_file_number,
5444
transactions,
5545
)
5646
}

mithril-common/src/chain_reader/fake_chain_reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ mod tests {
4848
async fn test_get_next_chain_block() {
4949
let expected_chain_point_next_actions = vec![
5050
ChainBlockNextAction::RollForward {
51-
parsed_block: ScannedBlock::new("hash-1", 1, 10, 20, Vec::<&str>::new()),
51+
parsed_block: ScannedBlock::new("hash-1", 1, 10, Vec::<&str>::new()),
5252
},
5353
ChainBlockNextAction::RollForward {
54-
parsed_block: ScannedBlock::new("hash-2", 2, 11, 21, Vec::<&str>::new()),
54+
parsed_block: ScannedBlock::new("hash-2", 2, 11, Vec::<&str>::new()),
5555
},
5656
ChainBlockNextAction::RollBackward {
5757
slot_number: build_chain_point(1).slot_number,

mithril-common/src/chain_reader/pallas_chain_reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl PallasChainReader {
7070
NextResponse::RollForward(raw_block, _forward_tip) => {
7171
let multi_era_block = MultiEraBlock::decode(&raw_block)
7272
.with_context(|| "PallasChainReader failed to decode raw block")?;
73-
let parsed_block = ScannedBlock::convert(multi_era_block, 0);
73+
let parsed_block = ScannedBlock::convert(multi_era_block);
7474
Ok(Some(ChainBlockNextAction::RollForward { parsed_block }))
7575
}
7676
NextResponse::RollBackward(rollback_point, _) => {
@@ -177,7 +177,7 @@ mod tests {
177177
let raw_block = get_fake_raw_block();
178178
let multi_era_block = MultiEraBlock::decode(&raw_block).unwrap();
179179

180-
ScannedBlock::convert(multi_era_block, 0)
180+
ScannedBlock::convert(multi_era_block)
181181
}
182182

183183
/// Sets up a mock server for related tests.

0 commit comments

Comments
 (0)