Commit graph

114 commits

Author SHA1 Message Date
Slyghtning
6cb54edf06
openchannel: optimize open channel request creation and err handling 2026-02-26 20:57:28 +01:00
Slyghtning
cd377f35f8
openchannel: recover deposits at runtime after PSBT finalize failure
If the PSBT finalize step succeeds but the stream fails before
ChanPending, deposits would remain stuck in OpeningChannel until the
next daemon restart. Run the recovery logic immediately so deposits are
resolved without requiring a restart.

Also, add tests for the following edge cases requested in review:

- Reorg: channel tx reorged, UTXOs reappear as unspent, deposits
  return to Deposited state.
- Daemon restart during channel opening: deposits in OpeningChannel
  recovered based on UTXO status (spent → ChannelPublished, unspent →
  Deposited).
- Mempool eviction: tx evicted, UTXOs unspent, deposits return to
  Deposited.
- Mempool rejection: tx never accepted, same recovery as eviction.
- Stream errors: lnd stream fails before PSBT finalize, error returned
  without errPsbtFinalized so deposits can be safely rolled back.
- PSBT finalize then stream abort: finalize succeeds but stream dies
  before ChanPending, error wrapped with errPsbtFinalized so caller
  triggers recovery instead of blind rollback.
- Duplicate outpoints: already covered by TestOpenChannelDuplicateOutpoints.
2026-02-26 20:57:27 +01:00
Slyghtning
e710ea5e8f
openchannel: reject duplicate outpoints in open channel request
Duplicate outpoints in the request lead to fee miscalculation and an
invalid PSBT with the same input listed twice. Validate early and return
a clear error message.
2026-02-26 20:57:27 +01:00
Slyghtning
dbac12ed78
deposit: add OnExpiry self-transitions to OpeningChannel and ChannelPublished
Both OpeningChannel and ChannelPublished lacked OnExpiry transitions.
handleBlockNotification fires OnExpiry on every new block once the
deposit is expired, regardless of the current state. Since both states
use NoOpAction or FinalizeDepositAction which release the FSM mutex
briefly, an OnExpiry SendEvent can sneak in. Add self-transitions so
the event is safely absorbed.
2026-02-26 20:57:27 +01:00
Slyghtning
52d884cec1
openchannel: return error on hash creation failure
Return an error instead of just logging when chainhash.NewHash fails in
the ChanPending handler. The hash variable would be nil and crash on the
subsequent String() call.
2026-02-26 20:57:27 +01:00
Slyghtning
eaf7883bcf
openchannel: fix shimPending data race
Protect the shimPending variable with a sync.Mutex since it is accessed
from multiple goroutines: the main loop goroutine and the server error
handling goroutine. Without synchronization this is a data race.
2026-02-26 20:57:27 +01:00
Slyghtning
b74dab8af4
loopd: instantiate static address open channel manager 2026-02-26 20:57:27 +01:00
Slyghtning
63097ee220
staticaddr: close quit channel only once 2026-02-26 20:57:26 +01:00
Slyghtning
dfc75f2e1a
staticaddr: open channel manager 2026-02-26 20:57:26 +01:00
Slyghtning
d12663ea7c
staticaddr: channel open states for deposit and fsm 2026-02-26 20:57:26 +01:00
Slyghtning
81012de948
staticaddr: replace block-based deposit detection with polling
Block-based deposit fetching from the internal lnd wallet was
susceptible to wallet syncing issues. Replace it with interval-based
polling. Reconciliation errors are now logged instead of being fatal,
improving resilience during transient failures.
2026-02-26 20:57:26 +01:00
Slyghtning
f1c138abf5
deposit: remove dead code in reconcileDeposits
Remove unreachable error check after filterNewDeposits which does not
return an error. The err variable was already handled from the
ListUnspent call above and could never be non-nil at this point.
2026-02-26 20:57:26 +01:00
Boris Nagaev
0b53296aa8
multi: factor out sweep fee clamping function 2026-01-15 03:06:22 -05:00
Boris Nagaev
258d33cce5
staticaddr: clear stale HTLC confs on re-register
- reset htlcConfirmed when the HTLC conf subscription errors and we re-register
- add regression test ensuring re-registers after a conf error require a fresh
  confirmation instead of sweeping on a stale one
