Commit graph

96 commits

Author SHA1 Message Date
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
1ab73a6272
loopout: ignore saved HTLC txid
If a reorg happens, the saved txid prevents loop-out from discoveing new txid.
2025-06-17 11:34:25 -03:00
Boris Nagaev
bb837a4aec
sweepbatcher: load sweeps in AddSweep
This is needed to run additional checks in AddSweep in the next commit.
2025-05-08 17:24:10 -03:00
Boris Nagaev
e8cf6386cc
sweepbatcher: allow adding groups of inputs
A group of inputs can be added by passing it in SweepRequest.Inputs field.
All the inputs belong to the same swap and are added to the same batch.
2025-04-03 09:49:46 -03:00
Boris Nagaev
3cbfadd27a
loop: fix race in loopOutSwap.payInvoiceAsync
The function used to call the method swapKit.swapInfo() which accessed many
fields of the swapKit which may change in parallel by handlePaymentResult called
by executeSwap (payInvoiceAsync is called in a goroutine). The fields are: cost,
state, and update time.
2025-03-19 15:00:31 +01:00
sputn1ck
3e3c863819
loopout: add asset accounting 2025-01-21 18:26:20 +01:00
sputn1ck
1440b6bb1d
loopout: add asset loop out payment flow 2025-01-21 18:26:19 +01:00
Boris Nagaev
80fcf19009
loopout: improve log messages
Original message "Checking preimage reveal height 231435 exceeded" was not clear
and could be interpreted that the swap has expired. Now the same message looks
like this: "Checking if preimage reveal height 231435 was exceeded".
2025-01-18 11:49:50 -03:00
Boris Nagaev
2f22f96e73
loopout: re-target sweep's feerate every block
Add type loopOutSweepFeerateProvider which determines confTarget based on
distance to swap expiration, then determines feerate and fee using. Fee rate
is plugged into sweepbatcher using WithCustomFeeRate. Option WithPublishDelay
is used to make sure fee-rate is updated by loopout.go before the value is used
by sweepbatcher.

When determining confTarget, there are few adjustments over raw distance to
cltv_expiry:
 - make sure confTarget is positive (if the swap has expired, raw distance is
   negative)
 - If confTarget is less than or equal to DefaultSweepConfTargetDelta (10),
   cap it with urgentSweepConfTarget and apply fee factor (1.1x).

Also, if feerate is less than floor (1 sat/vbyte), then the floor is used.

DefaultSweepConfTargetDelta was decreased from 18 to 10.

Every block 100 sats/kw fee bump is disabled. Sweepbatcher re-targets feerate
every block according to current mempool conditions and the number of blocks
until expiry.

Added tests for loopOutSweepFeerateProvider simulating various conditions.
2024-11-11 20:35:35 -03:00
Boris Nagaev
f8c1607154
loopout, liquidity: turn vars to constants
There are some numeric constants that used to be defined as vars complicating
their usage. They were turned into constants: MinLoopOutPreimageRevealDelta,
DefaultSweepConfTarget, DefaultHtlcConfTarget, DefaultSweepConfTargetDelta.

