Skip to content

Conversation

@Klakurka
Copy link
Member

@Klakurka Klakurka commented Jan 5, 2026

Description

To be able to properly save orphaned txs, we need to have an orphaned column, which this adds.

Test plan

For now, it's sufficient to make sure things are just running as expected after adding the db column. We'll be utilizing this in a follow-up branch.

Summary by CodeRabbit

  • New Features
    • Added orphaned status tracking for transactions to monitor their validation state.
    • Transactions that cannot be found during confirmation are now automatically marked as orphaned.
    • Enhanced transaction confirmation process with improved error handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@Klakurka Klakurka requested review from chedieck and lissavxo January 5, 2026 01:29
@Klakurka Klakurka self-assigned this Jan 5, 2026
@Klakurka Klakurka added the enhancement (UI/UX/feature) New feature or request label Jan 5, 2026
@Klakurka Klakurka removed the request for review from chedieck January 5, 2026 01:29
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

📝 Walkthrough

Walkthrough

This pull request introduces a new orphaned column to the Transaction table, adds a new service function to mark transactions as orphaned, and integrates orphaned transaction handling into the TX_CONFIRMED error path when a 404 response is encountered.

Changes

Cohort / File(s) Summary
Database Schema Updates
prisma-local/migrations/20260104000000_transaction_orphaned_column/migration.sql, prisma-local/schema.prisma
Adds a non-null orphaned boolean column to the Transaction table with a default value of false; updates Prisma model to reflect schema addition.
Transaction Service
services/transactionService.ts
Introduces new exported function markTransactionsOrphaned(hash: string) that updates all transactions with a given hash to set orphaned to true.
Chronik Service Integration
services/chronikService.ts
Imports and integrates markTransactionsOrphaned into TX_CONFIRMED error handling; when a 404 error is caught, calls markTransactionsOrphaned(msg.txid) before logging; preserves existing error handling for non-404 errors.

Sequence Diagram

sequenceDiagram
    participant ChronikService
    participant TransactionService
    participant Database

    ChronikService->>ChronikService: Receive TX_CONFIRMED event
    ChronikService->>Database: Attempt transaction confirmation
    Database-->>ChronikService: 404 Not Found Error
    ChronikService->>TransactionService: markTransactionsOrphaned(txid)
    TransactionService->>Database: UPDATE Transaction SET orphaned=true WHERE hash=txid
    Database-->>TransactionService: Confirmation
    TransactionService-->>ChronikService: Return
    ChronikService->>ChronikService: Log orphaned transaction
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A column hops into the table with care,
When transactions get lost in the air,
We mark them orphaned, with boolean grace,
404 finds its rightful place!
bounces

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required Description and Test plan sections with adequate detail about the purpose and verification approach, though it lacks the 'Related to #' issue reference.
Title check ✅ Passed The title 'feat: added tx orphaning' clearly and concisely summarizes the main change: adding transaction orphaning functionality. It accurately reflects the primary objective of enabling orphaned transaction handling.
✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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 (3)
services/transactionService.ts (1)

632-641: Consider returning the update count for observability.

The implementation is correct, but returning the count of affected transactions would aid debugging and logging. Additionally, consider adding a log statement to track orphaning events.

🔎 Proposed enhancement
-export async function markTransactionsOrphaned (hash: string): Promise<void> {
-  await prisma.transaction.updateMany({
+export async function markTransactionsOrphaned (hash: string): Promise<number> {
+  const result = await prisma.transaction.updateMany({
     where: {
       hash
     },
     data: {
       orphaned: true
     }
   })
+  if (result.count > 0) {
+    console.log(`[TX] Marked ${result.count} transaction(s) as orphaned for hash ${hash}`)
+  }
+  return result.count
 }
services/chronikService.ts (2)

636-644: Consider wrapping the orphan-marking call in a try-catch.

If markTransactionsOrphaned fails (e.g., database connectivity issue), the error will propagate silently since the outer catch block has already handled the 404. This could leave transactions in an inconsistent state without proper logging.

🔎 Proposed fix
         } catch (e: any) {
           const msg404 = String(e?.message ?? e)
           const is404 = /not found in the index|404/.test(msg404)
           if (is404) {
             console.log(`${this.CHRONIK_MSG_PREFIX}: [${msg.msgType}] tx ${msg.txid} not found in chronik, marking as orphaned`)
-            await markTransactionsOrphaned(msg.txid)
+            try {
+              await markTransactionsOrphaned(msg.txid)
+            } catch (orphanErr: any) {
+              console.error(`${this.CHRONIK_MSG_PREFIX}: failed to mark tx ${msg.txid} as orphaned`, orphanErr)
+            }
           } else {
             console.error(`${this.CHRONIK_MSG_PREFIX}: confirmed tx handler failed for ${msg.txid}`, e)
           }
         }

637-638: Consider extracting the 404 detection pattern.

The regex /not found in the index|404/ is duplicated (also at line 601). Consider extracting it as a constant or helper function. Also, the variable msg404 is misleading since it holds the full error message, not specifically a 404 message.

🔎 Proposed refactor
+const NOT_FOUND_PATTERN = /not found in the index|404/
+
+const isNotFoundError = (err: any): boolean => {
+  const message = String(err?.message ?? err)
+  return NOT_FOUND_PATTERN.test(message)
+}

 // Then in fetchTxWithRetry (line 601):
-        const is404 = /not found in the index|404/.test(msg)
+        const is404 = isNotFoundError(e)

 // And in TX_CONFIRMED handler:
         } catch (e: any) {
-          const msg404 = String(e?.message ?? e)
-          const is404 = /not found in the index|404/.test(msg404)
+          const is404 = isNotFoundError(e)
           if (is404) {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1025cd2 and 615910d.

📒 Files selected for processing (4)
  • prisma-local/migrations/20260104000000_transaction_orphaned_column/migration.sql
  • prisma-local/schema.prisma
  • services/chronikService.ts
  • services/transactionService.ts
🧰 Additional context used
🧬 Code graph analysis (1)
services/chronikService.ts (1)
services/transactionService.ts (1)
  • markTransactionsOrphaned (632-641)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run Tests
🔇 Additional comments (3)
prisma-local/schema.prisma (1)

74-74: Schema change looks good.

The new orphaned field with @default(false) is correctly defined. If future queries frequently filter by orphaned status, consider adding an index.

prisma-local/migrations/20260104000000_transaction_orphaned_column/migration.sql (1)

1-2: Migration is correct and safe.

The migration correctly adds the orphaned column with NOT NULL DEFAULT false, ensuring existing transactions remain unaffected.

services/chronikService.ts (1)

11-11: Import added correctly.

@Klakurka Klakurka changed the title Added tx orphaning feat: added tx orphaning Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement (UI/UX/feature) New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants