mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
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.
This commit is contained in:
parent
9a65806c09
commit
95d627af4e
@ -110,6 +110,11 @@ type Request struct {
|
||||
// ChangeAddr is a closure that will provide the Assembler with a
|
||||
// change address for the funding transaction if needed.
|
||||
ChangeAddr func() (btcutil.Address, error)
|
||||
|
||||
// Musig2 if true, then musig2 will be used to generate the funding
|
||||
// output. By definition, this'll also use segwit v1 (taproot) for the
|
||||
// funding output.
|
||||
Musig2 bool
|
||||
}
|
||||
|
||||
// Intent is returned by an Assembler and represents the base functionality the
|
||||
|
@ -35,6 +35,11 @@ type ShimIntent struct {
|
||||
// a normal channel. Until this height, it's considered frozen, so it
|
||||
// can only be cooperatively closed by the responding party.
|
||||
thawHeight uint32
|
||||
|
||||
// musig2 determines if the funding output should use musig2 to
|
||||
// generate an aggregate key to use as the taproot-native multi-sig
|
||||
// output.
|
||||
musig2 bool
|
||||
}
|
||||
|
||||
// FundingOutput returns the witness script, and the output that creates the
|
||||
@ -48,6 +53,19 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) {
|
||||
}
|
||||
|
||||
totalAmt := s.localFundingAmt + s.remoteFundingAmt
|
||||
|
||||
// If musig2 is active, then we'll return a single aggregated key
|
||||
// rather than using the "existing" funding script.
|
||||
if s.musig2 {
|
||||
// Similar to the existing p2wsh script, we'll always ensure
|
||||
// the keys are sorted before use.
|
||||
return input.GenTaprootFundingScript(
|
||||
s.localKey.PubKey,
|
||||
s.remoteKey,
|
||||
int64(totalAmt),
|
||||
)
|
||||
}
|
||||
|
||||
return input.GenFundingPkScript(
|
||||
s.localKey.PubKey.SerializeCompressed(),
|
||||
s.remoteKey.SerializeCompressed(),
|
||||
@ -171,13 +189,20 @@ type CannedAssembler struct {
|
||||
// a normal channel. Until this height, it's considered frozen, so it
|
||||
// can only be cooperatively closed by the responding party.
|
||||
thawHeight uint32
|
||||
|
||||
// musig2 determines if the funding output should use musig2 to
|
||||
// generate an aggregate key to use as the taproot-native multi-sig
|
||||
// output.
|
||||
musig2 bool
|
||||
}
|
||||
|
||||
// NewCannedAssembler creates a new CannedAssembler from the material required
|
||||
// to construct a funding output and channel point.
|
||||
//
|
||||
// TODO(roasbeef): pass in chan type instead?
|
||||
func NewCannedAssembler(thawHeight uint32, chanPoint wire.OutPoint,
|
||||
fundingAmt btcutil.Amount, localKey *keychain.KeyDescriptor,
|
||||
remoteKey *btcec.PublicKey, initiator bool) *CannedAssembler {
|
||||
remoteKey *btcec.PublicKey, initiator, musig2 bool) *CannedAssembler {
|
||||
|
||||
return &CannedAssembler{
|
||||
initiator: initiator,
|
||||
@ -186,6 +211,7 @@ func NewCannedAssembler(thawHeight uint32, chanPoint wire.OutPoint,
|
||||
fundingAmt: fundingAmt,
|
||||
chanPoint: chanPoint,
|
||||
thawHeight: thawHeight,
|
||||
musig2: musig2,
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,6 +241,7 @@ func (c *CannedAssembler) ProvisionChannel(req *Request) (Intent, error) {
|
||||
remoteKey: c.remoteKey,
|
||||
chanPoint: &c.chanPoint,
|
||||
thawHeight: c.thawHeight,
|
||||
musig2: c.musig2,
|
||||
}
|
||||
|
||||
if c.initiator {
|
||||
|
@ -531,6 +531,7 @@ func (p *PsbtAssembler) ProvisionChannel(req *Request) (Intent, error) {
|
||||
intent := &PsbtIntent{
|
||||
ShimIntent: ShimIntent{
|
||||
localFundingAmt: p.fundingAmt,
|
||||
musig2: req.Musig2,
|
||||
},
|
||||
State: PsbtShimRegistered,
|
||||
BasePsbt: p.basePsbt,
|
||||
|
@ -476,6 +476,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
|
||||
ShimIntent: ShimIntent{
|
||||
localFundingAmt: localContributionAmt,
|
||||
remoteFundingAmt: r.RemoteAmt,
|
||||
musig2: r.Musig2,
|
||||
},
|
||||
InputCoins: selectedCoins,
|
||||
coinLocker: w.cfg.CoinLocker,
|
||||
|
@ -2974,11 +2974,11 @@ func testSingleFunderExternalFundingTx(miner *rpctest.Harness,
|
||||
thawHeight := uint32(200)
|
||||
aliceExternalFunder := chanfunding.NewCannedAssembler(
|
||||
thawHeight, *chanPoint, btcutil.Amount(chanAmt), &aliceFundingKey,
|
||||
bobFundingKey.PubKey, true,
|
||||
bobFundingKey.PubKey, true, false,
|
||||
)
|
||||
bobShimIntent, err := chanfunding.NewCannedAssembler(
|
||||
thawHeight, *chanPoint, btcutil.Amount(chanAmt), &bobFundingKey,
|
||||
aliceFundingKey.PubKey, false,
|
||||
aliceFundingKey.PubKey, false, false,
|
||||
).ProvisionChannel(&chanfunding.Request{
|
||||
LocalAmt: btcutil.Amount(chanAmt),
|
||||
MinConfs: 1,
|
||||
|
@ -1819,10 +1819,12 @@ func newFundingShimAssembler(chanPointShim *lnrpc.ChanPointShim, initiator bool,
|
||||
|
||||
// With all the parts assembled, we can now make the canned assembler
|
||||
// to pass into the wallet.
|
||||
//
|
||||
// TODO(roasbeef): update to support musig2
|
||||
return chanfunding.NewCannedAssembler(
|
||||
chanPointShim.ThawHeight, *chanPoint,
|
||||
btcutil.Amount(chanPointShim.Amt), &localKeyDesc,
|
||||
remoteKey, initiator,
|
||||
remoteKey, initiator, false,
|
||||
), nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user