Also make liquidity.defaultHtlcConfTarget a constant, not a var.
2024-11-11 20:35:35 -03:00
Boris Nagaev
6c62ded35b
loopout: remove dead code
The first result of function sweepConfTarget was not used. The function
was renamed to canSweep to better reflect what it does.
2024-11-11 20:35:35 -03:00
Andras Banki-Horvath
08aa4db35d
loopout: correctly account for the prepay amount when calculating costs
Previously we'd not account for the prepay amount which resulted in the
total swap cost reported being lower than what it actually is.
2024-06-03 14:54:18 +02:00
Andras Banki-Horvath
0d0af5bf24
loopout: use the request defined payment timeout 2024-05-23 17:17:21 +02:00
Andras Banki-Horvath
56902352cd
loopout: fix negative reported fees 2024-05-23 16:48:05 +02:00
Slyghtning
1cea76bf01
loopout: send prepay over outgoing chan set 2024-04-15 20:08:46 +02:00
Andras Banki-Horvath
06fd21fd05
loop: fill the correct HTLC in loopout update 2024-03-21 14:59:24 +01:00
Andras Banki-Horvath
5294b4ff07
loop: clean up server cost calculation for slightly better UX
Previously we'd calculate the server costs (swap fees) by accounting for
both the on-chain HTLC and the off-chain payment which was confusing as
server cost fluctuated by the amount of the swap itself. Now we'll only
add the actual cost when the swap happened, so the server cost will go
form zero to the actual fee value paid.
2024-03-04 16:15:21 +01:00
Andras Banki-Horvath
e1ddb50dfe
loopout+sweepbatcher: calculate the per sweep onchain fees correctly
Previously we'd report the fees per sweep as the total sweep cost of a
batch. With this change the reported cost will be the proportional fee
which should be equal for all sweeps except if there's any rounding
difference in which case that is paid by the sweep belonging to the
first input of the batch tx.
2024-03-04 16:15:21 +01:00
George Tsagkarelis
0914074b10
loop: integrate sweepbatcher to loopout flow 2024-01-23 20:38:10 +02:00
George Tsagkarelis
b43fa11cc1
utils: add htlc & swap related helpers 2024-01-23 20:38:08 +02:00
George Tsagkarelis
a9be69b281
multi: use isExternalAddr flag 2024-01-23 20:38:07 +02:00
GoodDaisy
e45101cccd chore: fix typos 2023-12-03 13:20:44 +08:00
George Tsagkarelis
2a8a6cefc0
loop: fix musig2 typo 2023-07-19 16:19:24 +02:00
sputn1ck
becc8a38d8
multi: use context in loopdb call
This commit adds a context to our loopdb interface, which we should use
in the sqlite migration.
2023-06-19 12:28:32 +02:00
Andras Banki-Horvath
cd91f90ed2
loop: use MuSig2 1.0 scheme for the new MuSig2 swaps 2023-03-20 20:08:43 +01:00
Andras Banki-Horvath
da4bcbea10
loopdb: refactor the SwapContract to hold all HTLC keys
This commit adds a new struct to hold all HTLC keys and refactors the
SwapContract which is used by both loopin and loopout swaps to use this
new struct. The newly added internal keys will for now hold the script
keys to keep everything equivalent but are already stored and read back
if the protocol version is set to MuSig2.
2023-03-20 20:08:43 +01:00
Andras Banki-Horvath
a7451622e5
mod: bump LND and lndclient to include musig2 1.0rc2 changes
This commit bumps LND and lndclient to make it possible to upgrade
taproot HTLC construction with a MuSig2 version. This is required to
support both old (MuSig2 0.4) and new (MuSig2 1.0) clients.
2023-02-06 20:46:03 +01:00
sputn1ck
4baf88c414
multi: fix linter issues
This commit fixes outstanding linter issues, that we're not found by
running `make lint` locally. The linter issues were found by running
`docker run -v $(pwd):/build loop-tools golangci-lint run --whole-files`

I added the `revive` to the excludes as it would be to much of a
refactor and IMO seems unneccesary. E.g.
`interface.go:222:6: exported: type name will be used as
loop.LoopInTerms by other packages, and that stutters; consider
 calling this InTerms (revive)`. I think `loop.LoopInTerms` is fine.
