Skip to content

feat: add migrations manager to manage synchronous and asynchronous migrations#7273

Closed
hansieodendaal wants to merge 1 commit intotari-project:developmentfrom
hansieodendaal:ho_migration_manager
Closed

feat: add migrations manager to manage synchronous and asynchronous migrations#7273
hansieodendaal wants to merge 1 commit intotari-project:developmentfrom
hansieodendaal:ho_migration_manager

Conversation

@hansieodendaal
Copy link
Copy Markdown
Contributor

@hansieodendaal hansieodendaal commented Jul 1, 2025

Description

Motivation and Context

How Has This Been Tested?

What process can a PR reviewer use to test or verify this change?

Breaking Changes

  • None
  • Requires data directory on base node to be deleted
  • Requires hard fork
  • Other - Please specify

Summary by CodeRabbit

  • New Features

    • Added the ability to search for payment references using output hashes via a new gRPC method, providing more detailed spent and unspent output metadata.
    • Expanded response details for payment reference lookups, including spent timestamps and output hashes.
  • Bug Fixes

    • Improved handling and clarity of payment reference and mined info retrieval, ensuring more consistent and accurate data.
  • Chores

    • Updated configuration files to allow the new gRPC search method.
    • Enhanced migration framework and index rebuilding for database upgrades.
    • Improved documentation and comments for better clarity.

@hansieodendaal hansieodendaal requested a review from a team as a code owner July 1, 2025 07:12
@hansieodendaal hansieodendaal marked this pull request as draft July 1, 2025 07:12
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 1, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change introduces a new gRPC method for searching payment references via output hash, updates the protocol buffer definitions, and refactors the backend and database interfaces to support unified mined info retrieval by both payment reference and output hash. It also implements a migration framework, updates PayRef index handling, and enhances migration logic and metadata tracking.

Changes

File(s) Change Summary
applications/minotari_app_grpc/proto/base_node.proto Added new RPC method SearchPaymentReferencesViaOutputHash, new fields to PaymentReferenceResponse, and updated comments.
applications/minotari_node/src/grpc/base_node_grpc_server.rs, applications/minotari_node/src/grpc/readiness_grpc_server.rs Implemented new gRPC streaming method for searching payment references via output hash; refactored existing search logic for consistency.
applications/minotari_node/src/grpc_method.rs Added new enum variant for the new gRPC method and updated related logic and tests.
base_layer/core/src/base_node/comms_interface/comms_request.rs, base_layer/core/src/base_node/comms_interface/comms_response.rs, base_layer/core/src/base_node/comms_interface/inbound_handlers.rs Replaced and extended request/response enum variants and handling for mined info queries; updated display implementations.
base_layer/core/src/base_node/comms_interface/local_interface.rs Added async methods for fetching mined info by payref and output hash; updated output mined info fetching to use output hash.
base_layer/core/src/chain_storage/async_db.rs, base_layer/core/src/chain_storage/blockchain_backend.rs, base_layer/core/src/chain_storage/blockchain_database.rs Unified and extended methods for fetching mined info by payref/output hash; updated method signatures and documentation.
base_layer/core/src/chain_storage/error.rs Added migration-related error variants to the error enum.
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs, base_layer/core/src/chain_storage/lmdb_db/migrations.rs, base_layer/core/src/chain_storage/lmdb_db/mod.rs Refactored PayRef index handling, rebuilt migration logic, exposed migration metadata enums, added migration framework module.
base_layer/core/src/chain_storage/lmdb_db/lmdb.rs Added clarifying comment about LMDB put semantics.
base_layer/core/src/chain_storage/utxo_mined_info.rs Introduced new MinedInfo struct aggregating input/output mined data.
base_layer/core/src/test_helpers/blockchain.rs Updated test backend to use new mined info retrieval methods.
base_layer/core/tests/chain_storage_tests/chain_storage.rs, base_layer/core/tests/tests/block_sync.rs, base_layer/core/tests/tests/block_validation.rs, comms/dht/src/connectivity/test.rs Commented or updated logger initialization lines in tests and comments.
common/config/presets/c_base_node_b_mining_allow_methods.toml, common/config/presets/c_base_node_b_non_mining_allow_methods.toml Added or commented new gRPC method to allowed methods in config.
infrastructure/storage/src/lmdb_store/store.rs Corrected how resize threshold is passed in LMDB store.
integration_tests/tests/features/WalletTransactions.feature Updated scenario descriptions to specify "SHA3X mining node".

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BaseNodeGrpcServer
    participant BlockchainDb

    Client->>BaseNodeGrpcServer: SearchPaymentReferencesViaOutputHash(request)
    BaseNodeGrpcServer->>BlockchainDb: fetch_mined_info_by_output_hash(output_hash)
    BlockchainDb-->>BaseNodeGrpcServer: MinedInfo (input/output details)
    BaseNodeGrpcServer-->>Client: stream PaymentReferenceResponse (with spent/unspent metadata)
Loading

Possibly related PRs

  • tari-project/tari#7210: Modifies LMDB database migration logic for PayRef index rebuilding, directly connected to migration handling in this PR.
  • tari-project/tari#7154: Adds the original SearchPaymentReferences RPC and PayRef system, related as both PRs extend payment reference search capabilities.

Suggested reviewers

  • SWvheerden

Poem

In the warren of code, a new tunnel appears,
Search by output hash—now the answer is near!
Mined info united, migrations in tow,
The PayRef index rebuilt, onward we go.
With a hop and a stream, responses do dash—
Hooray for new queries, and output hash!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hansieodendaal hansieodendaal force-pushed the ho_migration_manager branch from 9c3f3b0 to 5e2761d Compare July 1, 2025 07:16
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 1, 2025

Test Results (Integration tests)

 2 files  1 errors  1 suites   15m 14s ⏱️
 8 tests 7 ✅ 0 💤 1 ❌
10 runs  7 ✅ 0 💤 3 ❌

For more details on these parsing errors and failures, see this check.

Results for commit 0035cbe.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 1, 2025

Test Results (CI)

    3 files    126 suites   45m 38s ⏱️
1 367 tests 1 329 ✅ 0 💤  38 ❌
4 099 runs  3 985 ✅ 0 💤 114 ❌

For more details on these failures, see this check.

Results for commit 0035cbe.

♻️ This comment has been updated with latest results.

@hansieodendaal hansieodendaal force-pushed the ho_migration_manager branch from 5e2761d to 773a1d1 Compare July 2, 2025 06:58
Added a migrations manager to manage migrations. This also enables asynchronous
migration steps.
@hansieodendaal hansieodendaal force-pushed the ho_migration_manager branch from 773a1d1 to 0035cbe Compare July 2, 2025 13:58
@hansieodendaal
Copy link
Copy Markdown
Contributor Author

hansieodendaal commented Jul 2, 2025

This is the wrong approach as the way we implemented lmdb we do not have proper read/write locks in the backend. Adding or re-building payref indexes is also going to be declassified as a migration and will be moved and run in the domain application layer once the blockchain database is properly built and has started.

As per discussion witn @SWvheerden and @sdbondi.

@SWvheerden
Copy link
Copy Markdown
Collaborator

*not application layer, domain layer
Application layer = minotari_node, console_wallet etc

@hansieodendaal hansieodendaal deleted the ho_migration_manager branch August 14, 2025 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants