Skip to content

Commit

Permalink
multi: fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Jul 23, 2023
1 parent 5c09d61 commit 7764f65
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 106 deletions.
2 changes: 1 addition & 1 deletion htlcswitch/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func (l *channelLink) syncChanStates() error {
// very same nonce that we sent above, as they should
// take the latest verification nonce we send.
if chanState.ChanType.IsTaproot() {
fundingLockedMsg.NextLocalNonce = localChanSyncMsg.LocalNonce
fundingLockedMsg.NextLocalNonce = localChanSyncMsg.LocalNonce //nolint:lll
}

// For channels that negotiated the option-scid-alias
Expand Down
4 changes: 1 addition & 3 deletions lnwallet/chancloser/chancloser.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,6 @@ func (c *ChanCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message,
"new co op close offer: %w", err)
}

break

// Otherwise, if we are the initiator, and we just sent a
// signature for a taproot channel, then we'll ensure that the
// fee rate matches up exactly.
Expand Down Expand Up @@ -755,7 +753,7 @@ func (c *ChanCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message,
matchingSig := c.priorFeeOffers[remoteProposedFee]
if c.cfg.Channel.ChanType().IsTaproot() {
muSession := c.cfg.MusigSession
localSig, remoteSig, closeOpts, err = muSession.CombineClosingOpts( //nolint:ll
localSig, remoteSig, closeOpts, err = muSession.CombineClosingOpts( //nolint:lll
*matchingSig.PartialSig,
*closeSignedMsg.PartialSig,
)
Expand Down
11 changes: 7 additions & 4 deletions lnwallet/chancloser/chancloser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ func (m *mockChannel) FundingTxOut() *wire.TxOut {
return nil
}

func (m *mockChannel) MultiSigKeys() (keychain.KeyDescriptor, keychain.KeyDescriptor) {
func (m *mockChannel) MultiSigKeys() (
keychain.KeyDescriptor, keychain.KeyDescriptor) {

return m.localKey, m.remoteKey
}

Expand Down Expand Up @@ -250,7 +252,9 @@ func newMockMusigSession() *mockMusigSession {
return &mockMusigSession{}
}

func (m *mockMusigSession) ProposalClosingOpts() ([]lnwallet.ChanCloseOpt, error) {
func (m *mockMusigSession) ProposalClosingOpts() ([]lnwallet.ChanCloseOpt,
error) {

return nil, nil
}

Expand All @@ -267,7 +271,6 @@ func (m *mockMusigSession) ClosingNonce() (*musig2.Nonces, error) {
}

func (m *mockMusigSession) InitRemoteNonce(nonce *musig2.Nonces) {
return
}

type mockCoopFeeEstimator struct {
Expand Down Expand Up @@ -565,7 +568,7 @@ func TestTaprootFastClose(t *testing.T) {
ogOffer := bobOffer.FeeSatoshis
bobOffer.FeeSatoshis /= 2

aliceMsgs, _, err = aliceCloser.ProcessCloseMsg(bobOffer)
_, _, err = aliceCloser.ProcessCloseMsg(bobOffer)
require.Error(t, err)
require.Contains(t, err.Error(), "was not accepted")

Expand Down
11 changes: 6 additions & 5 deletions lnwallet/chancloser/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type CoopFeeEstimator interface {
// 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
// closing process.
type Channel interface {
type Channel interface { //nolint:interfacebloat
// ChannelPoint returns the channel point of the target channel.
ChannelPoint() *wire.OutPoint

Expand Down Expand Up @@ -70,10 +70,11 @@ type Channel interface {
// CreateCloseProposal creates a new co-op close proposal in the form
// of a valid signature, the chainhash of the final txid, and our final
// balance in the created state.
CreateCloseProposal(proposedFee btcutil.Amount, localDeliveryScript []byte,
remoteDeliveryScript []byte,
closeOpt ...lnwallet.ChanCloseOpt) (input.Signature, *chainhash.Hash,
btcutil.Amount, error)
CreateCloseProposal(proposedFee btcutil.Amount,
localDeliveryScript []byte, remoteDeliveryScript []byte,
closeOpt ...lnwallet.ChanCloseOpt,
) (
input.Signature, *chainhash.Hash, btcutil.Amount, error)

// CompleteCooperativeClose persistently "completes" the cooperative
// close by producing a fully signed co-op close transaction.
Expand Down
68 changes: 39 additions & 29 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ func NewLightningChannel(signer input.Signer,
state.RevocationProducer,
)
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{
Expand Down Expand Up @@ -1474,7 +1474,8 @@ func (lc *LightningChannel) createSignDesc() error {
}
} else {
multiSigScript, err = input.GenMultiSigScript(
localKey.SerializeCompressed(), remoteKey.SerializeCompressed(),
localKey.SerializeCompressed(),
remoteKey.SerializeCompressed(),
)
if err != nil {
return err
Expand Down Expand Up @@ -3365,7 +3366,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
// If this is a taproot channel, then we'll need to set the
// method type to ensure we generate a valid signature.
if chanType.IsTaproot() {
sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod
sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod //nolint:lll
}

sigBatch = append(sigBatch, sigJob)
Expand Down Expand Up @@ -3433,7 +3434,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
// If this is a taproot channel, then we'll need to set the
// method type to ensure we generate a valid signature.
if chanType.IsTaproot() {
sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod
sigJob.SignDesc.SignMethod = input.TaprootScriptSpendSignMethod //nolint:lll
}

sigBatch = append(sigBatch, sigJob)
Expand Down Expand Up @@ -3879,7 +3880,6 @@ type NewCommitState struct {
// HTLC's on the commitment transaction. Finally, the new set of pending HTLCs
// for the remote party's commitment are also returned.
func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {

lc.Lock()
defer lc.Unlock()

Expand Down Expand Up @@ -4572,8 +4572,9 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
htlcAmt := int64(htlc.Amount.ToSatoshis())

if chanType.IsTaproot() {
// TODO(roasbeef): add abstraction in front
prevFetcher := txscript.NewCannedPrevOutputFetcher(
// TODO(roasbeef): add abstraction in
// front
prevFetcher := txscript.NewCannedPrevOutputFetcher( //nolint:lll
htlc.ourPkScript, htlcAmt,
)
hashCache := txscript.NewTxSigHashes(
Expand All @@ -4582,9 +4583,11 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
tapLeaf := txscript.NewBaseTapLeaf(
htlc.ourWitnessScript,
)
return txscript.CalcTapscriptSignaturehash(
hashCache, sigHashType, successTx, 0,
prevFetcher, tapLeaf,

return txscript.CalcTapscriptSignaturehash( //nolint:lll
hashCache, sigHashType,
successTx, 0, prevFetcher,
tapLeaf,
)
}

Expand Down Expand Up @@ -4643,8 +4646,9 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
timeoutTx, err := CreateHtlcTimeoutTx(
chanType, isLocalInitiator, op,
outputAmt, htlc.Timeout,
uint32(localChanCfg.CsvDelay), leaseExpiry,
keyRing.RevocationKey, keyRing.ToLocalKey,
uint32(localChanCfg.CsvDelay),
leaseExpiry, keyRing.RevocationKey,
keyRing.ToLocalKey,
)
if err != nil {
return nil, err
Expand All @@ -4653,8 +4657,9 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
htlcAmt := int64(htlc.Amount.ToSatoshis())

if chanType.IsTaproot() {
// TODO(roasbeef): add abstraction in front
prevFetcher := txscript.NewCannedPrevOutputFetcher(
// TODO(roasbeef): add abstraction in
// front
prevFetcher := txscript.NewCannedPrevOutputFetcher( //nolint:lll
htlc.ourPkScript, htlcAmt,
)
hashCache := txscript.NewTxSigHashes(
Expand All @@ -4663,13 +4668,17 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
tapLeaf := txscript.NewBaseTapLeaf(
htlc.ourWitnessScript,
)
return txscript.CalcTapscriptSignaturehash(
hashCache, sigHashType, timeoutTx, 0,
prevFetcher, tapLeaf,

return txscript.CalcTapscriptSignaturehash( //nolint:lll
hashCache, sigHashType,
timeoutTx, 0, prevFetcher,
tapLeaf,
)
}

hashCache := input.NewTxSigHashesV0Only(timeoutTx)
hashCache := input.NewTxSigHashesV0Only(
timeoutTx,
)
sigHash, err := txscript.CalcWitnessSigHash(
htlc.ourWitnessScript, hashCache,
sigHashType, timeoutTx, 0,
Expand Down Expand Up @@ -4809,8 +4818,9 @@ var _ error = (*InvalidCommitSigError)(nil)
// 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.
//
//nolint:funlen
func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {

lc.Lock()
defer lc.Unlock()

Expand Down Expand Up @@ -4936,7 +4946,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
// exact signature and commitment we failed to
// verify against in order to aide debugging.
var txBytes bytes.Buffer
localCommitTx.Serialize(&txBytes)
_ = localCommitTx.Serialize(&txBytes)
return &InvalidPartialCommitSigError{
invalidPartialSigError: &sigErr,
InvalidCommitSigError: InvalidCommitSigError{ //nolint:lll
Expand All @@ -4959,7 +4969,6 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
return err
}
lc.musigSessions.LocalSession = newLocalSession

} else {
multiSigScript := lc.signDesc.WitnessScript
prevFetcher := txscript.NewCannedPrevOutputFetcher(
Expand All @@ -4972,8 +4981,8 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
localCommitTx, 0, int64(lc.channelState.Capacity),
)
if err != nil {
// TODO(roasbeef): fetchview has already mutated the HTLCs...
// * need to either roll-back, or make pure
// TODO(roasbeef): fetchview has already mutated the
// HTLCs... * need to either roll-back, or make pure
return err
}

Expand All @@ -4992,10 +5001,11 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
// commitment we failed to verify against in order to
// aide debugging.
var txBytes bytes.Buffer
localCommitTx.Serialize(&txBytes)
_ = localCommitTx.Serialize(&txBytes)

return &InvalidCommitSigError{
commitHeight: nextHeight,
commitSig: commitSigs.CommitSig.ToSignatureBytes(),
commitSig: commitSigs.CommitSig.ToSignatureBytes(), //nolint:lll
sigHash: sigHash,
commitTx: txBytes.Bytes(),
}
Expand Down Expand Up @@ -5047,7 +5057,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {

localCommitmentView.sig = sigBytes[:]
} else {
localCommitmentView.sig = commitSigs.CommitSig.ToSignatureBytes()
localCommitmentView.sig = commitSigs.CommitSig.ToSignatureBytes() //nolint:lll
}

lc.localCommitChain.addCommitment(localCommitmentView)
Expand Down Expand Up @@ -7284,7 +7294,6 @@ func (lc *LightningChannel) CompleteCooperativeClose(
finalSchnorrSig.Serialize(),
}
} else {

// For regular channels, we'll need to , construct the witness
// stack minding the order of the pubkeys+sigs on the stack.
ourKey := lc.channelState.LocalChanCfg.MultiSigKey.PubKey.
Expand All @@ -7296,7 +7305,6 @@ func (lc *LightningChannel) CompleteCooperativeClose(
remoteSig,
)
closeTx.TxIn[0].Witness = witness

}

// Validate the finalized transaction to ensure the output script is
Expand Down Expand Up @@ -8261,7 +8269,9 @@ func (lc *LightningChannel) FundingTxOut() *wire.TxOut {
}

// 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()
defer lc.RUnlock()

Expand Down
Loading

0 comments on commit 7764f65

Please sign in to comment.