Commit Graph

126 Commits

Author SHA1 Message Date
Elle Mouton
fde982ad78
input: extract to_local script builders
Factor out the building of the delay and revoke scripts from
NewLocalCommitScriptTree so that they can be re-used later on.
2024-01-18 17:56:48 +02:00
bitcoin-lightning
b72fc9529e docs: fix typos 2023-12-21 15:21:35 +00:00
yyforyongyu
ae09ab2a21
input: use lnutils.SyncMap to store musig2 sessions 2023-11-25 07:25:18 +08:00
Oliver Gugger
b0bb853f77
Merge pull request #8092 from yyforyongyu/fix-peer-unit-test
multi: fix peer unit test and disable `paralleltest`
2023-10-17 10:18:27 +00:00
yyforyongyu
34e0c7b5e0
input+sweep: make sure input with no fee rate is not added to cluster
This commit makes sure an input is only added to the cluster when it has
successfully estimated its fee rate. Previously, when an error is
returned from `feeRateForPreference`, we'd still add this input to the
cluster, resulting a **lower** fee rates being used because when
averaging the fee rates, we'd think this input has zero fee rate
specified.

An unit test is patched to make the method `clusterByLockTime` more
robust.
2023-10-13 17:00:53 +08:00
yyforyongyu
22600b47f1
multi: disable linter paralleltest 2023-10-13 13:50:09 +08:00
Olaoluwa Osuntokun
ce93b236aa
input+lnwallet: modify musig2 interfaces use explicit optional local nonces
In this commit, we modify the musig2 interfaces to instead use an
explicit value for the local nonces. Before this commit, we used the
functional option, but we want to also support specifying this value
over RPC for the remote signer. The functional option pattern is opaque,
so we can't get the nonce value we need. To get around this, we'll just
make this an explicit pointer, then map this to the functional option at
the very last moment.
2023-09-18 11:42:13 -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
a244a30f32
input: create new ScriptDesciptor interface
In this commit, we add a new interface, the `ScriptDesciptor` to
abstract over details of a given output script. The purpose of this
interface, and the taproot superset, is to be able to paper over the
differences of a p2wsh vs a p2tr output. With this new interface, we can
treat them as the same, but then use a type assertion to get at any
control block related methods if needed.
2023-08-22 16:33:44 -07:00
Olaoluwa Osuntokun
7e2d04a310
contractcourt: update UTXO nursery to support taproot chans 2023-08-22 16:33:42 -07:00
Olaoluwa Osuntokun
fa07a2d248
input: HtlcSucceedInput to support sweeping for taproot chans 2023-08-22 16:33:25 -07:00
Olaoluwa Osuntokun
b00cf25590
input: add new HtlcSecondLevelAnchorInput types for taproot chans 2023-08-22 16:33:22 -07:00
Olaoluwa Osuntokun
b39f5884ad
input: update IsHtlcSpendRevoke for taproot chans
For taproot channels, the revocation witness is a single sig as the
keyspend path is used.
2023-08-22 16:33:17 -07:00
Olaoluwa Osuntokun
8d0435397d
input: add new SecondLevelScriptTree to support second level HTLC spends 2023-08-22 16:32:48 -07:00
Olaoluwa Osuntokun
4c7da7df49
input: update all taproot script spends to optionally make the ctrl block
In this commit, we update all the taproot scripts spends to optionally
make the control block. This is useful in cases where we've already
created the control block, or may not have the items needed to construct
it in the first place.

