Commit Graph

654 Commits

Author SHA1 Message Date
yyforyongyu
5a72d5258f htlcswitch+itest: catch link quit signal when processing hodlQueue
This commit makes sure when processing resolutions, e.g, settling
invoices, when the link is already broken, the process would exit with
an error. This fixes the issue we found in the itest, where an
unexpected empty remote pending commitment was created although the
remote peer is already offline.
2025-03-21 03:25:24 +08:00
yyforyongyu
be4c4cc8ff multi: improve logging 2025-03-21 03:24:26 +08:00
yyforyongyu
66c94cf51f contractcourt: add String to CommitSet for logging 2025-03-21 03:24:26 +08:00
Olaoluwa Osuntokun
8432e706d3 multi: extract new DeriveHeightHint() function, use for new rbf closer
With this commit, we make sure we set the right height hint, even if the
channel is a zero conf channel.
2025-03-18 11:44:20 -05:00
Oliver Gugger
0e9b7c5fa2 contractcourt: fix rebase issue with removed variadic option
The optional variadic functional parameters probably got lost during a
rebase.
2025-03-10 21:52:02 +01:00
fuyangpengqi
150f72414a refactor: use a more straightforward return value
Signed-off-by: fuyangpengqi <995764973@qq.com>
2025-02-28 17:09:56 +08:00
yyforyongyu
9f7e2bfd96 contractcourt: fix errorlint 2025-02-20 23:14:12 +08:00
yyforyongyu
b184afe227 sweep: handle missing inputs during fee bumping
This commit handles the case when the input is missing during the RBF
process, which could happen when the bumped tx has inputs being spent by
a third party. Normally we should be able to catch the spend early via
the spending notification and never attempt to fee bump the record.
However, due to the possible race between block notification and spend
notification, this cannot be guaranteed. Thus, we need to handle the
case during the RBF when seeing a `ErrMissingInputs`, which can only
happen when the inputs are spent by others.
2025-02-20 14:40:53 +08:00
Eng Zer Jun
e56a7945be refactor: replace math.Min and math.Max with built-in min/max
Reference: https://github.com/lightningnetwork/lnd/pull/9451#pullrequestreview-2580942691
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-02-06 09:46:40 +08:00
Elle
e9dd01b60d Merge pull request #9274 from ziggie1984/remove-2x-value
The sweeper subsystem uses now also the configured budget values for HTLCs
2025-01-13 19:09:11 +02:00
Oliver Gugger
b958667811 Merge pull request #9355 from Roasbeef/rapid-fuzz-htlc-blobs
contractcourt: add rapid derived fuzz test for HtlcAuxBlob
2025-01-13 10:35:53 -06:00
ziggie
5cd88f7e48 contractcourt: remove 2xamount requirement for the sweeper. 2025-01-08 08:57:50 +01:00
chloefeal
852a8d8746 chore: fix typo 2025-01-05 20:45:35 +08:00
yyforyongyu
ecd82a3bcb contractcourt: include custom records on replayed htlc
Add another case in addition to #9357.
2024-12-20 17:54:13 +08:00
yyforyongyu
4806b2fda7 multi: optimize loggings around changes from blockbeat 2024-12-20 17:54:08 +08:00
yyforyongyu
fecd5ac735 contractcourt: make sure launchResolvers is called on new blockbeat
This is an oversight from addressing this commment:
https://github.com/lightningnetwork/lnd/pull/9277#discussion_r1882410396

