Commit Graph

486 Commits

Author SHA1 Message Date
yyforyongyu
a252cb4528
contractcourt: fix test flake in TestTaprootBriefcase
When the numTweaks is zero, we should return a nil instead of
initializing an empty map as we'd get the following error,

```
Diff:
--- Expected
+++ Actual
@@ -11007,4 +11007,3 @@
},
-  BreachedHtlcTweaks: (contractcourt.htlcTapTweaks) {
-  },
+  BreachedHtlcTweaks: (contractcourt.htlcTapTweaks) <nil>,
```
2023-09-05 07:44:02 +08: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
92da6b1d44
multi: fix linter warnings with updated linter 2023-08-22 16:34:47 -07:00
Olaoluwa Osuntokun
a2b277cf1d
multi: fix linter errors 2023-08-22 16:34:15 -07:00
Olaoluwa Osuntokun
4b0139c9ba
lnwallet: update channel state machine to use new ScriptDescriptor interface
In this commit, we update the channel state machine to use the new
ScriptDescriptor interface. This fixes some subtle issues with the
existing commits, as for p2wsh we always sign the same witness script,
but for p2tr, the witness script differs depending on which branch is
taken.

With the new abstractions, we can treat p2wsh and p2tr as the same
mostly, right up until we need to obtain a control block or a tap tweak.

All tests have been updated accordingly.
2023-08-22 16:33:46 -07:00
Olaoluwa Osuntokun
7e2d04a310
contractcourt: update UTXO nursery to support taproot chans 2023-08-22 16:33:42 -07:00
Olaoluwa Osuntokun
cdcde6e0a5
contractcourt: update breach arbiter to support taproot chans
In this commit, we update the breach arb to support taproot channels. We
utilize the new taproot briefcase space to store both control blocks,
and also the first+second level scripts for the set of HTLCs.
2023-08-22 16:33:40 -07:00
Olaoluwa Osuntokun
df2a2d83ea
contractcourt: update htlcSuccessResolver for taproot chans 2023-08-22 16:33:38 -07:00
Olaoluwa Osuntokun
23f7ee39c7
contractcourt: update htlcTimeoutResolver for taproot chans 2023-08-22 16:33:36 -07:00
Olaoluwa Osuntokun
47f70dae3a
contractcourt: update commitSweepResolver for taproot chans 2023-08-22 16:33:34 -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
Olaoluwa Osuntokun
a1788fe4a2
contractcourt: add new taproot briefcase to store ctrl block and tap tweaks
In this commit, we add a new taproot specific briefcase to store the
control block and tap tweaks for all taproot outputs. We chose this
route as many of the existing fields are serialized in line, so we
aren't able to serialize this new taproot specific information in the
existing briefcase.
2023-08-22 16:33:27 -07:00
Olaoluwa Osuntokun
ee59e3f181
lnwallet: update NewAnchorResolution to support taproot anchors 2023-08-22 16:32:59 -07:00
Olaoluwa Osuntokun
d4a6be1c9f
contractcourt: for taproot channels, wait for conf in closeObserver
This ensures that we end up playing the target output on chain for
taproot channels.
2023-08-22 16:32:23 -07:00
Olaoluwa Osuntokun
9ce817511d
contractcourt: update chain watcher to understand the taproot pkscript
In this commit, we update the chain watcher to be able to generate the
correct pkScript so it can register for confirmation and spend
notifications for taproot channels.
2023-08-22 16:32:15 -07:00
Olaoluwa Osuntokun
11c62e3951
lnwallet+htlcswitch: add NewCommitState struct, modify send/recv sig to accept
In this commit, we add a new NewCommitState struct. This preps us for
the future change wherein a partial signature is also added to the mix.
All related tests and type signatures have also been updated
accordingly.
2023-08-22 16:31:18 -07:00
Olaoluwa Osuntokun
5e511e35fd
lnwallet: update CommitScriptAnchors to add taproot awareness
We also update some of the resolutions (even though they aren't hooked
up yet), as they need to be able to properly re-create the set of
scripts.
2023-08-22 16:31:02 -07:00
Olaoluwa Osuntokun
9a65806c09
input+wallet: extract musig2 session management into new module
In this commit, we extract the musig2 session management into a new
module. This allows us to re-use the session logic elsewhere in unit
tests so we don't need to instantiate the entire wallet.
2023-08-22 16:30:39 -07:00
yyforyongyu
92671ad250
contractcourt: register conf notification before publish tx
This commit moves the confirmation registration before publishing the tx
to make sure the conf event won't be missed.
2023-08-10 20:36:41 +08: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
c88ff14477
contractcourt: add tests for mempool rejection.
Add a test where the channel arbitrator starts up correctly
when a prior unilateral close of a channel did not broadcast
for specific reasons.
Also add a test which ensures that when a crib output is
rejected by the bitcoin backend the startup works correctly
for specific errors.
2023-07-26 00:03:17 +02: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
Olaoluwa Osuntokun
7f95810359
Merge pull request #7710 from carlaKC/7297-updateaddtlvs
Channeldb: Store HTLC Extra TLVs in Onion Blob Varbytes
2023-06-16 14:31:11 -05:00
yyforyongyu
3857b9e9a6
contractcourt: improve logging for failing dangling htlcs 2023-06-07 17:34:06 +08:00
Carla Kirk-Cohen
2fc8e9d617
multi: update channel db HTLC OnionBlob to array
We know that onion blobs in lightning are _exactly_ 1366 bytes in
lightning, but they are currently expressed as a byte slice in
channeldb's HTLC struct. Blobs are currently serialized as var bytes,
so we can take advantage of this known length and variable length
to add additional data to the inline serialization of our HTLCs, which
are otherwise not easily extensible (without creating a new bucket).
2023-06-02 11:01:43 -04:00
Matt Morehouse
da10cb95b5
contractcourt: fully use chanPoint variable
When we create a temporary chanPoint variable to shorten up the code, we
should use it everywhere for consistency and clarity.
2023-05-31 10:56:08 -05:00
Olaoluwa Osuntokun
7686d10075 contractcourt: force the sweeper to always resolve outgoing HTLCs
In this commit, we attempt to fix an issue that may lead to force closes due
to small value HTLCs. The sweeper has built in a "negative yield" heuristic
where it won't sweep something that'll result in paying more fees than the
HTLC amount. However for HTLCs, we want to always sweep them, as we don't
cancel back the HTLCs before the outgoing contract is fully resolved.