We also add the control block to the sign descriptor itself.
2023-08-22 16:32:46 -07:00
Olaoluwa Osuntokun
405a435a84
input: add weight estimation + tests for all taproot witness gen types 2023-08-22 16:32:44 -07:00
Olaoluwa Osuntokun
d3c7c51f7e
input: add new witness gen types for all taproot spends 2023-08-22 16:32:42 -07:00
Olaoluwa Osuntokun
a5f67b451e
input: add new ParseSignature helper func 2023-08-22 16:32:37 -07:00
Olaoluwa Osuntokun
349eee3263
input: ensure sessionOpts is properly threaded through 2023-08-22 16:31:47 -07:00
Olaoluwa Osuntokun
001c5b0e0b
input: use multmutex to increase concurrency for musig session manager
By using the multimutex here, we'll no longer rely on a single mutex for
the entire musig session set like we used to. Instead, we can use the
session ID to key into a map of mutexes and use those directly.
2023-08-22 16:30:47 -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
Olaoluwa Osuntokun
4733da5ccb
input: eliminate CSV trick for HTLC outputs 2023-08-22 16:30:36 -07:00
Olaoluwa Osuntokun
6ce7f5d29e
input: use explicit CSV 1 script for to remote output
We undo the prior hack here to make the final script more readable. The
difference is just 1 byte between the two.
2023-08-22 16:30:34 -07:00
Olaoluwa Osuntokun
0c74f894c4
input: fix linter errors 2023-08-22 16:30:31 -07:00
Olaoluwa Osuntokun
8fc8640432
input: use script path for revocation clause for to_local output
In this commit, we modify the to_local script to use a script path for
the revocation scenario. With this change, we ensure that the internal
key is always revealed which means the anchor outputs can still always
be swept.
2023-08-22 16:30:28 -07:00
Olaoluwa Osuntokun
7f05c765c3
input: restore usage of NUMS key for to_remote output
In this commit, we restore usage of the NUMS key for the to remote
output, as this allows a remote party to scan the chain in order to find
their remote output that in emergency recovery scenarios.
2023-08-22 16:30:26 -07:00
Olaoluwa Osuntokun
5e921376c4
input: add exhaustive unit tests for new taproot scripts 2023-08-22 16:30:23 -07:00
Olaoluwa Osuntokun
b8d1596428
input: add new maybeAppendSighashType helper func 2023-08-22 16:30:20 -07:00
Olaoluwa Osuntokun
3393cc182d
input: add spending funcs for second level HTLC tapscript ctrl blocks 2023-08-22 16:30:18 -07:00
Olaoluwa Osuntokun
89a365758a
input: add taproot second level HTLC scripts 2023-08-22 16:30:15 -07:00
Olaoluwa Osuntokun
d8fa0516e9
input: add spending funcs for taproot receiver HTLC ctrl blocks 2023-08-22 16:30:13 -07:00
Olaoluwa Osuntokun
b2d244cf2a
input: add taproot script funcs for receiver HTLCs 2023-08-22 16:30:10 -07:00
Olaoluwa Osuntokun
164b60675b
input: add spending funcs for taproot sender HTLCs 2023-08-22 16:30:07 -07:00
Olaoluwa Osuntokun
7e7de11cfd
input: add tapscript utils for the sender HTLC script
Unlike the old HTLC scripts, we now need to handle the various control
block interactions. As is, we opt to simply re-compute the entire tree
when needed, as the tree only has two leaves.
2023-08-22 16:30:05 -07:00
Olaoluwa Osuntokun
734dc0f085
input: add TaprootOutputKeyAnchor for taproot anchor outputs 2023-08-22 16:30:02 -07:00
Olaoluwa Osuntokun
50bf3b6177
input: add TaprootCommitScriptToRemote for taproot to remote script 2023-08-22 16:30:00 -07:00
Olaoluwa Osuntokun
5f81919284
input: add TaprootCommitScriptToSelf for taproot to self script 2023-08-22 16:29:57 -07:00
Olaoluwa Osuntokun
9d0c04bfa2
input: add GenTaprootFundingScript based on musig2
In this commit, we add GenTaprootFundingScript, which'll return the
taproot pkScript and output for a taproot+musig2 channel. This uses
musig2 key aggregation with sorting activated.

The final key produced uses a bip86 tweak, meaning that the output key
provably doesn't commit to any script path. In the future, we may want
to permit this, as then it allows for a greater degree of
programmability of the funding output.
2023-08-22 16:29:55 -07:00
Olaoluwa Osuntokun
92868cfaa5
input: add PayToTaprootScript helper func
In this commit, we add a helper function to take a taproot output key
and turn it into a v1 witness program.
2023-08-22 16:29:52 -07:00
yyforyongyu
aff4320208
multi: improve logging re resolution flow 2023-08-10 13:50:03 +08:00
Olaoluwa Osuntokun
66a85bf9db
Merge pull request #7473 from emilioziniades/realign-witness-types
input+lnrpc: realign witness types
2023-04-13 16:09:01 -07:00
Emilio Ziniades
d8b9a2d042
input: note to update witness type protobuf 2023-04-12 21:58:12 +02:00
Oliver Gugger
79c275253c
input: set initial script allocation size
The default allocation of 500 bytes for the script that is
used in NewScriptBuilder is way too much for most of our scripts.
With the new functional option we can tune the allocation to exactly
what we need.
2023-04-11 11:15:36 +02:00
Oliver Gugger
a47345bd6f
input: add script size unit and benchmark tests 2023-04-11 11:15:36 +02:00
Oliver Gugger
ce5fa2e043
multi: add version to MuSig2 API, bump btcd/btcec to v2.3.2
With this commit we bump the github.com/btcd/btcec/v2 library to v2.3.2
which implements the MuSig2 BIP version v1.0.0rc2. With this the
github.com/btcsuite/btcd/btcec/v2/schnorr/musig2 package becomes
v1.0.0rc2 and the github.com/lightningnetwork/lnd/internal/musig2v040
stays at the old v0.4.0 version.
2023-02-03 18:30:10 +01:00
Oliver Gugger
0e5ce71b33
input+lnwallet: put MuSig2 types behind interface
We put the calls that don't use musig2 package specific types as
parameters or return values behind an interface so we can easily call
those directly in the RPC without needing to know the underlying
implementation version. Some calls can't be used in the interface
because they use the specific package version's types. These calls are
implemented in helper functions in the input package instead that do the
necessary type switches.
2023-02-03 18:30:10 +01:00
Oliver Gugger
cb9f2d0398
input+lnrpc: make key sorting optional in input pkg
To allow us to properly test all test vectors, we can't default to true
on key sorting. Instead we add a parameter to the input package and move
the default value to the RPC server.
2023-02-03 18:30:09 +01:00
Oliver Gugger
13789f5d95
input+lnwallet: move some MuSig2 calls to input pkg
As a preparation for making it possible to version switch calls to the
MuSig2 API, we move some of the calls to the input package where in a
future commit we'll call the corresponding code in the correct package.
2023-02-03 18:30:09 +01:00