Commit graph

15206 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
da1282c17e
lnwallet: refactor revocation tests to test for tweakless+taproot 2023-08-22 16:31:57 -07:00
Olaoluwa Osuntokun
3270a29e3e
lnwallet: handle nonce init in ProcessChanSyncMsg
In this commit, we update the logic to handle nonce init in
ProcessChanSyncMsg. Once a channel is already open, this is where we'll
get the new nonce data from the remote party we'll use to gain the nonce
we need to sign for their next state.
2023-08-22 16:31:54 -07:00
Olaoluwa Osuntokun
911becb431
lnwallet: move nonce generation into generateRevocation
Before this commit, we would conditionally generate nonces in
RevokeCurrentCommitment. We move this to generateRevocation as this is
called when doing channel sync, and we want to make sure we send the
correct set of nonces.
2023-08-22 16:31:52 -07:00
Olaoluwa Osuntokun
76f0f67b7c
channeldb: update ChanSyncMsg to populate nonce info
In this commit, we update the ChanSyncMsg to populate nonce information.
With this change, we can now hide nonce generation further down in the
pipeline and ensure that all callers will have the expected fields
populated.
2023-08-22 16:31:49 -07:00
Olaoluwa Osuntokun
349eee3263
input: ensure sessionOpts is properly threaded through 2023-08-22 16:31:47 -07:00
Olaoluwa Osuntokun
d2bc4f29e1
lnwallet: fix bug in deriveMusig2Shachain
In this commit, we fix a bug in the `deriveMusig2Shachain` function
where it didn't actually use the passed in revocation root as part of
the hmac invocation.

We also modify the function to be more generally useable as well, as now
the caller can just pass in the revocation root things should be derived
from.
2023-08-22 16:31:44 -07:00
Olaoluwa Osuntokun
83f1bd4717
lnwallet: return structured error from VerifyCommitSig 2023-08-22 16:31:41 -07:00
Olaoluwa Osuntokun
3879138018
lnwallet: update internal co-op close flow to support musig2 keyspend
In this commit, we update the co-op close flow to support the new musig2
keyspend flow. We'll use some new functional options to allow a caller
to pass in an active musig2 session. If this is present, then we'll use
that to complete the musig2 flow by signing with a partial signature,
and then ultimately combining the signatures at the end.
2023-08-22 16:31:38 -07:00
Olaoluwa Osuntokun
c9fc508083
lnwallet/chanvalidate: update ValidateChannel to recognize taproot chans 2023-08-22 16:31:36 -07:00
Olaoluwa Osuntokun
b38f9000d5
lnwallet: update testAddSettleWorkflow to test the new taproot flow 2023-08-22 16:31:33 -07:00
Olaoluwa Osuntokun
39d5dffd56
lnwallet: update genHtlcSigValidationJobs to be taproot aware
In this commit, we update the genHtlcSigValidationJobs function to be
taproot aware. As we actually need a schnorr signature for the taproot
validation, we need to coerce the entire wire type into a schnorr sig
with the ForceSchnorr() method.
2023-08-22 16:31:31 -07:00
Olaoluwa Osuntokun
5336f03ac6
lnwallet: update to genRemoteHtlcSigJobs to generate taproot jobs
In this commit, we update the genRemoteHtlcSigJobs function to be able
to generate taproot jobs. We also modify the sigpool to now use a
input.Signature everywhere. This'll allow us to pass around both ECDSA
and Schnorr signatures via the same interface.

We use a tapscript sighash in this case, as all the HTLC spends will
actually be script path spends.
2023-08-22 16:31:28 -07:00
Olaoluwa Osuntokun
ca21c4bdb4
lnwallet: update channel state machine to add musig session initialization
In this commit, we update the channel state machine with a new set of
functional options that can be used to create/set the musig session
state. When a channel is made during the funding process, the set of
nonces we want to use is already known, so we allow them to be passed
in. Similarly, once the channel is confirmed, then we'll need to create
another channel instance that this times carries the newly generated
nonces to send along side funding_locked.

