multi: fix linter warnings

This commit is contained in:
Olaoluwa Osuntokun committed 2023-08-22 16:32:00 -07:00
1 parent da1282c17e
commit aaba144804
11 files changed
+111 -95

No files matched your search

+1 -1
View File
@@ -706,7 +706,7 @@ func (l *channelLink) syncChanStates() error {
// very same nonce that we sent above, as they should // very same nonce that we sent above, as they should
// take the latest verification nonce we send. // take the latest verification nonce we send.
if chanState.ChanType.IsTaproot() { if chanState.ChanType.IsTaproot() {
fundingLockedMsg.NextLocalNonce = localChanSyncMsg.LocalNonce fundingLockedMsg.NextLocalNonce = localChanSyncMsg.LocalNonce //nolint:lll
} }
// For channels that negotiated the option-scid-alias // For channels that negotiated the option-scid-alias
+1 -3
View File
@@ -688,8 +688,6 @@ func (c *ChanCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message,
"new co op close offer: %w", err) "new co op close offer: %w", err)
} }
break
// Otherwise, if we are the initiator, and we just sent a // Otherwise, if we are the initiator, and we just sent a
// signature for a taproot channel, then we'll ensure that the // signature for a taproot channel, then we'll ensure that the
// fee rate matches up exactly. // fee rate matches up exactly.
@@ -755,7 +753,7 @@ func (c *ChanCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message,
matchingSig := c.priorFeeOffers[remoteProposedFee] matchingSig := c.priorFeeOffers[remoteProposedFee]
if c.cfg.Channel.ChanType().IsTaproot() { if c.cfg.Channel.ChanType().IsTaproot() {
muSession := c.cfg.MusigSession muSession := c.cfg.MusigSession
localSig, remoteSig, closeOpts, err = muSession.CombineClosingOpts( //nolint:ll localSig, remoteSig, closeOpts, err = muSession.CombineClosingOpts( //nolint:lll
*matchingSig.PartialSig, *matchingSig.PartialSig,
*closeSignedMsg.PartialSig, *closeSignedMsg.PartialSig,
) )
+7 -4
View File
@@ -211,7 +211,9 @@ func (m *mockChannel) FundingTxOut() *wire.TxOut {
return nil return nil
} }
func (m *mockChannel) MultiSigKeys() (keychain.KeyDescriptor, keychain.KeyDescriptor) { func (m *mockChannel) MultiSigKeys() (
keychain.KeyDescriptor, keychain.KeyDescriptor) {
return m.localKey, m.remoteKey return m.localKey, m.remoteKey
} }
@@ -250,7 +252,9 @@ func newMockMusigSession() *mockMusigSession {
return &mockMusigSession{} return &mockMusigSession{}
} }
func (m *mockMusigSession) ProposalClosingOpts() ([]lnwallet.ChanCloseOpt, error) { func (m *mockMusigSession) ProposalClosingOpts() ([]lnwallet.ChanCloseOpt,
error) {
return nil, nil return nil, nil
} }
@@ -267,7 +271,6 @@ func (m *mockMusigSession) ClosingNonce() (*musig2.Nonces, error) {
} }
func (m *mockMusigSession) InitRemoteNonce(nonce *musig2.Nonces) { func (m *mockMusigSession) InitRemoteNonce(nonce *musig2.Nonces) {
return
} }
type mockCoopFeeEstimator struct { type mockCoopFeeEstimator struct {
@@ -565,7 +568,7 @@ func TestTaprootFastClose(t *testing.T) {
ogOffer := bobOffer.FeeSatoshis ogOffer := bobOffer.FeeSatoshis
bobOffer.FeeSatoshis /= 2 bobOffer.FeeSatoshis /= 2
aliceMsgs, _, err = aliceCloser.ProcessCloseMsg(bobOffer) _, _, err = aliceCloser.ProcessCloseMsg(bobOffer)
require.Error(t, err) require.Error(t, err)
require.Contains(t, err.Error(), "was not accepted") require.Contains(t, err.Error(), "was not accepted")
+6 -5
View File
@@ -27,7 +27,7 @@ type CoopFeeEstimator interface {
// Channel abstracts away from the core channel state machine by exposing an // Channel abstracts away from the core channel state machine by exposing an
// interface that requires only the methods we need to carry out the channel // interface that requires only the methods we need to carry out the channel
// closing process. // closing process.
type Channel interface { type Channel interface { //nolint:interfacebloat
// ChannelPoint returns the channel point of the target channel. // ChannelPoint returns the channel point of the target channel.
ChannelPoint() *wire.OutPoint ChannelPoint() *wire.OutPoint
@@ -70,10 +70,11 @@ type Channel interface {
// CreateCloseProposal creates a new co-op close proposal in the form // CreateCloseProposal creates a new co-op close proposal in the form
// of a valid signature, the chainhash of the final txid, and our final // of a valid signature, the chainhash of the final txid, and our final
// balance in the created state. // balance in the created state.
CreateCloseProposal(proposedFee btcutil.Amount, localDeliveryScript []byte, CreateCloseProposal(proposedFee btcutil.Amount,
remoteDeliveryScript []byte, localDeliveryScript []byte, remoteDeliveryScript []byte,
closeOpt ...lnwallet.ChanCloseOpt) (input.Signature, *chainhash.Hash, closeOpt ...lnwallet.ChanCloseOpt,
btcutil.Amount, error) ) (
input.Signature, *chainhash.Hash, btcutil.Amount, error)
// CompleteCooperativeClose persistently "completes" the cooperative // CompleteCooperativeClose persistently "completes" the cooperative
// close by producing a fully signed co-op close transaction. // close by producing a fully signed co-op close transaction.
+39 -29
View File
@@ -1400,7 +1400,7 @@ func NewLightningChannel(signer input.Signer,
state.RevocationProducer, state.RevocationProducer,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to derive shachain: %v", err) return nil, fmt.Errorf("unable to derive shachain: %w", err)
} }
lc := &LightningChannel{ lc := &LightningChannel{
@@ -1472,7 +1472,8 @@ func (lc *LightningChannel) createSignDesc() error {
} }
} else { } else {
multiSigScript, err = input.GenMultiSigScript( multiSigScript, err = input.GenMultiSigScript(
localKey.SerializeCompressed(), remoteKey.SerializeCompressed(), localKey.SerializeCompressed(),
remoteKey.SerializeCompressed(),
) )
if err != nil { if err != nil {
return err return err
@@ -3363,7 +3364,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
// If this is a taproot channel, then we'll need to set the // If this is a taproot channel, then we'll need to set the
// method type to ensure we generate a valid signature. // method type to ensure we generate a valid signature.
if chanType.IsTaproot() { if chanType.IsTaproot() {
sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod //nolint:lll
} }
sigBatch = append(sigBatch, sigJob) sigBatch = append(sigBatch, sigJob)
@@ -3431,7 +3432,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
// If this is a taproot channel, then we'll need to set the // If this is a taproot channel, then we'll need to set the
// method type to ensure we generate a valid signature. // method type to ensure we generate a valid signature.
if chanType.IsTaproot() { if chanType.IsTaproot() {
sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod //nolint:lll
} }
sigBatch = append(sigBatch, sigJob) sigBatch = append(sigBatch, sigJob)
@@ -3877,7 +3878,6 @@ type NewCommitState struct {
// HTLC's on the commitment transaction. Finally, the new set of pending HTLCs // HTLC's on the commitment transaction. Finally, the new set of pending HTLCs
// for the remote party's commitment are also returned. // for the remote party's commitment are also returned.
func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) { func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
lc.Lock() lc.Lock()
defer lc.Unlock() defer lc.Unlock()
@@ -4570,8 +4570,9 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
htlcAmt := int64(htlc.Amount.ToSatoshis()) htlcAmt := int64(htlc.Amount.ToSatoshis())
if chanType.IsTaproot() { if chanType.IsTaproot() {
// TODO(roasbeef): add abstraction in front // TODO(roasbeef): add abstraction in
prevFetcher := txscript.NewCannedPrevOutputFetcher( // front
prevFetcher := txscript.NewCannedPrevOutputFetcher( //nolint:lll
htlc.ourPkScript, htlcAmt, htlc.ourPkScript, htlcAmt,
) )
hashCache := txscript.NewTxSigHashes( hashCache := txscript.NewTxSigHashes(
@@ -4580,9 +4581,11 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
tapLeaf := txscript.NewBaseTapLeaf( tapLeaf := txscript.NewBaseTapLeaf(
htlc.ourWitnessScript, htlc.ourWitnessScript,
) )
return txscript.CalcTapscriptSignaturehash(
hashCache, sigHashType, successTx, 0, return txscript.CalcTapscriptSignaturehash( //nolint:lll
prevFetcher, tapLeaf, hashCache, sigHashType,
successTx, 0, prevFetcher,
tapLeaf,
) )
} }
@@ -4641,8 +4644,9 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
timeoutTx, err := CreateHtlcTimeoutTx( timeoutTx, err := CreateHtlcTimeoutTx(
chanType, isLocalInitiator, op, chanType, isLocalInitiator, op,
outputAmt, htlc.Timeout, outputAmt, htlc.Timeout,
uint32(localChanCfg.CsvDelay), leaseExpiry, uint32(localChanCfg.CsvDelay),
keyRing.RevocationKey, keyRing.ToLocalKey, leaseExpiry, keyRing.RevocationKey,
keyRing.ToLocalKey,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@@ -4651,8 +4655,9 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
htlcAmt := int64(htlc.Amount.ToSatoshis()) htlcAmt := int64(htlc.Amount.ToSatoshis())
if chanType.IsTaproot() { if chanType.IsTaproot() {
// TODO(roasbeef): add abstraction in front // TODO(roasbeef): add abstraction in
prevFetcher := txscript.NewCannedPrevOutputFetcher( // front
prevFetcher := txscript.NewCannedPrevOutputFetcher( //nolint:lll
htlc.ourPkScript, htlcAmt, htlc.ourPkScript, htlcAmt,
) )
hashCache := txscript.NewTxSigHashes( hashCache := txscript.NewTxSigHashes(
@@ -4661,13 +4666,17 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
tapLeaf := txscript.NewBaseTapLeaf( tapLeaf := txscript.NewBaseTapLeaf(
htlc.ourWitnessScript, htlc.ourWitnessScript,
) )
return txscript.CalcTapscriptSignaturehash(
hashCache, sigHashType, timeoutTx, 0, return txscript.CalcTapscriptSignaturehash( //nolint:lll
prevFetcher, tapLeaf, hashCache, sigHashType,
timeoutTx, 0, prevFetcher,
tapLeaf,
) )
} }
hashCache := input.NewTxSigHashesV0Only(timeoutTx) hashCache := input.NewTxSigHashesV0Only(
timeoutTx,
)
sigHash, err := txscript.CalcWitnessSigHash( sigHash, err := txscript.CalcWitnessSigHash(
htlc.ourWitnessScript, hashCache, htlc.ourWitnessScript, hashCache,
sigHashType, timeoutTx, 0, sigHashType, timeoutTx, 0,
@@ -4807,8 +4816,9 @@ var _ error = (*InvalidCommitSigError)(nil)
// to our local commitment chain. Once we send a revocation for our prior // to our local commitment chain. Once we send a revocation for our prior
// state, then this newly added commitment becomes our current accepted channel // state, then this newly added commitment becomes our current accepted channel
// state. // state.
//
//nolint:funlen
func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error { func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
lc.Lock() lc.Lock()
defer lc.Unlock() defer lc.Unlock()
@@ -4934,7 +4944,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
// exact signature and commitment we failed to // exact signature and commitment we failed to
// verify against in order to aide debugging. // verify against in order to aide debugging.
var txBytes bytes.Buffer var txBytes bytes.Buffer
localCommitTx.Serialize(&txBytes) _ = localCommitTx.Serialize(&txBytes)
return &InvalidPartialCommitSigError{ return &InvalidPartialCommitSigError{
invalidPartialSigError: &sigErr, invalidPartialSigError: &sigErr,
InvalidCommitSigError: InvalidCommitSigError{ //nolint:lll InvalidCommitSigError: InvalidCommitSigError{ //nolint:lll
@@ -4957,7 +4967,6 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
return err return err
} }
lc.musigSessions.LocalSession = newLocalSession lc.musigSessions.LocalSession = newLocalSession
} else { } else {
multiSigScript := lc.signDesc.WitnessScript multiSigScript := lc.signDesc.WitnessScript
prevFetcher := txscript.NewCannedPrevOutputFetcher( prevFetcher := txscript.NewCannedPrevOutputFetcher(
@@ -4970,8 +4979,8 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
localCommitTx, 0, int64(lc.channelState.Capacity), localCommitTx, 0, int64(lc.channelState.Capacity),
) )
if err != nil { if err != nil {
// TODO(roasbeef): fetchview has already mutated the HTLCs... // TODO(roasbeef): fetchview has already mutated the
// * need to either roll-back, or make pure // HTLCs... * need to either roll-back, or make pure
return err return err
} }
@@ -4990,10 +4999,11 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
// commitment we failed to verify against in order to // commitment we failed to verify against in order to
// aide debugging. // aide debugging.
var txBytes bytes.Buffer var txBytes bytes.Buffer
localCommitTx.Serialize(&txBytes) _ = localCommitTx.Serialize(&txBytes)
return &InvalidCommitSigError{ return &InvalidCommitSigError{
commitHeight: nextHeight, commitHeight: nextHeight,
commitSig: commitSigs.CommitSig.ToSignatureBytes(), commitSig: commitSigs.CommitSig.ToSignatureBytes(), //nolint:lll
sigHash: sigHash, sigHash: sigHash,
commitTx: txBytes.Bytes(), commitTx: txBytes.Bytes(),
} }
@@ -5045,7 +5055,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
localCommitmentView.sig = sigBytes[:] localCommitmentView.sig = sigBytes[:]
} else { } else {
localCommitmentView.sig = commitSigs.CommitSig.ToSignatureBytes() localCommitmentView.sig = commitSigs.CommitSig.ToSignatureBytes() //nolint:lll
} }
lc.localCommitChain.addCommitment(localCommitmentView) lc.localCommitChain.addCommitment(localCommitmentView)
@@ -7282,7 +7292,6 @@ func (lc *LightningChannel) CompleteCooperativeClose(
finalSchnorrSig.Serialize(), finalSchnorrSig.Serialize(),
} }
} else { } else {
// For regular channels, we'll need to , construct the witness // For regular channels, we'll need to , construct the witness
// stack minding the order of the pubkeys+sigs on the stack. // stack minding the order of the pubkeys+sigs on the stack.
ourKey := lc.channelState.LocalChanCfg.MultiSigKey.PubKey. ourKey := lc.channelState.LocalChanCfg.MultiSigKey.PubKey.
@@ -7294,7 +7303,6 @@ func (lc *LightningChannel) CompleteCooperativeClose(
remoteSig, remoteSig,
) )
closeTx.TxIn[0].Witness = witness closeTx.TxIn[0].Witness = witness
} }
// Validate the finalized transaction to ensure the output script is // Validate the finalized transaction to ensure the output script is
@@ -8259,7 +8267,9 @@ func (lc *LightningChannel) FundingTxOut() *wire.TxOut {
} }
// MultiSigKeys returns the set of multi-sig keys for an channel. // MultiSigKeys returns the set of multi-sig keys for an channel.
func (lc *LightningChannel) MultiSigKeys() (keychain.KeyDescriptor, keychain.KeyDescriptor) { func (lc *LightningChannel) MultiSigKeys() (keychain.KeyDescriptor,
keychain.KeyDescriptor) {
lc.RLock() lc.RLock()
defer lc.RUnlock() defer lc.RUnlock()
+40 -26
View File
@@ -61,7 +61,8 @@ func assertOutputExistsByValue(t *testing.T, commitTx *wire.MsgTx,
// testAddSettleWorkflow tests a simple channel scenario where Alice and Bob // testAddSettleWorkflow tests a simple channel scenario where Alice and Bob
// add, the settle an HTLC between themselves. // add, the settle an HTLC between themselves.
func testAddSettleWorkflow(t *testing.T, tweakless bool, func testAddSettleWorkflow(t *testing.T, tweakless bool,
chanTypeModifier channeldb.ChannelType, storeFinalHtlcResolutions bool) { chanTypeModifier channeldb.ChannelType,
storeFinalHtlcResolutions bool) {
// Create a test channel which will be used for the duration of this // Create a test channel which will be used for the duration of this
// unittest. The channel will be funded evenly with Alice having 5 BTC, // unittest. The channel will be funded evenly with Alice having 5 BTC,
@@ -196,23 +197,26 @@ func testAddSettleWorkflow(t *testing.T, tweakless bool,
aliceChannel.currentHeight, 1) aliceChannel.currentHeight, 1)
} }
aliceChanState := aliceChannel.channelState
bobChanState := bobChannel.channelState
// Both commitment transactions should have three outputs, and one of // Both commitment transactions should have three outputs, and one of
// them should be exactly the amount of the HTLC. // them should be exactly the amount of the HTLC.
numOutputs := 3 numOutputs := 3
if chanTypeModifier.HasAnchors() { if chanTypeModifier.HasAnchors() {
// In this case we expect two extra outputs as both sides need an // In this case we expect two extra outputs as both sides need
// anchor output. // an anchor output.
numOutputs = 5 numOutputs = 5
} }
if len(aliceChannel.channelState.LocalCommitment.CommitTx.TxOut) != numOutputs { if len(aliceChanState.LocalCommitment.CommitTx.TxOut) != numOutputs {
t.Fatalf("alice should have three commitment outputs, instead "+ t.Fatalf("alice should have three commitment outputs, instead "+
"have %v", "have %v",
len(aliceChannel.channelState.LocalCommitment.CommitTx.TxOut)) len(aliceChanState.LocalCommitment.CommitTx.TxOut))
} }
if len(bobChannel.channelState.LocalCommitment.CommitTx.TxOut) != numOutputs { if len(bobChanState.LocalCommitment.CommitTx.TxOut) != numOutputs {
t.Fatalf("bob should have three commitment outputs, instead "+ t.Fatalf("bob should have three commitment outputs, instead "+
"have %v", "have %v",
len(bobChannel.channelState.LocalCommitment.CommitTx.TxOut)) len(bobChanState.LocalCommitment.CommitTx.TxOut))
} }
assertOutputExistsByValue(t, assertOutputExistsByValue(t,
aliceChannel.channelState.LocalCommitment.CommitTx, aliceChannel.channelState.LocalCommitment.CommitTx,
@@ -367,7 +371,7 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
}) })
} }
t.Run("anchors", func(t *testing.T) { t.Run("anchors", func(t *testing.T) { //nolint:paralleltest
testAddSettleWorkflow( testAddSettleWorkflow(
t, true, t, true,
channeldb.AnchorOutputsBit|channeldb.ZeroHtlcTxFeeBit, channeldb.AnchorOutputsBit|channeldb.ZeroHtlcTxFeeBit,
@@ -375,12 +379,13 @@ func TestSimpleAddSettleWorkflow(t *testing.T) {
) )
}) })
t.Run("taproot", func(t *testing.T) { t.Run("taproot", func(t *testing.T) { //nolint:paralleltest
testAddSettleWorkflow( testAddSettleWorkflow(
t, true, channeldb.SimpleTaprootFeatureBit, false, t, true, channeldb.SimpleTaprootFeatureBit, false,
) )
}) })
//nolint:paralleltest
t.Run("storeFinalHtlcResolutions=true", func(t *testing.T) { t.Run("storeFinalHtlcResolutions=true", func(t *testing.T) {
testAddSettleWorkflow(t, false, 0, true) testAddSettleWorkflow(t, false, 0, true)
}) })
@@ -3105,8 +3110,10 @@ func TestChanSyncOweCommitment(t *testing.T) {
spew.Sdump(aliceMsgsToSend[4])) spew.Sdump(aliceMsgsToSend[4]))
} }
if commitSigMsg.CommitSig != aliceNewCommit.CommitSig { if commitSigMsg.CommitSig != aliceNewCommit.CommitSig {
t.Fatalf("commit sig msgs don't match: expected %x got %x", t.Fatalf("commit sig msgs don't match: expected "+
aliceNewCommit.CommitSig, commitSigMsg.CommitSig) "%x got %x",
aliceNewCommit.CommitSig,
commitSigMsg.CommitSig)
} }
if len(commitSigMsg.HtlcSigs) != len(aliceNewCommit.HtlcSigs) { if len(commitSigMsg.HtlcSigs) != len(aliceNewCommit.HtlcSigs) {
t.Fatalf("wrong number of htlc sigs: expected %v, got %v", t.Fatalf("wrong number of htlc sigs: expected %v, got %v",
@@ -3539,10 +3546,10 @@ func testChanSyncOweRevocation(t *testing.T, chanType channeldb.ChannelType) {
func TestChanSyncOweRevocation(t *testing.T) { func TestChanSyncOweRevocation(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("tweakless", func(t *testing.T) { t.Run("tweakless", func(t *testing.T) { //nolint:paralleltest
testChanSyncOweRevocation(t, channeldb.SingleFunderTweaklessBit) testChanSyncOweRevocation(t, channeldb.SingleFunderTweaklessBit)
}) })
t.Run("taproot", func(t *testing.T) { t.Run("taproot", func(t *testing.T) { //nolint:paralleltest
taprootBits := channeldb.SimpleTaprootFeatureBit | taprootBits := channeldb.SimpleTaprootFeatureBit |
channeldb.AnchorOutputsBit | channeldb.AnchorOutputsBit |
channeldb.ZeroHtlcTxFeeBit | channeldb.ZeroHtlcTxFeeBit |
@@ -3631,7 +3638,9 @@ func testChanSyncOweRevocationAndCommit(t *testing.T,
assertBobSendsRevokeAndCommit := func() { assertBobSendsRevokeAndCommit := func() {
t.Helper() t.Helper()
bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(aliceSyncMsg) bobMsgsToSend, _, _, err := bobChannel.ProcessChanSyncMsg(
aliceSyncMsg,
)
if err != nil { if err != nil {
t.Fatalf("unable to process chan sync msg: %v", err) t.Fatalf("unable to process chan sync msg: %v", err)
} }
@@ -3641,26 +3650,31 @@ func testChanSyncOweRevocationAndCommit(t *testing.T,
} }
bobReRevoke, ok := bobMsgsToSend[0].(*lnwire.RevokeAndAck) bobReRevoke, ok := bobMsgsToSend[0].(*lnwire.RevokeAndAck)
if !ok { if !ok {
t.Fatalf("expected bob to re-send revoke, instead sending: %v", t.Fatalf("expected bob to re-send revoke, instead "+
spew.Sdump(bobMsgsToSend[0])) "sending: %v", spew.Sdump(bobMsgsToSend[0]))
} }
if !reflect.DeepEqual(bobReRevoke, bobRevocation) { if !reflect.DeepEqual(bobReRevoke, bobRevocation) {
t.Fatalf("revocation msgs don't match: expected %v, got %v", t.Fatalf("revocation msgs don't match: expected %v, "+
bobRevocation, bobReRevoke) "got %v", bobRevocation, bobReRevoke)
} }
bobReCommitSigMsg, ok := bobMsgsToSend[1].(*lnwire.CommitSig) bobReCommitSigMsg, ok := bobMsgsToSend[1].(*lnwire.CommitSig)
if !ok { if !ok {
t.Fatalf("expected bob to re-send commit sig, instead sending: %v", t.Fatalf("expected bob to re-send commit sig, "+
"instead sending: %v",
spew.Sdump(bobMsgsToSend[1])) spew.Sdump(bobMsgsToSend[1]))
} }
if bobReCommitSigMsg.CommitSig != bobNewCommit.CommitSig { if bobReCommitSigMsg.CommitSig != bobNewCommit.CommitSig {
t.Fatalf("commit sig msgs don't match: expected %x got %x", t.Fatalf("commit sig msgs don't match: expected %x "+
"got %x",
bobNewCommit.CommitSigs.CommitSig, bobNewCommit.CommitSigs.CommitSig,
bobReCommitSigMsg.CommitSig) bobReCommitSigMsg.CommitSig)
} }
if len(bobReCommitSigMsg.HtlcSigs) != len(bobNewCommit.HtlcSigs) { if len(bobReCommitSigMsg.HtlcSigs) !=
t.Fatalf("wrong number of htlc sigs: expected %v, got %v", len(bobNewCommit.HtlcSigs) {
t.Fatalf("wrong number of htlc sigs: expected %v, "+
"got %v",
len(bobNewCommit.HtlcSigs), len(bobNewCommit.HtlcSigs),
len(bobReCommitSigMsg.HtlcSigs)) len(bobReCommitSigMsg.HtlcSigs))
} }
@@ -3715,12 +3729,12 @@ func testChanSyncOweRevocationAndCommit(t *testing.T,
func TestChanSyncOweRevocationAndCommit(t *testing.T) { func TestChanSyncOweRevocationAndCommit(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("tweakless", func(t *testing.T) { t.Run("tweakless", func(t *testing.T) { //nolint:paralleltest
testChanSyncOweRevocationAndCommit( testChanSyncOweRevocationAndCommit(
t, channeldb.SingleFunderTweaklessBit, t, channeldb.SingleFunderTweaklessBit,
) )
}) })
t.Run("taproot", func(t *testing.T) { t.Run("taproot", func(t *testing.T) { //nolint:paralleltest
taprootBits := channeldb.SimpleTaprootFeatureBit | taprootBits := channeldb.SimpleTaprootFeatureBit |
channeldb.AnchorOutputsBit | channeldb.AnchorOutputsBit |
channeldb.ZeroHtlcTxFeeBit | channeldb.ZeroHtlcTxFeeBit |
@@ -3944,12 +3958,12 @@ func testChanSyncOweRevocationAndCommitForceTransition(t *testing.T,
func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) { func TestChanSyncOweRevocationAndCommitForceTransition(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("tweakless", func(t *testing.T) { t.Run("tweakless", func(t *testing.T) { //nolint:paralleltest
testChanSyncOweRevocationAndCommitForceTransition( testChanSyncOweRevocationAndCommitForceTransition(
t, channeldb.SingleFunderTweaklessBit, t, channeldb.SingleFunderTweaklessBit,
) )
}) })
t.Run("taproot", func(t *testing.T) { t.Run("taproot", func(t *testing.T) { //nolint:paralleltest
taprootBits := channeldb.SimpleTaprootFeatureBit | taprootBits := channeldb.SimpleTaprootFeatureBit |
channeldb.AnchorOutputsBit | channeldb.AnchorOutputsBit |
channeldb.ZeroHtlcTxFeeBit | channeldb.ZeroHtlcTxFeeBit |
+6 -3
View File
@@ -534,10 +534,12 @@ func ForceStateTransition(chanA, chanB *LightningChannel) error {
return err return err
} }
if _, _, _, _, err := chanA.ReceiveRevocation(bobRevocation); err != nil { _, _, _, _, err = chanA.ReceiveRevocation(bobRevocation)
if err != nil {
return err return err
} }
if err := chanA.ReceiveNewCommitment(bobNewCommit.CommitSigs); err != nil { err = chanA.ReceiveNewCommitment(bobNewCommit.CommitSigs)
if err != nil {
return err return err
} }
@@ -545,7 +547,8 @@ func ForceStateTransition(chanA, chanB *LightningChannel) error {
if err != nil { if err != nil {
return err return err
} }
if _, _, _, _, err := chanB.ReceiveRevocation(aliceRevocation); err != nil { _, _, _, _, err = chanB.ReceiveRevocation(aliceRevocation)
if err != nil {
return err return err
} }
+1 -19
View File
@@ -8,7 +8,6 @@ import (
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input"
) )
const ( const (
@@ -48,7 +47,7 @@ var (
// //
// In order to spend the segwit v1 (taproot) HTLC output, the witness for the // In order to spend the segwit v1 (taproot) HTLC output, the witness for the
// passed transaction should be: // passed transaction should be:
// - <sender sig> <receiver sig> <preimage> <sucess_script> <control_block> // - <sender sig> <receiver sig> <preimage> <success_script> <control_block>
func CreateHtlcSuccessTx(chanType channeldb.ChannelType, initiator bool, func CreateHtlcSuccessTx(chanType channeldb.ChannelType, initiator bool,
htlcOutput wire.OutPoint, htlcAmt btcutil.Amount, csvDelay, htlcOutput wire.OutPoint, htlcAmt btcutil.Amount, csvDelay,
leaseExpiry uint32, revocationKey, delayKey *btcec.PublicKey) ( leaseExpiry uint32, revocationKey, delayKey *btcec.PublicKey) (
@@ -136,22 +135,6 @@ func CreateHtlcTimeoutTx(chanType channeldb.ChannelType, initiator bool,
var pkScript []byte var pkScript []byte
// Depending on if this is a taproot channel or not, we'll create a v0
// vs v1 segwit script.
if chanType.IsTaproot() {
taprootOutputKey, err := input.TaprootSecondLevelHtlcScript(
revocationKey, delayKey, csvDelay,
)
if err != nil {
return nil, err
}
pkScript, err = input.PayToTaprootScript(taprootOutputKey)
if err != nil {
return nil, err
}
} else {
// Next, we'll generate the script used as the output for all second // Next, we'll generate the script used as the output for all second
// level HTLC which forces a covenant w.r.t what can be done with all // level HTLC which forces a covenant w.r.t what can be done with all
// HTLC outputs. // HTLC outputs.
@@ -164,7 +147,6 @@ func CreateHtlcTimeoutTx(chanType channeldb.ChannelType, initiator bool,
} }
pkScript = scriptInfo.PkScript pkScript = scriptInfo.PkScript
}
// Finally, the output is simply the amount of the HTLC (minus the // Finally, the output is simply the amount of the HTLC (minus the
// required fees), paying to the regular second level HTLC script. // required fees), paying to the regular second level HTLC script.
+7 -3
View File
@@ -373,7 +373,9 @@ func testVectors(t *testing.T, chanType channeldb.ChannelType, test testCase) {
require.Equal( require.Equal(
t, test.RemoteSigHex, t, test.RemoteSigHex,
hex.EncodeToString(remoteNewCommit.CommitSig.ToSignatureBytes()), hex.EncodeToString(
remoteNewCommit.CommitSig.ToSignatureBytes(),
),
) )
for i, sig := range remoteNewCommit.HtlcSigs { for i, sig := range remoteNewCommit.HtlcSigs {
@@ -398,8 +400,10 @@ func testVectors(t *testing.T, chanType channeldb.ChannelType, test testCase) {
var txBytes bytes.Buffer var txBytes bytes.Buffer
require.NoError(t, forceCloseSum.CloseTx.Serialize(&txBytes)) require.NoError(t, forceCloseSum.CloseTx.Serialize(&txBytes))
require.Equal(t, test.ExpectedCommitmentTxHex, require.Equal(
hex.EncodeToString(txBytes.Bytes())) t, test.ExpectedCommitmentTxHex,
hex.EncodeToString(txBytes.Bytes()),
)
// Obtain the second level transactions that the local node's channel // Obtain the second level transactions that the local node's channel
// state machine has produced. Store them in a map indexed by commit tx // state machine has produced. Store them in a map indexed by commit tx
-1
View File
@@ -2448,7 +2448,6 @@ func (l *LightningWallet) ValidateChannel(channelState *channeldb.OpenChannel,
if err != nil { if err != nil {
return err return err
} }
} else { } else {
witnessScript, err := input.GenMultiSigScript( witnessScript, err := input.GenMultiSigScript(
localKey.SerializeCompressed(), localKey.SerializeCompressed(),
+3 -1
View File
@@ -31,7 +31,9 @@ func NewMusigChanCloser(channel *lnwallet.LightningChannel) *MusigChanCloser {
// ProposalClosingOpts returns the options that should be used when // ProposalClosingOpts returns the options that should be used when
// generating a new co-op close signature. // generating a new co-op close signature.
func (m *MusigChanCloser) ProposalClosingOpts() ([]lnwallet.ChanCloseOpt, error) { func (m *MusigChanCloser) ProposalClosingOpts() (
[]lnwallet.ChanCloseOpt, error) {
switch { switch {
case m.localNonce == nil: case m.localNonce == nil:
return nil, fmt.Errorf("local nonce not generated") return nil, fmt.Errorf("local nonce not generated")