Skip to content

chore: fix regression bug#7276

Merged
SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden:sw_fix_regression_bug
Jul 2, 2025
Merged

chore: fix regression bug#7276
SWvheerden merged 2 commits intotari-project:developmentfrom
SWvheerden:sw_fix_regression_bug

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented Jul 2, 2025

Description

Fixes a migration bug introduced in #7266

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling during block reorganization to prevent unnecessary errors when certain entries are missing.
  • Tests

    • Simplified test code by removing redundant cloning of arguments.

@SWvheerden SWvheerden requested a review from a team as a code owner July 2, 2025 12:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 2, 2025

Walkthrough

The updates refine error handling in the LMDB database code by introducing explicit handling for missing PayRef entries during block reorganization. Additionally, test code in the stats collector module is simplified by removing unnecessary cloning of metadata keys. No public interfaces or exported entities are changed.

Changes

File(s) Change Summary
.../lmdb_db/lmdb_db.rs Enhanced error handling in delete_block_inputs_outputs to explicitly handle missing PayRef cases.
.../lmdb_db/stats_collector.rs Removed redundant .clone() calls on MetadataKey in tests; simplified argument passing.

Poem

A bunny hops through code so neat,
Handling errors, never skipping a beat.
No more clones where none are due,
PayRefs checked, as rabbits do.
With logs and tests both clear and bright,
The warren’s code feels just right!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee9f76d and 006e0bc.

📒 Files selected for processing (2)
  • base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (1 hunks)
  • base_layer/core/src/chain_storage/lmdb_db/stats_collector.rs (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: hansieodendaal
PR: tari-project/tari#6963
File: comms/core/src/peer_manager/manager.rs:60-68
Timestamp: 2025-05-26T02:40:23.812Z
Learning: PeerDatabaseSql in the Tari codebase has been specifically refactored to handle concurrent access and mitigate blocking I/O concerns on async executor threads. The implementation has been tested under high load at both system level and through unit tests like test_concurrent_add_or_update_and_get_closest_peers which validates concurrent read/write operations.
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (3)

undefined

<retrieved_learning>
Learnt from: hansieodendaal
PR: #7266
File: base_layer/core/src/chain_storage/blockchain_database.rs:457-461
Timestamp: 2025-06-26T13:18:55.867Z
Learning: The MinedInfo struct in the Tari blockchain database contains two optional fields: input: Option<InputMinedInfo> and output: Option<OutputMinedInfo>. This design allows methods returning MinedInfo to always return a valid struct rather than wrapping it in Option, with "not found" scenarios represented through the internal optional fields.
</retrieved_learning>

<retrieved_learning>
Learnt from: hansieodendaal
PR: #6963
File: common_sqlite/src/error.rs:88-92
Timestamp: 2025-05-23T07:49:57.349Z
Learning: In the StorageError enum in common_sqlite/src/error.rs, the HexError variant should keep the manual From implementation rather than using #[from] attribute, as it stores a String representation of the error rather than the HexError type itself.
</retrieved_learning>

<retrieved_learning>
Learnt from: hansieodendaal
PR: #7123
File: comms/core/src/peer_manager/storage/database.rs:1517-1541
Timestamp: 2025-05-29T09:42:20.881Z
Learning: In the hard_delete_all_stale_peers method in comms/core/src/peer_manager/storage/database.rs, the SQL query intentionally uses exact equality (peers.features = ?) rather than bitwise operations (peers.features & ? != 0) when matching COMMUNICATION_NODE features. This is the intended behavior to match only peers with exactly the COMMUNICATION_NODE feature, excluding those with additional feature flags.
</retrieved_learning>

🧬 Code Graph Analysis (1)
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (2)
base_layer/core/src/chain_storage/lmdb_db/lmdb.rs (1)
  • lmdb_delete (170-183)
base_layer/common_types/src/types/fixed_hash.rs (1)
  • to_hex (141-143)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: file licenses
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: cargo check with stable
  • GitHub Check: ci
🔇 Additional comments (2)
base_layer/core/src/chain_storage/lmdb_db/stats_collector.rs (1)

520-527: No changes required: MetadataKey is Copy

Confirmed that in base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (line 3013), MetadataKey is defined with

#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
pub enum MetadataKey { … }

so it implements Copy and can be reused after passing by value. The test will compile as written without a .clone().

base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (1)

1162-1179: Excellent fix for the PayRef deletion regression during reorg.

This change properly addresses the migration bug by adding explicit error handling for PayRef deletion during block reorganization. The logic is sound:

  1. Success case: Appropriately logs the deletion at debug level
  2. ValueNotFound case: Correctly ignores missing PayRef entries, which can occur during migrations when not all outputs have PayRef entries yet
  3. Other errors: Properly logs and propagates unexpected errors

The fix is targeted and safe - ignoring ValueNotFound errors during PayRef deletion is appropriate since the desired end state (no PayRef entry) is already achieved. The explanatory comment clearly documents why this behavior is acceptable during migrations.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

Copy link
Copy Markdown
Contributor

@MCozhusheck MCozhusheck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, migrating from minotari_node version 4.1.0 started working on this branch build

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 2, 2025

Test Results (CI)

    3 files    126 suites   41m 10s ⏱️
1 367 tests 1 367 ✅ 0 💤 0 ❌
4 099 runs  4 099 ✅ 0 💤 0 ❌

Results for commit 006e0bc.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 2, 2025

Test Results (Integration tests)

 2 files  10 suites   1h 4m 10s ⏱️
33 tests 28 ✅ 2 💤 3 ❌
39 runs  28 ✅ 2 💤 9 ❌

For more details on these failures, see this check.

Results for commit 006e0bc.

@SWvheerden SWvheerden merged commit 4bbc859 into tari-project:development Jul 2, 2025
16 of 17 checks passed
sdbondi added a commit to sdbondi/tari that referenced this pull request Jul 4, 2025
* development:
  chore: fix regression bug (tari-project#7276)
  feat!: expand gRPC readiness status to contain current processed block info (tari-project#7262)
  fix!: payref migration and indexes, add grpc query via output hash (tari-project#7266)
  feat: auto zero value coinbase reward calculation (tari-project#7259)
  feat!: improve grpc token supply (tari-project#7261)
  chore: new release v4.7.0-pre.0 (tari-project#7268)
  fix: get_all_completed_transactions limit issues (tari-project#7267)
  fix: ledger builds (tari-project#7260)
  feat: offline signing (tari-project#7122)
  test: verify accumulated difficulty (tari-project#7243)
@SWvheerden SWvheerden deleted the sw_fix_regression_bug branch July 7, 2025 14:34
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