2025-12-17 10:11:30 +01:00
Boris Nagaev
f274c689b1
staticaddr: add unit test for HTLC re-registration 2025-12-17 09:21:51 +01:00
Slyghtning
1dd145bc32
staticaddr: re-register on htlc tx conf error 2025-12-17 09:21:51 +01:00
Slyghtning
780584993b
staticaddr: unit test CalculateWithdrawalTxValues 2025-12-09 12:21:51 +01:00
Slyghtning
880694c8df
staticaddr: harden and test signMusig2Tx 2025-12-09 12:21:51 +01:00
Slyghtning
078399da80
staticaddr: replace ServerWithdrawDeposits rpc /w ServerPsbtWithdrawDeposits 2025-12-09 12:21:51 +01:00
Slyghtning
a918842374
staticutil: refactor methods into utils 2025-12-09 12:21:51 +01:00
Boris Nagaev
6d480cfd9e
staticaddr: require positive heights at startup
Loop now guards all static-address managers against zero block heights: each
constructor returns an error when invoked with a non-positive current height,
and `loopd` validates the height from `GetInfo` before instantiating them.
Tests and helper code were updated accordingly so we fail fast instead of
registering chain notifications with invalid hints.
2025-11-16 01:24:01 -03:00
Boris Nagaev
deced54665
staticaddr/withdraw: make error log unique
Make it easier to distinguish this error from a similar error few lines above.
2025-11-16 00:26:02 -03:00
Slyghtning
152385885f
staticaddr: exclude close-to-expiry depositis from SelectDeposits 2025-10-08 16:24:46 +02:00
Slyghtning
9f57c8ee01
loopin: add loop-in constants to filter expired deposits 2025-10-08 11:38:37 +02:00
Slyghtning
51258af025
staticaddr: fast-flag support
--fast allows the client to expedite the publishing
of on-chain swap transactions with change, e.g. if --amount was specified.
2025-10-07 08:53:39 +02:00
Slyghtning
55081cd8fe
staticaddr: ignoreUnknown flag for DepositsForOutpoints 2025-09-26 12:03:48 +02:00
Slyghtning
a877cfdc4c
staticaddr: checkChange method for sweep signing 2025-09-25 11:13:35 +02:00
Slyghtning
2ee772b251
staticaddr: selected swap amount migration
The selected_amount column of all previous
swaps is filled with the total value of
deposits that partook in these swaps.
2025-09-25 11:13:35 +02:00
Slyghtning
581761a12f
staticaddr: arbitrary loop-in amount
In this commit we add a new function SelectDeposits
to the loop-in manager. It coin-selects deposits that
meet an arbitrary swap amount provided by the client.
We have to ensure that the server creates the correct
change outputs for the htlc- and sweepless sweep
transactions.
2025-09-25 11:13:34 +02:00
Slyghtning
d0670f109b
staticaddr: add nil checks for withdrawals 2025-09-15 13:53:30 +02:00
Slyghtning
b36f1651a3
staticaddr: poll new deposits on block arrival 2025-09-08 16:52:36 +02:00
Slyghtning
a1fb489a47
Merge pull request #996 from hieblmi/fix-971
staticaddr: monitor tx id of expiry sweep
2025-08-27 13:31:59 +02:00
Slyghtning
0ee9a617e6
staticaddr: log errors in manager.Run 2025-08-26 09:47:18 +02:00
Slyghtning
6ee4cf96f0
staticaddr: monitor tx id of expiry sweep 2025-08-22 16:14:18 +02:00
Slyghtning
1930be8cc7
staticaddr: round up withdrawal tx weight to the nearest satoshi
this commit fixes issue
https://github.com/lightninglabs/loop/issues/966
2025-08-21 09:34:15 +02:00
Slyghtning
b2a4d7af2d
staticaddr: show deposits as part of cli swap output 2025-08-20 17:07:29 +02:00
Slyghtning
a41334dd3d
staticaddr: add swap hash to deposit structs 2025-08-20 16:58:20 +02:00
Slyghtning
e98f733ef8
linter: fix lint issues after linter v2 update 2025-08-19 21:57:00 +02:00
Slyghtning
fe7622db87
staticaddr: fetch deposits as part of swap retrieval
since deposits have been normalized in the db in the
context of a static address swap this commit now
retrieves the deposit information as part of
GetLoopInByHash and GetStaticAddressLoopInSwapsByStates.
2025-08-01 11:26:33 +02:00
Slyghtning
d7ac3148c9
staticaddr: relax scope of ToDeposit 2025-08-01 11:26:33 +02:00
Slyghtning
a1af860527
staticaddr: remove unused fsm transition 2025-08-01 11:26:33 +02:00
Slyghtning
6e7441ba8d
staticaddr: migrate swap hashes to deposits 2025-08-01 11:26:32 +02:00
Slyghtning
35901d1247
staticaddr: don't append to public variable PendingStates 2025-08-01 10:34:16 +02:00
Slyghtning
e948c94b95
staticaddr: method to fetch deposits by outpoints 2025-07-29 15:52:54 +02:00
Andras Banki-Horvath
31f996cb37
build: bump tapd to v0.6.1 and lnd to v0.19.2-beta 2025-07-16 19:05:32 +02:00
Slyghtning
412fe7ffd9
staticaddr: simplify withdrawal fsm transition
previously upon recovery, a withdrawing deposit was
first transitioned into the Deposited state by the
deposit manager, and then again into the Withdrawing
state by the withdrawal manager. The first transition
is unnecessary, so we just remain in the Withdrawing
state upon recovery.
2025-07-02 15:42:12 +02:00
Boris Nagaev
51b74512b8
staticaddr: fix error formatting in the log 2025-06-24 01:44:32 -03:00
Boris Nagaev
61542197f6
staticaddr: use tx hash not *wire.MsgTx as a key
Do not rely on GetActiveDepositsInState reusing the same *wire.MsgTx
pointer for a unique transaction.
2025-06-24 01:44:32 -03:00
Boris Nagaev
38aaa4d07a
staticaddr: recover withdrawals in parallel
Use errgroup to publish each transaction in a separate goroutine.
Publishing a transaction can take a while in neutrino mode.
2025-06-24 01:44:32 -03:00
Boris Nagaev
3ed8c7a9fc
staticaddr/withdraw: log PublishTransaction start 2025-06-24 01:44:32 -03:00