Commit Graph

174 Commits

Author SHA1 Message Date
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
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
ziggie
8890f83bde
contratcourt: refactor resolving htlc logic
Refactor the part where we are failing back the incoming htlc
when the channel of the corresponding outgoing htlc is force
closed. We do this because in furture commits we separate the
logic when we fail back the incoming htlc (abandonForward).
Right now we fail abandon dust forwards and non-dust forwards
only when the commitment transaction is confirmed. Later we will
move the canceling of the upstream htlc when the commitment
transaction is broadcasted instead of waiting until the commitment
tx is confirmed. The reason for that is that dust cannot be enforced
onchain anyways so there is no reason to wait.
2024-11-07 18:32:45 +01:00
ziggie
98a270bd30
contractcourt: improve robustness 2024-11-07 18:32:44 +01:00
Oliver Gugger
e99e6662cf
multi: update linter, fix new issues 2024-08-20 19:14:44 +02:00
Keagan McClelland
33934449ac
multi: refactor select methods within channeldb to use ChannelParty
Also in this commit is a small adjustment to the call-sites to get
the boundaries stitched back together.
2024-07-31 14:50:26 -07:00
ziggie
e413759669
contractcourt: Always register anchors with sweeper.
Even if no HTLCs are at stake we are going to register the anchor
outputs with the sweeper subsystem with a default high deadline.
We need to do this, because otherwise we are not able to bump the
fee of the closing transaction manually.
2024-07-30 20:31:29 +02:00
yyforyongyu
d992cf94d6
multi: add SpewLogClosure to avoid code repetition 2024-07-25 22:18:49 +08:00
yyforyongyu
b6049ff94b
multi: add NewLogClosure in lnutils to avoid repetition
And replaces all usage of `logClosure` with `lnutils.LogClosure`.
2024-07-25 21:25:23 +08:00
yyforyongyu
e45db07a10
contractcourt+itest: make sure ChannelArbitrator has the latest htlcs 2024-05-21 00:53:23 +08:00
yyforyongyu
1470adbed2
contractcourt: share deadlines between CPFP anchors and HTLCs
This commit changes how the deadline is calculated for CPFP anchor
sweeping. In order to sweep the second-level HTLCs, we need to first
get the FC tx confirmed. If we use a larger conf target for CPFP, we'd
end up having few blocks to sweep the HTLCs, as these two sweeping txns
share the deadline of the HTLC, as shown below,
```
More aggressive on the CPFP part.
|-CPFP-|-----HTLC-----|

Share the deadlines evenly.
|---CPFP---|---HTLC---|

More aggressive on the HTLC part.
|-----CPFP-----|-HTLC-|
```
In this commit, we decide to share the deadlines evenly as a starting
point so neither side will have a short of deadlines.
2024-05-18 07:45:09 +08:00
yyforyongyu
f5a321d0d3
contractcourt: remove unused param to please linter 2024-04-19 21:33:39 +08:00
yyforyongyu
49cfb91af1
contractcourt: make sure sweep happens immediately on startup
This commit makes sure the time-sensitive outputs are swept immediately
during startup.
2024-04-19 21:33:39 +08:00
yyforyongyu
07466c4f8c
multi: query circuit map inside contractcourt
This commit adds a new config method `QueryIncomingCircuit` that can be
used to query the payment's incoming circuit for giving its outgoing
circuit key.
2024-04-19 21:33:35 +08:00
yyforyongyu
6f0c2b5bab
contractcourt: specify deadline and budget for anchor output 2024-04-19 21:33:34 +08:00
yyforyongyu
f4035ade05
contractcourt: calculate value left when searching for commit deadline
This commit changes `findCommitmentDeadline` to
`findCommitmentDeadlineAndValue` to calculate the value left from all
the time-sensitive HTLCs after subtracting their budgets. This value is
then used to calculate the budget to be used when sweeping the anchor
output.
2024-04-19 21:33:34 +08:00
yyforyongyu
cab180a52e
contractcourt: specify deadline and budget for htlc timeout 2024-04-19 21:33:34 +08:00
yyforyongyu
d1ad07fa21
contractcourt+lnwallet: specify deadline and budget for htlc success 2024-04-19 21:33:33 +08:00
yyforyongyu
530eed92a0
multi: rename FeePreference to FeeEstimateInfo
Results from running,
```
gofmt -d -w -r 'FeePreference -> FeeEstimateInfo' .
```
2024-04-19 21:33:21 +08:00
Keagan McClelland
bc3feba267 contractcourt+lnrpc+lnd: s/BreachArbiter/BreachArbitrator
Since we have two other examples of XArbitrator, we rename
BreachArbiter to BreachArbitrator to keep things consistent.
The aim is to reduce the amount of lore you need to know to
intuit where things are or what they do.
2024-02-06 13:32:47 -07:00
Slyghtning
8c04c1e7ce
contractcourt: log amount if incoming htlc times out 2023-11-08 09:56:03 +01:00
Yong
939375f1a5
sweeper: relax anchor sweeping when there's no deadline pressure (#7965)
* sweep: use longer variable name for clarity in `addToState`