where we should focus on skipping the close events but not the
resolvers.
2024-12-20 17:54:08 +08:00
yyforyongyu
ea7d6a509b contractcourt: register conf notification once and cancel when confirmed 2024-12-20 17:54:08 +08:00
yyforyongyu
a6d3a0fa99 contractcourt: process channel close event on new beat 2024-12-20 17:54:07 +08:00
yyforyongyu
c5b3033427 contractcourt: add close event handlers in ChannelArbitrator
To prepare the next commit where we would handle the event upon
receiving a blockbeat.
2024-12-20 17:54:07 +08:00
yyforyongyu
6eb9bb1ed6 multi: add new method ChainArbitrator.RedispatchBlockbeat
This commit adds a new method to enable us resending the blockbeat in
`ChainArbitrator`, which is needed for the channel restore as the chain
watcher and channel arbitrator are added after the start of the chain
arbitrator.
2024-12-20 17:54:07 +08:00
yyforyongyu
4d765668cc contractcourt: use close height instead of best height
This commit adds the closing height to the logging and fixes a wrong
height used in handling the breach event.
2024-12-20 17:54:07 +08:00
yyforyongyu
3822c23833 contractcourt: notify blockbeat for chainWatcher
We now start notifying the blockbeat from the ChainArbitrator to the
chainWatcher.
2024-12-20 17:54:07 +08:00
yyforyongyu
8237598ed1 contractcourt: handle blockbeat in chainWatcher 2024-12-20 17:54:07 +08:00
yyforyongyu
4e30598263 contractcourt: add method handleCommitSpend
To prepare for the blockbeat handler.
2024-12-20 17:54:07 +08:00
yyforyongyu
c1a9390c36 contractcourt: register spend notification during init
This commit moves the creation of the spending notification from `Start`
to `newChainWatcher` so we subscribe the spending event before handling
the block, which is needed to properly handle the blockbeat.
2024-12-20 17:54:06 +08:00
yyforyongyu
07cb3aef00 contractcourt: implement Consumer on chainWatcher 2024-12-20 17:54:06 +08:00
yyforyongyu
63aa5aa6e9 contractcourt: offer outgoing htlc one block earlier before its expiry
We need to offer the outgoing htlc one block earlier to make sure when
the expiry height hits, the sweeper will not miss sweeping it in the
same block. This also means the outgoing contest resolver now only does
one thing - watch for preimage spend till height expiry-1, which can
easily be moved into the timeout resolver instead in the future.
2024-12-20 17:54:06 +08:00
yyforyongyu
819c15fa0b contractcourt: break launchResolvers into two steps
In this commit, we break the old `launchResolvers` into two steps - step
one is to launch the resolvers synchronously, and step two is to
actually waiting for the resolvers to be resolved. This is critical as
in the following commit we will require the resolvers to be launched at
the same blockbeat when a force close event is sent by the chain watcher.
2024-12-20 17:54:06 +08:00
yyforyongyu
d2e81a19fd contractcourt: fix concurrent access to launched 2024-12-20 17:54:06 +08:00
yyforyongyu
4f5ccb8650 contractcourt: fix concurrent access to resolved
This commit makes `resolved` an atomic bool to avoid data race. This
field is now defined in `contractResolverKit` to avoid code duplication.
2024-12-20 17:54:06 +08:00
yyforyongyu
47722292c5 contractcourt: add Launch method to outgoing contest resolver 2024-12-20 17:54:05 +08:00
yyforyongyu
ef98c52d10 contractcourt: add Launch method to incoming contest resolver
A minor refactor is done to support implementing `Launch`.
2024-12-20 17:54:05 +08:00
yyforyongyu
025d787fd2 invoices: exit early when the subscriber chan is nil
When calling `NotifyExitHopHtlc` it is allowed to pass a chan to
subscribe to the HTLC's resolution when it's settled. However, this
method will also return immediately if there's already a resolution,
which means it behaves like a notifier and a getter. If the caller
decides to only use the getter to do a non-blocking lookup, it can pass
a nil subscriber chan to bypass the notification.
2024-12-20 17:54:05 +08:00
yyforyongyu
71aec7bd94 contractcourt: add Launch method to htlc timeout resolver
This commit breaks the `Resolve` into two parts - the first part is
moved into a `Launch` method that handles sending sweep requests, and
the second part remains in `Resolve` which handles waiting for the
spend. Since we are using both utxo nursery and sweeper at the same
time, to make sure this change doesn't break the existing behavior, we
implement the `Launch` as following,
- zero-fee htlc - handled by the sweeper
- direct output from the remote commit - handled by the sweeper
- legacy htlc - handled by the utxo nursery
2024-12-20 17:54:05 +08:00
yyforyongyu
cf105e67f4 contractcourt: add Launch method to htlc success resolver
This commit breaks the `Resolve` into two parts - the first part is
moved into a `Launch` method that handles sending sweep requests, and
the second part remains in `Resolve` which handles waiting for the
spend. Since we are using both utxo nursery and sweeper at the same
time, to make sure this change doesn't break the existing behavior, we
implement the `Launch` as following,
- zero-fee htlc - handled by the sweeper
- direct output from the remote commit - handled by the sweeper
- legacy htlc - handled by the utxo nursery
2024-12-20 17:54:05 +08:00
yyforyongyu
913f5d4657 contractcourt: add Launch method to commit resolver 2024-12-20 17:54:05 +08:00
yyforyongyu
a98763494f contractcourt: add Launch method to anchor/breach resolver
We will use this and its following commits to break the original
`Resolve` methods into two parts - the first part is moved to a new
method `Launch`, which handles sending a sweep request to the sweeper.
The second part remains in `Resolve`, which is mainly waiting for a
spending tx.

