Commit graph

625 commits

Author SHA1 Message Date
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
yyforyongyu
71295534bb
contractcourt: remove block subscription in channel arbitrator
This commit removes the block subscriptions used in `ChannelArbitrator`,
replaced them with the blockbeat managed by `BlockbeatDispatcher`.
2024-12-20 17:54:02 +08:00
yyforyongyu
045f8432b7
contractcourt: remove block subscription in chain arbitrator
This commit removes the block subscriptions used in `ChainArbitrator`
and replaced them with the blockbeat managed by `BlockbeatDispatcher`.
2024-12-20 17:54:02 +08:00
yyforyongyu
5f9d473702
contractcourt: remove waitForHeight in resolvers
The sweeper can handle the waiting so there's no need to wait for blocks
inside the resolvers. By offering the inputs prior to their mature
heights also guarantees the inputs with the same deadline are
aggregated.
2024-12-20 17:54:02 +08:00
yyforyongyu
801fd6b85b
multi: implement Consumer on subsystems
This commit implements `Consumer` on `TxPublisher`, `UtxoSweeper`,
`ChainArbitrator` and `ChannelArbitrator`.
2024-12-20 17:54:01 +08:00
Oliver Gugger
7544a2b232
Merge pull request #9319 from thirdkeyword/master
chore: fix some problematic method name in comment
2024-12-19 08:30:39 +01:00
thirdkeyword
4c844bfb77 chore: fix some problematic method name in comment
Signed-off-by: thirdkeyword <fliterdashen@gmail.com>
2024-12-19 13:57:07 +08:00
George Tsagkarelis
231dd6b464
contractcourt: include custom records on replayed htlc
When notifying the invoice registry for an exit hop htlc we also want to
include its custom records. The channelLink, the other caller of this
method, already populates this field. So we make sure the contest
resolver does so too.
2024-12-16 10:29:27 +01:00
Olaoluwa Osuntokun
fb429d658b
Merge pull request #9330 from ProofOfKeags/update/fn2
multi: update to fn v2
2024-12-09 12:56:23 +01:00
ziggie
17bc8827c5
contractcourt: refactor start up of arbitrators
We decouple the state machine of the channel arbitrator from
the start-up process so that we can startup the whole daemon
reliably.
2024-12-05 15:11:12 +01:00
Keagan McClelland
ed2989ae33
multi: update to fn v2 2024-12-04 13:19:00 -07:00
Elle Mouton
ab7aae0708
multi: rename nolint:lll to nolint:ll
Find and replace all nolint instances refering to the `lll` linter and
replace with `ll` which is the name of our custom version of the `lll`
linter which can be used to ignore log lines during linting.

The next commit will do the configuration of the custom linter and
disable the default one.
2024-12-02 09:14:21 +02:00
Elle Mouton
439a6c7d6c
multi: rename chan DB Open method to OpenForTesting 2024-11-28 13:51:15 +02:00
Elle Mouton
adcaa8802f
multi: remove kvdb.Tx from ChannelGraphSource.ForAllOutgoingChannels
and the same for ChannelStateDB.FetchChannel. Most of the calls to these
methods provide a `nil` Tx anyways. The only place that currently
provides a non-nil tx is in the `localchans.Manager`. It takes the
transaction provided to the `ForAllOutgoingChannels` callback and passes
it to it's `updateEdge` method. Note, however, that the
`ForAllOutgoingChannels` call is a call to the graph db and the call to
`updateEdge` is a call to the `ChannelStateDB`. There is no reason that
these two calls need to happen under the same transaction as they are
reading from two completely disjoint databases. And so in the effort to
completely split untangle the relationship between the two databases, we
now dont use the same transaction for these two calls.
2024-11-28 13:49:41 +02:00
Elle Mouton
9f54ec90aa
multi+refactor: move models package to graph/db
All the structs defined in the `channeldb/models` package are graph
related. So once we move all the graph CRUD code to the graph package,
it makes sense to have the schema structs there too. So this just moves
the `models` package over to `graph/db/models`.
2024-11-28 13:34:33 +02:00
Elle Mouton
b707fd55b2
contractcourt: use graphdb outpoint helpers
Start using the single set of exported write/read functions for
wire.Outpoint.
2024-11-28 13:34:08 +02:00
Elle Mouton
c2923e2214
multi: remove PrefixLog
And instead use the new btclog Logger `WithPrefix` method.
2024-11-27 10:44:32 +02:00
ziggie
5486f32444
multi: introduce an option for resolutions
We don't always need the resolutions in the local force close
summary so we make it an option.
2024-11-20 09:18:24 +01:00
Olaoluwa Osuntokun
87b4991bb6
lnwallet: add whoseCommit to FetchLeavesFromCommit
This is useful for additional context to know which commit the
AuxLeafStore is fetching the leaves for.
2024-11-14 16:09:58 -08:00
Olaoluwa Osuntokun
ba16a74491
sweep: expand NotifyBroadcast to include an outpoint index
In this commit, we expand the `NotifyBroadcast` to include an outpoint
index. This is useful as it indicates the index of a given required tx
out input.
2024-11-14 16:09:58 -08:00
Olaoluwa Osuntokun
ab41f28a8f
contractcourt: pass in new aux resolution blob to sweeper in resolvers
With this commit, we update all the resolvers to pass in the new htlc
resolution blobs. Along the way, we remove the old blocking guard on
this resolution logic for HTLCs with blobs.
2024-11-14 16:09:58 -08:00
Olaoluwa Osuntokun
7ef2683586
contractcourt: update encode/decode for taproot aux data
When we read/write the aux data, we need to make sure we always set the
new fields for aux HTLCs.
2024-11-14 16:09:58 -08:00
Olaoluwa Osuntokun
9b8adf5f5c
contractcourt: add HtlcBlobs to taprootBriefcase
In this commit, we add the set of HtlcBlobs to the taprootBriefcase
struct. This new field will store all the resolution blobs for a given
HTLC. We also add some new property based tests along the way for
adequate test coverage.
2024-11-14 16:09:58 -08:00
Olaoluwa Osuntokun
1e7c5415ae
input: add new Preimage method to input.Input
In this commit, we add a new method to obtain an option of a preimage to
the input.Input struct. This is useful for callers that have an Input,
and want to optionally obtain the preimage.
2024-11-14 16:09:58 -08:00
ziggie
59f32682a5
contractcourt: introduce option for commitKey. 2024-11-07 22:40:53 +01:00
ziggie
7aa9ade4c2
contratcourt: dont consider dust htlc for anchor sweep
Now that we cancel dust htlcs prematurely even before the
commitment tx is confirmed we don't consider dust htlcs when
creating the cpfp transaction.
2024-11-07 22:40:52 +01:00
ziggie
8ed8665d50
contractcourt: Cancel dust htlcs prematurely
We will now cancel dust htlcs on the local/remote commits after
we decided to go onchain. This can be done because dust cannot
be enforced onchain and therefore there is no way to also reveil
the preimage onchain.
2024-11-07 22:40:52 +01:00
ziggie
20dc7f29f8
multi: fix typo and add comment. 2024-11-07 18:32:45 +01:00
ziggie
328a711dbe
contractcourt: enhance chainAction type
We distinguish between dangling and dust htlcs. This does not
change any logic but only introduces new types to later act on them
differently when we begin to fail dust htlcs earlier in a later
commit.
2024-11-07 18:32:45 +01:00