Skip to content
Closed
22 changes: 19 additions & 3 deletions lnwallet/chanfunding/canned_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
)
Expand Down Expand Up @@ -56,6 +58,14 @@ type ShimIntent struct {
// generate an aggregate key to use as the taproot-native multi-sig
// output.
musig2 bool

// tapscriptRoot is the root of the tapscript tree that will be used to
// create the funding output. This field will only be utilized if the
// musig2 flag above is set to true.
//
// TODO(roasbeef): fold above into new chan type? sum type like thing,
// includes the tapscript root, etc
tapscriptRoot fn.Option[chainhash.Hash]
}

// FundingOutput returns the witness script, and the output that creates the
Expand All @@ -73,12 +83,18 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) {
// If musig2 is active, then we'll return a single aggregated key
// rather than using the "existing" funding script.
if s.musig2 {
var scriptOpts []input.FundingScriptOpt
s.tapscriptRoot.WhenSome(func(root chainhash.Hash) {
scriptOpts = append(
scriptOpts, input.WithTapscriptRoot(root),
)
})

// 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),
s.localKey.PubKey, s.remoteKey, int64(totalAmt),
scriptOpts...,
)
}

Expand Down
1 change: 1 addition & 0 deletions lnwallet/chanfunding/psbt_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ func (p *PsbtAssembler) ProvisionChannel(req *Request) (Intent, error) {
ShimIntent: ShimIntent{
localFundingAmt: p.fundingAmt,
musig2: req.Musig2,
tapscriptRoot: req.TapscriptRoot,
},
State: PsbtShimRegistered,
BasePsbt: p.basePsbt,
Expand Down
13 changes: 7 additions & 6 deletions lnwallet/chanfunding/wallet_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
// we will call the specialized coin selection function for
// that.
case r.FundUpToMaxAmt != 0 && r.MinFundAmt != 0:

// We need to ensure that manually selected coins, which
// are spent entirely on the channel funding, leave
// enough funds in the wallet to cover for a reserve.
// We need to ensure that manually selected coins,
// which are spent entirely on the channel funding,
// leave enough funds in the wallet to cover for a
// reserve.
reserve := r.WalletReserve
if len(manuallySelectedCoins) > 0 {
sumCoins := func(
Expand All @@ -386,8 +386,8 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {

// If sufficient reserve funds are available we
// don't have to provide for it during coin
// selection. The manually selected coins can be
// spent entirely on the channel funding. If
// selection. The manually selected coins can
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking out of curiousity, did you change your editor's settings? Because it looks to me like this fit perfectly before...

// be spent entirely on the channel funding. If
// the excess of coins cover the reserve
// partially then we have to provide for the
// rest during coin selection.
Expand Down Expand Up @@ -501,6 +501,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
localFundingAmt: localContributionAmt,
remoteFundingAmt: r.RemoteAmt,
musig2: r.Musig2,
tapscriptRoot: r.TapscriptRoot,
},
InputCoins: selectedCoins,
coinLocker: w.cfg.CoinLocker,
Expand Down