multi: fix linter errors

This commit is contained in:
Olaoluwa Osuntokun committed 2023-08-22 16:34:15 -07:00
1 parent d3e4bca772
commit a2b277cf1d
20 files changed
+187 -144

No files matched your search

+10 -6
View File
@@ -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
}
+7 -3
View File
@@ -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
}
+1 -1
View File
@@ -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>
+2
View File
@@ -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,
+16 -5
View File
@@ -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
}
}
+23 -52
View File
@@ -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,
+9 -4
View File
@@ -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: