Skip to content

Conversation

@Rcc999
Copy link
Contributor

@Rcc999 Rcc999 commented Oct 28, 2025

Description

Closes: #137

Research on the possible scenarios:

Without digest: Pre-submission errors (network failures, invalid transactions, RPC timeouts) - transaction never reached Sui network.
With digest: Execution errors (insufficient gas, object conflicts, Move runtime errors, wrong package_id call ..) - transaction was submitted and assigned a digest but failed during execution.


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

Record and propagate Sui transaction digests for batch mint operations, including capturing and storing the digest on failures

New Features:

  • Persist failed Sui transaction digest in the database when a mint operation finalizes as failed

Enhancements:

  • Refactor SuiClient to return structured {success, digest} results and attach digest to thrown errors
  • Update Indexer to interpret structured mint results, set status and record suiTxDigest for both successes and failures
  • Extend CFStorage update statements to include sui_tx_id for both minted and failed records

Tests:

  • Add a test verifying that failed transaction digest is captured and stored in the DB

@Rcc999 Rcc999 requested a review from a team as a code owner October 28, 2025 13:49
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 28, 2025

Reviewer's Guide

This PR refactors the Sui minting client to return structured success/digest results, updates the indexer and storage layers to persist failed transaction digests and statuses, and adjusts tests to accommodate and verify the new failure handling logic.

ER diagram for nbtc_minting table updates

erDiagram
NBTC_MINTING {
  tx_id varchar
  vout int
  block_hash varchar
  block_height int
  sui_recipient varchar
  amount_sats int
  status varchar
  created_at int
  updated_at int
  retry_count int
  sui_tx_id varchar
}
Loading

Class diagram for updated SuiClient minting methods

classDiagram
class SuiClient {
  +mintNbtc(transaction, blockHeight, txIndex, proof): SuiTxDigest
  +tryMintNbtc(transaction, blockHeight, txIndex, proof): SuiTxResult
  +mintNbtcBatch(mintArgs): SuiTxDigest
  +tryMintNbtcBatch(mintArgs): SuiTxResult
}
class SuiTransactionError {
  +suiTxDigest: string
}
class SuiTxResult {
  +success: boolean
  +digest: string
}
SuiClient --> SuiTransactionError
SuiClient --> SuiTxResult
Loading

Class diagram for updated Indexer.processFinalizedTransactions logic

classDiagram
class Indexer {
  +processFinalizedTransactions()
}
Indexer --> SuiClient : uses
Indexer --> Storage : uses
Loading

Class diagram for updated CFStorage.batchUpdateNbtcTxs method

classDiagram
class CFStorage {
  +batchUpdateNbtcTxs(updates)
}
CFStorage --> D1Database : uses
Loading

File-Level Changes

Change Details Files
Enhanced SuiClient to return structured results and capture digests on errors
  • mintNbtc and mintNbtcBatch now return the transaction digest and attach it to thrown errors
  • tryMintNbtc and tryMintNbtcBatch updated to return { success, digest } instead of boolean or raw digest
  • Error logging now includes the captured suiTxDigest from failures
packages/btcindexer/src/sui_client.ts
Updated indexer logic to handle structured mint results and record failures
  • Consume result.success and result.digest to determine status and digest
  • Set status to MINTED or FINALIZED_FAILED based on success flag
  • Pass sui_tx_id to batchUpdateNbtcTxs and include in logs
packages/btcindexer/src/btcindexer.ts
Persist sui_tx_id on both success and failure in CFStorage
  • Extended SQL update statements to include sui_tx_id for minted and failed cases
  • Bind sui_tx_id parameter and increment retry_count on failures
packages/btcindexer/src/cf-storage.ts
Adjusted tests for the new structured return type and added failure-case coverage
  • Updated mocks in btcindexer tests to return { success, digest }
  • Replaced raw digest expectations with object-based success/digest checks
  • Added a new test to verify storing failed sui_tx_id and status update
packages/btcindexer/src/btcindexer.test.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#137 Store failed Sui transaction IDs (digests) in the database when a mint transaction is finalized as failed.

Possibly linked issues


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

@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 there - 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.

Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

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

we should continue using tryMintNbtcBatch and handle the results there, and return a tuple (succes | failure, txDigest |null). And then the invoking funciton should decide what to do with it

Signed-off-by: Rayane Charif <[email protected]>
Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

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

the logic is incorrect

Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

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

The error handling is still not clear, its a little bit too complex, which is not needed. We already inspect the effects. Please take a look at what the code already does

Signed-off-by: Rayane Charif <[email protected]>
Signed-off-by: Rayane Charif <[email protected]>
Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

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

left few comments

Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

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

this is still incorrect, we treat all on chain aborts as successful mints

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.

indexer: add failed sui tx to the database for easier debugging

3 participants