Skip to content

fix: re-sync exchange transactions after later status changes#3752

Draft
TaprootFreak wants to merge 4 commits into
developfrom
fix/exchange-tx-status-sync
Draft

fix: re-sync exchange transactions after later status changes#3752
TaprootFreak wants to merge 4 commits into
developfrom
fix/exchange-tx-status-sync

Conversation

@TaprootFreak
Copy link
Copy Markdown
Collaborator

Summary

Exchange transaction (exchange_tx) rows could get permanently stuck on status='failed' even after the exchange later confirmed the transaction (Completed). The later status change was never persisted, leaving downstream balance reporting with phantom pending entries.

Root cause: the hourly cleanupStalePendingDeposits job flips long-pending deposits to failed. getSyncSinceDate then computed the re-sync window only from pending rows — once a transaction was flipped to failed it no longer kept the window open, fell outside the fetch window, and a later Completed event from the exchange was never re-fetched or persisted.

Changes

  • getSyncSinceDate now widens the re-sync window from transactions in status In ('pending', 'failed'), bounded by a new exchangeTxSyncRecheckDays horizon (default 7 days, env-overridable) so the window cannot grow unbounded.
  • Added EXCHANGE_TX_SYNC_RECHECK_DAYS to config and .env.example.
  • Added exchange-tx.service.spec.ts covering getSyncSinceDate (query construction + window arithmetic).

Test plan

  • lint, format check, type-check, build pass
  • New exchange-tx.service.spec.ts passes (4 tests)
  • Verify on DEV that a deposit confirmed after the stale-cleanup flip is re-synced to ok

Exchange transaction status updates were not persisted on a later sync
once a row left the 'pending' state. The sync window (getSyncSinceDate)
only widened for still-pending transactions, so a deposit that was
flipped to 'failed' by the local stale-pending cleanup never re-entered
the fetch window and a subsequent confirmation on the exchange was lost.

Widen the sync window to also cover recently-failed transactions within
a bounded re-check horizon, so a status change on the exchange reliably
reaches the database.
Add a regression spec for getSyncSinceDate, the .env.example entry for
EXCHANGE_TX_SYNC_RECHECK_DAYS, and a comment clarifying that the recheck
horizon is keyed on externalCreated to align with getAllTransactions.
Rework the getSyncSinceDate spec so it genuinely covers the fix
instead of re-implementing the WHERE clause in the mock. The query
test now captures the findOne argument and asserts the status and
externalCreated predicates, and the date-logic tests mock a fixed
result without re-deriving the filter. Adopt the standard
Test.createTestingModule setup used across the repo.
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.

1 participant