What changed, and why it matters
This commit is purely a code cleanup: it removes extra blank lines, shortens lines that were too long, and adds linter suppression comments where needed. There are no functional changes to the program's behavior, so it does not fix or introduce any security issue.
No security action needed; this is a style-only refactor. Reviewers may verify that no logic changed and that all added //nolint directives are justified.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit addresses linting issues (gci blank lines and ll line length > 80) across contractcourt, input, lnwallet, and watchtower packages. Changes include removing double blank lines, splitting long lines, adding //nolint:ll comments, and refactoring test code structure without altering logic or constants. No production code semantics are changed.
Changed components
contractcourt/channel_arbitrator.gocontractcourt/utxonursery.gocontractcourt/utxonursery_test.goinput/size_test.golnwallet/channel_test.gowatchtower/blob/type.goInspect captured patch +223 / −101
diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go
index a1b6f64..458a8a0 100644
--- a/contractcourt/channel_arbitrator.go
+++ b/contractcourt/channel_arbitrator.go
@@ -2466,8 +2466,6 @@ func (c *ChannelArbitrator) prepContractResolutions(
continue
}
-
-
resolver := newSuccessResolver(
resolution, height, htlc, chanType,
resolverCfg,
@@ -2497,8 +2495,6 @@ func (c *ChannelArbitrator) prepContractResolutions(
continue
}
-
-
resolver := newTimeoutResolver(
resolution, height, htlc, chanType,
resolverCfg,
@@ -2540,8 +2536,6 @@ func (c *ChannelArbitrator) prepContractResolutions(
continue
}
-
-
resolver := newIncomingContestResolver(
resolution, height, htlc, chanType,
resolverCfg,
@@ -2574,7 +2568,6 @@ func (c *ChannelArbitrator) prepContractResolutions(
continue
}
-
resolver := newOutgoingContestResolver(
resolution, height, htlc, chanType,
resolverCfg,
diff --git a/contractcourt/utxonursery.go b/contractcourt/utxonursery.go
index 815ac30..2f534ec 100644
--- a/contractcourt/utxonursery.go
+++ b/contractcourt/utxonursery.go
@@ -604,7 +604,6 @@ func (u *UtxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
return nil
}
-
// NurseryReport attempts to return a nursery report stored for the target
// outpoint. A nursery report details the maturity/sweeping progress for a
// contract that was previously force closed. If a report entry for the target
@@ -1543,6 +1542,7 @@ func makeKidOutput(outpoint, originChanPoint *wire.OutPoint,
// This is an HTLC either if it's an incoming HTLC on our commitment
// transaction, or is an outgoing HTLC on the commitment transaction of
// the remote peer.
+ //nolint:ll
isHtlc := (witnessType == input.HtlcAcceptedSuccessSecondLevel ||
witnessType == input.TaprootHtlcAcceptedSuccessSecondLevel ||
witnessType == input.TaprootHtlcAcceptedSuccessSecondLevelFinal ||
diff --git a/contractcourt/utxonursery_test.go b/contractcourt/utxonursery_test.go
index 7ca984d..f9dd302 100644
--- a/contractcourt/utxonursery_test.go
+++ b/contractcourt/utxonursery_test.go
@@ -1492,12 +1492,12 @@ func TestMakeBabyOutputWitnessType(t *testing.T) {
name: "staging taproot",
pkScript: taprootPkScript,
isFinalTaproot: false,
- expectedWitType: input.TaprootHtlcOfferedTimeoutSecondLevel,
+ expectedWitType: input.TaprootHtlcOfferedTimeoutSecondLevel, //nolint:ll
},
{
- name: "production taproot final",
- pkScript: taprootPkScript,
- isFinalTaproot: true,
+ name: "production taproot final",
+ pkScript: taprootPkScript,
+ isFinalTaproot: true,
expectedWitType: input.TaprootHtlcOfferedTimeoutSecondLevelFinal, //nolint:ll
},
}
@@ -1571,8 +1571,8 @@ func TestIncubateConfigWitnessTypeSelection(t *testing.T) {
expectedOutgoing: input.HtlcOfferedRemoteTimeout,
},
{
- name: "staging taproot incoming+outgoing",
- pkScript: taprootPkScript,
+ name: "staging taproot incoming+outgoing",
+ pkScript: taprootPkScript,
expectedIncoming: input.TaprootHtlcAcceptedSuccessSecondLevel, //nolint:ll
expectedOutgoing: input.TaprootHtlcOfferedRemoteTimeout,
},
@@ -1598,33 +1598,37 @@ func TestIncubateConfigWitnessTypeSelection(t *testing.T) {
opt(&cfg)
}
- isFinalTaproot := cfg.chanType.UnwrapOr(0).IsTaprootFinal()
+ isFinal := cfg.chanType.UnwrapOr(
+ 0,
+ ).IsTaprootFinal()
- // Verify incoming HTLC witness type selection.
- isTaproot := txscript.IsPayToTaproot(tc.pkScript)
+ // Verify incoming HTLC witness type.
+ isTaproot := txscript.IsPayToTaproot(
+ tc.pkScript,
+ )
- var incomingWit input.StandardWitnessType
+ var inWit input.StandardWitnessType
switch {
- case isFinalTaproot:
- incomingWit = input.TaprootHtlcAcceptedSuccessSecondLevelFinal //nolint:ll
+ case isFinal:
+ inWit = input.TaprootHtlcAcceptedSuccessSecondLevelFinal //nolint:ll
case isTaproot:
- incomingWit = input.TaprootHtlcAcceptedSuccessSecondLevel //nolint:ll
+ inWit = input.TaprootHtlcAcceptedSuccessSecondLevel //nolint:ll
default:
- incomingWit = input.HtlcAcceptedSuccessSecondLevel
+ inWit = input.HtlcAcceptedSuccessSecondLevel //nolint:ll
}
- require.Equal(t, tc.expectedIncoming, incomingWit)
+ require.Equal(t, tc.expectedIncoming, inWit)
- // Verify outgoing remote HTLC witness type selection.
- var outgoingWit input.StandardWitnessType
+ // Verify outgoing remote HTLC witness type.
+ var outWit input.StandardWitnessType
switch {
- case isFinalTaproot:
- outgoingWit = input.TaprootHtlcOfferedRemoteTimeoutFinal //nolint:ll
+ case isFinal:
+ outWit = input.TaprootHtlcOfferedRemoteTimeoutFinal //nolint:ll
case isTaproot:
- outgoingWit = input.TaprootHtlcOfferedRemoteTimeout
+ outWit = input.TaprootHtlcOfferedRemoteTimeout //nolint:ll
default:
- outgoingWit = input.HtlcOfferedRemoteTimeout
+ outWit = input.HtlcOfferedRemoteTimeout
}
- require.Equal(t, tc.expectedOutgoing, outgoingWit)
+ require.Equal(t, tc.expectedOutgoing, outWit)
})
}
}
diff --git a/input/size_test.go b/input/size_test.go
index b089a83..88a66c7 100644
--- a/input/size_test.go
+++ b/input/size_test.go
@@ -1421,10 +1421,12 @@ var witnessSizeTests = []witnessSizeTest{
KeyDesc: keychain.KeyDescriptor{
PubKey: testKey.PubKey(),
},
- WitnessScript: commitScriptTree.SettleLeaf.Script,
- HashType: txscript.SigHashAll,
- InputIndex: 0,
- SignMethod: input.TaprootScriptSpendSignMethod,
+ WitnessScript: commitScriptTree.
+ SettleLeaf.Script,
+ HashType: txscript.SigHashAll,
+ InputIndex: 0,
+ SignMethod: input.
+ TaprootScriptSpendSignMethod,
}
witness, err := input.TaprootCommitSpendSuccess(
@@ -1444,8 +1446,9 @@ var witnessSizeTests = []witnessSizeTest{
require.NoError(t, err)
signer := &dummySigner{}
- commitScriptTree, err := input.NewRemoteCommitScriptTree(
- testKey.PubKey(), input.NoneTapLeaf(),
+ cst, err := input.NewRemoteCommitScriptTree(
+ testKey.PubKey(),
+ input.NoneTapLeaf(),
input.WithProdScripts(),
)
require.NoError(t, err)
@@ -1454,15 +1457,113 @@ var witnessSizeTests = []witnessSizeTest{
KeyDesc: keychain.KeyDescriptor{
PubKey: testKey.PubKey(),
},
- WitnessScript: commitScriptTree.SettleLeaf.Script,
+ WitnessScript: cst.SettleLeaf.Script,
HashType: txscript.SigHashAll,
InputIndex: 0,
- SignMethod: input.TaprootScriptSpendSignMethod,
+ SignMethod: input.
+ TaprootScriptSpendSignMethod,
}
witness, err := input.TaprootCommitRemoteSpend(
signer, signDesc, testTx,
- commitScriptTree.TapscriptTree,
+ cst.TapscriptTree,
+ )
+ require.NoError(t, err)
+
+ return witness
+ },
+ },
+ {
+ name: "taproot offered remote timeout final",
+ expSize: input.TaprootHtlcOfferedRemoteTimeoutWitnessSizeFinal,
+ genWitness: func(t *testing.T) wire.TxWitness {
+ senderKey, err := btcec.NewPrivateKey()
+ require.NoError(t, err)
+
+ receiverKey, err := btcec.NewPrivateKey()
+ require.NoError(t, err)
+
+ revokeKey, err := btcec.NewPrivateKey()
+ require.NoError(t, err)
+
+ var payHash [32]byte
+
+ signer := &dummySigner{}
+
+ htlcScriptTree, err := input.ReceiverHTLCScriptTaproot(
+ testCLTVExpiry, senderKey.PubKey(),
+ receiverKey.PubKey(), revokeKey.PubKey(),
+ payHash[:], lntypes.Remote,
+ input.NoneTapLeaf(),
+ input.WithProdScripts(),
+ )
+ require.NoError(t, err)
+
+ timeoutLeaf := htlcScriptTree.TimeoutTapLeaf
+
+ signDesc := &input.SignDescriptor{
+ KeyDesc: keychain.KeyDescriptor{
+ PubKey: senderKey.PubKey(),
+ },
+ WitnessScript: timeoutLeaf.Script,
+ HashType: txscript.SigHashAll,
+ InputIndex: 0,
+ SignMethod: input.
+ TaprootScriptSpendSignMethod,
+ }
+
+ witness, err := input.ReceiverHTLCScriptTaprootTimeout(
+ signer, signDesc, testTx, testCLTVExpiry,
+ revokeKey.PubKey(),
+ htlcScriptTree.TapscriptTree,
+ )
+ require.NoError(t, err)
+
+ return witness
+ },
+ },
+ {
+ name: "taproot accepted remote success final",
+ expSize: input.TaprootHtlcAcceptedRemoteSuccessWitnessSizeFinal,
+ genWitness: func(t *testing.T) wire.TxWitness {
+ senderKey, err := btcec.NewPrivateKey()
+ require.NoError(t, err)
+
+ receiverKey, err := btcec.NewPrivateKey()
+ require.NoError(t, err)
+
+ revokeKey, err := btcec.NewPrivateKey()
+ require.NoError(t, err)
+
+ var payHash [32]byte
+
+ signer := &dummySigner{}
+
+ htlcScriptTree, err := input.SenderHTLCScriptTaproot(
+ senderKey.PubKey(), receiverKey.PubKey(),
+ revokeKey.PubKey(), payHash[:],
+ lntypes.Remote, input.NoneTapLeaf(),
+ input.WithProdScripts(),
+ )
+ require.NoError(t, err)
+
+ successLeaf := htlcScriptTree.SuccessTapLeaf
+ scriptTree := htlcScriptTree.TapscriptTree
+
+ signDesc := &input.SignDescriptor{
+ KeyDesc: keychain.KeyDescriptor{
+ PubKey: receiverKey.PubKey(),
+ },
+ WitnessScript: successLeaf.Script,
+ HashType: txscript.SigHashAll,
+ InputIndex: 0,
+ SignMethod: input.
+ TaprootScriptSpendSignMethod,
+ }
+
+ witness, err := input.SenderHTLCScriptTaprootRedeem(
+ signer, signDesc, testTx, testPreimage,
+ revokeKey.PubKey(), scriptTree,
)
require.NoError(t, err)
diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go
index 7afe2af..ab96d33 100644
--- a/lnwallet/channel_test.go
+++ b/lnwallet/channel_test.go
@@ -3587,51 +3587,48 @@ func testChanSyncOweCommitment(t *testing.T,
}
// TestChanSyncTaprootLocalNonces tests the nonce synchronization behavior for
-// taproot channels. The nonce field populated depends on the channel type:
-// - Staging taproot (SimpleTaprootFeatureBit): only LocalNonce is populated.
-// - Final taproot (TaprootFinalBit): only LocalNonces is populated.
+// taproot channels. The nonce field populated is auto-detected from the
+// channel type:
+// - Staging taproot: only LocalNonce is populated (legacy format).
+// - Final taproot: only LocalNonces map is populated (map format).
func TestChanSyncTaprootLocalNonces(t *testing.T) {
t.Parallel()
- chanType := channeldb.SimpleTaprootFeatureBit
- aliceChannel, bobChannel, err := CreateTestChannels(t, chanType)
- require.NoError(t, err)
+ // Staging taproot channels use the legacy single nonce field.
+ t.Run(
+ "staging channel populates LocalNonce",
+ func(t *testing.T) {
+ chanType := channeldb.SimpleTaprootFeatureBit
+ aliceChannel, bobChannel, err := CreateTestChannels(
+ t, chanType,
+ )
+ require.NoError(t, err)
- // Also create a pair of final taproot channels. Final taproot channels
- // populate the map-based LocalNonces field instead of the legacy
- // LocalNonce field.
- finalChanType := channeldb.SimpleTaprootFeatureBit |
- channeldb.TaprootFinalBit
- aliceFinalChan, bobFinalChan, err := CreateTestChannels(
- t, finalChanType,
- )
- require.NoError(t, err)
+ assertNoChanSyncNeeded(t, aliceChannel, bobChannel)
- fundingTxid := aliceChannel.channelState.FundingOutpoint.Hash
- finalFundingTxid := aliceFinalChan.channelState.FundingOutpoint.Hash
+ aliceChanSyncMsg, err :=
+ aliceChannel.channelState.ChanSyncMsg()
+ require.NoError(t, err)
+ bobChanSyncMsg, err :=
+ bobChannel.channelState.ChanSyncMsg()
+ require.NoError(t, err)
- t.Run("staging taproot only populates LocalNonce", func(t *testing.T) {
- assertNoChanSyncNeeded(t, aliceChannel, bobChannel)
+ // Only LocalNonce should be populated.
+ require.True(t, aliceChanSyncMsg.LocalNonce.IsSome())
+ require.True(t, aliceChanSyncMsg.LocalNonces.IsNone())
+ require.True(t, bobChanSyncMsg.LocalNonce.IsSome())
+ require.True(t, bobChanSyncMsg.LocalNonces.IsNone())
+ },
+ )
- // Staging taproot channels populate only the legacy
- // LocalNonce field.
- aliceChanSyncMsg, err := aliceChannel.channelState.ChanSyncMsg()
- require.NoError(t, err)
- bobChanSyncMsg, err := bobChannel.channelState.ChanSyncMsg()
+ // Final taproot channels use the map-based nonce field.
+ t.Run("final channel populates LocalNonces", func(t *testing.T) {
+ chanType := channeldb.SimpleTaprootFeatureBit |
+ channeldb.TaprootFinalBit
+ aliceChannel, _, err := CreateTestChannels(t, chanType)
require.NoError(t, err)
- // Only LocalNonce should be populated.
- require.True(t, aliceChanSyncMsg.LocalNonce.IsSome())
- require.True(t, aliceChanSyncMsg.LocalNonces.IsNone())
- require.True(t, bobChanSyncMsg.LocalNonce.IsSome())
- require.True(t, bobChanSyncMsg.LocalNonces.IsNone())
- })
-
- t.Run("final taproot only populates LocalNonces", func(t *testing.T) {
- // Final taproot channels populate only the map-based
- // LocalNonces field.
- aliceFinalState := aliceFinalChan.channelState
- aliceChanSyncMsg, err := aliceFinalState.ChanSyncMsg()
+ aliceChanSyncMsg, err := aliceChannel.channelState.ChanSyncMsg()
require.NoError(t, err)
// Only LocalNonces should be populated.
@@ -3642,25 +3639,31 @@ func TestChanSyncTaprootLocalNonces(t *testing.T) {
require.Len(t, noncesData.NoncesMap, 1)
})
- t.Run("sync with only LocalNonces field", func(t *testing.T) {
- // Final taproot channels send messages with only the
- // LocalNonces field populated. Verify that the receiving side
- // can process such a message.
- aliceFinalState := aliceFinalChan.channelState
- aliceChanSyncMsg, err := aliceFinalState.ChanSyncMsg()
+ t.Run("sync with final channel LocalNonces", func(t *testing.T) {
+ chanType := channeldb.SimpleTaprootFeatureBit |
+ channeldb.TaprootFinalBit
+ aliceChannel, bobChannel, err := CreateTestChannels(
+ t, chanType,
+ )
+ require.NoError(t, err)
+
+ fundingTxid := aliceChannel.channelState.FundingOutpoint.Hash
+
+ // Both channels are final, so both use map nonces.
+ aliceChanSyncMsg, err := aliceChannel.channelState.ChanSyncMsg()
require.NoError(t, err)
- bobChanSyncMsg, err := bobFinalChan.channelState.ChanSyncMsg()
+ bobChanSyncMsg, err := bobChannel.channelState.ChanSyncMsg()
require.NoError(t, err)
- bobFinalChan.pendingVerificationNonce = &musig2.Nonces{
+ bobChannel.pendingVerificationNonce = &musig2.Nonces{
PubNonce: extractCommitmentNonce(
- t, bobChanSyncMsg, finalFundingTxid,
+ t, bobChanSyncMsg, fundingTxid,
),
}
- // Bob should be able to process Alice's message which has
- // only the LocalNonces field populated.
- bobMsgsToSend, _, _, err := bobFinalChan.ProcessChanSyncMsg(
+ // Bob should be able to process Alice's message with only
+ // LocalNonces.
+ bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(
ctxb, aliceChanSyncMsg,
)
require.NoError(t, err)
@@ -3668,22 +3671,28 @@ func TestChanSyncTaprootLocalNonces(t *testing.T) {
})
t.Run("sync with only legacy LocalNonce field", func(t *testing.T) {
- aliceChanSyncMsg, err := aliceChannel.channelState.ChanSyncMsg()
+ chanType := channeldb.SimpleTaprootFeatureBit
+ aliceChan, bobChan, err := CreateTestChannels(t, chanType)
require.NoError(t, err)
- bobChanSyncMsg, err := bobChannel.channelState.ChanSyncMsg()
+
+ fundTxid := aliceChan.channelState.FundingOutpoint.Hash
+
+ aliceChanSyncMsg, err := aliceChan.channelState.ChanSyncMsg()
+ require.NoError(t, err)
+ bobChanSyncMsg, err := bobChan.channelState.ChanSyncMsg()
require.NoError(t, err)
// Simulate an older peer that only sends LocalNonce.
aliceModifiedMsg := *aliceChanSyncMsg
aliceModifiedMsg.LocalNonces = lnwire.OptLocalNonces{}
- bobChannel.pendingVerificationNonce = &musig2.Nonces{
+ bobChan.pendingVerificationNonce = &musig2.Nonces{
PubNonce: extractCommitmentNonce(
- t, bobChanSyncMsg, fundingTxid,
+ t, bobChanSyncMsg, fundTxid,
),
}
- bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(
+ bobMsgsToSend, _, _, err := bobChan.ProcessChanSyncMsg(
ctxb, &aliceModifiedMsg,
)
require.NoError(t, err)
@@ -3691,15 +3700,21 @@ func TestChanSyncTaprootLocalNonces(t *testing.T) {
})
t.Run("error when LocalNonces missing txid", func(t *testing.T) {
- aliceChanSyncMsg, err := aliceChannel.channelState.ChanSyncMsg()
+ chanType := channeldb.SimpleTaprootFeatureBit
+ aliceChan, bobChan, err := CreateTestChannels(t, chanType)
require.NoError(t, err)
- bobChanSyncMsg, err := bobChannel.channelState.ChanSyncMsg()
+
+ fundTxid := aliceChan.channelState.FundingOutpoint.Hash
+
+ aliceChanSyncMsg, err := aliceChan.channelState.ChanSyncMsg()
+ require.NoError(t, err)
+ bobChanSyncMsg, err := bobChan.channelState.ChanSyncMsg()
require.NoError(t, err)
// Use a wrong txid in the LocalNonces map.
wrongTxid := chainhash.Hash{0xff, 0xff}
nonce := extractCommitmentNonce(
- t, aliceChanSyncMsg, fundingTxid,
+ t, aliceChanSyncMsg, fundTxid,
)
aliceModifiedMsg := *aliceChanSyncMsg
noncesMap := map[chainhash.Hash]lnwire.Musig2Nonce{
@@ -3709,13 +3724,13 @@ func TestChanSyncTaprootLocalNonces(t *testing.T) {
lnwire.LocalNoncesData{NoncesMap: noncesMap},
)
- bobChannel.pendingVerificationNonce = &musig2.Nonces{
+ bobChan.pendingVerificationNonce = &musig2.Nonces{
PubNonce: extractCommitmentNonce(
- t, bobChanSyncMsg, fundingTxid,
+ t, bobChanSyncMsg, fundTxid,
),
}
- _, _, _, err = bobChannel.ProcessChanSyncMsg(
+ _, _, _, err = bobChan.ProcessChanSyncMsg(
ctxb, &aliceModifiedMsg,
)
require.Error(t, err)
@@ -3726,14 +3741,22 @@ func TestChanSyncTaprootLocalNonces(t *testing.T) {
})
t.Run("error when both fields missing", func(t *testing.T) {
- aliceChanSyncMsg, err := aliceChannel.channelState.ChanSyncMsg()
+ chanType := channeldb.SimpleTaprootFeatureBit
+ aliceChan, _, err := CreateTestChannels(t, chanType)
+ require.NoError(t, err)
+
+ aliceChanSyncMsg, err := aliceChan.channelState.ChanSyncMsg()
require.NoError(t, err)
aliceEmptyMsg := *aliceChanSyncMsg
aliceEmptyMsg.LocalNonce = lnwire.OptMusig2NonceTLV{}
aliceEmptyMsg.LocalNonces = lnwire.OptLocalNonces{}
- _, _, _, err = bobChannel.ProcessChanSyncMsg(
+ // Create a bob to process against.
+ _, bobChan, err := CreateTestChannels(t, chanType)
+ require.NoError(t, err)
+
+ _, _, _, err = bobChan.ProcessChanSyncMsg(
ctxb, &aliceEmptyMsg,
)
require.Error(t, err)
diff --git a/watchtower/blob/type.go b/watchtower/blob/type.go
index 9c0fbb1..00415af 100644
--- a/watchtower/blob/type.go
+++ b/watchtower/blob/type.go
@@ -90,7 +90,8 @@ const (
// production taproot channel using final scripts with
// OP_CHECKSIGVERIFY optimizations.
TypeAltruistTaprootFinalCommit = Type(
- FlagCommitOutputs | FlagTaprootChannel | FlagTaprootFinalChannel,
+ FlagCommitOutputs | FlagTaprootChannel |
+ FlagTaprootFinalChannel,
)
)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.