In the future, we'll start to make more uneconomical decisions about if we
should go to chain at all for small value HTLCs, and also do things like
cancel back early if the HTLC is small and we think we might be contested by
chain fees.
2023-05-26 15:15:36 -07:00
yyforyongyu
186569c610
contractcourt: skip checkpoint timeout resolver upon mempool spend
Previously when a block spend is found for the outpoint, our htlc
timeout resolver will do a checkpoint, which implicitly creates a db
record if there isn't one. Now, if the spend is found in mempool,
the resolver will be deleted once the contract is resolved. Later on
when the spend is found in the block again, the resolver will be created
again, but never gets resolved this time.
2023-04-28 20:38:01 +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
yyforyongyu
556c38fefd
contractcourt+lnd: watch for preimage reveal in mempool
This commit extends the current htlc timeout resolver to also watch for
preimage spend in mempool for a full node backend.

If mempool enabled, the resolver will watch the spend of the htlc output
in mempool and blocks **concurrently**, as if they are independent.

Ideally, a transaction will first appear in mempool then in a block.
However, there's no guarantee it will appear in **our** mempool since
there's no global mempool, thus we need to watch the spend in two places
in case it doesn't go through our mempool.

The current design favors the spend event found in blocks, that is, when
the tx is confirmed, we'd abort the monitoring and conitnue since the
outpoint cannot be double spent and re-appear in mempool again. This is
not true in the rare case of reorg, and we will handle reorg seperately.
2023-04-19 01:18:19 +08:00
yyforyongyu
7ef8072724
contractcourt: refactor spendHtlcOutput for clarity
Also fixes the docs and rename `isSuccessSpend` to `isPreimageSpend`.
2023-04-19 01:18:19 +08:00
yyforyongyu
edba938996
multi: add new build tag integration
This commit adds a new build tag `integration` and removes the old tag
`rpctest` for clarity. Multiple unnecessary usages of `build !rpctest`
is also removed.
2023-02-23 21:56:09 +08:00
yyforyongyu
6618ab493a
multi: enhance loggings and fix logging format
Also adds TODO for a possible bug.
2023-02-23 21:56:08 +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
yyforyongyu
84fd911b47
multi: fix make lint
Fixes new lint errors caught by the latest version.
2022-11-18 20:48:23 +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
yyforyongyu
5ed37166ef
contractcourt: return htlcResolution when currentHeight has reached expiry
Only create the sweep tx when the height has reached, otherwise we will
get a broadcast error. Previously it wasn't caught by itest due to the
blocks were mined very fast, so the lock time was always reached.
2022-10-27 01:11:35 +08:00
yyforyongyu
2285bfdf9f
contractcourt+brontide: fix typo and inaccurate logging 2022-10-27 01:11:35 +08:00
Eng Zer Jun
c70e39cd21
multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:46:54 +08:00
Eng Zer Jun
d1541d6628
contractcourt: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 08:58:16 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
Olaoluwa Osuntokun
cd313eba24
contractcourt: the breach arb now uses P2TR outputs for sweep addrs 2022-08-11 17:26:10 -07:00
Oliver Gugger
850330a34e
multi: fix linter issues
Fix some issues found by the new nonamedreturn rule and rename some
nolint comment to the new rule name.
2022-07-14 09:30:53 +02:00
eugene
3fc53c673b
contractcourt: set proper height hint for zero-conf channels
The contractcourt's chain watcher is now zero-conf aware and will use
an appropriate heightHint when scanning the chain.
2022-07-07 17:10:29 -04:00
eugene
c9f5912601
channeldb: BigSize migration, store zero-conf, scid-alias bits
This introduces a BigSize migration that is used to expand the width
of the ChannelStatus and ChannelType fields. Three channel "types"
are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit.
ScidAliasChanBit denotes that the scid-alias channel type was
negotiated for the channel. ScidAliasFeatureBit denotes that the
scid-alias feature bit was negotiated during the *lifetime* of the
channel. Several helper functions on the OpenChannel struct are
exposed to aid callers from different packages.

The RefreshShortChanID has been renamed to Refresh.

A new function BroadcastHeight is used to guard access to the
mutable FundingBroadcastHeight member. This prevents data races.
2022-07-07 17:10:27 -04:00