Commit graph

15188 commits

Author SHA1 Message Date
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
Olaoluwa Osuntokun
7ae4bf0672
lnwire: sort records in ExtractRecords
This ensures that the caller doesn't need to worry about the TLV type
ordering of the records the pass into the function.
2023-08-22 16:29:47 -07:00
Olaoluwa Osuntokun
25dfbadd23
lnwire: add ShutdownNonce to Shutdown 2023-08-22 16:29:45 -07:00
Olaoluwa Osuntokun
ca4609e394
lnwire: add LocalNonce to RevokeAndAck 2023-08-22 16:29:42 -07:00
Olaoluwa Osuntokun
4a62652ad2
lnwire: add PartialSig to CommitSig 2023-08-22 16:29:40 -07:00
Olaoluwa Osuntokun
5223b6f381
lnwire: add LocalNonce to ChannelReestablish 2023-08-22 16:29:38 -07:00
Olaoluwa Osuntokun
8afb60da17
lnwire: add LocalNonce to FundingLocked 2023-08-22 16:29:36 -07:00
Olaoluwa Osuntokun
79c473cc46
lnwire: add PartialSig to FundingSigned 2023-08-22 16:29:34 -07:00
Olaoluwa Osuntokun
292b8db8f0
lnwire: add PartialSig to FundingCreated 2023-08-22 16:29:31 -07:00
Olaoluwa Osuntokun
ee279fbde3
lnwire: add LocalNonce to AcceptChannel 2023-08-22 16:29:29 -07:00
Olaoluwa Osuntokun
7c5ba067ab
lnwire: add LocalNonce to OpenChannel 2023-08-22 16:29:27 -07:00
Olaoluwa Osuntokun
14949c972d
lnwire: add new musig2 partial signature type
In this commit, we add the new types that'll house musig signatures with
and without their nonces. We send the nonce along with the sig
everywhere but the co-op close flow.
2023-08-22 16:29:24 -07:00
Olaoluwa Osuntokun
5b7caaea6d
lnwire: add new Musig2Nonce TLV record 2023-08-22 16:29:22 -07:00
Olaoluwa Osuntokun
b368e476c5
lnwire: update Sig to support both ECDSA and schnorr sigs
In this commit, we update the Sig type to support ECDSA and schnorr
signatures. We need to do this as the HTLC signatures will become
schnorr sigs for taproot channels. The current spec draft opts to
overload this field since both the sigs are actually 64 bytes in length.
The only consideration with this move is that callers need to "coerce" a
sig to the proper type if they need schnorr signatures.
2023-08-22 16:29:19 -07:00
Olaoluwa Osuntokun
eccc77315b
lnwire: add feature bits for simple taproot chans 2023-08-22 16:29:17 -07:00
Oliver Gugger
e49f6fcdd3
Merge pull request #7648 from guggero/initial-forwarding-policy
funding: fix flake in itest caused by persistent fee param changes
2023-08-22 15:15:28 +02:00
yyforyongyu
6820b08b53
funding: put assertNoFwdingPolicy in wait.NoError 2023-08-22 11:10:15 +08:00
yyforyongyu
0a6b05d2de
funding: catching barrier signal in receivedChannelReady
There is a race condition,
- goroutine_1: performing `stateStep` under `channelReadySent`. Once
  `receivedChannelReady` returns true, it will mark the channel state as
  `addedToRouterGraph`, which will delete the initial forwarding policy
  for private channels.
- goroutine_2: performing `handleChannelReady`, which processes the
  remote's channelReady message. It will ask brontide to `AddNewChannel`
  in the end.
- goroutine_3: performing `handleNewActiveChannel` in brontide, which
  will query the initial forwarding policy and fail to find it because
  it's already deleted in goroutine_1.

To fix it, we require `receivedChannelReady` to also check that the
channel's barrier signal in the map `handleChannelReadyBarriers` doesn't
exist, as this signal is removed once `handleChannelReady` finishes
adding the channel in brontide.
2023-08-22 09:52:49 +08:00
yyforyongyu
32d8208272
funding: add new method handleChannelReadyReceived
This commit is a pure code move. We add a new method
`handleChannelReadyReceived` to handle the channel's state change after
the remote's channel ready message is received.
2023-08-22 09:52:46 +08:00