* sweeper: add more docs and debug logs

* sweep: prioritize smaller inputs when adding wallet UTXOs

This commit sorts wallet UTXOs by their values when using them for
sweeping inputs. This way we'd avoid locking large UTXOs when sweeping
inputs and also provide an opportunity to aggregate wallet UTXOs.

* contractcourt+itest: relax anchor sweeping for CPFP purpose

This commit changes from always sweeping anchor for a local force close
to only do so when there is an actual time pressure. After this change,
a forced anchor sweeping will only be attempted when the deadline is
less than 144 blocks.

* docs: update release notes

* itest: update test `testMultiHopHtlcLocalChainClaim` to skip CPFP

Since we now only perform CPFP when both the fee rate is higher and the
deadline is less than 144, we need to update the test to reflect that
Bob will not CPFP the force close tx for the channle Alice->Bob.

* itest: fix `testMultiHopRemoteForceCloseOnChainHtlcTimeout`

* itest: update related tests to reflect anchor sweeping

This commit updates all related tests to reflect the latest anchor
sweeping behavior. Previously, anchor sweeping is always attempted as
CPFP when a force close is broadcast, while now it only happens when the
deadline is less than 144. For non-CPFP purpose sweeping, it will happen
after one block is mined after the force close transaction is confirmed
as the anchor will be resent to the sweeper with a floor fee rate, hence
making it economical to sweep.
2023-10-12 17:18:59 +02:00
András Bánki-Horváth
ad5cd9c8bb
multi: extend InvoiceDB methods with a context argument (#8066)
* multi: extend InvoiceDB methods with a context argument

This commit adds a context to InvoiceDB's methods. Along this refactor
we also extend InvoiceRegistry methods with contexts where it makes
sense. This change is essential to be able to provide kvdb and sqldb
implementations for InvoiceDB.

* channeldb: restrict invoice tests to only use an InvoiceDB instance

* docs: update release notes for 0.18.0
2023-10-11 13:42:59 +02:00
Olaoluwa Osuntokun
de54a603b7
lnwallet+contractcourt: gracefully handle auto force close post data loss
In this commit, update the start up logic to gracefully handle a
seemingly rare case. In this case, a peer detects local data loss with a
set of active HTLCs. These HTLCs then eventually expire (they may or may
not actually "exist"), causing a force close decision. Before this PR,
this attempt would fail with a fatal error that can impede start up.

To better handle such a scenario, we'll now catch the error when we fail
to force close due to entering the DLP and instead terminate the state
machine at the broadcast state. When a commitment transaction eventually
confirms, we'll play it as normal.

Fixes https://github.com/lightningnetwork/lnd/issues/7984
2023-09-15 18:29:09 -07:00
Yong
d24f12bd0b
contractcourt: fix potential panic during startup (#7936)
Related to this fix 5a28582719, we may not
have the historical data for old channels so we skip it here too.
2023-08-29 10:27:09 -07:00
Olaoluwa Osuntokun
2010239b63
contractcourt: update the anchor resolver for taproot chans 2023-08-22 16:33:32 -07:00
Olaoluwa Osuntokun
47d4eb341d
contractcourt: store new taproot resolution info in new key
We pull the information from the sign descriptors and store them in the
resolutions. However, the resolvers created end up duplicating the
resolution data, so we update the sign descs as needed during start up.
2023-08-22 16:33:30 -07:00
yyforyongyu
a1671a8674
contractcourt: rename htlcResolvers to resolvers
This commit changes the name returned from `prepContractResolutions`
from `htlcResolvers` to `resolvers` to avoid confusion as there are
multiple types of resolvers returned.
2023-08-10 20:25:15 +08:00
yyforyongyu
aff4320208
multi: improve logging re resolution flow 2023-08-10 13:50:03 +08:00
ziggie
8314f0a879
contractcourt: handle mempool min fee error.
In case the mempool backend signals that our transaction does not
meet fee requirements when publishing it we will continue to
start up now. The transaction will be rebroadcasted in the
background and a specific log message will be printed to let the
user know that he could increase his mempool size to at least
have this transaction in his own mempool.
2023-07-25 01:13:24 +02:00
yyforyongyu
3857b9e9a6
contractcourt: improve logging for failing dangling htlcs 2023-06-07 17:34:06 +08:00
yyforyongyu
56dcda0f7c
contractcourt: add debug logs for unresolved contracts 2023-04-28 20:38:00 +08:00
yyforyongyu
dccf9c77ca
lnd+contractcourt: add more debug logs
This commit adds more debug logs for witness beacon and channel
arbitrator.
2023-04-19 01:18:19 +08:00
positiveblue
5ff5225245
multi: break invoice depenency on channeldb
Now that we have the new package `lnd/channeldb/models` we can invert the
depenency between `channeldb` and `invoices`.

- Move all the invoice related types and errors to the
`invoices` package.

- Ensure that all the packages dealing with invoices use the types and
  interfaces defined in the `invoices` package.

- Implement the InvoiceDB interface (defined in `lnd/invoices`) in
  channeldb.

- Add new mock for InterfaceDB.

- `InvoiceRegistery` tests are now in its own subpacakge (they need to
  import both invoices & channeldb). This is temporary until we can
  decouple them.
2023-01-16 07:31:09 -08:00
positiveblue
383cb40f8d
multi: create channeldb/models package
Add a new subpackage to `lnd/channeldb` to hold some of the types that
are used in the package itself and in other packages that should not
depend on `channeldb`.
2023-01-16 07:14:55 -08:00
Joost Jager
511fb00777
htlcswitch: add final htlc event to notifier 2022-10-27 16:42:36 +02:00
Joost Jager
28256b7ea8
htlcswitch: keep final htlc outcome 2022-10-27 16:42:36 +02:00
Olaoluwa Osuntokun
9b0718ae35
contractcourt: unify the lease specific HTLC sweeping logic
In this commit, we consolidate the _lease specific_ logic for the
success and timeout HTLC resolvers. We do this with the addition of a
new struct which is then composed via struct embedding with the two
existing structs. This fixes a flake in the integration tests by
ensuring the height is set up front, rather than eventually once the
height matches the lock time.
2022-06-01 16:42:33 -07:00
Olaoluwa Osuntokun
54adc6996b
Merge pull request #6322 from Crypt-iQ/handoff_deadlock_fix
contractcourt: deadlock fix via temporary unmerged map
2022-05-03 15:12:20 -07:00
eugene
f7b3da4bb2
htlcswitch+lntest: modify Switch to persist resolution messages
Include unit tests for the Switch, and integration tests that
exercise the persistence logic.
2022-04-29 16:40:19 -04:00
eugene
ef83370dcf
contractcourt: deadlock fix via temporary unmerged map
The main idea is that NotifyContractUpdate adds the ContractUpdate to
a map called unmerged. It is populated in Start by shallow-copying the
activeHTLCs map values (htlcSet). The htlcSets underlying maps are not
copied, and so unmerged will just contain pointers to them. This should
be fine since unmerged will not modify them. At the call-sites of
activeHTLCs, it is updated to include the unmerged sets. This happens
with a mutex and should not cause any data race, even though it is
copying the underlying map pointers. No persistence should be
necessary since on restart, activeHTLCs and unmerged will just be
populated again.
2022-04-19 17:24:21 -04:00
Joost Jager
721fb4ee88
contractcourt: add onchain interception 2022-04-13 11:31:33 +02:00
Antoni Spaanderman
1516310257
channelarbitrator: fix typo in comment [skip ci] 2022-03-27 15:54:56 +02:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
eugene
8607e8c28a
multi: reliable hand-off from htlcswitch to contractcourt
This is achieved by changing the 1-way handoff to a 2-way handoff
with a done channel.
2022-02-24 13:35:15 -05:00
eugene
ebaffb953a server+contractcourt: hand-off BreachCloseInfo to channel arbitrator
This also changes the chain_watcher and breacharbiter handoff. The
new logic ensures that the channel is only marked as pending closed
when the channel arbitrator has persisted the resolutions and commit
set.
2022-01-25 15:42:20 -05:00
eugene
b7407882ac contractcourt: create breachResolver if BreachResolution present
Also transitions to the proper state based on if this is a legacy
breach in the channel arbitrator or a modern breach with a resolver.
2022-01-25 15:42:20 -05:00
Olaoluwa Osuntokun
2e42476f29
Merge pull request #6151 from C-Otto/force-close-logging
contractcourt: use "info" log level for messages leading to force-clo…
2022-01-20 16:59:26 -08:00