Skip to content

feat: rename tables, add statuses#54

Merged
sczembor merged 4 commits intomasterfrom
stan/rename-tables
Aug 7, 2025
Merged

feat: rename tables, add statuses#54
sczembor merged 4 commits intomasterfrom
stan/rename-tables

Conversation

@sczembor
Copy link
Contributor

@sczembor sczembor commented Aug 7, 2025

Description

Closes: #52


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included doc comments for public functions
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary

Summary by Sourcery

Introduce persistent status tracking by renaming the processed_blocks and nbtc_txs tables, adding a status column to both schemas, and updating SQL logic to filter and update records by status instead of deleting them. Regenerate worker types with updated configuration.

New Features:

  • Add status column to BTC blocks and nBTC minting tables
  • Rename processed_blocks to btc_blocks and nbtc_txs to nbtc_minting

Enhancements:

  • Convert block and transaction deletion logic to status updates and filter queries by status
  • Update all D1 SQL statements and indexes to reflect renamed tables and new statuses

Build:

  • Regenerate worker-configuration types with updated hash and mnemonic

Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
@sczembor sczembor requested a review from a team as a code owner August 7, 2025 13:53
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 7, 2025

Reviewer's Guide

This PR refactors the database schema by renaming two core tables and introducing explicit status columns for block and minting records; it updates all D1 queries and transaction workflows in the Indexer to reference the new tables and handle status transitions, adjusts the initial max-height lookup, and regenerates the Wrangler type definitions.

Class diagram for Indexer storage and status handling changes

classDiagram
    class Indexer {
        +scanNewBlocks()
        +processFinalizedTransactions()
        +updateConfirmationsAndFinalize(latestHeight)
        +findNbtcDeposits(tx)
        +selectFinalizedNbtcTxs(pendingTxs, latestHeight)
        +update block and minting statuses
    }
    class D1PreparedStatement
    Indexer --> D1PreparedStatement : uses
Loading

File-Level Changes

Change Details Files
Rename tables and extend schema with status columns
  • Renamed processed_blocks to btc_blocks and added status (‘new’
‘scanned’)
  • Renamed nbtc_txs to nbtc_minting and preserved status lifecycle
  • Adjusted timestamp defaults to REAL unixepoch('subsec')
  • Updated indexes to reflect new table names and status column
  • Update Indexer queries and status transitions
    • Modified INSERT/SELECT/UPDATE statements to use btc_blocks and nbtc_minting
    • Replaced DELETE of processed_rows with status updates
    • Added status filtering (e.g. WHERE status = 'new') in scans
    • Updated status transition statements (scanned, confirming, finalized, minted, failed, reorg)
    packages/btcindexer/src/btcindexer.ts
    Adjust initial chain-tip retrieval
    • Changed SELECT MAX(height) to query btc_blocks instead of processed_blocks
    packages/btcindexer/src/index.ts
    Regenerate Wrangler type definitions
    • Updated worker-configuration.d.ts hash header
    • Replaced default SUI_SIGNER_MNEMONIC value
    packages/btcindexer/worker-configuration.d.ts

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link
    Contributor

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

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

    Hey @sczembor - I've reviewed your changes and they look great!


    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    Signed-off-by: sczembor <43810037+sczembor@users.noreply.github.com>
    @robert-zaremba robert-zaremba requested a review from Copilot August 7, 2025 14:31
    Copy link
    Contributor

    Copilot AI left a 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 implements a database schema refactor to support persistent status tracking for Bitcoin block processing and nBTC minting transactions. The changes rename existing tables for clarity and introduce status-based workflow management instead of deletion-based processing.

    • Rename processed_blocks to btc_blocks and nbtc_txs to nbtc_minting for better semantic clarity
    • Add status columns to track processing states instead of deleting records
    • Update all SQL queries and indexes to use the new table names and status-based filtering

    Reviewed Changes

    Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

    File Description
    packages/btcindexer/src/index.ts Update table name reference in latest block query
    packages/btcindexer/src/btcindexer.ts Comprehensive updates to use new table names, status-based filtering, and timestamp functions
    packages/btcindexer/db/migrations/0001_initial_schema.sql Database schema migration with table renames, status columns, and updated indexes

    sczembor and others added 2 commits August 7, 2025 20:31
    Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
    Signed-off-by: sczembor <43810037+sczembor@users.noreply.github.com>
    Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
    @sczembor sczembor merged commit 47d2635 into master Aug 7, 2025
    11 checks passed
    @sczembor sczembor deleted the stan/rename-tables branch August 7, 2025 18:35
    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.

    nbtc indexing: update the d1 to queue and rename

    3 participants