-
Notifications
You must be signed in to change notification settings - Fork 52
feat: compute and persist blocks transactions block range roots #2995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Test Results 5 files ± 0 172 suites ±0 39m 42s ⏱️ ±0s Results for commit 95e8736. ± Comparison against base commit 78d4c0d. This pull request removes 9 and adds 73 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
internal/mithril-persistence/src/database/query/block_range_root/delete_block_range_root.rs
Outdated
Show resolved
Hide resolved
internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs
Outdated
Show resolved
Hide resolved
internal/mithril-persistence/src/database/repository/cardano_transaction_repository.rs
Show resolved
Hide resolved
internal/mithril-persistence/src/database/query/block_range_root/insert_block_range.rs
Outdated
Show resolved
Hide resolved
internal/mithril-persistence/src/database/query/block_range_root/get_block_range_root.rs
Outdated
Show resolved
Hide resolved
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
058d476 to
3e48a76
Compare
… 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.
3e48a76 to
95e8736
Compare
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