Commit graph

1985 commits

Author SHA1 Message Date
Slyghtning
d00b78ef6b
sweepbatcher: consolidate identical change pkscripts
batch separate change outputs with identical pkscripts
are tallied up and consolidated to a single change output.
2025-07-29 21:22:17 +02:00
Slyghtning
245a66610b
utils: bip69 output sorting 2025-07-29 18:03:11 +02:00
Boris Nagaev
54652dc641
sweepbatcher: subtle adjustments for change
- ensurePresigned: use passed minRelayFeeRate instead of chainfee.FeePerKwFloor
 - presign: use minRelayFeeRate for start and minRelayFee
 - presign: make sure minRelayFeeRate is set
 - add tests for presign to test this new behavior; make sure the number of
   transactions is lower if minRelayFeeRate is higher
 - update error message in constructUnsignedTx: use <, not <= (more accurate)
 - use utils.DustLimitForPkScript instead of lnwallet.DustLimitForSize in tests
 - in tests adjust amounts to edge values, add controls
2025-07-29 12:33:56 +02:00
Slyghtning
29348a94df
sweepbatcher: consider min relay fee when constructing batch tx
if constructUnsignedTx constructs a batch transaction that is
below the minimum relay fee, an error is returned.
2025-07-29 12:33:56 +02:00
Slyghtning
bc7d155e69
sweepbatcher: consider change in presigning and batch tx
Presigning sweeps takes change outputs into account.
Each primary deposit id of a sweep group points to
an optional change output.
sweepbatcher.presign scans all passed sweeps for
change outputs and passes them to constructUnsignedTx.
Optional change of a swap is encoded in its sweeps
as a pointer to the same change output. This change
is taken into account when constructing the unsigned
batch transaction when it comes to tx weight and
outputs.
2025-07-29 12:33:55 +02:00
Slyghtning
8399a63091
sweepbatcher: consider optional change in greedy selection 2025-07-29 12:33:55 +02:00
Slyghtning
f30db74756
sweepbatcher: optional change in sweep struct
This commit adds an optional change output to the sweep struct.
2025-07-29 12:33:55 +02:00
Slyghtning
94168c3fe5
utils: function to get dust limit for a pkscript. 2025-07-29 12:33:54 +02:00
Boris Nagaev
bce9b5d45d
Merge pull request #975 from starius/spend-reorgs
sweepbatcher: fix reorg detection
2025-07-24 03:12:42 -03:00
Boris Nagaev
534c71b742
sweepbatcher: minimumSweepFeeRate fixes confTarget
This is already done in GetConfTargetAndFeeRate. The fix is just a double check.
2025-07-24 02:30:15 -03:00
Boris Nagaev
8431784338
sweepbatcher: update feerate outside AddSweep
AddSweep may not be called after getting the first confirmation, but feerate
updates are still needed in case of reorg.

Update test TestFeeRateGrows not to call AddSweep again and make sure feerate
is updated itself.
2025-07-24 02:22:06 -03:00
Boris Nagaev
5c9f6f7d7a
loopout: more logging in sweeping code 2025-07-24 02:22:06 -03:00
Boris Nagaev
957ca21e61
sweepbatcher: fix reorg detection
The reorg channel is now passed to RegisterSpendNtfn, and waiting for spend
notifications remains active even after the transaction receives its first
confirmation. The dedicated goroutine previously used to wait for the spend
is no longer needed, as we now handle both spend and potential reorg events
in the main event loop while the batch is running.

