Skip to content
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

feat: add migration to remove bad blocks #6803

Merged

Conversation

stringhandler
Copy link
Collaborator

@stringhandler stringhandler commented Feb 18, 2025

Adds a migration to clear the bad blocks table. This should be done in future for any bug fixes that cause bad blocks

Summary by CodeRabbit

  • Bug Fixes
    • Improved the update process to manage legacy data more effectively. By addressing known data inconsistencies, the system now clears problematic records during updates, enhancing overall reliability and performance. End-users should experience smoother transitions and improved consistency, ensuring a more robust experience. This enhancement is part of our ongoing effort to optimize performance and maintain data integrity.
  • Improvements
    • Updated migration logic to enhance the handling of bad blocks, ensuring better data integrity during version updates.

@stringhandler stringhandler requested a review from a team as a code owner February 18, 2025 13:04
Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

The changes update the migration process in the LMDB database by modifying the migration version constant from 1 to 2. A new conditional block checks if the current migration version is less than 2 and, if so, clears the bad blocks list in a write transaction and logs the operation. Finally, the migration version is updated in the metadata database along with additional log statements to provide more clarity during the migration.

Changes

File(s) Change Summary
base_layer/.../lmdb_db.rs Updated migration version constant from 1 to 2. Added a conditional block in run_migrations to clear the bad blocks list with a write transaction, log the affected rows, and update the migration version in the metadata database.

Sequence Diagram(s)

sequenceDiagram
    participant RM as run_migrations
    participant WT as Write Transaction
    participant MD as Metadata DB
    participant LOG as Logger

    RM->>RM: Check current migration version
    alt Migration version < 2
        RM->>WT: Begin transaction to clear bad blocks list
        WT->>LOG: Log number of rows cleared
        RM->>MD: Update migration version to 2
    else
        RM->>LOG: Log that no migration is needed
    end
Loading

Poem

I’m a bunny on a coding spree,
Clearing bad blocks with a hop and a glee.
Version 2 now leads the way,
Logging each step in a bright display.
Here’s to changes in the byte-sized land,
A fluffy leap where logic is grand!


📜 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 c558154 and aaada12.

📒 Files selected for processing (1)
  • base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: cargo check with stable
  • GitHub Check: clippy

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (1)

2893-2900: LGTM! Well-structured migration with proper transaction handling.

The migration logic is well-implemented with:

  • Atomic transaction for clearing bad blocks
  • Proper version check and update
  • Informative logging of the operation

Consider adding error logging to help with debugging if the migration fails.

Add error logging before returning errors:

 let txn = db.write_transaction()?;
 info!(target: LOG_TARGET, "Clearing bad blocks list due to median timestamp bug in nextnet");
-let rows_affected = lmdb_clear(&txn, &db.bad_blocks)?;
+let rows_affected = match lmdb_clear(&txn, &db.bad_blocks) {
+    Ok(count) => count,
+    Err(e) => {
+        error!(target: LOG_TARGET, "Failed to clear bad blocks: {}", e);
+        return Err(e);
+    }
+};
 txn.commit()?;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11d9926 and c558154.

📒 Files selected for processing (1)
  • base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test (mainnet, stagenet)
  • GitHub Check: machete
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: clippy
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: cargo check with stable
🔇 Additional comments (1)
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (1)

2876-2876: LGTM! Migration version increment.

The increment of MIGRATION_VERSION from 1 to 2 is appropriate for introducing a new migration.

Copy link

Test Results (CI)

1 039 tests   1 038 ✅  10m 4s ⏱️
   29 suites      0 💤
    1 files        1 ❌

For more details on these failures, see this check.

Results for commit aaada12.

@SWvheerden SWvheerden merged commit 26a8fec into tari-project:development Feb 18, 2025
11 of 15 checks passed
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