Skip to content

feat: implement Melt SAGA pattern for atomic melt operations#875

Draft
a1denvalu3 wants to merge 1 commit intocashubtc:mainfrom
a1denvalu3:feat/melt-saga
Draft

feat: implement Melt SAGA pattern for atomic melt operations#875
a1denvalu3 wants to merge 1 commit intocashubtc:mainfrom
a1denvalu3:feat/melt-saga

Conversation

@a1denvalu3
Copy link
Collaborator

Summary

This PR implements the SAGA pattern for melt operations to ensure atomicity and crash recovery. It introduces a state machine (MeltSaga) that persists the operation state before and after critical side effects (Lightning payments).

Changes

  • cashu/mint/melt_saga.py: Added MeltSaga class handling the Setup -> Payment -> Finalize/Compensate lifecycle.
  • cashu/mint/ledger.py:
    • Refactored melt() to use MeltSaga.
    • Added recover_incomplete_melt_sagas() to check for and recover/rollback incomplete operations on startup.
  • cashu/core/base.py: Added MeltSagaState enum and Saga model.
  • cashu/mint/migrations.py: Added database migration for saga_state table.
  • Tests: Added comprehensive tests in tests/mint/test_mint_melt_saga.py.

Motivation

To prevent inconsistent states (e.g., proofs spent but invoice unpaid, or invoice paid but proofs unspent) in case of mint crashes or network failures during the melt process.

@github-project-automation github-project-automation bot moved this to Backlog in nutshell Jan 21, 2026
@a1denvalu3 a1denvalu3 marked this pull request as draft January 21, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant