multi: fix linter errors
This commit is contained in:
20 files changed
+187
-144
No files matched your search
@@ -565,8 +565,8 @@ func convertToSecondLevelRevoke(bo *breachedOutput, breachInfo *retributionInfo,
|
||||
bo.signDesc.Output.PkScript = spendingTx.TxOut[spendInputIndex].PkScript
|
||||
|
||||
// For taproot outputs, the taptweak also needs to be swapped out. We
|
||||
// do this unconditionaly as this field isn't used at all for segwit v0
|
||||
// outputs.
|
||||
// do this unconditionally as this field isn't used at all for segwit
|
||||
// v0 outputs.
|
||||
bo.signDesc.TapTweak = bo.secondLevelTapTweak[:]
|
||||
|
||||
// Finally, we'll need to adjust the witness program in the
|
||||
@@ -1234,7 +1234,9 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
|
||||
case isTaproot:
|
||||
witnessType = input.TaprootRemoteCommitSpend
|
||||
|
||||
case !isTaproot && breachInfo.LocalOutputSignDesc.SingleTweak == nil:
|
||||
case !isTaproot &&
|
||||
breachInfo.LocalOutputSignDesc.SingleTweak == nil:
|
||||
|
||||
witnessType = input.CommitSpendNoDelayTweakless
|
||||
|
||||
case !isTaproot:
|
||||
@@ -1296,7 +1298,6 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
|
||||
// to sweep the HTLC output.
|
||||
var htlcWitnessType input.StandardWitnessType
|
||||
switch {
|
||||
|
||||
case isTaproot && breachedHtlc.IsIncoming:
|
||||
htlcWitnessType = input.TaprootHtlcAcceptedRevoke
|
||||
|
||||
@@ -1652,7 +1653,9 @@ func taprootBriefcaseFromRetInfo(retInfo *retributionInfo) *taprootBriefcase {
|
||||
|
||||
// applyTaprootRetInfo attaches the taproot specific inforamtion in the tapCase
|
||||
// to the passed retInfo struct.
|
||||
func applyTaprootRetInfo(tapCase *taprootBriefcase, retInfo *retributionInfo) error {
|
||||
func applyTaprootRetInfo(tapCase *taprootBriefcase,
|
||||
retInfo *retributionInfo) error {
|
||||
|
||||
for i := range retInfo.breachedOutputs {
|
||||
bo := retInfo.breachedOutputs[i]
|
||||
|
||||
@@ -1725,7 +1728,8 @@ func (rs *RetributionStore) Add(ret *retributionInfo) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if retBucket.Put(outBuf.Bytes(), retBuf.Bytes()); err != nil {
|
||||
err = retBucket.Put(outBuf.Bytes(), retBuf.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1552,6 +1552,7 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
if c.CommitResolution != nil {
|
||||
commitResolution := c.CommitResolution
|
||||
commitSignDesc := commitResolution.SelfOutputSignDesc
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.CommitSweepCtrlBlock = commitSignDesc.ControlBlock
|
||||
}
|
||||
|
||||
@@ -1569,7 +1570,6 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
resID := newResolverID(
|
||||
htlc.SignedSuccessTx.TxIn[0].PreviousOutPoint,
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID] = ctrlBlock
|
||||
|
||||
@@ -1584,6 +1584,7 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
}
|
||||
} else {
|
||||
resID := newResolverID(htlc.ClaimOutpoint)
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.IncomingHtlcCtrlBlocks[resID] = ctrlBlock
|
||||
}
|
||||
}
|
||||
@@ -1601,7 +1602,6 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
resID := newResolverID(
|
||||
htlc.SignedTimeoutTx.TxIn[0].PreviousOutPoint,
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID] = ctrlBlock
|
||||
|
||||
@@ -1618,9 +1618,9 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
}
|
||||
} else {
|
||||
resID := newResolverID(htlc.ClaimOutpoint)
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.OutgoingHtlcCtrlBlocks[resID] = ctrlBlock
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if c.AnchorResolution != nil {
|
||||
@@ -1651,6 +1651,7 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
htlc.SignedSuccessTx.TxIn[0].PreviousOutPoint,
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
ctrlBlock := tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID]
|
||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||
|
||||
@@ -1662,6 +1663,7 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
} else {
|
||||
resID = newResolverID(htlc.ClaimOutpoint)
|
||||
|
||||
//nolint:lll
|
||||
ctrlBlock := tapCase.CtrlBlocks.IncomingHtlcCtrlBlocks[resID]
|
||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||
}
|
||||
@@ -1677,6 +1679,7 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
htlc.SignedTimeoutTx.TxIn[0].PreviousOutPoint,
|
||||
)
|
||||
|
||||
//nolint:lll
|
||||
ctrlBlock := tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID]
|
||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||
|
||||
@@ -1688,6 +1691,7 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
} else {
|
||||
resID = newResolverID(htlc.ClaimOutpoint)
|
||||
|
||||
//nolint:lll
|
||||
ctrlBlock := tapCase.CtrlBlocks.OutgoingHtlcCtrlBlocks[resID]
|
||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
|
||||
// remote key (us in this case), those that don't, and a third where
|
||||
// there is no tweak and the output is delayed. On the local commitment
|
||||
// our output will always be delayed. We'll rely on the presence of the
|
||||
// commitment tweak to to discern which type of commitment this is.
|
||||
// commitment tweak to discern which type of commitment this is.
|
||||
var witnessType input.WitnessType
|
||||
switch {
|
||||
// The local delayed output for a taproot channel.
|
||||
|
||||
@@ -209,7 +209,7 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
|
||||
// If this is our commitment transaction, then we'll need to
|
||||
// populate the witness for the second-level HTLC transaction.
|
||||
switch {
|
||||
// For taproot channels, the witness for sweeping with sucess
|
||||
// For taproot channels, the witness for sweeping with success
|
||||
// looks like:
|
||||
// - <sender sig> <receiver sig> <preimage> <success_script>
|
||||
// <control_block>
|
||||
|
||||
@@ -245,12 +245,14 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx() (
|
||||
|
||||
var secondLevelInput input.HtlcSecondLevelAnchorInput
|
||||
if isTaproot {
|
||||
//nolint:lll
|
||||
secondLevelInput = input.MakeHtlcSecondLevelSuccessTaprootInput(
|
||||
h.htlcResolution.SignedSuccessTx,
|
||||
h.htlcResolution.SignDetails, h.htlcResolution.Preimage,
|
||||
h.broadcastHeight,
|
||||
)
|
||||
} else {
|
||||
//nolint:lll
|
||||
secondLevelInput = input.MakeHtlcSecondLevelSuccessAnchorInput(
|
||||
h.htlcResolution.SignedSuccessTx,
|
||||
h.htlcResolution.SignDetails, h.htlcResolution.Preimage,
|
||||
|
||||
@@ -161,6 +161,7 @@ func (h *htlcTimeoutResolver) claimCleanUp(
|
||||
// - <sender sig> <receiver sig> <preimage> <success_script>
|
||||
// <control_block>
|
||||
case h.isTaproot() && h.htlcResolution.SignedTimeoutTx == nil:
|
||||
//nolint:lll
|
||||
preimageBytes = spendingInput.Witness[taprootRemotePreimageIndex]
|
||||
|
||||
// The witness stack when the remote party sweeps the output on a
|
||||
@@ -174,7 +175,7 @@ func (h *htlcTimeoutResolver) claimCleanUp(
|
||||
// element, then we're actually on the losing side of a breach
|
||||
// attempt...
|
||||
case h.isTaproot() && len(spendingInput.Witness) == 1:
|
||||
return nil, fmt.Errorf("breach attempt failed...")
|
||||
return nil, fmt.Errorf("breach attempt failed")
|
||||
|
||||
// Otherwise, they'll be spending directly from our commitment output.
|
||||
// In which case the witness stack looks like:
|
||||
@@ -250,6 +251,8 @@ func (h *htlcTimeoutResolver) chainDetailsToWatch() (*wire.OutPoint, []byte, err
|
||||
// points to. We can directly grab the outpoint, then also extract the
|
||||
// witness script (the last element of the witness stack) to
|
||||
// re-construct the pkScript we need to watch.
|
||||
//
|
||||
//nolint:lll
|
||||
outPointToWatch := h.htlcResolution.SignedTimeoutTx.TxIn[0].PreviousOutPoint
|
||||
witness := h.htlcResolution.SignedTimeoutTx.TxIn[0].Witness
|
||||
|
||||
@@ -263,7 +266,8 @@ func (h *htlcTimeoutResolver) chainDetailsToWatch() (*wire.OutPoint, []byte, err
|
||||
// these together to reconstruct the taproot output key, then map that
|
||||
// into a v1 witness program.
|
||||
case h.isTaproot():
|
||||
// First, we'll parse the control block into something we can use.
|
||||
// First, we'll parse the control block into something we can
|
||||
// use.
|
||||
ctrlBlockBytes := witness[len(witness)-1]
|
||||
ctrlBlock, err := txscript.ParseControlBlock(ctrlBlockBytes)
|
||||
if err != nil {
|
||||
@@ -282,6 +286,9 @@ func (h *htlcTimeoutResolver) chainDetailsToWatch() (*wire.OutPoint, []byte, err
|
||||
ctrlBlock.InternalKey, tapscriptRoot,
|
||||
)
|
||||
scriptToWatch, err = txscript.PayToTaprootScript(outputKey)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// For regular channels, the witness script is the last element on the
|
||||
// stack. We can then use this to re-derive the output that we're
|
||||
@@ -323,6 +330,7 @@ func isPreimageSpend(isTaproot bool, spend *chainntnfs.SpendDetail,
|
||||
// <control_block>
|
||||
case isTaproot && !localCommit:
|
||||
preImageIdx := taprootRemotePreimageIndex
|
||||
//nolint:lll
|
||||
return len(spendingWitness) == remoteTaprootWitnessSuccessSize &&
|
||||
len(spendingWitness[preImageIdx]) == lntypes.HashSize
|
||||
|
||||
@@ -335,7 +343,8 @@ func isPreimageSpend(isTaproot bool, spend *chainntnfs.SpendDetail,
|
||||
//
|
||||
// - <receiver sig> <preimage> <success_script> <control_block>
|
||||
case isTaproot && localCommit:
|
||||
return len(spendingWitness[localPreimageIndex]) == lntypes.HashSize
|
||||
return len(spendingWitness[localPreimageIndex]) ==
|
||||
lntypes.HashSize
|
||||
|
||||
// If this is the non-taproot, remote commitment then the only possible
|
||||
// spends for outgoing HTLCs are:
|
||||
@@ -350,7 +359,8 @@ func isPreimageSpend(isTaproot bool, spend *chainntnfs.SpendDetail,
|
||||
// revoked their output.
|
||||
case !isTaproot && !localCommit:
|
||||
return len(spendingWitness) == expectedRemoteWitnessSuccessSize &&
|
||||
len(spendingWitness[remotePreimageIndex]) == lntypes.HashSize
|
||||
len(spendingWitness[remotePreimageIndex]) ==
|
||||
lntypes.HashSize
|
||||
|
||||
// Otherwise, for our non-taproot commitment, the only possible spends
|
||||
// for an outgoing HTLC are:
|
||||
@@ -364,7 +374,8 @@ func isPreimageSpend(isTaproot bool, spend *chainntnfs.SpendDetail,
|
||||
case !isTaproot:
|
||||
fallthrough
|
||||
default:
|
||||
return len(spendingWitness[localPreimageIndex]) == lntypes.HashSize
|
||||
return len(spendingWitness[localPreimageIndex]) ==
|
||||
lntypes.HashSize
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,48 +22,6 @@ const (
|
||||
secondLevelHtlcTweakCtrlBlockType tlv.Type = 2
|
||||
)
|
||||
|
||||
// tlvDecoder is an interface to support more generic decoding of TLV records.
|
||||
type tlvDecoder interface {
|
||||
// DecodeRecords returns a slice of TLV records that should be decoded.
|
||||
DecodeRecords() []tlv.Record
|
||||
|
||||
// Decode decodes the given reader into the target struct.
|
||||
Decode(r io.Reader) error
|
||||
}
|
||||
|
||||
// makeAndDecodeStream takes a tlvDecoder and decodes the records encoded in
|
||||
// the stream into it.
|
||||
//
|
||||
// TODO(roasbeef): use elsewhere
|
||||
func makeAndDecodeStream(r io.Reader, d tlvDecoder) error {
|
||||
stream, err := tlv.NewStream(d.DecodeRecords()...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return stream.Decode(r)
|
||||
}
|
||||
|
||||
// tlvEncoder is an interface to support more generic encoding of TLV records.
|
||||
type tlvEncoder interface {
|
||||
// EncodeRecords returns a slice of TLV records that should be encoded.
|
||||
EncodeRecords() []tlv.Record
|
||||
|
||||
// Encode encodes the target struct into the given writer.
|
||||
Encode(w io.Writer) error
|
||||
}
|
||||
|
||||
// makeAnEncodeStream takes a tlvEncoder and encodes the records into the
|
||||
// target writer as a TLV stream.
|
||||
func makeAndEncodeStream[E tlvEncoder](w io.Writer, e E) error {
|
||||
stream, err := tlv.NewStream(e.EncodeRecords()...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return stream.Encode(w)
|
||||
}
|
||||
|
||||
// taprootBriefcase is a supplemental storage struct that contains all the
|
||||
// information we need to sweep taproot outputs.
|
||||
type taprootBriefcase struct {
|
||||
@@ -107,6 +65,7 @@ func (t *taprootBriefcase) Encode(w io.Writer) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return stream.Encode(w)
|
||||
}
|
||||
|
||||
@@ -116,13 +75,15 @@ func (t *taprootBriefcase) Decode(r io.Reader) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return stream.Decode(r)
|
||||
}
|
||||
|
||||
// resolverCtrlBlocks is a map of resolver IDs to their corresponding control block.
|
||||
// resolverCtrlBlocks is a map of resolver IDs to their corresponding control
|
||||
// block.
|
||||
type resolverCtrlBlocks map[resolverID][]byte
|
||||
|
||||
// newResolverCtrlBlockss returns a new instance of the resolverCtrlBlocks
|
||||
// newResolverCtrlBlockss returns a new instance of the resolverCtrlBlocks.
|
||||
func newResolverCtrlBlocks() resolverCtrlBlocks {
|
||||
return make(resolverCtrlBlocks)
|
||||
}
|
||||
@@ -170,32 +131,34 @@ func (r *resolverCtrlBlocks) Encode(w io.Writer) error {
|
||||
}
|
||||
|
||||
// Decode decodes the given reader into the target struct.
|
||||
func (t *resolverCtrlBlocks) Decode(r io.Reader) error {
|
||||
func (r *resolverCtrlBlocks) Decode(reader io.Reader) error {
|
||||
var buf [8]byte
|
||||
|
||||
numBlocks, err := tlv.ReadVarInt(r, &buf)
|
||||
numBlocks, err := tlv.ReadVarInt(reader, &buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := uint64(0); i < numBlocks; i++ {
|
||||
var id resolverID
|
||||
if _, err := io.ReadFull(r, id[:]); err != nil {
|
||||
if _, err := io.ReadFull(reader, id[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ctrlBlock []byte
|
||||
if err := varBytesDecoder(r, &ctrlBlock, &buf, 0); err != nil {
|
||||
err := varBytesDecoder(reader, &ctrlBlock, &buf, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
(*t)[id] = ctrlBlock
|
||||
(*r)[id] = ctrlBlock
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// resolverCtrlBlocksEncoder is a custom TLV encoder for the resolverCtrlBlocks
|
||||
// resolverCtrlBlocksEncoder is a custom TLV encoder for the
|
||||
// resolverCtrlBlocks.
|
||||
func resolverCtrlBlocksEncoder(w io.Writer, val any, buf *[8]byte) error {
|
||||
if typ, ok := val.(*resolverCtrlBlocks); ok {
|
||||
return (*typ).Encode(w)
|
||||
@@ -204,7 +167,7 @@ func resolverCtrlBlocksEncoder(w io.Writer, val any, buf *[8]byte) error {
|
||||
return tlv.NewTypeForEncodingErr(val, "resolverCtrlBlocks")
|
||||
}
|
||||
|
||||
// rsolverCtrlBlocksDecoder is a custom TLV decoder for the resolverCtrlBlocks
|
||||
// rsolverCtrlBlocksDecoder is a custom TLV decoder for the resolverCtrlBlocks.
|
||||
func resolverCtrlBlocksDecoder(r io.Reader, val any, buf *[8]byte,
|
||||
l uint64) error {
|
||||
|
||||
@@ -218,6 +181,7 @@ func resolverCtrlBlocksDecoder(r io.Reader, val any, buf *[8]byte,
|
||||
}
|
||||
|
||||
*typ = resolverBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -315,6 +279,7 @@ func ctrlBlockDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
|
||||
}
|
||||
|
||||
*typ = &ctrlBlocks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -333,8 +298,10 @@ func newCtrlBlocksRecord(blks **ctrlBlocks) tlv.Record {
|
||||
if err := ctrlBlockEncoder(&b, blks, &buf); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return uint64(len(b.Bytes()))
|
||||
}
|
||||
|
||||
return tlv.MakeDynamicRecord(
|
||||
taprootCtrlBlockType, blks, recordSize, ctrlBlockEncoder,
|
||||
ctrlBlockDecoder,
|
||||
@@ -549,7 +516,8 @@ func (h *htlcTapTweaks) Decode(reader io.Reader) error {
|
||||
// tapTweaks stores the set of taptweaks needed to perform keyspends for the
|
||||
// commitment outputs.
|
||||
type tapTweaks struct {
|
||||
// AnchorTweak is the tweak used to derive the key used to spend the anchor output.
|
||||
// AnchorTweak is the tweak used to derive the key used to spend the
|
||||
// anchor output.
|
||||
AnchorTweak []byte
|
||||
|
||||
// BreachedHtlcTweaks stores the set of tweaks needed to sweep the
|
||||
@@ -590,6 +558,7 @@ func tapTweaksDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
|
||||
}
|
||||
|
||||
*typ = &tapTweaks
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -607,8 +576,10 @@ func newTapTweaksRecord(tweaks **tapTweaks) tlv.Record {
|
||||
if err := tapTweaksEncoder(&b, tweaks, &buf); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return uint64(len(b.Bytes()))
|
||||
}
|
||||
|
||||
return tlv.MakeDynamicRecord(
|
||||
taprootTapTweakType, tweaks, recordSize, tapTweaksEncoder,
|
||||
tapTweaksDecoder,
|
||||
|
||||
@@ -543,10 +543,13 @@ func (u *UtxoNursery) NurseryReport(
|
||||
// confirmation of the commitment transaction.
|
||||
switch kid.WitnessType() {
|
||||
|
||||
case input.HtlcAcceptedSuccessSecondLevel,
|
||||
input.TaprootHtlcAcceptedSuccessSecondLevel:
|
||||
// An HTLC output on our commitment transaction
|
||||
// where the second-layer transaction hasn't
|
||||
//nolint:lll
|
||||
case input.TaprootHtlcAcceptedSuccessSecondLevel:
|
||||
fallthrough
|
||||
case input.HtlcAcceptedSuccessSecondLevel:
|
||||
// An HTLC output on our commitment
|
||||
// transaction where the second-layer
|
||||
// transaction hasn't
|
||||
// yet confirmed.
|
||||
report.AddLimboStage1SuccessHtlc(&kid)
|
||||
|
||||
@@ -575,6 +578,7 @@ func (u *UtxoNursery) NurseryReport(
|
||||
// it.
|
||||
report.AddLimboDirectHtlc(&kid)
|
||||
|
||||
//nolint:lll
|
||||
case input.TaprootHtlcAcceptedSuccessSecondLevel:
|
||||
fallthrough
|
||||
case input.TaprootHtlcOfferedTimeoutSecondLevel:
|
||||
@@ -595,6 +599,7 @@ func (u *UtxoNursery) NurseryReport(
|
||||
// balance.
|
||||
switch kid.WitnessType() {
|
||||
|
||||
//nolint:lll
|
||||
case input.TaprootHtlcAcceptedSuccessSecondLevel:
|
||||
fallthrough
|
||||
case input.TaprootHtlcOfferedTimeoutSecondLevel:
|
||||
|
||||
+2
-1
@@ -425,7 +425,8 @@ func MakeHtlcSecondLevelTimeoutAnchorInput(signedTx *wire.MsgTx,
|
||||
// transaction. The sweeper is also able to generate witnesses on demand to
|
||||
// sweep the second level HTLC aggregated with other transactions.
|
||||
func MakeHtlcSecondLevelTimeoutTaprootInput(signedTx *wire.MsgTx,
|
||||
signDetails *SignDetails, heightHint uint32) HtlcSecondLevelAnchorInput {
|
||||
signDetails *SignDetails,
|
||||
heightHint uint32) HtlcSecondLevelAnchorInput {
|
||||
|
||||
createWitness := func(signer Signer, txn *wire.MsgTx,
|
||||
hashCache *txscript.TxSigHashes,
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
)
|
||||
|
||||
// UnknownScriptTypeErr is returned when an unknown script type is encountered.
|
||||
var UnknownScriptTypeErr = errors.New("unknown script type")
|
||||
// ErrUnknownScriptType is returned when an unknown script type is encountered.
|
||||
var ErrUnknownScriptType = errors.New("unknown script type")
|
||||
|
||||
// ScriptPath is used to indicate the spending path of a given script. Possible
|
||||
// paths include: timeout, success, revocation, and others.
|
||||
@@ -28,8 +28,8 @@ const (
|
||||
// breached.
|
||||
ScriptPathRevocation
|
||||
|
||||
// ScriptPathDelay is a script path used when a contract has has
|
||||
// relative delay that must elapse before it can be swept.
|
||||
// ScriptPathDelay is a script path used when a contract has relative
|
||||
// delay that must elapse before it can be swept.
|
||||
ScriptPathDelay
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ type ScriptDescriptor interface {
|
||||
|
||||
// WitnessScriptForPath returns the witness script for the given
|
||||
// spending path. An error is returned if the path is unknown. This is
|
||||
// useful as when constructing a contrl block for a given path, one
|
||||
// useful as when constructing a control block for a given path, one
|
||||
// also needs witness script being signed.
|
||||
WitnessScriptForPath(path ScriptPath) ([]byte, error)
|
||||
}
|
||||
|
||||
+13
-13
@@ -648,12 +648,12 @@ type HtlcScriptTree struct {
|
||||
func (h *HtlcScriptTree) WitnessScriptToSign() []byte {
|
||||
switch h.htlcType {
|
||||
// For incoming HLTCs on our local commitment, we care about verifying
|
||||
// the sucess path.
|
||||
// the success path.
|
||||
case htlcLocalIncoming:
|
||||
return h.SuccessTapLeaf.Script
|
||||
|
||||
// For incoming HTLCs on the remote party's commitment, we want to sign
|
||||
// the the timeout path for them.
|
||||
// the timeout path for them.
|
||||
case htlcRemoteIncoming:
|
||||
return h.TimeoutTapLeaf.Script
|
||||
|
||||
@@ -1526,7 +1526,7 @@ func SecondLevelHtlcScript(revocationKey, delayKey *btcec.PublicKey,
|
||||
// if statement.
|
||||
builder.AddOp(txscript.OP_IF)
|
||||
|
||||
// If this this is the revocation case, then we'll push the revocation
|
||||
// If this is the revocation case, then we'll push the revocation
|
||||
// public key on the stack.
|
||||
builder.AddData(revocationKey.SerializeCompressed())
|
||||
|
||||
@@ -1778,8 +1778,8 @@ func TaprootHtlcSpendSuccess(signer Signer, signDesc *SignDescriptor,
|
||||
|
||||
var ctrlBlock []byte
|
||||
if signDesc.ControlBlock == nil {
|
||||
// Now that we have the sweep signature, we'll construct the control
|
||||
// block needed to spend the script path.
|
||||
// Now that we have the sweep signature, we'll construct the
|
||||
// control block needed to spend the script path.
|
||||
redeemControlBlock := MakeTaprootCtrlBlock(
|
||||
signDesc.WitnessScript, revokeKey, tapscriptTree,
|
||||
)
|
||||
@@ -1804,9 +1804,9 @@ func TaprootHtlcSpendSuccess(signer Signer, signDesc *SignDescriptor,
|
||||
return witnessStack, nil
|
||||
}
|
||||
|
||||
// LeaseSecondLevelHtlcScript is the uniform script that's used as the output for
|
||||
// the second-level HTLC transactions. The second level transaction acts as a
|
||||
// sort of covenant, ensuring that a 2-of-2 multi-sig output can only be
|
||||
// LeaseSecondLevelHtlcScript is the uniform script that's used as the output
|
||||
// for the second-level HTLC transactions. The second level transaction acts as
|
||||
// a sort of covenant, ensuring that a 2-of-2 multi-sig output can only be
|
||||
// spent in a particular way, and to a particular output.
|
||||
//
|
||||
// Possible Input Scripts:
|
||||
@@ -2070,7 +2070,7 @@ var _ TapscriptDescriptor = (*CommitScriptTree)(nil)
|
||||
// remote party, and also verifying signatures on our transactions. As an
|
||||
// example, when we create an outgoing HTLC for the remote party, we want to
|
||||
// sign their success path.
|
||||
func (s *CommitScriptTree) WitnessScriptToSign() []byte {
|
||||
func (c *CommitScriptTree) WitnessScriptToSign() []byte {
|
||||
// TODO(roasbeef): abstraction leak here? always dependent
|
||||
return nil
|
||||
}
|
||||
@@ -2795,20 +2795,20 @@ func NewAnchorScriptTree(anchorKey *btcec.PublicKey,
|
||||
// remote party, and also verifying signatures on our transactions. As an
|
||||
// example, when we create an outgoing HTLC for the remote party, we want to
|
||||
// sign their success path.
|
||||
func (s *AnchorScriptTree) WitnessScriptToSign() []byte {
|
||||
return s.SweepLeaf.Script
|
||||
func (a *AnchorScriptTree) WitnessScriptToSign() []byte {
|
||||
return a.SweepLeaf.Script
|
||||
}
|
||||
|
||||
// WitnessScriptForPath returns the witness script for the given spending path.
|
||||
// An error is returned if the path is unknown.
|
||||
func (s *AnchorScriptTree) WitnessScriptForPath(path ScriptPath,
|
||||
func (a *AnchorScriptTree) WitnessScriptForPath(path ScriptPath,
|
||||
) ([]byte, error) {
|
||||
|
||||
switch path {
|
||||
case ScriptPathDelay:
|
||||
fallthrough
|
||||
case ScriptPathSuccess:
|
||||
return s.SweepLeaf.Script, nil
|
||||
return a.SweepLeaf.Script, nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown script path: %v", path)
|
||||
|
||||
+11
-6
@@ -247,8 +247,8 @@ const (
|
||||
// ....HTLCOutputs...
|
||||
// - LockTime: 4 bytes
|
||||
BaseTaprootCommitmentTxWeight = (4 + 1 + FundingInputSize + 3 +
|
||||
2*TaprootCommitmentOutput + 2*TaprootCommitmentAnchorOutput + 4) *
|
||||
witnessScaleFactor
|
||||
2*TaprootCommitmentOutput + 2*TaprootCommitmentAnchorOutput +
|
||||
4) * witnessScaleFactor
|
||||
|
||||
// CommitWeight 724 weight.
|
||||
CommitWeight = BaseCommitmentTxWeight + WitnessCommitmentTxWeight
|
||||
@@ -637,7 +637,8 @@ const (
|
||||
// - ctrl block size: 1 byte
|
||||
// - base control block: 33 bytes
|
||||
// - merkle proof: 32
|
||||
TaprootToLocalRevokeWitnessSize = 1 + 1 + 65 + 1 + TaprootToLocalRevokeScriptSize + 1 + 33 + 32
|
||||
TaprootToLocalRevokeWitnessSize = (1 + 1 + 65 + 1 +
|
||||
TaprootToLocalRevokeScriptSize + 1 + 33 + 32)
|
||||
|
||||
// TaprootToRemoteScriptSize
|
||||
// - OP_DATA: 1 byte
|
||||
@@ -656,8 +657,9 @@ const (
|
||||
// - taproot_to_local_script_size: 36 bytes
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
TaprootToRemoteWitnessSize = 1 + 1 + 65 + 1 + TaprootToRemoteScriptSize +
|
||||
1 + TaprootBaseControlBlockWitnessSize
|
||||
TaprootToRemoteWitnessSize = (1 + 1 + 65 + 1 +
|
||||
TaprootToRemoteScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize)
|
||||
|
||||
// TaprootAnchorWitnessSize: 67 bytes
|
||||
//
|
||||
@@ -691,12 +693,14 @@ const (
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
//nolint:lll
|
||||
TaprootSecondLevelRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootAcceptedRevokeWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
//nolint:lll
|
||||
TaprootAcceptedRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootOfferedRevokeWitnessSize:
|
||||
@@ -716,7 +720,8 @@ const (
|
||||
// - cltv_expiry: 4 bytes
|
||||
// - OP_CHECKLOCKTIMEVERIFY: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootHtlcOfferedRemoteTimeoutScriptSize = 1 + 32 + 1 + 1 + 1 + 1 + 1 + 4 + 1 + 1
|
||||
TaprootHtlcOfferedRemoteTimeoutScriptSize = (1 + 32 + 1 + 1 + 1 + 1 +
|
||||
1 + 4 + 1 + 1)
|
||||
|
||||
// TaprootHtlcOfferedRemoteTimeoutwitSize: 176 bytes
|
||||
// - number_of_witness_elements: 1 byte
|
||||
|
||||
+33
-12
@@ -850,7 +850,8 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
|
||||
signer := &dummySigner{}
|
||||
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
||||
testCSVDelay, testKey.PubKey(), testKey.PubKey(),
|
||||
testCSVDelay, testKey.PubKey(),
|
||||
testKey.PubKey(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -858,10 +859,11 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
PubKey: testKey.PubKey(),
|
||||
},
|
||||
//nolint:lll
|
||||
WitnessScript: commitScriptTree.SettleLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.TaprootCommitSpendSuccess(
|
||||
@@ -869,6 +871,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
commitScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -881,7 +884,8 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
|
||||
signer := &dummySigner{}
|
||||
commitScriptTree, err := input.NewLocalCommitScriptTree(
|
||||
testCSVDelay, testKey.PubKey(), testKey.PubKey(),
|
||||
testCSVDelay, testKey.PubKey(),
|
||||
testKey.PubKey(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -889,10 +893,11 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
PubKey: testKey.PubKey(),
|
||||
},
|
||||
//nolint:lll
|
||||
WitnessScript: commitScriptTree.RevocationLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.TaprootCommitSpendRevoke(
|
||||
@@ -900,6 +905,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
commitScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -911,6 +917,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
require.NoError(t, err)
|
||||
|
||||
signer := &dummySigner{}
|
||||
//nolint:lll
|
||||
commitScriptTree, err := input.NewRemoteCommitScriptTree(
|
||||
testKey.PubKey(),
|
||||
)
|
||||
@@ -920,10 +927,11 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
PubKey: testKey.PubKey(),
|
||||
},
|
||||
//nolint:lll
|
||||
WitnessScript: commitScriptTree.SettleLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.TaprootCommitRemoteSpend(
|
||||
@@ -931,6 +939,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
commitScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -962,6 +971,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1002,6 +1012,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
scriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1038,6 +1049,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1062,6 +1074,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
senderKey.PubKey(), receiverKey.PubKey(),
|
||||
revokeKey.PubKey(), payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
signDesc := &input.SignDescriptor{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
@@ -1077,6 +1090,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1102,6 +1116,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||
payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
signDesc := &input.SignDescriptor{
|
||||
KeyDesc: keychain.KeyDescriptor{
|
||||
@@ -1117,6 +1132,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
signer, signDesc, testTx,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1142,6 +1158,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||
payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
timeoutLeaf := htlcScriptTree.TimeoutTapLeaf
|
||||
|
||||
@@ -1152,14 +1169,16 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: timeoutLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.ReceiverHTLCScriptTaprootTimeout(
|
||||
signer, signDesc, testTx, testCLTVExpiry,
|
||||
revokeKey.PubKey(), htlcScriptTree.TapscriptTree,
|
||||
revokeKey.PubKey(),
|
||||
htlcScriptTree.TapscriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1197,7 +1216,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: timeoutLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
receiverSig, err := signer.SignOutputRaw(
|
||||
testTx, receiverDesc,
|
||||
@@ -1211,7 +1230,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: timeoutLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.SenderHTLCScriptTaprootTimeout(
|
||||
@@ -1220,6 +1239,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
scriptTree,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
return witness
|
||||
},
|
||||
},
|
||||
@@ -1256,7 +1276,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: successLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.SenderHTLCScriptTaprootRedeem(
|
||||
@@ -1290,6 +1310,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
receiverKey.PubKey(), revokeKey.PubKey(),
|
||||
payHash[:], false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
successsLeaf := htlcScriptTree.SuccessTapLeaf
|
||||
scriptTree := htlcScriptTree.TapscriptTree
|
||||
@@ -1301,7 +1322,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: successsLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
senderSig, err := signer.SignOutputRaw(
|
||||
testTx, senderDesc,
|
||||
@@ -1315,7 +1336,7 @@ var witnessSizeTests = []witnessSizeTest{
|
||||
WitnessScript: successsLeaf.Script,
|
||||
HashType: txscript.SigHashAll,
|
||||
InputIndex: 0,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod,
|
||||
SignMethod: input.TaprootScriptSpendSignMethod, //nolint:lll
|
||||
}
|
||||
|
||||
witness, err := input.ReceiverHTLCScriptTaprootRedeem(
|
||||
|
||||
+8
-8
@@ -522,8 +522,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block must " +
|
||||
"be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := TaprootCommitSpendSuccess(
|
||||
@@ -544,8 +544,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block must " +
|
||||
"be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := TaprootCommitRemoteSpend(
|
||||
@@ -589,8 +589,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block must " +
|
||||
"be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := TaprootHtlcSpendSuccess(
|
||||
@@ -677,8 +677,8 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
||||
|
||||
// The control block bytes must be set at this point.
|
||||
if desc.ControlBlock == nil {
|
||||
return nil, fmt.Errorf("control block must be " +
|
||||
"set for taproot spend")
|
||||
return nil, fmt.Errorf("control block " +
|
||||
"must be set for taproot spend")
|
||||
}
|
||||
|
||||
witness, err := ReceiverHTLCScriptTaprootTimeout(
|
||||
|
||||
@@ -719,7 +719,6 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
|
||||
// In case of anchors, the timeout txs will be aggregated into one.
|
||||
if lntest.CommitTypeHasAnchors(channelType) {
|
||||
|
||||
expectedTxes = 1
|
||||
}
|
||||
|
||||
@@ -733,7 +732,6 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
// into one.
|
||||
numInputs := 1
|
||||
if lntest.CommitTypeHasAnchors(channelType) {
|
||||
|
||||
numInputs = numInvoices + 1
|
||||
}
|
||||
|
||||
@@ -845,7 +843,6 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
// For anchor channels thhis is one block earlier.
|
||||
numBlocks := uint32(defaultCSV - 1)
|
||||
if lntest.CommitTypeHasAnchors(channelType) {
|
||||
|
||||
numBlocks = defaultCSV - 2
|
||||
}
|
||||
ht.MineBlocks(numBlocks)
|
||||
@@ -992,7 +989,6 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
|
||||
// In addition, if this is an anchor-enabled channel, further add the
|
||||
// anchor size.
|
||||
if lntest.CommitTypeHasAnchors(channelType) {
|
||||
|
||||
carolExpectedBalance += btcutil.Amount(anchorSize)
|
||||
}
|
||||
|
||||
|
||||
@@ -102,13 +102,14 @@ func testBasicChannelFunding(ht *lntest.HarnessTest) {
|
||||
// Dave only supports tweakless, channel will be downgraded to
|
||||
// this type if Carol supports anchors.
|
||||
case lnrpc.CommitmentType_STATIC_REMOTE_KEY:
|
||||
if expType == lnrpc.CommitmentType_ANCHORS {
|
||||
switch expType {
|
||||
case lnrpc.CommitmentType_ANCHORS:
|
||||
expType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
|
||||
} else if expType == lnrpc.CommitmentType_SIMPLE_TAPROOT {
|
||||
case lnrpc.CommitmentType_SIMPLE_TAPROOT:
|
||||
expType = lnrpc.CommitmentType_STATIC_REMOTE_KEY
|
||||
}
|
||||
|
||||
// Dave only supoprts legacy type, channel will be downgraded
|
||||
// Dave only supports legacy type, channel will be downgraded
|
||||
// to this type.
|
||||
case lnrpc.CommitmentType_LEGACY:
|
||||
expType = lnrpc.CommitmentType_LEGACY
|
||||
|
||||
@@ -37,7 +37,8 @@ func breachRetributionTestCase(ht *lntest.HarnessTest,
|
||||
"Carol",
|
||||
append(
|
||||
nodeArgs,
|
||||
[]string{"--hodl.exit-settle", "--nolisten", "--minbackoff=1h"}...,
|
||||
[]string{"--hodl.exit-settle", "--nolisten",
|
||||
"--minbackoff=1h"}...,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -55,9 +55,10 @@ func (d *DummySigner) ComputeInputScript(tx *wire.MsgTx,
|
||||
// all signing parties must be provided, including the public key of the local
|
||||
// signing key. If nonces of other parties are already known, they can be
|
||||
// submitted as well to reduce the number of method calls necessary later on.
|
||||
func (d *DummySigner) MuSig2CreateSession(input.MuSig2Version, keychain.KeyLocator,
|
||||
[]*btcec.PublicKey, *input.MuSig2Tweaks,
|
||||
[][musig2.PubNonceSize]byte, ...musig2.SessionOption) (*input.MuSig2SessionInfo, error) {
|
||||
func (d *DummySigner) MuSig2CreateSession(input.MuSig2Version,
|
||||
keychain.KeyLocator, []*btcec.PublicKey, *input.MuSig2Tweaks,
|
||||
[][musig2.PubNonceSize]byte, ...musig2.SessionOption,
|
||||
) (*input.MuSig2SessionInfo, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
+23
-5
@@ -2513,8 +2513,8 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// If our balance exceeds the remote party's dust limit, instantiate
|
||||
// the sign descriptor for our output.
|
||||
if ourAmt >= int64(chanState.RemoteChanCfg.DustLimit) {
|
||||
// As we're about to sweep our own output w/o a delay, we'll obtain
|
||||
// the witness script for the success/delay path.
|
||||
// As we're about to sweep our own output w/o a delay, we'll
|
||||
// obtain the witness script for the success/delay path.
|
||||
witnessScript, err := ourScript.WitnessScriptForPath(
|
||||
input.ScriptPathDelay,
|
||||
)
|
||||
@@ -2537,6 +2537,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// spend (as our output on their revoked tx still needs the
|
||||
// delay), and set the control block.
|
||||
if scriptTree, ok := ourScript.(input.TapscriptDescriptor); ok {
|
||||
//nolint:lll
|
||||
br.LocalOutputSignDesc.SignMethod = input.TaprootScriptSpendSignMethod
|
||||
|
||||
ctrlBlock, err := scriptTree.CtrlBlockForPath(
|
||||
@@ -2546,6 +2547,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//nolint:lll
|
||||
br.LocalOutputSignDesc.ControlBlock, err = ctrlBlock.ToBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -2581,7 +2583,8 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// For taproot channels, the remote output (the revoked output)
|
||||
// is spent with a script path to ensure all information 3rd
|
||||
// parties need to sweep anchors is revealed on chain.
|
||||
if scriptTree, ok := theirScript.(input.TapscriptDescriptor); ok {
|
||||
scriptTree, ok := theirScript.(input.TapscriptDescriptor)
|
||||
if ok {
|
||||
//nolint:lll
|
||||
br.RemoteOutputSignDesc.SignMethod = input.TaprootScriptSpendSignMethod
|
||||
|
||||
@@ -2591,6 +2594,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//nolint:lll
|
||||
br.RemoteOutputSignDesc.ControlBlock, err = ctrlBlock.ToBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -6480,6 +6484,8 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
|
||||
|
||||
// For taproot channels, we'll need to set some additional
|
||||
// fields to ensure the output can be swept.
|
||||
//
|
||||
//nolint:lll
|
||||
if scriptTree, ok := selfScript.(input.TapscriptDescriptor); ok {
|
||||
commitResolution.SelfOutputSignDesc.SignMethod =
|
||||
input.TaprootScriptSpendSignMethod
|
||||
@@ -6490,6 +6496,7 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//nolint:lll
|
||||
commitResolution.SelfOutputSignDesc.ControlBlock, err = ctrlBlock.ToBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -6836,6 +6843,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
//nolint:lll
|
||||
secondLevelScriptTree, err := input.TaprootSecondLevelScriptTree(
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
||||
)
|
||||
@@ -6952,9 +6960,12 @@ func newIncomingHtlcResolution(signer input.Signer,
|
||||
HashType: txscript.SigHashAll,
|
||||
}
|
||||
|
||||
//nolint:lll
|
||||
if scriptTree, ok := scriptInfo.(input.TapscriptDescriptor); ok {
|
||||
signDesc.SignMethod = input.TaprootScriptSpendSignMethod
|
||||
ctrlBlock, err := scriptTree.CtrlBlockForPath(scriptPath)
|
||||
ctrlBlock, err := scriptTree.CtrlBlockForPath(
|
||||
scriptPath,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -6979,7 +6990,8 @@ func newIncomingHtlcResolution(signer input.Signer,
|
||||
secondLevelOutputAmt := htlc.Amt.ToSatoshis() - htlcFee
|
||||
successTx, err := CreateHtlcSuccessTx(
|
||||
chanType, isCommitFromInitiator, op, secondLevelOutputAmt,
|
||||
csvDelay, leaseExpiry, keyRing.RevocationKey, keyRing.ToLocalKey,
|
||||
csvDelay, leaseExpiry, keyRing.RevocationKey,
|
||||
keyRing.ToLocalKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -7068,6 +7080,7 @@ func newIncomingHtlcResolution(signer input.Signer,
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
//nolint:lll
|
||||
secondLevelScriptTree, err := input.TaprootSecondLevelScriptTree(
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
||||
)
|
||||
@@ -7429,6 +7442,7 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//nolint:lll
|
||||
commitResolution.SelfOutputSignDesc.ControlBlock, err = ctrlBlock.ToBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -7823,6 +7837,7 @@ func NewAnchorResolution(chanState *channeldb.OpenChannel,
|
||||
return nil, err
|
||||
}
|
||||
if chanState.ChanType.IsTaproot() && !isLocalCommit {
|
||||
//nolint:ineffassign
|
||||
localAnchor, remoteAnchor = remoteAnchor, localAnchor
|
||||
}
|
||||
|
||||
@@ -7868,6 +7883,7 @@ func NewAnchorResolution(chanState *channeldb.OpenChannel,
|
||||
signDesc.SignMethod = input.TaprootKeySpendSignMethod
|
||||
signDesc.HashType = txscript.SigHashDefault
|
||||
|
||||
//nolint:lll
|
||||
signDesc.PrevOutputFetcher = txscript.NewCannedPrevOutputFetcher(
|
||||
localAnchor.PkScript(), int64(anchorSize),
|
||||
)
|
||||
@@ -7888,6 +7904,8 @@ func NewAnchorResolution(chanState *channeldb.OpenChannel,
|
||||
// When we're playing the force close of a remote
|
||||
// commitment, as this is a "tweakless" channel type,
|
||||
// we don't need a tweak value at all.
|
||||
//
|
||||
//nolint:lll
|
||||
signDesc.KeyDesc = chanState.LocalChanCfg.PaymentBasePoint
|
||||
}
|
||||
|
||||
|
||||
+13
-11
@@ -425,6 +425,9 @@ func SecondLevelHtlcScript(chanType channeldb.ChannelType, initiator bool,
|
||||
witnessScript, err := input.LeaseSecondLevelHtlcScript(
|
||||
revocationKey, delayKey, csvDelay, leaseExpiry,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkScript, err := input.WitnessScriptHash(witnessScript)
|
||||
if err != nil {
|
||||
@@ -440,6 +443,9 @@ func SecondLevelHtlcScript(chanType channeldb.ChannelType, initiator bool,
|
||||
witnessScript, err := input.SecondLevelHtlcScript(
|
||||
revocationKey, delayKey, csvDelay,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pkScript, err := input.WitnessScriptHash(witnessScript)
|
||||
if err != nil {
|
||||
@@ -528,6 +534,7 @@ func CommitScriptAnchors(chanType channeldb.ChannelType,
|
||||
case chanType.IsTaproot():
|
||||
anchorScript = func(key *btcec.PublicKey,
|
||||
) (input.ScriptDescriptor, error) {
|
||||
|
||||
return input.NewAnchorScriptTree(
|
||||
key,
|
||||
)
|
||||
@@ -1096,9 +1103,6 @@ func genTaprootHtlcScript(isIncoming, ourCommit bool, timeout uint32,
|
||||
keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], ourCommit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Finally, we're paying the remote party via an HTLC, which is being
|
||||
// added to their commitment transaction. Therefore, we use the
|
||||
@@ -1108,12 +1112,9 @@ func genTaprootHtlcScript(isIncoming, ourCommit bool, timeout uint32,
|
||||
timeout, keyRing.LocalHtlcKey, keyRing.RemoteHtlcKey,
|
||||
keyRing.RevocationKey, rHash[:], ourCommit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return htlcScriptTree, nil
|
||||
return htlcScriptTree, err
|
||||
}
|
||||
|
||||
// genHtlcScript generates the proper P2WSH public key scripts for the HTLC
|
||||
@@ -1131,11 +1132,11 @@ func genHtlcScript(chanType channeldb.ChannelType, isIncoming, ourCommit bool,
|
||||
chanType, isIncoming, ourCommit, timeout, rHash,
|
||||
keyRing,
|
||||
)
|
||||
} else {
|
||||
return genTaprootHtlcScript(
|
||||
isIncoming, ourCommit, timeout, rHash, keyRing,
|
||||
)
|
||||
}
|
||||
|
||||
return genTaprootHtlcScript(
|
||||
isIncoming, ourCommit, timeout, rHash, keyRing,
|
||||
)
|
||||
}
|
||||
|
||||
// addHTLC adds a new HTLC to the passed commitment transaction. One of four
|
||||
@@ -1174,6 +1175,7 @@ func addHTLC(commitTx *wire.MsgTx, ourCommit bool,
|
||||
} else {
|
||||
paymentDesc.theirPkScript = pkScript
|
||||
|
||||
//nolint:lll
|
||||
paymentDesc.theirWitnessScript = scriptInfo.WitnessScriptToSign()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user