2022-12-15 18:08:38 +01:00
Andras Banki-Horvath
bdb4b773ed
swap: refactor htlc construction to allow passing of internal keys
This commit is a refactor of how we construct htlcs to make it possible
to pass in internal keys for the sender and receiver when creating P2TR
htlcs. Furthermore the commit also cleans up constructors to not pass in
script versions and output types to make the code more readable.
2022-11-30 18:16:44 +01:00
Andras Banki-Horvath
a9dbaee102
loopout: log failed sweeps to allow out of band publish 2022-07-27 20:44:45 +02:00
Andras Banki-Horvath
f8da106338
loopout: use psbt when obtaining the MuSig2 signature
In this commit we deprecate the sighash field from the
MuSig2SignSweepReq request in favour of using a psbt serialized sweep
transaction instead. This way the sever gains full transparency about
client sweep requests and can assemble the sighash to sign on its own.
2022-07-12 19:54:25 +02:00
Andras Banki-Horvath
5d7b0abdf5
loopout: add unit test for the MuSig2 sweep case 2022-06-30 16:59:59 +02:00
Andras Banki-Horvath
82b58e5c0e
loopout: attempt cooperative musig2 sweep
This commit adds optional cooperative musig2 sweep by calling the server
to create a partial signature for the sweep if we'd otherwise be allowed
to spend the htlc. If the cooperative musig2 spend fails, we always fall
back to use the scriptpath spend.
2022-06-30 16:59:59 +02:00
Andras Banki-Horvath
a252e2c706
loopdb: add the local pubkey's keylocator to the persisted contract 2022-06-30 16:59:57 +02:00
Andras Banki-Horvath
391ef57ea3
loopout: enable p2tr without keyspend 2022-06-30 16:59:55 +02:00
Andras Banki-Horvath
00cf4bf71c
multi: make the next protocol version optional 2022-06-30 16:59:54 +02:00
Carla Kirk-Cohen
c7ef4297c0
multi: update sweeping to allow different sighashes and claim scripts
Taproot spends require a different sighash, so we update our HtlcScript
interface to provide the appropriate sighash when sweeping. We also add
distinct Timeout/Success Script functions to allow for tapleaf spends
which have different locking scripts for different paths. Note that the
timeout and success paths will be the same for segwit v0 htlcs, because
it has a single branched script containing all spend paths.

In future iterations, this differentiation of claim scripts can also
be used to use musig2 to collaboratively keyspend P2TR htlcs with the
server. This script can be expressed as PriorityScript (because we'll
try to keyspend as a priority, and then fall back to a tap leaf spend).
As we've done here, segwit v0 spends would just return their single
script for PriorityScript, and the claim would be no different from
our other claims.
2022-06-09 10:20:16 +02:00
sputn1ck
efb6f75d60
swap: add lasthop, outgoingchanids to swapinfo 2022-05-31 16:26:51 +02:00
Carsten Otto
b0044e0994 loopout: remove double space in log message 2022-05-06 17:34:19 +02:00
Harsha Goli
7a16e3b25d
multi: bump btcec/v2 and btcutil to new versions 2022-03-25 11:00:16 +01:00
Andras Banki-Horvath
32d55dc814
loopout: do not report prepays and fix plugin type if acquire fails 2022-02-18 08:42:42 +01:00
Andras Banki-Horvath
ffd52aba2f
loopout: add low/high routing plugin 2022-02-14 10:14:47 +01:00
Andras Banki-Horvath
1d1354d2cb
config: make total payment timeout and retries configurable 2022-02-14 10:14:47 +01:00
Andras Banki-Horvath
1943edfd78
loopout: use optional routing plugin for the main swap invoice 2022-02-14 10:14:46 +01:00
carla
d1c26a20da
multi: surface server swap initiation grpc error codes
Formatting our error was stifling any grpc error returned by the
server. Instead, we bubble up our grpc error, setting an unknown
code if the server did not specifically return an error code.
2021-07-19 10:28:34 +02:00
carla
f166ce899d
loopout: cancel swap with server when off-chain fails 2021-05-24 08:46:03 +02:00
carla
16111352a8
multi: add cancel swap function to execute config 2021-05-24 08:40:14 +02:00
carla
4040bb356d
loopout: refactor payInvoice to return more payment information
We're going to want more information about our failures going
forward, so we refactor payInvoice to return a full payment
status. The primary change in this commit is that we surface
both types of payment failures (result.err when we fail immediately,
and lnrpc.Failure when our payment is failed back) and return them
in the failure() method, rather than combining this information
at a lower level.
2021-05-24 08:40:13 +02:00
carla
9db8bd5f2a
loopout: do not reveal preimage if time to safe reveal has passed 2021-05-12 14:09:28 +02:00
Oliver Gugger
2a732a4385
loop: add initiator string to user agent 2020-11-06 10:43:03 +01:00