mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-19 05:35:18 +01:00
# Implement Saga Pattern for Swap Operations with Recovery Mechanism ## Overview This PR refactors the swap operation implementation to use the saga pattern - a distributed transaction pattern that provides reliable transaction management through explicit state tracking and compensation-based error handling. The implementation includes a robust recovery mechanism that automatically handles swap operations interrupted by crashes, power loss, or network failures. ## What Changed **Saga Pattern Implementation:** - Introduced a strict linear state machine for swaps: `Initial` → `SetupComplete` → `Signed` → `Completed` - New modular `swap_saga` module with state validation, compensation logic, and saga orchestration - Automatic rollback of database changes on failure, ensuring atomic swap operations - Replaced previous swap implementation (`swap.rs`, `blinded_message_writer.rs`) with saga-based approach **Recovery Mechanism:** - Added `operation_id` and `operation_kind` columns to database schema for tracking which operation proofs belong to - New `recover_from_bad_swaps()` method that runs on mint startup to handle incomplete swaps - For proofs left in `PENDING` state from swap operations: - If blind signatures exist: marks proofs as `SPENT` (swap completed but not finalized) - If no blind signatures exist: removes proofs from database (swap failed partway through) - Database migrations included for both PostgreSQL and SQLite
33 lines
1023 B
TOML
33 lines
1023 B
TOML
[package]
|
|
name = "cdk-sql-common"
|
|
version.workspace = true
|
|
edition.workspace = true
|
|
authors = ["CDK Developers"]
|
|
description = "Generic SQL storage backend for CDK"
|
|
license.workspace = true
|
|
homepage = "https://github.com/cashubtc/cdk"
|
|
repository = "https://github.com/cashubtc/cdk.git"
|
|
rust-version.workspace = true # MSRV
|
|
readme = "README.md"
|
|
|
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
[features]
|
|
default = ["mint", "wallet", "auth"]
|
|
mint = ["cdk-common/mint"]
|
|
wallet = ["cdk-common/wallet"]
|
|
auth = ["cdk-common/auth"]
|
|
prometheus = ["cdk-prometheus"]
|
|
[dependencies]
|
|
async-trait.workspace = true
|
|
cdk-common = { workspace = true, features = ["test"] }
|
|
cdk-prometheus = { workspace = true, optional = true }
|
|
bitcoin.workspace = true
|
|
thiserror.workspace = true
|
|
tracing.workspace = true
|
|
tokio.workspace = true
|
|
serde.workspace = true
|
|
serde_json.workspace = true
|
|
lightning-invoice.workspace = true
|
|
once_cell.workspace = true
|
|
uuid.workspace = true
|