mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
input+lnwallet: update taproot scripts to accept optional aux leaf
In this commit, we update all the taproot scripts to also accept an optional aux leaf. This aux leaf can be used to add more redemption paths for advanced channels, or just as an extra commitment space.
This commit is contained in:
parent
8588c9bfd7
commit
1aae47fd71
11 changed files with 273 additions and 108 deletions
|
@ -646,6 +646,13 @@ type HtlcScriptTree struct {
|
||||||
// TimeoutTapLeaf is the tapleaf for the timeout path.
|
// TimeoutTapLeaf is the tapleaf for the timeout path.
|
||||||
TimeoutTapLeaf txscript.TapLeaf
|
TimeoutTapLeaf txscript.TapLeaf
|
||||||
|
|
||||||
|
// AuxLeaf is an auxiliary leaf that can be used to extend the base
|
||||||
|
// HTLC script tree with new spend paths, or just as extra commitment
|
||||||
|
// space. When present, this leaf will always be in the right-most area
|
||||||
|
// of the tapscript tree.
|
||||||
|
AuxLeaf AuxTapLeaf
|
||||||
|
|
||||||
|
// htlcType is the type of HTLC script this is.
|
||||||
htlcType htlcType
|
htlcType htlcType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,8 +733,8 @@ var _ TapscriptDescriptor = (*HtlcScriptTree)(nil)
|
||||||
// senderHtlcTapScriptTree builds the tapscript tree which is used to anchor
|
// senderHtlcTapScriptTree builds the tapscript tree which is used to anchor
|
||||||
// the HTLC key for HTLCs on the sender's commitment.
|
// the HTLC key for HTLCs on the sender's commitment.
|
||||||
func senderHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
func senderHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
revokeKey *btcec.PublicKey, payHash []byte,
|
revokeKey *btcec.PublicKey, payHash []byte, hType htlcType,
|
||||||
hType htlcType) (*HtlcScriptTree, error) {
|
auxLeaf AuxTapLeaf) (*HtlcScriptTree, error) {
|
||||||
|
|
||||||
// First, we'll obtain the tap leaves for both the success and timeout
|
// First, we'll obtain the tap leaves for both the success and timeout
|
||||||
// path.
|
// path.
|
||||||
|
@ -744,11 +751,14 @@ func senderHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tapLeaves := []txscript.TapLeaf{successTapLeaf, timeoutTapLeaf}
|
||||||
|
auxLeaf.WhenSome(func(l txscript.TapLeaf) {
|
||||||
|
tapLeaves = append(tapLeaves, l)
|
||||||
|
})
|
||||||
|
|
||||||
// With the two leaves obtained, we'll now make the tapscript tree,
|
// With the two leaves obtained, we'll now make the tapscript tree,
|
||||||
// then obtain the root from that
|
// then obtain the root from that
|
||||||
tapscriptTree := txscript.AssembleTaprootScriptTree(
|
tapscriptTree := txscript.AssembleTaprootScriptTree(tapLeaves...)
|
||||||
successTapLeaf, timeoutTapLeaf,
|
|
||||||
)
|
|
||||||
|
|
||||||
tapScriptRoot := tapscriptTree.RootNode.TapHash()
|
tapScriptRoot := tapscriptTree.RootNode.TapHash()
|
||||||
|
|
||||||
|
@ -767,6 +777,7 @@ func senderHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
},
|
},
|
||||||
SuccessTapLeaf: successTapLeaf,
|
SuccessTapLeaf: successTapLeaf,
|
||||||
TimeoutTapLeaf: timeoutTapLeaf,
|
TimeoutTapLeaf: timeoutTapLeaf,
|
||||||
|
AuxLeaf: auxLeaf,
|
||||||
htlcType: hType,
|
htlcType: hType,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -801,7 +812,8 @@ func senderHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
// unilaterally spend the created output.
|
// unilaterally spend the created output.
|
||||||
func SenderHTLCScriptTaproot(senderHtlcKey, receiverHtlcKey,
|
func SenderHTLCScriptTaproot(senderHtlcKey, receiverHtlcKey,
|
||||||
revokeKey *btcec.PublicKey, payHash []byte,
|
revokeKey *btcec.PublicKey, payHash []byte,
|
||||||
whoseCommit lntypes.ChannelParty) (*HtlcScriptTree, error) {
|
whoseCommit lntypes.ChannelParty, auxLeaf AuxTapLeaf) (*HtlcScriptTree,
|
||||||
|
error) {
|
||||||
|
|
||||||
var hType htlcType
|
var hType htlcType
|
||||||
if whoseCommit.IsLocal() {
|
if whoseCommit.IsLocal() {
|
||||||
|
@ -814,8 +826,8 @@ func SenderHTLCScriptTaproot(senderHtlcKey, receiverHtlcKey,
|
||||||
// tree that includes the top level output script, as well as the two
|
// tree that includes the top level output script, as well as the two
|
||||||
// tap leaf paths.
|
// tap leaf paths.
|
||||||
return senderHtlcTapScriptTree(
|
return senderHtlcTapScriptTree(
|
||||||
senderHtlcKey, receiverHtlcKey, revokeKey, payHash,
|
senderHtlcKey, receiverHtlcKey, revokeKey, payHash, hType,
|
||||||
hType,
|
auxLeaf,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1285,8 +1297,8 @@ func ReceiverHtlcTapLeafSuccess(receiverHtlcKey *btcec.PublicKey,
|
||||||
// receiverHtlcTapScriptTree builds the tapscript tree which is used to anchor
|
// receiverHtlcTapScriptTree builds the tapscript tree which is used to anchor
|
||||||
// the HTLC key for HTLCs on the receiver's commitment.
|
// the HTLC key for HTLCs on the receiver's commitment.
|
||||||
func receiverHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
func receiverHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
revokeKey *btcec.PublicKey, payHash []byte,
|
revokeKey *btcec.PublicKey, payHash []byte, cltvExpiry uint32,
|
||||||
cltvExpiry uint32, hType htlcType) (*HtlcScriptTree, error) {
|
hType htlcType, auxLeaf AuxTapLeaf) (*HtlcScriptTree, error) {
|
||||||
|
|
||||||
// First, we'll obtain the tap leaves for both the success and timeout
|
// First, we'll obtain the tap leaves for both the success and timeout
|
||||||
// path.
|
// path.
|
||||||
|
@ -1303,11 +1315,14 @@ func receiverHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tapLeaves := []txscript.TapLeaf{timeoutTapLeaf, successTapLeaf}
|
||||||
|
auxLeaf.WhenSome(func(l txscript.TapLeaf) {
|
||||||
|
tapLeaves = append(tapLeaves, l)
|
||||||
|
})
|
||||||
|
|
||||||
// With the two leaves obtained, we'll now make the tapscript tree,
|
// With the two leaves obtained, we'll now make the tapscript tree,
|
||||||
// then obtain the root from that
|
// then obtain the root from that
|
||||||
tapscriptTree := txscript.AssembleTaprootScriptTree(
|
tapscriptTree := txscript.AssembleTaprootScriptTree(tapLeaves...)
|
||||||
timeoutTapLeaf, successTapLeaf,
|
|
||||||
)
|
|
||||||
|
|
||||||
tapScriptRoot := tapscriptTree.RootNode.TapHash()
|
tapScriptRoot := tapscriptTree.RootNode.TapHash()
|
||||||
|
|
||||||
|
@ -1326,6 +1341,7 @@ func receiverHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
},
|
},
|
||||||
SuccessTapLeaf: successTapLeaf,
|
SuccessTapLeaf: successTapLeaf,
|
||||||
TimeoutTapLeaf: timeoutTapLeaf,
|
TimeoutTapLeaf: timeoutTapLeaf,
|
||||||
|
AuxLeaf: auxLeaf,
|
||||||
htlcType: hType,
|
htlcType: hType,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -1361,7 +1377,7 @@ func receiverHtlcTapScriptTree(senderHtlcKey, receiverHtlcKey,
|
||||||
func ReceiverHTLCScriptTaproot(cltvExpiry uint32,
|
func ReceiverHTLCScriptTaproot(cltvExpiry uint32,
|
||||||
senderHtlcKey, receiverHtlcKey, revocationKey *btcec.PublicKey,
|
senderHtlcKey, receiverHtlcKey, revocationKey *btcec.PublicKey,
|
||||||
payHash []byte, whoseCommit lntypes.ChannelParty,
|
payHash []byte, whoseCommit lntypes.ChannelParty,
|
||||||
) (*HtlcScriptTree, error) {
|
auxLeaf AuxTapLeaf) (*HtlcScriptTree, error) {
|
||||||
|
|
||||||
var hType htlcType
|
var hType htlcType
|
||||||
if whoseCommit.IsLocal() {
|
if whoseCommit.IsLocal() {
|
||||||
|
@ -1375,7 +1391,7 @@ func ReceiverHTLCScriptTaproot(cltvExpiry uint32,
|
||||||
// tap leaf paths.
|
// tap leaf paths.
|
||||||
return receiverHtlcTapScriptTree(
|
return receiverHtlcTapScriptTree(
|
||||||
senderHtlcKey, receiverHtlcKey, revocationKey, payHash,
|
senderHtlcKey, receiverHtlcKey, revocationKey, payHash,
|
||||||
cltvExpiry, hType,
|
cltvExpiry, hType, auxLeaf,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1605,8 +1621,8 @@ func TaprootSecondLevelTapLeaf(delayKey *btcec.PublicKey,
|
||||||
|
|
||||||
// SecondLevelHtlcTapscriptTree construct the indexed tapscript tree needed to
|
// SecondLevelHtlcTapscriptTree construct the indexed tapscript tree needed to
|
||||||
// generate the tap tweak to create the final output and also control block.
|
// generate the tap tweak to create the final output and also control block.
|
||||||
func SecondLevelHtlcTapscriptTree(delayKey *btcec.PublicKey,
|
func SecondLevelHtlcTapscriptTree(delayKey *btcec.PublicKey, csvDelay uint32,
|
||||||
csvDelay uint32) (*txscript.IndexedTapScriptTree, error) {
|
auxLeaf AuxTapLeaf) (*txscript.IndexedTapScriptTree, error) {
|
||||||
|
|
||||||
// First grab the second level leaf script we need to create the top
|
// First grab the second level leaf script we need to create the top
|
||||||
// level output.
|
// level output.
|
||||||
|
@ -1615,9 +1631,14 @@ func SecondLevelHtlcTapscriptTree(delayKey *btcec.PublicKey,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tapLeaves := []txscript.TapLeaf{secondLevelTapLeaf}
|
||||||
|
auxLeaf.WhenSome(func(l txscript.TapLeaf) {
|
||||||
|
tapLeaves = append(tapLeaves, l)
|
||||||
|
})
|
||||||
|
|
||||||
// Now that we have the sole second level script, we can create the
|
// Now that we have the sole second level script, we can create the
|
||||||
// tapscript tree that commits to both the leaves.
|
// tapscript tree that commits to both the leaves.
|
||||||
return txscript.AssembleTaprootScriptTree(secondLevelTapLeaf), nil
|
return txscript.AssembleTaprootScriptTree(tapLeaves...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaprootSecondLevelHtlcScript is the uniform script that's used as the output
|
// TaprootSecondLevelHtlcScript is the uniform script that's used as the output
|
||||||
|
@ -1637,12 +1658,12 @@ func SecondLevelHtlcTapscriptTree(delayKey *btcec.PublicKey,
|
||||||
//
|
//
|
||||||
// The keyspend path require knowledge of the top level revocation private key.
|
// The keyspend path require knowledge of the top level revocation private key.
|
||||||
func TaprootSecondLevelHtlcScript(revokeKey, delayKey *btcec.PublicKey,
|
func TaprootSecondLevelHtlcScript(revokeKey, delayKey *btcec.PublicKey,
|
||||||
csvDelay uint32) (*btcec.PublicKey, error) {
|
csvDelay uint32, auxLeaf AuxTapLeaf) (*btcec.PublicKey, error) {
|
||||||
|
|
||||||
// First, we'll make the tapscript tree that commits to the redemption
|
// First, we'll make the tapscript tree that commits to the redemption
|
||||||
// path.
|
// path.
|
||||||
tapScriptTree, err := SecondLevelHtlcTapscriptTree(
|
tapScriptTree, err := SecondLevelHtlcTapscriptTree(
|
||||||
delayKey, csvDelay,
|
delayKey, csvDelay, auxLeaf,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1667,17 +1688,21 @@ type SecondLevelScriptTree struct {
|
||||||
|
|
||||||
// SuccessTapLeaf is the tapleaf for the redemption path.
|
// SuccessTapLeaf is the tapleaf for the redemption path.
|
||||||
SuccessTapLeaf txscript.TapLeaf
|
SuccessTapLeaf txscript.TapLeaf
|
||||||
|
|
||||||
|
// AuxLeaf is an optional leaf that can be used to extend the script
|
||||||
|
// tree.
|
||||||
|
AuxLeaf AuxTapLeaf
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaprootSecondLevelScriptTree constructs the tapscript tree used to spend the
|
// TaprootSecondLevelScriptTree constructs the tapscript tree used to spend the
|
||||||
// second level HTLC output.
|
// second level HTLC output.
|
||||||
func TaprootSecondLevelScriptTree(revokeKey, delayKey *btcec.PublicKey,
|
func TaprootSecondLevelScriptTree(revokeKey, delayKey *btcec.PublicKey,
|
||||||
csvDelay uint32) (*SecondLevelScriptTree, error) {
|
csvDelay uint32, auxLeaf AuxTapLeaf) (*SecondLevelScriptTree, error) {
|
||||||
|
|
||||||
// First, we'll make the tapscript tree that commits to the redemption
|
// First, we'll make the tapscript tree that commits to the redemption
|
||||||
// path.
|
// path.
|
||||||
tapScriptTree, err := SecondLevelHtlcTapscriptTree(
|
tapScriptTree, err := SecondLevelHtlcTapscriptTree(
|
||||||
delayKey, csvDelay,
|
delayKey, csvDelay, auxLeaf,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1698,6 +1723,7 @@ func TaprootSecondLevelScriptTree(revokeKey, delayKey *btcec.PublicKey,
|
||||||
InternalKey: revokeKey,
|
InternalKey: revokeKey,
|
||||||
},
|
},
|
||||||
SuccessTapLeaf: tapScriptTree.LeafMerkleProofs[0].TapLeaf,
|
SuccessTapLeaf: tapScriptTree.LeafMerkleProofs[0].TapLeaf,
|
||||||
|
AuxLeaf: auxLeaf,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2079,6 +2105,12 @@ type CommitScriptTree struct {
|
||||||
// RevocationLeaf is the leaf used to spend the output with the
|
// RevocationLeaf is the leaf used to spend the output with the
|
||||||
// revocation key signature.
|
// revocation key signature.
|
||||||
RevocationLeaf txscript.TapLeaf
|
RevocationLeaf txscript.TapLeaf
|
||||||
|
|
||||||
|
// AuxLeaf is an auxiliary leaf that can be used to extend the base
|
||||||
|
// commitment script tree with new spend paths, or just as extra
|
||||||
|
// commitment space. When present, this leaf will always be in the
|
||||||
|
// left-most or right-most area of the tapscript tree.
|
||||||
|
AuxLeaf AuxTapLeaf
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compile time check to ensure CommitScriptTree implements the
|
// A compile time check to ensure CommitScriptTree implements the
|
||||||
|
@ -2143,8 +2175,9 @@ func (c *CommitScriptTree) Tree() ScriptTree {
|
||||||
|
|
||||||
// NewLocalCommitScriptTree returns a new CommitScript tree that can be used to
|
// NewLocalCommitScriptTree returns a new CommitScript tree that can be used to
|
||||||
// create and spend the commitment output for the local party.
|
// create and spend the commitment output for the local party.
|
||||||
func NewLocalCommitScriptTree(csvTimeout uint32,
|
func NewLocalCommitScriptTree(csvTimeout uint32, selfKey,
|
||||||
selfKey, revokeKey *btcec.PublicKey) (*CommitScriptTree, error) {
|
revokeKey *btcec.PublicKey, auxLeaf AuxTapLeaf) (*CommitScriptTree,
|
||||||
|
error) {
|
||||||
|
|
||||||
// First, we'll need to construct the tapLeaf that'll be our delay CSV
|
// First, we'll need to construct the tapLeaf that'll be our delay CSV
|
||||||
// clause.
|
// clause.
|
||||||
|
@ -2164,9 +2197,13 @@ func NewLocalCommitScriptTree(csvTimeout uint32,
|
||||||
// the two leaves, and then obtain a root from that.
|
// the two leaves, and then obtain a root from that.
|
||||||
delayTapLeaf := txscript.NewBaseTapLeaf(delayScript)
|
delayTapLeaf := txscript.NewBaseTapLeaf(delayScript)
|
||||||
revokeTapLeaf := txscript.NewBaseTapLeaf(revokeScript)
|
revokeTapLeaf := txscript.NewBaseTapLeaf(revokeScript)
|
||||||
tapScriptTree := txscript.AssembleTaprootScriptTree(
|
|
||||||
delayTapLeaf, revokeTapLeaf,
|
tapLeaves := []txscript.TapLeaf{delayTapLeaf, revokeTapLeaf}
|
||||||
)
|
auxLeaf.WhenSome(func(l txscript.TapLeaf) {
|
||||||
|
tapLeaves = append(tapLeaves, l)
|
||||||
|
})
|
||||||
|
|
||||||
|
tapScriptTree := txscript.AssembleTaprootScriptTree(tapLeaves...)
|
||||||
tapScriptRoot := tapScriptTree.RootNode.TapHash()
|
tapScriptRoot := tapScriptTree.RootNode.TapHash()
|
||||||
|
|
||||||
// Now that we have our root, we can arrive at the final output script
|
// Now that we have our root, we can arrive at the final output script
|
||||||
|
@ -2184,6 +2221,7 @@ func NewLocalCommitScriptTree(csvTimeout uint32,
|
||||||
},
|
},
|
||||||
SettleLeaf: delayTapLeaf,
|
SettleLeaf: delayTapLeaf,
|
||||||
RevocationLeaf: revokeTapLeaf,
|
RevocationLeaf: revokeTapLeaf,
|
||||||
|
AuxLeaf: auxLeaf,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2253,7 +2291,7 @@ func TaprootCommitScriptToSelf(csvTimeout uint32,
|
||||||
selfKey, revokeKey *btcec.PublicKey) (*btcec.PublicKey, error) {
|
selfKey, revokeKey *btcec.PublicKey) (*btcec.PublicKey, error) {
|
||||||
|
|
||||||
commitScriptTree, err := NewLocalCommitScriptTree(
|
commitScriptTree, err := NewLocalCommitScriptTree(
|
||||||
csvTimeout, selfKey, revokeKey,
|
csvTimeout, selfKey, revokeKey, NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2579,7 +2617,7 @@ func CommitScriptToRemoteConfirmed(key *btcec.PublicKey) ([]byte, error) {
|
||||||
// NewRemoteCommitScriptTree constructs a new script tree for the remote party
|
// NewRemoteCommitScriptTree constructs a new script tree for the remote party
|
||||||
// to sweep their funds after a hard coded 1 block delay.
|
// to sweep their funds after a hard coded 1 block delay.
|
||||||
func NewRemoteCommitScriptTree(remoteKey *btcec.PublicKey,
|
func NewRemoteCommitScriptTree(remoteKey *btcec.PublicKey,
|
||||||
) (*CommitScriptTree, error) {
|
auxLeaf AuxTapLeaf) (*CommitScriptTree, error) {
|
||||||
|
|
||||||
// First, construct the remote party's tapscript they'll use to sweep
|
// First, construct the remote party's tapscript they'll use to sweep
|
||||||
// their outputs.
|
// their outputs.
|
||||||
|
@ -2595,10 +2633,16 @@ func NewRemoteCommitScriptTree(remoteKey *btcec.PublicKey,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tapLeaf := txscript.NewBaseTapLeaf(remoteScript)
|
||||||
|
|
||||||
|
tapLeaves := []txscript.TapLeaf{tapLeaf}
|
||||||
|
auxLeaf.WhenSome(func(l txscript.TapLeaf) {
|
||||||
|
tapLeaves = append(tapLeaves, l)
|
||||||
|
})
|
||||||
|
|
||||||
// With this script constructed, we'll map that into a tapLeaf, then
|
// With this script constructed, we'll map that into a tapLeaf, then
|
||||||
// make a new tapscript root from that.
|
// make a new tapscript root from that.
|
||||||
tapLeaf := txscript.NewBaseTapLeaf(remoteScript)
|
tapScriptTree := txscript.AssembleTaprootScriptTree(tapLeaves...)
|
||||||
tapScriptTree := txscript.AssembleTaprootScriptTree(tapLeaf)
|
|
||||||
tapScriptRoot := tapScriptTree.RootNode.TapHash()
|
tapScriptRoot := tapScriptTree.RootNode.TapHash()
|
||||||
|
|
||||||
// Now that we have our root, we can arrive at the final output script
|
// Now that we have our root, we can arrive at the final output script
|
||||||
|
@ -2615,6 +2659,7 @@ func NewRemoteCommitScriptTree(remoteKey *btcec.PublicKey,
|
||||||
InternalKey: &TaprootNUMSKey,
|
InternalKey: &TaprootNUMSKey,
|
||||||
},
|
},
|
||||||
SettleLeaf: tapLeaf,
|
SettleLeaf: tapLeaf,
|
||||||
|
AuxLeaf: auxLeaf,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2631,9 +2676,9 @@ func NewRemoteCommitScriptTree(remoteKey *btcec.PublicKey,
|
||||||
// <remotepubkey> OP_CHECKSIG
|
// <remotepubkey> OP_CHECKSIG
|
||||||
// 1 OP_CHECKSEQUENCEVERIFY OP_DROP
|
// 1 OP_CHECKSEQUENCEVERIFY OP_DROP
|
||||||
func TaprootCommitScriptToRemote(remoteKey *btcec.PublicKey,
|
func TaprootCommitScriptToRemote(remoteKey *btcec.PublicKey,
|
||||||
) (*btcec.PublicKey, error) {
|
auxLeaf AuxTapLeaf) (*btcec.PublicKey, error) {
|
||||||
|
|
||||||
commitScriptTree, err := NewRemoteCommitScriptTree(remoteKey)
|
commitScriptTree, err := NewRemoteCommitScriptTree(remoteKey, auxLeaf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,7 +853,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
signer := &dummySigner{}
|
signer := &dummySigner{}
|
||||||
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
||||||
testCSVDelay, testKey.PubKey(),
|
testCSVDelay, testKey.PubKey(),
|
||||||
testKey.PubKey(),
|
testKey.PubKey(), input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -887,7 +887,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
signer := &dummySigner{}
|
signer := &dummySigner{}
|
||||||
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
||||||
testCSVDelay, testKey.PubKey(),
|
testCSVDelay, testKey.PubKey(),
|
||||||
testKey.PubKey(),
|
testKey.PubKey(), input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -921,7 +921,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
signer := &dummySigner{}
|
signer := &dummySigner{}
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
commitScriptTree, err := input.NewRemoteCommitScriptTree(
|
commitScriptTree, err := input.NewRemoteCommitScriptTree(
|
||||||
testKey.PubKey(),
|
testKey.PubKey(), input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -988,6 +988,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
|
|
||||||
scriptTree, err := input.SecondLevelHtlcTapscriptTree(
|
scriptTree, err := input.SecondLevelHtlcTapscriptTree(
|
||||||
testKey.PubKey(), testCSVDelay,
|
testKey.PubKey(), testCSVDelay,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1027,6 +1028,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
|
|
||||||
scriptTree, err := input.SecondLevelHtlcTapscriptTree(
|
scriptTree, err := input.SecondLevelHtlcTapscriptTree(
|
||||||
testKey.PubKey(), testCSVDelay,
|
testKey.PubKey(), testCSVDelay,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1075,6 +1077,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
htlcScriptTree, err := input.SenderHTLCScriptTaproot(
|
htlcScriptTree, err := input.SenderHTLCScriptTaproot(
|
||||||
senderKey.PubKey(), receiverKey.PubKey(),
|
senderKey.PubKey(), receiverKey.PubKey(),
|
||||||
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1116,7 +1119,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
|
htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
|
||||||
testCLTVExpiry, senderKey.PubKey(),
|
testCLTVExpiry, senderKey.PubKey(),
|
||||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||||
payHash[:], lntypes.Remote,
|
payHash[:], lntypes.Remote, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1158,7 +1161,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
|
htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
|
||||||
testCLTVExpiry, senderKey.PubKey(),
|
testCLTVExpiry, senderKey.PubKey(),
|
||||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||||
payHash[:], lntypes.Remote,
|
payHash[:], lntypes.Remote, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1205,6 +1208,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
htlcScriptTree, err := input.SenderHTLCScriptTaproot(
|
htlcScriptTree, err := input.SenderHTLCScriptTaproot(
|
||||||
senderKey.PubKey(), receiverKey.PubKey(),
|
senderKey.PubKey(), receiverKey.PubKey(),
|
||||||
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1265,6 +1269,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
htlcScriptTree, err := input.SenderHTLCScriptTaproot(
|
htlcScriptTree, err := input.SenderHTLCScriptTaproot(
|
||||||
senderKey.PubKey(), receiverKey.PubKey(),
|
senderKey.PubKey(), receiverKey.PubKey(),
|
||||||
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1310,7 +1315,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||||
htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
|
htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
|
||||||
testCLTVExpiry, senderKey.PubKey(),
|
testCLTVExpiry, senderKey.PubKey(),
|
||||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||||
payHash[:], lntypes.Remote,
|
payHash[:], lntypes.Remote, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1396,7 +1401,7 @@ func genTimeoutTx(t *testing.T,
|
||||||
if chanType.IsTaproot() {
|
if chanType.IsTaproot() {
|
||||||
tapscriptTree, err = input.SenderHTLCScriptTaproot(
|
tapscriptTree, err = input.SenderHTLCScriptTaproot(
|
||||||
testPubkey, testPubkey, testPubkey, testHash160,
|
testPubkey, testPubkey, testPubkey, testHash160,
|
||||||
lntypes.Remote,
|
lntypes.Remote, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -1465,7 +1470,7 @@ func genSuccessTx(t *testing.T, chanType channeldb.ChannelType) *wire.MsgTx {
|
||||||
if chanType.IsTaproot() {
|
if chanType.IsTaproot() {
|
||||||
tapscriptTree, err = input.ReceiverHTLCScriptTaproot(
|
tapscriptTree, err = input.ReceiverHTLCScriptTaproot(
|
||||||
testCLTVExpiry, testPubkey, testPubkey, testPubkey,
|
testCLTVExpiry, testPubkey, testPubkey, testPubkey,
|
||||||
testHash160, lntypes.Remote,
|
testHash160, lntypes.Remote, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -21,6 +22,15 @@ const (
|
||||||
PubKeyFormatCompressedOdd byte = 0x03
|
PubKeyFormatCompressedOdd byte = 0x03
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AuxTapLeaf is a type alias for an optional tapscript leaf that may be added
|
||||||
|
// to the tapscript tree of HTLC and commitment outputs.
|
||||||
|
type AuxTapLeaf = fn.Option[txscript.TapLeaf]
|
||||||
|
|
||||||
|
// NoneTapLeaf returns an empty optional tapscript leaf.
|
||||||
|
func NoneTapLeaf() AuxTapLeaf {
|
||||||
|
return fn.None[txscript.TapLeaf]()
|
||||||
|
}
|
||||||
|
|
||||||
// NewTxSigHashesV0Only returns a new txscript.TxSigHashes instance that will
|
// NewTxSigHashesV0Only returns a new txscript.TxSigHashes instance that will
|
||||||
// only calculate the sighash midstate values for segwit v0 inputs and can
|
// only calculate the sighash midstate values for segwit v0 inputs and can
|
||||||
// therefore never be used for transactions that want to spend segwit v1
|
// therefore never be used for transactions that want to spend segwit v1
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package input
|
package input
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -31,7 +34,9 @@ type testSenderHtlcScriptTree struct {
|
||||||
htlcAmt int64
|
htlcAmt int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestSenderHtlcScriptTree(t *testing.T) *testSenderHtlcScriptTree {
|
func newTestSenderHtlcScriptTree(t *testing.T,
|
||||||
|
auxLeaf AuxTapLeaf) *testSenderHtlcScriptTree {
|
||||||
|
|
||||||
var preImage lntypes.Preimage
|
var preImage lntypes.Preimage
|
||||||
_, err := rand.Read(preImage[:])
|
_, err := rand.Read(preImage[:])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -48,7 +53,7 @@ func newTestSenderHtlcScriptTree(t *testing.T) *testSenderHtlcScriptTree {
|
||||||
payHash := preImage.Hash()
|
payHash := preImage.Hash()
|
||||||
htlcScriptTree, err := SenderHTLCScriptTaproot(
|
htlcScriptTree, err := SenderHTLCScriptTaproot(
|
||||||
senderKey.PubKey(), receiverKey.PubKey(), revokeKey.PubKey(),
|
senderKey.PubKey(), receiverKey.PubKey(), revokeKey.PubKey(),
|
||||||
payHash[:], lntypes.Remote,
|
payHash[:], lntypes.Remote, auxLeaf,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -207,13 +212,9 @@ func htlcSenderTimeoutWitnessGen(sigHash txscript.SigHashType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTaprootSenderHtlcSpend tests that all the positive and negative paths
|
func testTaprootSenderHtlcSpend(t *testing.T, auxLeaf AuxTapLeaf) {
|
||||||
// for the sender HTLC tapscript tree work as expected.
|
|
||||||
func TestTaprootSenderHtlcSpend(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
// First, create a new test script tree.
|
// First, create a new test script tree.
|
||||||
htlcScriptTree := newTestSenderHtlcScriptTree(t)
|
htlcScriptTree := newTestSenderHtlcScriptTree(t, auxLeaf)
|
||||||
|
|
||||||
spendTx := wire.NewMsgTx(2)
|
spendTx := wire.NewMsgTx(2)
|
||||||
spendTx.AddTxIn(&wire.TxIn{})
|
spendTx.AddTxIn(&wire.TxIn{})
|
||||||
|
@ -432,6 +433,26 @@ func TestTaprootSenderHtlcSpend(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTaprootSenderHtlcSpend tests that all the positive and negative paths
|
||||||
|
// for the sender HTLC tapscript tree work as expected.
|
||||||
|
func TestTaprootSenderHtlcSpend(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, hasAuxLeaf := range []bool{true, false} {
|
||||||
|
name := fmt.Sprintf("aux_leaf=%v", hasAuxLeaf)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var auxLeaf AuxTapLeaf
|
||||||
|
if hasAuxLeaf {
|
||||||
|
auxLeaf = fn.Some(txscript.NewBaseTapLeaf(
|
||||||
|
bytes.Repeat([]byte{0x01}, 32),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
testTaprootSenderHtlcSpend(t, auxLeaf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type testReceiverHtlcScriptTree struct {
|
type testReceiverHtlcScriptTree struct {
|
||||||
preImage lntypes.Preimage
|
preImage lntypes.Preimage
|
||||||
|
|
||||||
|
@ -452,7 +473,9 @@ type testReceiverHtlcScriptTree struct {
|
||||||
lockTime int32
|
lockTime int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestReceiverHtlcScriptTree(t *testing.T) *testReceiverHtlcScriptTree {
|
func newTestReceiverHtlcScriptTree(t *testing.T,
|
||||||
|
auxLeaf AuxTapLeaf) *testReceiverHtlcScriptTree {
|
||||||
|
|
||||||
var preImage lntypes.Preimage
|
var preImage lntypes.Preimage
|
||||||
_, err := rand.Read(preImage[:])
|
_, err := rand.Read(preImage[:])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -471,7 +494,7 @@ func newTestReceiverHtlcScriptTree(t *testing.T) *testReceiverHtlcScriptTree {
|
||||||
payHash := preImage.Hash()
|
payHash := preImage.Hash()
|
||||||
htlcScriptTree, err := ReceiverHTLCScriptTaproot(
|
htlcScriptTree, err := ReceiverHTLCScriptTaproot(
|
||||||
cltvExpiry, senderKey.PubKey(), receiverKey.PubKey(),
|
cltvExpiry, senderKey.PubKey(), receiverKey.PubKey(),
|
||||||
revokeKey.PubKey(), payHash[:], lntypes.Remote,
|
revokeKey.PubKey(), payHash[:], lntypes.Remote, auxLeaf,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -629,15 +652,11 @@ func htlcReceiverSuccessWitnessGen(sigHash txscript.SigHashType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTaprootReceiverHtlcSpend tests that all possible paths for redeeming an
|
func testTaprootReceiverHtlcSpend(t *testing.T, auxLeaf AuxTapLeaf) {
|
||||||
// accepted HTLC (on the commitment transaction) of the receiver work properly.
|
|
||||||
func TestTaprootReceiverHtlcSpend(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
// We'll start by creating the HTLC script tree (contains all 3 valid
|
// We'll start by creating the HTLC script tree (contains all 3 valid
|
||||||
// spend paths), and also a mock spend transaction that we'll be
|
// spend paths), and also a mock spend transaction that we'll be
|
||||||
// signing below.
|
// signing below.
|
||||||
htlcScriptTree := newTestReceiverHtlcScriptTree(t)
|
htlcScriptTree := newTestReceiverHtlcScriptTree(t, auxLeaf)
|
||||||
|
|
||||||
// TODO(roasbeef): issue with revoke key??? ctrl block even/odd
|
// TODO(roasbeef): issue with revoke key??? ctrl block even/odd
|
||||||
|
|
||||||
|
@ -891,6 +910,28 @@ func TestTaprootReceiverHtlcSpend(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTaprootReceiverHtlcSpend tests that all possible paths for redeeming an
|
||||||
|
// accepted HTLC (on the commitment transaction) of the receiver work properly.
|
||||||
|
func TestTaprootReceiverHtlcSpend(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, hasAuxLeaf := range []bool{true, false} {
|
||||||
|
name := fmt.Sprintf("aux_leaf=%v", hasAuxLeaf)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var auxLeaf AuxTapLeaf
|
||||||
|
if hasAuxLeaf {
|
||||||
|
auxLeaf = fn.Some(
|
||||||
|
txscript.NewBaseTapLeaf(
|
||||||
|
bytes.Repeat([]byte{0x01}, 32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
testTaprootReceiverHtlcSpend(t, auxLeaf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type testCommitScriptTree struct {
|
type testCommitScriptTree struct {
|
||||||
csvDelay uint32
|
csvDelay uint32
|
||||||
|
|
||||||
|
@ -905,7 +946,9 @@ type testCommitScriptTree struct {
|
||||||
*CommitScriptTree
|
*CommitScriptTree
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestCommitScriptTree(local bool) (*testCommitScriptTree, error) {
|
func newTestCommitScriptTree(local bool,
|
||||||
|
auxLeaf AuxTapLeaf) (*testCommitScriptTree, error) {
|
||||||
|
|
||||||
selfKey, err := btcec.NewPrivateKey()
|
selfKey, err := btcec.NewPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -925,10 +968,11 @@ func newTestCommitScriptTree(local bool) (*testCommitScriptTree, error) {
|
||||||
if local {
|
if local {
|
||||||
commitScriptTree, err = NewLocalCommitScriptTree(
|
commitScriptTree, err = NewLocalCommitScriptTree(
|
||||||
csvDelay, selfKey.PubKey(), revokeKey.PubKey(),
|
csvDelay, selfKey.PubKey(), revokeKey.PubKey(),
|
||||||
|
auxLeaf,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
commitScriptTree, err = NewRemoteCommitScriptTree(
|
commitScriptTree, err = NewRemoteCommitScriptTree(
|
||||||
selfKey.PubKey(),
|
selfKey.PubKey(), auxLeaf,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1020,12 +1064,8 @@ func localCommitRevokeWitGen(sigHash txscript.SigHashType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTaprootCommitScriptToSelf tests that the taproot script for redeeming
|
func testTaprootCommitScriptToSelf(t *testing.T, auxLeaf AuxTapLeaf) {
|
||||||
// one's output after a force close behaves as expected.
|
commitScriptTree, err := newTestCommitScriptTree(true, auxLeaf)
|
||||||
func TestTaprootCommitScriptToSelf(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
commitScriptTree, err := newTestCommitScriptTree(true)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
spendTx := wire.NewMsgTx(2)
|
spendTx := wire.NewMsgTx(2)
|
||||||
|
@ -1187,6 +1227,26 @@ func TestTaprootCommitScriptToSelf(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTaprootCommitScriptToSelf tests that the taproot script for redeeming
|
||||||
|
// one's output after a force close behaves as expected.
|
||||||
|
func TestTaprootCommitScriptToSelf(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, hasAuxLeaf := range []bool{true, false} {
|
||||||
|
name := fmt.Sprintf("aux_leaf=%v", hasAuxLeaf)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var auxLeaf AuxTapLeaf
|
||||||
|
if hasAuxLeaf {
|
||||||
|
auxLeaf = fn.Some(txscript.NewBaseTapLeaf(
|
||||||
|
bytes.Repeat([]byte{0x01}, 32),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
testTaprootCommitScriptToSelf(t, auxLeaf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func remoteCommitSweepWitGen(sigHash txscript.SigHashType,
|
func remoteCommitSweepWitGen(sigHash txscript.SigHashType,
|
||||||
commitScriptTree *testCommitScriptTree) witnessGen {
|
commitScriptTree *testCommitScriptTree) witnessGen {
|
||||||
|
|
||||||
|
@ -1220,12 +1280,8 @@ func remoteCommitSweepWitGen(sigHash txscript.SigHashType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTaprootCommitScriptRemote tests that the remote party can properly sweep
|
func testTaprootCommitScriptRemote(t *testing.T, auxLeaf AuxTapLeaf) {
|
||||||
// their output after force close.
|
commitScriptTree, err := newTestCommitScriptTree(false, auxLeaf)
|
||||||
func TestTaprootCommitScriptRemote(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
commitScriptTree, err := newTestCommitScriptTree(false)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
spendTx := wire.NewMsgTx(2)
|
spendTx := wire.NewMsgTx(2)
|
||||||
|
@ -1364,6 +1420,26 @@ func TestTaprootCommitScriptRemote(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTaprootCommitScriptRemote tests that the remote party can properly sweep
|
||||||
|
// their output after force close.
|
||||||
|
func TestTaprootCommitScriptRemote(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, hasAuxLeaf := range []bool{true, false} {
|
||||||
|
name := fmt.Sprintf("aux_leaf=%v", hasAuxLeaf)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var auxLeaf AuxTapLeaf
|
||||||
|
if hasAuxLeaf {
|
||||||
|
auxLeaf = fn.Some(txscript.NewBaseTapLeaf(
|
||||||
|
bytes.Repeat([]byte{0x01}, 32),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
testTaprootCommitScriptRemote(t, auxLeaf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type testAnchorScriptTree struct {
|
type testAnchorScriptTree struct {
|
||||||
sweepKey *btcec.PrivateKey
|
sweepKey *btcec.PrivateKey
|
||||||
|
|
||||||
|
@ -1599,25 +1675,21 @@ type testSecondLevelHtlcTree struct {
|
||||||
tapScriptRoot []byte
|
tapScriptRoot []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestSecondLevelHtlcTree() (*testSecondLevelHtlcTree, error) {
|
func newTestSecondLevelHtlcTree(t *testing.T,
|
||||||
|
auxLeaf AuxTapLeaf) *testSecondLevelHtlcTree {
|
||||||
|
|
||||||
delayKey, err := btcec.NewPrivateKey()
|
delayKey, err := btcec.NewPrivateKey()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
revokeKey, err := btcec.NewPrivateKey()
|
revokeKey, err := btcec.NewPrivateKey()
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const csvDelay = 6
|
const csvDelay = 6
|
||||||
|
|
||||||
scriptTree, err := SecondLevelHtlcTapscriptTree(
|
scriptTree, err := SecondLevelHtlcTapscriptTree(
|
||||||
delayKey.PubKey(), csvDelay,
|
delayKey.PubKey(), csvDelay, auxLeaf,
|
||||||
)
|
)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tapScriptRoot := scriptTree.RootNode.TapHash()
|
tapScriptRoot := scriptTree.RootNode.TapHash()
|
||||||
|
|
||||||
|
@ -1626,9 +1698,7 @@ func newTestSecondLevelHtlcTree() (*testSecondLevelHtlcTree, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
pkScript, err := PayToTaprootScript(htlcKey)
|
pkScript, err := PayToTaprootScript(htlcKey)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
const amt = 100
|
const amt = 100
|
||||||
|
|
||||||
|
@ -1643,7 +1713,7 @@ func newTestSecondLevelHtlcTree() (*testSecondLevelHtlcTree, error) {
|
||||||
amt: amt,
|
amt: amt,
|
||||||
scriptTree: scriptTree,
|
scriptTree: scriptTree,
|
||||||
tapScriptRoot: tapScriptRoot[:],
|
tapScriptRoot: tapScriptRoot[:],
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func secondLevelHtlcSuccessWitGen(sigHash txscript.SigHashType,
|
func secondLevelHtlcSuccessWitGen(sigHash txscript.SigHashType,
|
||||||
|
@ -1713,13 +1783,8 @@ func secondLevelHtlcRevokeWitnessgen(sigHash txscript.SigHashType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTaprootSecondLevelHtlcScript tests that a channel peer can properly
|
func testTaprootSecondLevelHtlcScript(t *testing.T, auxLeaf AuxTapLeaf) {
|
||||||
// spend the second level HTLC script to resolve HTLCs.
|
htlcScriptTree := newTestSecondLevelHtlcTree(t, auxLeaf)
|
||||||
func TestTaprootSecondLevelHtlcScript(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
htlcScriptTree, err := newTestSecondLevelHtlcTree()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
spendTx := wire.NewMsgTx(2)
|
spendTx := wire.NewMsgTx(2)
|
||||||
spendTx.AddTxIn(&wire.TxIn{})
|
spendTx.AddTxIn(&wire.TxIn{})
|
||||||
|
@ -1879,3 +1944,23 @@ func TestTaprootSecondLevelHtlcScript(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestTaprootSecondLevelHtlcScript tests that a channel peer can properly
|
||||||
|
// spend the second level HTLC script to resolve HTLCs.
|
||||||
|
func TestTaprootSecondLevelHtlcScript(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, hasAuxLeaf := range []bool{true, false} {
|
||||||
|
name := fmt.Sprintf("aux_leaf=%v", hasAuxLeaf)
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var auxLeaf AuxTapLeaf
|
||||||
|
if hasAuxLeaf {
|
||||||
|
auxLeaf = fn.Some(txscript.NewBaseTapLeaf(
|
||||||
|
bytes.Repeat([]byte{0x01}, 32),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
testTaprootSecondLevelHtlcScript(t, auxLeaf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6669,6 +6669,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
secondLevelScriptTree, err := input.TaprootSecondLevelScriptTree(
|
secondLevelScriptTree, err := input.TaprootSecondLevelScriptTree(
|
||||||
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
||||||
|
fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -6915,6 +6916,7 @@ func newIncomingHtlcResolution(signer input.Signer,
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
secondLevelScriptTree, err := input.TaprootSecondLevelScriptTree(
|
secondLevelScriptTree, err := input.TaprootSecondLevelScriptTree(
|
||||||
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
||||||
|
fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -225,9 +225,8 @@ func (w *WitnessScriptDesc) WitnessScriptForPath(
|
||||||
// party learns of the preimage to the revocation hash, then they can claim all
|
// party learns of the preimage to the revocation hash, then they can claim all
|
||||||
// the settled funds in the channel, plus the unsettled funds.
|
// the settled funds in the channel, plus the unsettled funds.
|
||||||
func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
||||||
selfKey, revokeKey *btcec.PublicKey, csvDelay, leaseExpiry uint32,
|
selfKey, revokeKey *btcec.PublicKey, csvDelay,
|
||||||
) (
|
leaseExpiry uint32) (input.ScriptDescriptor, error) {
|
||||||
input.ScriptDescriptor, error) {
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// For taproot scripts, we'll need to make a slightly modified script
|
// For taproot scripts, we'll need to make a slightly modified script
|
||||||
|
@ -237,7 +236,7 @@ func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
||||||
// Our "redeem" script here is just the taproot witness program.
|
// Our "redeem" script here is just the taproot witness program.
|
||||||
case chanType.IsTaproot():
|
case chanType.IsTaproot():
|
||||||
return input.NewLocalCommitScriptTree(
|
return input.NewLocalCommitScriptTree(
|
||||||
csvDelay, selfKey, revokeKey,
|
csvDelay, selfKey, revokeKey, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// If we are the initiator of a leased channel, then we have an
|
// If we are the initiator of a leased channel, then we have an
|
||||||
|
@ -321,7 +320,7 @@ func CommitScriptToRemote(chanType channeldb.ChannelType, initiator bool,
|
||||||
// with the sole tap leaf enforcing the 1 CSV delay.
|
// with the sole tap leaf enforcing the 1 CSV delay.
|
||||||
case chanType.IsTaproot():
|
case chanType.IsTaproot():
|
||||||
toRemoteScriptTree, err := input.NewRemoteCommitScriptTree(
|
toRemoteScriptTree, err := input.NewRemoteCommitScriptTree(
|
||||||
remoteKey,
|
remoteKey, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -427,7 +426,7 @@ func SecondLevelHtlcScript(chanType channeldb.ChannelType, initiator bool,
|
||||||
// For taproot channels, the pkScript is a segwit v1 p2tr output.
|
// For taproot channels, the pkScript is a segwit v1 p2tr output.
|
||||||
case chanType.IsTaproot():
|
case chanType.IsTaproot():
|
||||||
return input.TaprootSecondLevelScriptTree(
|
return input.TaprootSecondLevelScriptTree(
|
||||||
revocationKey, delayKey, csvDelay,
|
revocationKey, delayKey, csvDelay, input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// If we are the initiator of a leased channel, then we have an
|
// If we are the initiator of a leased channel, then we have an
|
||||||
|
@ -1095,6 +1094,7 @@ func GenTaprootHtlcScript(isIncoming bool, whoseCommit lntypes.ChannelParty,
|
||||||
htlcScriptTree, err = input.ReceiverHTLCScriptTaproot(
|
htlcScriptTree, err = input.ReceiverHTLCScriptTaproot(
|
||||||
timeout, keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
timeout, keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
||||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// We're being paid via an HTLC by the remote party, and the HTLC is
|
// We're being paid via an HTLC by the remote party, and the HTLC is
|
||||||
|
@ -1104,6 +1104,7 @@ func GenTaprootHtlcScript(isIncoming bool, whoseCommit lntypes.ChannelParty,
|
||||||
htlcScriptTree, err = input.SenderHTLCScriptTaproot(
|
htlcScriptTree, err = input.SenderHTLCScriptTaproot(
|
||||||
keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
keyRing.RemoteHtlcKey, keyRing.LocalHtlcKey,
|
||||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// We're sending an HTLC which is being added to our commitment
|
// We're sending an HTLC which is being added to our commitment
|
||||||
|
@ -1113,6 +1114,7 @@ func GenTaprootHtlcScript(isIncoming bool, whoseCommit lntypes.ChannelParty,
|
||||||
htlcScriptTree, err = input.SenderHTLCScriptTaproot(
|
htlcScriptTree, err = input.SenderHTLCScriptTaproot(
|
||||||
keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Finally, we're paying the remote party via an HTLC, which is being
|
// Finally, we're paying the remote party via an HTLC, which is being
|
||||||
|
@ -1122,6 +1124,7 @@ func GenTaprootHtlcScript(isIncoming bool, whoseCommit lntypes.ChannelParty,
|
||||||
htlcScriptTree, err = input.ReceiverHTLCScriptTaproot(
|
htlcScriptTree, err = input.ReceiverHTLCScriptTaproot(
|
||||||
timeout, keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
timeout, keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||||
keyRing.RevocationKey, rHash[:], whoseCommit,
|
keyRing.RevocationKey, rHash[:], whoseCommit,
|
||||||
|
input.NoneTapLeaf(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
@ -307,9 +308,11 @@ func newTaprootJusticeKit(sweepScript []byte,
|
||||||
|
|
||||||
keyRing := breachInfo.KeyRing
|
keyRing := breachInfo.KeyRing
|
||||||
|
|
||||||
|
// TODO(roasbeef): aux leaf tower updates needed
|
||||||
|
|
||||||
tree, err := input.NewLocalCommitScriptTree(
|
tree, err := input.NewLocalCommitScriptTree(
|
||||||
breachInfo.RemoteDelay, keyRing.ToLocalKey,
|
breachInfo.RemoteDelay, keyRing.ToLocalKey,
|
||||||
keyRing.RevocationKey,
|
keyRing.RevocationKey, fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -416,7 +419,9 @@ func (t *taprootJusticeKit) ToRemoteOutputSpendInfo() (*txscript.PkScript,
|
||||||
return nil, nil, 0, err
|
return nil, nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptTree, err := input.NewRemoteCommitScriptTree(toRemotePk)
|
scriptTree, err := input.NewRemoteCommitScriptTree(
|
||||||
|
toRemotePk, fn.None[txscript.TapLeaf](),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, 0, err
|
return nil, nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
@ -304,7 +305,9 @@ func TestJusticeKitRemoteWitnessConstruction(t *testing.T) {
|
||||||
name: "taproot commitment",
|
name: "taproot commitment",
|
||||||
blobType: TypeAltruistTaprootCommit,
|
blobType: TypeAltruistTaprootCommit,
|
||||||
expWitnessScript: func(pk *btcec.PublicKey) []byte {
|
expWitnessScript: func(pk *btcec.PublicKey) []byte {
|
||||||
tree, _ := input.NewRemoteCommitScriptTree(pk)
|
tree, _ := input.NewRemoteCommitScriptTree(
|
||||||
|
pk, fn.None[txscript.TapLeaf](),
|
||||||
|
)
|
||||||
|
|
||||||
return tree.SettleLeaf.Script
|
return tree.SettleLeaf.Script
|
||||||
},
|
},
|
||||||
|
@ -461,6 +464,7 @@ func TestJusticeKitToLocalWitnessConstruction(t *testing.T) {
|
||||||
|
|
||||||
script, _ := input.NewLocalCommitScriptTree(
|
script, _ := input.NewLocalCommitScriptTree(
|
||||||
csvDelay, delay, rev,
|
csvDelay, delay, rev,
|
||||||
|
fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
|
|
||||||
return script.RevocationLeaf.Script
|
return script.RevocationLeaf.Script
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
|
@ -123,7 +124,7 @@ func testJusticeDescriptor(t *testing.T, blobType blob.Type) {
|
||||||
|
|
||||||
if isTaprootChannel {
|
if isTaprootChannel {
|
||||||
toLocalCommitTree, err = input.NewLocalCommitScriptTree(
|
toLocalCommitTree, err = input.NewLocalCommitScriptTree(
|
||||||
csvDelay, toLocalPK, revPK,
|
csvDelay, toLocalPK, revPK, fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -174,7 +175,7 @@ func testJusticeDescriptor(t *testing.T, blobType blob.Type) {
|
||||||
toRemoteSequence = 1
|
toRemoteSequence = 1
|
||||||
|
|
||||||
commitScriptTree, err := input.NewRemoteCommitScriptTree(
|
commitScriptTree, err := input.NewRemoteCommitScriptTree(
|
||||||
toRemotePK,
|
toRemotePK, fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
|
@ -136,6 +137,7 @@ func genTaskTest(
|
||||||
if chanType.IsTaproot() {
|
if chanType.IsTaproot() {
|
||||||
scriptTree, _ := input.NewLocalCommitScriptTree(
|
scriptTree, _ := input.NewLocalCommitScriptTree(
|
||||||
csvDelay, toLocalPK, revPK,
|
csvDelay, toLocalPK, revPK,
|
||||||
|
fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
|
|
||||||
pkScript, _ := input.PayToTaprootScript(
|
pkScript, _ := input.PayToTaprootScript(
|
||||||
|
@ -189,7 +191,7 @@ func genTaskTest(
|
||||||
|
|
||||||
if chanType.IsTaproot() {
|
if chanType.IsTaproot() {
|
||||||
scriptTree, _ := input.NewRemoteCommitScriptTree(
|
scriptTree, _ := input.NewRemoteCommitScriptTree(
|
||||||
toRemotePK,
|
toRemotePK, fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
|
|
||||||
pkScript, _ := input.PayToTaprootScript(
|
pkScript, _ := input.PayToTaprootScript(
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
|
@ -230,12 +231,14 @@ func (c *mockChannel) createRemoteCommitTx(t *testing.T) {
|
||||||
|
|
||||||
// Construct the to-local witness script.
|
// Construct the to-local witness script.
|
||||||
toLocalScriptTree, err := input.NewLocalCommitScriptTree(
|
toLocalScriptTree, err := input.NewLocalCommitScriptTree(
|
||||||
c.csvDelay, c.toLocalPK, c.revPK,
|
c.csvDelay, c.toLocalPK, c.revPK, fn.None[txscript.TapLeaf](),
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to create to-local script")
|
require.NoError(t, err, "unable to create to-local script")
|
||||||
|
|
||||||
// Construct the to-remote witness script.
|
// Construct the to-remote witness script.
|
||||||
toRemoteScriptTree, err := input.NewRemoteCommitScriptTree(c.toRemotePK)
|
toRemoteScriptTree, err := input.NewRemoteCommitScriptTree(
|
||||||
|
c.toRemotePK, fn.None[txscript.TapLeaf](),
|
||||||
|
)
|
||||||
require.NoError(t, err, "unable to create to-remote script")
|
require.NoError(t, err, "unable to create to-remote script")
|
||||||
|
|
||||||
// Compute the to-local witness script hash.
|
// Compute the to-local witness script hash.
|
||||||
|
|
Loading…
Add table
Reference in a new issue