We also add some utility methods to permit callers to properly generate
nonces in the various contexts.
2023-08-22 16:31:25 -07:00
Olaoluwa Osuntokun
d2526c75f4
lnwallet: update genHTLC script to support segwit v0 + v1 (taproot) HTLCs 2023-08-22 16:31:23 -07:00
Olaoluwa Osuntokun
2a22f5b959
lnwallet: update CreateHtlcTimeoutTx+CreateHtlcSuccessTx for taproot 2023-08-22 16:31:20 -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
72d41ae408
lnwallet: export MusigCommitType enum
We need to export the enum as it'll now be used in areas such as the
chan closer.
2023-08-22 16:31:15 -07:00
Olaoluwa Osuntokun
a5d8f69516
peer: soft-disable towers with taproot channels
In this commit, we modify the starting logic to note attempt to add a
tower client for taproot channels. Instead, we'll just log that this
isn't available yet.
2023-08-22 16:31:13 -07:00
Olaoluwa Osuntokun
c6308130aa
lnwallet: add test case for musig2 channel funding 2023-08-22 16:31:10 -07:00
Olaoluwa Osuntokun
67ecefaac3
lnwallet: integrate new taproot channels into internal funding flow
In this commit, we build on all the prior commits and integrate the new
taproot channels into the existing internal funding flow. Along the way,
we do some refactoring to unify things like signing and verifying
incoming commitment transaction signatures.

For our local nonce, we use the existing functional option type to
derive the nonce based on the initial shachain pre-image we'll use as
our revocation.
2023-08-22 16:31:07 -07:00
Olaoluwa Osuntokun
9e8b00241f
lnwallet: set new musig2 bool for chanfunding.Request in handleFundingReserveRequest 2023-08-22 16:31:05 -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
cb0229d437
lnwallet: update CommitScriptToRemote to add taproot awareness 2023-08-22 16:31:00 -07:00
Olaoluwa Osuntokun
0e7e29455a
lnwallet: update CommitScriptToSelf to add taproot awareness 2023-08-22 16:30:57 -07:00
Olaoluwa Osuntokun
f7ba08e147
lnwallet: add new CommitmentTypeSimpleTaproot chan type
In this commit, we add a new wallet level channel type, along with the
new fields we'll need to accept from both parties within the
contribution messages. In this case, we now have a local nonce, along
with the internal musig session.
2023-08-22 16:30:54 -07:00
Olaoluwa Osuntokun
05b5391614
channeldb: add new db type for taproot channels 2023-08-22 16:30:52 -07:00
Olaoluwa Osuntokun
1ed6439c3a
lnwallet: add initial unit test coverage for musig chan session 2023-08-22 16:30:49 -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
dafc2a3e5a
lnwallet: add new structs to abstract over the asymmetric musig commitment state
In this commit, we add a series of abstractions that'll allow us to
easily do funding and also state updates for the new taproot channels. A
partial session is defined by the knowledge of a verification nonce.
Once the remote party sends a signature, we learn of their signing
nonce, and can then complete a session. By using a JIT nonce approach,
we ensure that the signer can generate their nonces randomly and also
at the very last step to avoid having to maintain state.

For our local nonces, we also have an option to use a counter based
nonce derived from the shachain instead of fully random nonces. This
allows us to not have to store ay additional state. Instead, when we
need to go to broadcast, we can just regenerate the nonce then use that
to broadcast.
2023-08-22 16:30:44 -07:00
Olaoluwa Osuntokun
95d627af4e
lnwallet/chanfunding: update assemblers to support musig2
In this commit, we update the set of intents and assemblers to recognize
musig2. For this change, we use a new bool, `musig2`, then use that to
determine if we need to use the new taproot funding scripts or not.
2023-08-22 16:30:42 -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
Olaoluwa Osuntokun
9851a6147b
lnwire: TestLightningWireProtocol quick check tests for taproot fields 2023-08-22 16:29:49 -07:00