Skip to content

Commit c7c0f67

Browse files
committed
Reduce compute block range roots footprints
By only loading a block range worth of transactions from db instead of loading them all at once.
1 parent eca2aa1 commit c7c0f67

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

mithril-signer/src/cardano_transactions_importer.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,16 @@ impl CardanoTransactionsImporter {
139139
if block_ranges.is_empty() {
140140
return Ok(());
141141
}
142-
let start = block_ranges[0].start;
143-
let end = block_ranges[block_ranges.len() - 1].end;
144-
145-
let transactions: Vec<CardanoTransaction> = self
146-
.transaction_store
147-
.get_transactions_between(start..=end)
148-
.await?;
149-
150-
let block_ranges_with_merkle_root: Vec<(BlockRange, MKTreeNode)> = block_ranges
151-
.into_iter()
152-
.map(|range| {
153-
let transactions_in_range = transactions
154-
.iter()
155-
.filter(|t| range.contains(&t.block_number))
156-
.map(|t| t.transaction_hash.clone())
157-
.collect::<Vec<_>>();
158-
let merkle_root = MKTree::new(&transactions_in_range)?.compute_root()?;
159-
Ok((range, merkle_root))
160-
})
161-
.collect::<StdResult<_>>()?;
142+
143+
let mut block_ranges_with_merkle_root: Vec<(BlockRange, MKTreeNode)> = vec![];
144+
for block_range in block_ranges {
145+
let transactions = self
146+
.transaction_store
147+
.get_transactions_between(block_range.start..=(block_range.end - 1))
148+
.await?;
149+
let merkle_root = MKTree::new(&transactions)?.compute_root()?;
150+
block_ranges_with_merkle_root.push((block_range, merkle_root));
151+
}
162152

163153
self.transaction_store
164154
.store_block_ranges(block_ranges_with_merkle_root)

0 commit comments

Comments
 (0)