feat: compute and persist blocks transactions block range roots#2995
Conversation
Test Results 5 files ± 0 172 suites ±0 39m 18s ⏱️ - 1m 35s Results for commit 212ec7b. ± Comparison against base commit e3edf71. This pull request removes 10 and adds 74 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for computing and persisting block-range Merkle roots for CardanoBlocksTransactions (in addition to the existing legacy CardanoTransactions roots), including new leaf types, persistence queries/records, and importer logic that computes + stores both root sets.
Changes:
- Introduce
CardanoBlockTransactionMkTreeNodeand related conversions to generate sortable Merkle leaves for blocks + transactions. - Extend the chain importer/store API to compute & persist new block-range roots, while still computing legacy roots.
- Add persistence-layer records + queries for the new
block_range_roottable and for retrieving blocks-with-transactions projections.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| mithril-common/src/entities/cardano_block.rs | Adds CardanoBlockTransactionMkTreeNode, leaf identifiers, and ordering for deterministic Merkle leaves. |
| mithril-common/src/crypto_helper/merkle_tree.rs | Adds MKTree::new_from_iter to build trees from iterators (used by new block/tx leaf sets). |
| internal/cardano-node/mithril-cardano-node-chain/src/chain_importer/api.rs | Extends ChainDataStore with APIs to fetch block+tx leaves and store new block-range roots. |
| internal/cardano-node/mithril-cardano-node-chain/src/chain_importer/block_ranges_importer.rs | Computes/stores new CardanoBlocksTransactions block-range roots and still computes legacy roots. |
| internal/cardano-node/mithril-cardano-node-chain/src/chain_importer/service.rs | Runs both new and legacy block-range root computations during import. |
| internal/cardano-node/mithril-cardano-node-chain/src/test/double/chain_data_store.rs | Updates in-memory store + tests for new block-range roots and block+tx retrieval. |
| internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs | Adds new root CRUD and retrieval of blocks-with-transactions; updates prune threshold logic to consider both root tables. |
| internal/mithril-persistence/src/database/record/cardano_block_transactions.rs | New record type for hydrated blocks + aggregated tx hashes and conversion to Merkle leaves. |
| internal/mithril-persistence/src/database/record/mod.rs | Exports new CardanoBlockTransactionsRecord. |
| internal/mithril-persistence/src/database/query/mod.rs | Wires in new block-range-root query module. |
| internal/mithril-persistence/src/database/query/block_range_root/* | Adds insert/get/delete queries for the new block_range_root table. |
| internal/mithril-persistence/src/database/query/cardano_block/mod.rs | Exposes new “get blocks with txs” query. |
| internal/mithril-persistence/src/database/query/cardano_block/get_cardano_block_with_transactions.rs | Adds query to fetch blocks and group-concat their tx hashes. |
| mithril-aggregator/src/database/repository/cardano_transaction_repository.rs | Implements new ChainDataStore methods via persistence repository. |
| mithril-signer/src/database/repository/cardano_transaction_repository.rs | Implements new ChainDataStore methods via persistence repository. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
058d476 to
3e48a76
Compare
3e48a76 to
95e8736
Compare
A type designed to be used to bridge the gap between a list of blocks and transactions extracted from a datasource and the Merkle Tree that will be used to compute their merkle root (grouped by block range).
…new block ranges in `ChainDataStore`
Allowing buidling of `MkTree` from any iterators instead of only the collections that can be sliced (supporting `BTreeSet` which is needed for `CardanoBlocksTransactions`).
…CardanoBlocksTransactions block ranges
… root Also make `CardanoTransactionRepository` remove the new block range roots on rollback.
…tory The `LegacyBlockRangeRootRetriever` impl can be removed since it's not used anymore, instead its the signer and aggregator transactions repository wrappers that implement it.
… "new" block range roots table The pruning remove all blocks and transactions below the highest stored legacy block range root. With the addition of a "new" block ranger roots table the pruning is updated to only delete data that have been computed into BOTH block ranges roots tables.
- better, more clear, naming for some symbols - add `BLOCK_RANGE_BATCH_SIZE` constant in `BlockRangeImporter`
95e8736 to
b91cbec
Compare
* mithril-cardano-node-chain from `0.1.19` to `0.1.20` * mithril-persistence from `0.2.63` to `0.2.64` * mithril-aggregator from `0.8.21` to `0.8.22` * mithril-common from `0.6.48` to `0.6.49` * mithril-signer from `0.3.14` to `0.3.15`
Content
This PR:
CardanoBlockTransactionMkTreeNodeinmithril-common, a type that represent a leaf of the merkle tree forCardanoBlocksTransactionsblock ranges roots and can be sorted.ChainDataImporterininternal/mithril-cardano-node-chaincompute and send to persistence the block ranges roots forCardanoBlocksTransactionsinternal/mithril-persistenceto store/retrieveCardanoBlocksTransactionsblock ranges roots and retrieveCardanoBlockTransactionMkTreeNodeImportant
The threshold for pruning data with the
ChainDataImporterWithPrunerhad to be updated to take in account that there's now two tables for block ranges roots (one "legacy" forCardanoTransactionsand one "new" forCardanoBlocksTransactions).The pruner prune data that have already be computed into block ranges roots, but now with two table we have to ensure that this computation was done for both so the threshold was modified to be "the minimum between the highest start block number of the 'new' and the 'legacy' stored block range roots" (before it was simply "the highest start block number stored in the legacy block range roots").
Details
mithril-commonCardanoBlockTransactionMkTreeNode:MKTreeNodeto compute block range roots forCardanoBlocksTransactionsMKTree::new_from_iterto allow construction from anyIntoIterator, as the existingnewworks only with types that can be sliced, which is not the case ofBTreeSet(the collection used when retrievingCardanoBlockTransactionMkTreeNodefrom the database).mithril-cardano-node-chainChainDataStore: addget_highest_block_range,get_blocks_and_transactions_in_range, andstore_block_range_rootsBlockRangeImporter:runmethod torun_legacyrunthat compute block ranges roots based on storedCardanoBlocksTransactionsmithril-persistenceCardanoBlockTransactionsRecordCardanoBlockTransactionsRecordfrom the sqlite databaseBlockRangeRootRecordcomputed fromCardanoBlocksTransactionsand stored in theblock_range_roottable (copied from the existing 'legacy' queries)CardanoTransactionRepository:CardanoBlockTransactionsRecordand theBlockRangeRootRecordforCardanoBlocksTransactionsget_highest_start_block_number_for_legacy_block_range_rootstoget_prune_blocks_thresholdand update it in the light of the fact that there's two block range roots tables.Pre-submit checklist
Issue(s)
Relates to #2908