Following this change, RegisterConfirmationsNtfn runs without a reorg channel,
as it would only detect deep reorgs that undo the final confirmation - something
we can't handle anyway. We can't track fully confirmed swaps indefinitely to
guard against such rare reorgs; instead, we can mitigate the risk by increasing
the required confirmation depth.
2025-07-24 02:21:20 -03:00
Boris Nagaev
22d345a534
sweepbatcher: fix flaky test
Since bb837a4aec AddSweep loads sweeps so
one of possible errors is sql.ErrTxDone. Full error that is fixed:
> fetchSweeps failed: failed to load sweep 0000000000000000000101:1:
> failed to fetch sweep data for 010101000000:
> failed to fetch loop out for 010101000000:
> sql: transaction has already been committed or rolled back
2025-07-24 02:19:25 -03:00
Boris Nagaev
36c5d6cee7
test: golang.org/x/net/context -> context 2025-07-24 02:19:25 -03:00
Boris Nagaev
2176e5245e
Merge pull request #978 from starius/static-binaries
make: set CGO_ENABLED=0
2025-07-24 01:37:09 -03:00
Boris Nagaev
b0051382cf
make: set CGO_ENABLED=0
Make loop and loopd binaries static, more portable.
2025-07-24 00:55:10 -03:00
András Bánki-Horváth
6b7158201a
Merge pull request #985 from bhandras/bump-lnd-tapd
build: bump tapd to v0.6.1 and lnd to v0.19.2-beta
2025-07-16 19:36:31 +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
András Bánki-Horváth
26b38cf874
Merge pull request #977 from bhandras/gemini-review 2025-07-09 21:50:56 +02:00
Andras Banki-Horvath
b72f5d2e32
github: enable gemini code review 2025-07-09 15:53:36 +02:00
Slyghtning
8464bd2b94
Merge pull request #973 from hieblmi/fix-withdraw-test
staticaddr: simplify withdrawal fsm transition
2025-07-02 18:24:13 +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
András Bánki-Horváth
c690537c5f
Merge pull request #974 from lightninglabs/dependabot/go_modules/tools/github.com/go-viper/mapstructure/v2-2.3.0
build(deps): bump github.com/go-viper/mapstructure/v2 from 2.2.1 to 2.3.0 in /tools
2025-07-01 15:44:32 +02:00
dependabot[bot]
357aa264df
build(deps): bump github.com/go-viper/mapstructure/v2 in /tools
Bumps [github.com/go-viper/mapstructure/v2](https://github.com/go-viper/mapstructure) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/go-viper/mapstructure/releases)
- [Changelog](https://github.com/go-viper/mapstructure/blob/main/CHANGELOG.md)
- [Commits](https://github.com/go-viper/mapstructure/compare/v2.2.1...v2.3.0)

---
updated-dependencies:
- dependency-name: github.com/go-viper/mapstructure/v2
  dependency-version: 2.3.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-01 13:32:16 +00:00
András Bánki-Horváth
20bdb7e257
Merge pull request #972 from lightninglabs/dependabot/go_modules/github.com/go-viper/mapstructure/v2-2.3.0
build(deps): bump github.com/go-viper/mapstructure/v2 from 2.2.1 to 2.3.0
2025-07-01 14:42:45 +02:00
dependabot[bot]
c6d5e41438
build(deps): bump github.com/go-viper/mapstructure/v2
Bumps [github.com/go-viper/mapstructure/v2](https://github.com/go-viper/mapstructure) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/go-viper/mapstructure/releases)
- [Changelog](https://github.com/go-viper/mapstructure/blob/main/CHANGELOG.md)
- [Commits](https://github.com/go-viper/mapstructure/compare/v2.2.1...v2.3.0)

---
updated-dependencies:
- dependency-name: github.com/go-viper/mapstructure/v2
  dependency-version: 2.3.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-27 16:38:10 +00:00
Boris Nagaev
1104e928ff
Merge pull request #952 from starius/presigned-fixes2
sweepbatcher: fixes for presigned mode
2025-06-27 09:32:07 -03:00
Boris Nagaev
0dc5d9eb69
sweepbatcher: check of conf notification has tx 2025-06-26 14:01:16 -03:00
Boris Nagaev
1794aa21e5
loopdb: remove unused method ConfirmBatch 2025-06-26 14:01:16 -03:00
Boris Nagaev
72caafa14e
sweepbatcher: fix a bug in dest address selection
For presigned possible remaining groups, the destination address of the current
batch was used instead of the destination address of an expected future batch.

TODO: reproduce in unit test "purged". For this, each swap should have a
separate destination address.
2025-06-26 14:01:16 -03:00
Boris Nagaev
64a24177ae
sweepbatcher: more logging in PresignSweepsGroup 2025-06-26 14:01:16 -03:00
Boris Nagaev
59a3af31cc
sweepbatcher: format pkscript as hex 2025-06-26 14:01:16 -03:00
Boris Nagaev
e7d5172a79
sweepbatcher: remove method Presign
Method Presign is not as reliable as SignTx, because it checks transaction by
txid and can miss for example if LockTime is different. SignTx can do everything
Presign was used for.
2025-06-26 14:01:16 -03:00
Boris Nagaev
f19f9f5288
sweepbatcher/presigned: minRelayFee edge cases
Make sure that broadcasted tx has feeRate >= minRelayFee.
Make sure that feeRate of broadcasted tx doesn't decrease.
2025-06-26 14:01:16 -03:00
Boris Nagaev
7735bdfe27
sweepbatcher: make sure HTLC.PkScript is filled 2025-06-26 14:01:16 -03:00
Boris Nagaev
d75f17df47
sweepbatcher: simplify presigned/purging test
It doesn't need loopdb, so remove that code.
2025-06-26 14:01:16 -03:00
Boris Nagaev
8a07107811
sweepbatcher: make sure dest pkscript is filled 2025-06-26 14:01:16 -03:00
Boris Nagaev
8c784ef761
sweepbatcher: pass utxo to fee provider 2025-06-26 14:01:16 -03:00
Boris Nagaev
7ebe2e5b30
loopout: close sweepbatcher quitChan
This is needed because sweepbatcher can use this channel in multiple
select statements to unblock itself if the caller cancels.
2025-06-26 14:01:16 -03:00
Boris Nagaev
b961e18fa0
sweepbatcher: fix OnChainFeePortion values
There were two mistakes.

In case of a swap with multiple sweeps only the fee of the first sweep
of a swap was accounted.

Rounding diff (the remainder) was attributed to all the sweeps rather than to
the first (primary) sweep of the batch. The sweep to attribute the remainder
was chosen by comparing SignatureScript which is always empty. New approach is
to find the primary sweep and to compare its outpoint directly.
2025-06-26 14:01:16 -03:00
Boris Nagaev
650cf20fe9
sweepbatcher: re-add sweeps after fully confirmed
In case of a reorg sweeps should not go to another batch but stay in the current
batch until it is reorg-safely confirmed. Only after that the remaining sweeps
are re-added to another batch.

Field sweep.completed is now set to true only for reorg-safely confirmed sweeps.

In handleConf we now use batch.persist() (i.e. store.UpdateSweepBatch) instead
of ConfirmBatch, because we set not only Confirmed flag, but also batchTxid.
2025-06-26 13:36:55 -03:00
Boris Nagaev
d2c168945b
test/chainnotifier: send to specific spend reg
This is needed to have multiple spending registrations running and to send
a notification to a specific spending registration.
2025-06-25 22:53:18 -03:00
Boris Nagaev
fab4a646df
Merge pull request #967 from starius/neutrino-fixes
staticaddr: neutrino fixes
2025-06-25 13:41:50 -03:00
András Bánki-Horváth
2538055d7d
Merge pull request #970 from bhandras/listswaps-assetclient-panic
loopd: avoid panic if asset client is not set
2025-06-24 18:09:32 +02:00
Andras Banki-Horvath
d12dc0362d
loopd: avoid panic if asset client is not set 2025-06-24 14:55:42 +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
6f50b27b7d
loopd: increase withdrawal manager start timeout
This is needed for neutrino.
2025-06-24 01:44:32 -03:00