Breach resolver currently doesn't do anything in its `Launch` since the
sweeping of justice outputs are not handled by the sweeper yet.
2024-12-20 17:54:04 +08:00
yyforyongyu
730b605ed4 contractcourt: add resolve handlers in htlcTimeoutResolver
This commit adds more methods to handle resolving the spending of the
output based on different spending paths.
2024-12-20 17:54:04 +08:00
yyforyongyu
7083302fa0 contractcourt: add methods to checkpoint states
This commit adds checkpoint methods in `htlcTimeoutResolver`, which are
similar to those used in `htlcSuccessResolver`.
2024-12-20 17:54:04 +08:00
yyforyongyu
bfc95b8b2c contractcourt: add sweep senders in htlcTimeoutResolver
This commit adds new methods to handle making sweep requests based on
the spending path used by the outgoing htlc output.
2024-12-20 17:54:04 +08:00
yyforyongyu
cb18940e75 contractcourt: remove redundant return value in claimCleanUp 2024-12-20 17:54:04 +08:00
yyforyongyu
c92d7f0fd0 contractcourt: add resolver handlers in htlcSuccessResolver
This commit refactors the `Resolve` method by adding two resolver
handlers to handle waiting for spending confirmations.
2024-12-20 17:54:04 +08:00
yyforyongyu
fb499bc4cc contractcourt: add sweep senders in htlcSuccessResolver
This commit is a pure refactor in which moves the sweep handling logic
into the new methods.
2024-12-20 17:54:04 +08:00
yyforyongyu
10e5a43e46 contractcourt: add spend path helpers in timeout/success resolver
This commit adds a few helper methods to decide how the htlc output
should be spent.
2024-12-20 17:54:03 +08:00
yyforyongyu
1f2cfc6a60 contractcourt: add verbose logging in resolvers
We now put the outpoint in the resolvers's logging so it's easier to
debug.
2024-12-20 17:54:03 +08:00
yyforyongyu
1d53e7d081 multi: improve loggings 2024-12-20 17:54:03 +08:00
yyforyongyu
45b243c91c contractcourt: fix linter funlen
Refactor the `Start` method to fix the linter error:
```
contractcourt/chain_arbitrator.go:568: Function 'Start' is too long (242 > 200) (funlen)
```
2024-12-20 17:54:03 +08:00
yyforyongyu
545cea0546 multi: start consumers with a starting blockbeat
This is needed so the consumers have an initial state about the current
block.
2024-12-20 17:54:02 +08:00
yyforyongyu
802353036e contractcourt: start channel arbitrator with blockbeat
To avoid calling GetBestBlock again.
2024-12-20 17:54:02 +08:00
yyforyongyu
e2e59bd90c contractcourt: remove the immediate param used in Resolve
This `immediate` flag was added as a hack so during a restart, the
pending resolvers would offer the inputs to the sweeper and ask it to
sweep them immediately. This is no longer need due to `blockbeat`, as
now during restart, a block is always sent to all subsystems via the
flow `ChainArb` -> `ChannelArb` -> resolvers -> sweeper. Thus, when
there are pending inputs offered, they will be processed by the sweeper
immediately.
2024-12-20 17:54:02 +08:00