From e63a879dfc14025b1f1d055f5977a6d9949c2e1f Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sun, 2 Jun 2024 18:47:17 -0300 Subject: [PATCH] lint: update configs, golangci-lint to v1.59.0 Remove deprecated and deactivated linters from .golangci.yml. Ignore too noisy linters: protogetter, depguard, mnd. Fix linter warnings. Use timeout instead of deadline in .golangci.yml. --- .golangci.yml | 21 ++++-------- bip39/wordlist_english.go | 4 +-- btc/bitcoind.go | 14 ++++---- btc/descriptors.go | 4 +-- btc/explorer_api.go | 4 +-- cmd/chantools/chanbackup.go | 5 +-- cmd/chantools/closepoolaccount.go | 13 ++++---- cmd/chantools/closepoolaccount_test.go | 2 -- cmd/chantools/compactdb.go | 5 +-- cmd/chantools/createwallet.go | 5 +-- cmd/chantools/deletepayments.go | 3 +- cmd/chantools/doc.go | 2 +- cmd/chantools/doublespendinputs.go | 5 +-- cmd/chantools/dropchannelgraph.go | 5 +-- cmd/chantools/dropgraphzombies.go | 3 +- cmd/chantools/dumpbackup.go | 3 +- cmd/chantools/dumpchannels.go | 4 +-- cmd/chantools/fakechanbackup.go | 7 ++-- cmd/chantools/filterbackup.go | 3 +- cmd/chantools/fixoldbackup.go | 2 +- cmd/chantools/forceclose.go | 3 +- cmd/chantools/genimportscript.go | 3 +- cmd/chantools/migratedb.go | 3 +- cmd/chantools/pullanchor.go | 13 ++++---- cmd/chantools/recoverloopin.go | 12 +++---- cmd/chantools/removechannel.go | 3 +- cmd/chantools/rescueclosed.go | 12 +++---- cmd/chantools/rescuefunding.go | 9 +++--- cmd/chantools/rescuetweakedkey.go | 5 +-- cmd/chantools/root.go | 5 +-- cmd/chantools/signmessage.go | 3 +- cmd/chantools/signpsbt.go | 5 +-- cmd/chantools/signrescuefunding.go | 9 +++--- cmd/chantools/sweepremoteclosed.go | 2 +- cmd/chantools/sweeptimelockmanual.go | 15 +++++---- cmd/chantools/testdata/wallet.db | Bin 106496 -> 106496 bytes cmd/chantools/vanitygen.go | 9 +++--- cmd/chantools/walletinfo.go | 5 +-- cmd/chantools/zombierecovery_findmatches.go | 2 +- cmd/chantools/zombierecovery_makeoffer.go | 31 +++++++++--------- cmd/chantools/zombierecovery_preparekeys.go | 7 ++-- cmd/chantools/zombierecovery_signoffer.go | 5 +-- lnd/aezeed.go | 6 ++-- lnd/brontide.go | 34 +++++++++----------- lnd/chanbackup.go | 2 -- lnd/channel.go | 3 +- lnd/hdkeychain.go | 11 ++++--- lnd/signer.go | 3 +- tools/Dockerfile | 4 +-- 49 files changed, 177 insertions(+), 161 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4e06d29..3439c36 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,6 @@ run: # timeout for analysis - deadline: 4m + timeout: 4m linters-settings: govet: @@ -12,7 +12,7 @@ linters-settings: whitespace: multi-func: true multi-if: true - tagliatelle: + tagliatelle: case: rules: json: snake @@ -31,17 +31,15 @@ linters: - gochecknoglobals - gosec - funlen - - maligned - varnamelen - wrapcheck - testpackage - gomnd - - goerr113 + - err113 - exhaustruct - forbidigo - gocognit - nestif - - ifshort - wsl - cyclop - gocyclo @@ -53,16 +51,9 @@ linters: - noctx - gofumpt - exhaustive - - # deprecated - - interfacer - - scopelint - - golint - - exhaustivestruct - - nosnakecase - - deadcode - - structcheck - - varcheck + - protogetter + - depguard + - mnd issues: exclude-rules: diff --git a/bip39/wordlist_english.go b/bip39/wordlist_english.go index 31a343e..ebdc22f 100644 --- a/bip39/wordlist_english.go +++ b/bip39/wordlist_english.go @@ -3,8 +3,8 @@ package bip39 import ( - "fmt" "hash/crc32" + "strconv" "strings" ) @@ -14,7 +14,7 @@ func init() { //nolint:gochecknoinits // $ crc32 english.txt // c1dbd296 checksum := crc32.ChecksumIEEE([]byte(english)) - if fmt.Sprintf("%x", checksum) != "c1dbd296" { + if strconv.FormatUint(uint64(checksum), 16) != "c1dbd296" { panic("english checksum invalid") } } diff --git a/btc/bitcoind.go b/btc/bitcoind.go index 98dd5a0..9e069b6 100644 --- a/btc/bitcoind.go +++ b/btc/bitcoind.go @@ -25,9 +25,9 @@ const ( type KeyExporter interface { Header() string - Format(*hdkeychain.ExtendedKey, *chaincfg.Params, string, uint32, - uint32) (string, error) - Trailer(uint32) string + Format(hdKey *hdkeychain.ExtendedKey, params *chaincfg.Params, + path string, branch, index uint32) (string, error) + Trailer(birthdayBlock uint32) string } // ParseFormat parses the given format name and returns its associated print @@ -67,7 +67,7 @@ func ExportKeys(extendedKey *hdkeychain.ExtendedKey, strPaths []string, path := paths[idx] // External branch first (/0/i). - for i := uint32(0); i < recoveryWindow; i++ { + for i := range recoveryWindow { path := append(path, 0, i) derivedKey, err := lnd.DeriveChildren(extendedKey, path) if err != nil { @@ -83,7 +83,7 @@ func ExportKeys(extendedKey *hdkeychain.ExtendedKey, strPaths []string, } // Now the internal branch (/1/i). - for i := uint32(0); i < recoveryWindow; i++ { + for i := range recoveryWindow { path := append(path, 1, i) derivedKey, err := lnd.DeriveChildren(extendedKey, path) if err != nil { @@ -254,7 +254,7 @@ func (p *Electrum) Header() string { } func (p *Electrum) Format(hdKey *hdkeychain.ExtendedKey, - params *chaincfg.Params, path string, branch, index uint32) (string, + params *chaincfg.Params, path string, _, _ uint32) (string, error) { privKey, err := hdKey.ECPrivKey() @@ -285,7 +285,7 @@ func (d *Descriptors) Header() string { } func (d *Descriptors) Format(hdKey *hdkeychain.ExtendedKey, - params *chaincfg.Params, path string, branch, index uint32) (string, + params *chaincfg.Params, _ string, _, _ uint32) (string, error) { privKey, err := hdKey.ECPrivKey() diff --git a/btc/descriptors.go b/btc/descriptors.go index 1d2afcd..e960b04 100644 --- a/btc/descriptors.go +++ b/btc/descriptors.go @@ -19,7 +19,7 @@ func descriptorSumPolymod(symbols []uint64) uint64 { for _, value := range symbols { top := chk >> 35 chk = (chk&0x7ffffffff)<<5 ^ value - for i := 0; i < 5; i++ { + for i := range 5 { if (top>>i)&1 != 0 { chk ^= generator[i] } @@ -57,7 +57,7 @@ func DescriptorSumCreate(s string) string { symbols := append(descriptorSumExpand(s), 0, 0, 0, 0, 0, 0, 0, 0) checksum := descriptorSumPolymod(symbols) ^ 1 builder := strings.Builder{} - for i := 0; i < 8; i++ { + for i := range 8 { builder.WriteByte(checksumCharset[(checksum>>(5*(7-i)))&31]) } return s + "#" + builder.String() diff --git a/btc/explorer_api.go b/btc/explorer_api.go index c36b902..b61038a 100644 --- a/btc/explorer_api.go +++ b/btc/explorer_api.go @@ -103,7 +103,7 @@ func (a *ExplorerAPI) Outpoint(addr string) (*TX, int, error) { } } - return nil, 0, fmt.Errorf("no tx found") + return nil, 0, errors.New("no tx found") } func (a *ExplorerAPI) Spends(addr string) ([]*TX, error) { @@ -193,7 +193,7 @@ func (a *ExplorerAPI) Address(outpoint string) (string, error) { } func (a *ExplorerAPI) PublishTx(rawTxHex string) (string, error) { - url := fmt.Sprintf("%s/tx", a.BaseURL) + url := a.BaseURL + "/tx" resp, err := http.Post(url, "text/plain", strings.NewReader(rawTxHex)) if err != nil { return "", fmt.Errorf("error posting data to API '%s', "+ diff --git a/cmd/chantools/chanbackup.go b/cmd/chantools/chanbackup.go index f8f3835..2cfb980 100644 --- a/cmd/chantools/chanbackup.go +++ b/cmd/chantools/chanbackup.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/lightninglabs/chantools/lnd" @@ -50,12 +51,12 @@ func (c *chanBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a backup file. if c.MultiFile == "" { - return fmt.Errorf("backup file is required") + return errors.New("backup file is required") } // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, true) if err != nil { diff --git a/cmd/chantools/closepoolaccount.go b/cmd/chantools/closepoolaccount.go index d9f3d30..54eb43d 100644 --- a/cmd/chantools/closepoolaccount.go +++ b/cmd/chantools/closepoolaccount.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -367,7 +368,7 @@ func bruteForceAccountScript(accountBaseKey *hdkeychain.ExtendedKey, maxNumBatchKeys uint32, targetScript []byte) (*poolAccount, error) { // The outermost loop is over the possible accounts. - for i := uint32(0); i < maxNumAccounts; i++ { + for i := range maxNumAccounts { accountExtendedKey, err := accountBaseKey.DeriveNonStandard(i) if err != nil { return nil, fmt.Errorf("error deriving account key: "+ @@ -430,7 +431,7 @@ func bruteForceAccountScript(accountBaseKey *hdkeychain.ExtendedKey, log.Debugf("Tried account index %d of %d", i, maxNumAccounts) } - return nil, fmt.Errorf("account script not derived") + return nil, errors.New("account script not derived") } func fastScript(keyIndex, expiryFrom, expiryTo uint32, traderKey, auctioneerKey, @@ -442,7 +443,7 @@ func fastScript(keyIndex, expiryFrom, expiryTo uint32, traderKey, auctioneerKey, return nil, err } if script.Class() != txscript.WitnessV0ScriptHashTy { - return nil, fmt.Errorf("incompatible script class") + return nil, errors.New("incompatible script class") } traderKeyTweak := poolscript.TraderKeyTweak(batchKey, secret, traderKey) @@ -492,7 +493,7 @@ func fastScript(keyIndex, expiryFrom, expiryTo uint32, traderKey, auctioneerKey, }, nil } - return nil, fmt.Errorf("account script not derived") + return nil, errors.New("account script not derived") } func fastScriptTaproot(scriptVersion poolscript.Version, keyIndex, expiryFrom, @@ -504,7 +505,7 @@ func fastScriptTaproot(scriptVersion poolscript.Version, keyIndex, expiryFrom, return nil, err } if parsedScript.Class() != txscript.WitnessV1TaprootTy { - return nil, fmt.Errorf("incompatible script class") + return nil, errors.New("incompatible script class") } traderKeyTweak := poolscript.TraderKeyTweak(batchKey, secret, traderKey) @@ -601,5 +602,5 @@ func fastScriptTaproot(scriptVersion poolscript.Version, keyIndex, expiryFrom, }, nil } - return nil, fmt.Errorf("account script not derived") + return nil, errors.New("account script not derived") } diff --git a/cmd/chantools/closepoolaccount_test.go b/cmd/chantools/closepoolaccount_test.go index fac5ddd..76848cd 100644 --- a/cmd/chantools/closepoolaccount_test.go +++ b/cmd/chantools/closepoolaccount_test.go @@ -70,8 +70,6 @@ func TestClosePoolAccount(t *testing.T) { ) for _, tc := range testAccounts { - tc := tc - t.Run(tc.name, func(tt *testing.T) { tt.Parallel() diff --git a/cmd/chantools/compactdb.go b/cmd/chantools/compactdb.go index a17436a..61b7038 100644 --- a/cmd/chantools/compactdb.go +++ b/cmd/chantools/compactdb.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/coreos/bbolt" @@ -52,10 +53,10 @@ to create a copy of it to a destination file, compacting it in the process.`, func (c *compactDBCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a source and destination channel DB. if c.SourceDB == "" { - return fmt.Errorf("source channel DB is required") + return errors.New("source channel DB is required") } if c.DestDB == "" { - return fmt.Errorf("destination channel DB is required") + return errors.New("destination channel DB is required") } if c.TxMaxSize <= 0 { c.TxMaxSize = defaultTxMaxSize diff --git a/cmd/chantools/createwallet.go b/cmd/chantools/createwallet.go index 2ee162b..762acad 100644 --- a/cmd/chantools/createwallet.go +++ b/cmd/chantools/createwallet.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "os" "strings" @@ -63,7 +64,7 @@ func (c *createWalletCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a wallet DB. if c.WalletDBDir == "" { - return fmt.Errorf("wallet DB directory is required") + return errors.New("wallet DB directory is required") } // Make sure the directory (and parents) exists. @@ -143,7 +144,7 @@ func (c *createWalletCommand) Execute(_ *cobra.Command, _ []string) error { } if !bytes.Equal(pw, pw2) { - return fmt.Errorf("passwords don't match") + return errors.New("passwords don't match") } if len(pw) > 0 { diff --git a/cmd/chantools/deletepayments.go b/cmd/chantools/deletepayments.go index cdb9ef9..17b4275 100644 --- a/cmd/chantools/deletepayments.go +++ b/cmd/chantools/deletepayments.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/lightninglabs/chantools/lnd" @@ -45,7 +46,7 @@ run lnd ` + lndVersion + ` or later after using this command!'`, func (c *deletePaymentsCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, false) if err != nil { diff --git a/cmd/chantools/doc.go b/cmd/chantools/doc.go index 59b2973..3a26393 100644 --- a/cmd/chantools/doc.go +++ b/cmd/chantools/doc.go @@ -10,7 +10,7 @@ func newDocCommand() *cobra.Command { Use: "doc", Short: "Generate the markdown documentation of all commands", Hidden: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return doc.GenMarkdownTree(rootCmd, "./doc") }, } diff --git a/cmd/chantools/doublespendinputs.go b/cmd/chantools/doublespendinputs.go index db9aeec..47475ed 100644 --- a/cmd/chantools/doublespendinputs.go +++ b/cmd/chantools/doublespendinputs.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "strconv" @@ -96,7 +97,7 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error { // Make sure we have at least one input. if len(c.InputOutpoints) == 0 { - return fmt.Errorf("inputoutpoints are required") + return errors.New("inputoutpoints are required") } api := newExplorerAPI(c.APIURL) @@ -308,7 +309,7 @@ func (c *doubleSpendInputs) Execute(_ *cobra.Command, _ []string) error { func iterateOverPath(baseKey *hdkeychain.ExtendedKey, addr btcutil.Address, path []uint32, maxTries uint32) (*hdkeychain.ExtendedKey, error) { - for i := uint32(0); i < maxTries; i++ { + for i := range maxTries { // Check for both the external and internal branch. for _, branch := range []uint32{0, 1} { // Create the path to derive the key. diff --git a/cmd/chantools/dropchannelgraph.go b/cmd/chantools/dropchannelgraph.go index 2a4f22a..d7f2b8d 100644 --- a/cmd/chantools/dropchannelgraph.go +++ b/cmd/chantools/dropchannelgraph.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "time" @@ -82,7 +83,7 @@ chantools dropchannelgraph \ func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, false) if err != nil { @@ -91,7 +92,7 @@ func (c *dropChannelGraphCommand) Execute(_ *cobra.Command, _ []string) error { defer func() { _ = db.Close() }() if c.NodeIdentityKey == "" { - return fmt.Errorf("node identity key is required") + return errors.New("node identity key is required") } idKeyBytes, err := hex.DecodeString(c.NodeIdentityKey) diff --git a/cmd/chantools/dropgraphzombies.go b/cmd/chantools/dropgraphzombies.go index f665d01..7daf893 100644 --- a/cmd/chantools/dropgraphzombies.go +++ b/cmd/chantools/dropgraphzombies.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/lightninglabs/chantools/lnd" @@ -52,7 +53,7 @@ run lnd ` + lndVersion + ` or later after using this command!'`, func (c *dropGraphZombiesCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, false) if err != nil { diff --git a/cmd/chantools/dumpbackup.go b/cmd/chantools/dumpbackup.go index 9e3e76f..0574ca8 100644 --- a/cmd/chantools/dumpbackup.go +++ b/cmd/chantools/dumpbackup.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/davecgh/go-spew/spew" @@ -47,7 +48,7 @@ func (c *dumpBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a backup file. if c.MultiFile == "" { - return fmt.Errorf("backup file is required") + return errors.New("backup file is required") } multiFile := chanbackup.NewMultiFile(c.MultiFile) keyRing := &lnd.HDKeyRing{ diff --git a/cmd/chantools/dumpchannels.go b/cmd/chantools/dumpchannels.go index cccdfdd..f7b59ed 100644 --- a/cmd/chantools/dumpchannels.go +++ b/cmd/chantools/dumpchannels.go @@ -55,7 +55,7 @@ given lnd channel.db gile in a human readable format.`, func (c *dumpChannelsCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, true) if err != nil { @@ -67,7 +67,7 @@ func (c *dumpChannelsCommand) Execute(_ *cobra.Command, _ []string) error { (c.Pending && c.WaitingClose) || (c.Closed && c.Pending && c.WaitingClose) { - return fmt.Errorf("can only specify one flag at a time") + return errors.New("can only specify one flag at a time") } if c.Closed { diff --git a/cmd/chantools/fakechanbackup.go b/cmd/chantools/fakechanbackup.go index c838451..74acaae 100644 --- a/cmd/chantools/fakechanbackup.go +++ b/cmd/chantools/fakechanbackup.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "io/ioutil" "net" @@ -156,7 +157,7 @@ func (c *fakeChanBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Now parse the remote node info. splitNodeInfo := strings.Split(c.NodeAddr, "@") if len(splitNodeInfo) != 2 { - return fmt.Errorf("--remote_node_addr expected in format: " + + return errors.New("--remote_node_addr expected in format: " + "pubkey@host:port") } pubKeyBytes, err := hex.DecodeString(splitNodeInfo[0]) @@ -192,7 +193,7 @@ func (c *fakeChanBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Parse the short channel ID. splitChanID := strings.Split(c.ShortChanID, "x") if len(splitChanID) != 3 { - return fmt.Errorf("--short_channel_id expected in format: " + + return errors.New("--short_channel_id expected in format: " + "xx", ) } @@ -216,7 +217,7 @@ func (c *fakeChanBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Is the outpoint and/or short channel ID correct? if uint32(chanOutputIdx) != chanOp.Index { - return fmt.Errorf("output index of --short_channel_id must " + + return errors.New("output index of --short_channel_id must " + "be equal to index on --channelpoint") } diff --git a/cmd/chantools/filterbackup.go b/cmd/chantools/filterbackup.go index 46d8b24..e4aac94 100644 --- a/cmd/chantools/filterbackup.go +++ b/cmd/chantools/filterbackup.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" "strings" @@ -59,7 +60,7 @@ func (c *filterBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a backup file. if c.MultiFile == "" { - return fmt.Errorf("backup file is required") + return errors.New("backup file is required") } multiFile := chanbackup.NewMultiFile(c.MultiFile) keyRing := &lnd.HDKeyRing{ diff --git a/cmd/chantools/fixoldbackup.go b/cmd/chantools/fixoldbackup.go index 39e000b..cf91129 100644 --- a/cmd/chantools/fixoldbackup.go +++ b/cmd/chantools/fixoldbackup.go @@ -53,7 +53,7 @@ func (c *fixOldBackupCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a backup file. if c.MultiFile == "" { - return fmt.Errorf("backup file is required") + return errors.New("backup file is required") } multiFile := chanbackup.NewMultiFile(c.MultiFile) keyRing := &lnd.HDKeyRing{ diff --git a/cmd/chantools/forceclose.go b/cmd/chantools/forceclose.go index f6362aa..13c9867 100644 --- a/cmd/chantools/forceclose.go +++ b/cmd/chantools/forceclose.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -79,7 +80,7 @@ func (c *forceCloseCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("rescue DB is required") + return errors.New("rescue DB is required") } db, err := lnd.OpenDB(c.ChannelDB, true) if err != nil { diff --git a/cmd/chantools/genimportscript.go b/cmd/chantools/genimportscript.go index eb84ffc..8db3215 100644 --- a/cmd/chantools/genimportscript.go +++ b/cmd/chantools/genimportscript.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" "time" @@ -145,7 +146,7 @@ func (c *genImportScriptCommand) Execute(_ *cobra.Command, _ []string) error { paths = [][]uint32{derivationPath} case c.LndPaths && c.DerivationPath != "": - return fmt.Errorf("cannot use --lndpaths and --derivationpath " + + return errors.New("cannot use --lndpaths and --derivationpath " + "at the same time") case c.LndPaths: diff --git a/cmd/chantools/migratedb.go b/cmd/chantools/migratedb.go index 7730266..6ef9880 100644 --- a/cmd/chantools/migratedb.go +++ b/cmd/chantools/migratedb.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/lightninglabs/chantools/lnd" @@ -41,7 +42,7 @@ run lnd ` + lndVersion + ` or later after using this command!'`, func (c *migrateDBCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, false) if err != nil { diff --git a/cmd/chantools/pullanchor.go b/cmd/chantools/pullanchor.go index ec4041e..313f734 100644 --- a/cmd/chantools/pullanchor.go +++ b/cmd/chantools/pullanchor.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "math" @@ -87,10 +88,10 @@ func (c *pullAnchorCommand) Execute(_ *cobra.Command, _ []string) error { // Make sure all input is provided. if c.SponsorInput == "" { - return fmt.Errorf("sponsor input is required") + return errors.New("sponsor input is required") } if len(c.AnchorAddrs) == 0 { - return fmt.Errorf("at least one anchor addr is required") + return errors.New("at least one anchor addr is required") } for _, anchorAddr := range c.AnchorAddrs { err = lnd.CheckAddress( @@ -430,7 +431,7 @@ func findAnchorKey(rootKey *hdkeychain.ExtendedKey, // Loop through the local multisig keys to find the target anchor // script. - for index := uint32(0); index < math.MaxInt16; index++ { + for index := range uint32(math.MaxInt16) { currentKey, err := localMultisig.DeriveNonStandard(index) if err != nil { return nil, nil, fmt.Errorf("error deriving child "+ @@ -468,7 +469,7 @@ func findAnchorKey(rootKey *hdkeychain.ExtendedKey, }, script, nil } - return nil, nil, fmt.Errorf("no matching pubkeys found") + return nil, nil, errors.New("no matching pubkeys found") } func findTaprootAnchorKey(rootKey *hdkeychain.ExtendedKey, @@ -489,7 +490,7 @@ func findTaprootAnchorKey(rootKey *hdkeychain.ExtendedKey, // Loop through the local multisig keys to find the target anchor // script. - for index := uint32(0); index < math.MaxInt16; index++ { + for index := range uint32(math.MaxInt16) { currentKey, err := localPayment.DeriveNonStandard(index) if err != nil { return nil, nil, fmt.Errorf("error deriving child "+ @@ -526,5 +527,5 @@ func findTaprootAnchorKey(rootKey *hdkeychain.ExtendedKey, }, scriptTree, nil } - return nil, nil, fmt.Errorf("no matching pubkeys found") + return nil, nil, errors.New("no matching pubkeys found") } diff --git a/cmd/chantools/recoverloopin.go b/cmd/chantools/recoverloopin.go index 8b70944..c25b739 100644 --- a/cmd/chantools/recoverloopin.go +++ b/cmd/chantools/recoverloopin.go @@ -25,7 +25,7 @@ import ( ) var ( - errSwapNotFound = fmt.Errorf("loop in swap not found") + errSwapNotFound = errors.New("loop in swap not found") ) type recoverLoopInCommand struct { @@ -125,15 +125,15 @@ func (c *recoverLoopInCommand) Execute(_ *cobra.Command, _ []string) error { } if c.TxID == "" { - return fmt.Errorf("txid is required") + return errors.New("txid is required") } if c.SwapHash == "" { - return fmt.Errorf("swap_hash is required") + return errors.New("swap_hash is required") } if c.LoopDbDir == "" { - return fmt.Errorf("loop_db_dir is required") + return errors.New("loop_db_dir is required") } err = lnd.CheckAddress( @@ -207,7 +207,7 @@ func (c *recoverLoopInCommand) Execute(_ *cobra.Command, _ []string) error { // set, as a lot of failure cases steam from the output amount being // wrong. if loopIn.Contract.ExternalHtlc && c.OutputAmt == 0 { - return fmt.Errorf("output_amt is required for external htlc") + return errors.New("output_amt is required for external htlc") } fmt.Println("Loop expires at block height", loopIn.Contract.CltvExpiry) @@ -289,7 +289,7 @@ func (c *recoverLoopInCommand) Execute(_ *cobra.Command, _ []string) error { } } if rawTx == nil { - return fmt.Errorf("failed to brute force key index, " + + return errors.New("failed to brute force key index, " + "please try again with a higher start key " + "index") } diff --git a/cmd/chantools/removechannel.go b/cmd/chantools/removechannel.go index 63b450b..15697ff 100644 --- a/cmd/chantools/removechannel.go +++ b/cmd/chantools/removechannel.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "strconv" "strings" @@ -53,7 +54,7 @@ run lnd ` + lndVersion + ` or later after using this command!`, func (c *removeChannelCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a channel DB. if c.ChannelDB == "" { - return fmt.Errorf("channel DB is required") + return errors.New("channel DB is required") } db, err := lnd.OpenDB(c.ChannelDB, false) if err != nil { diff --git a/cmd/chantools/rescueclosed.go b/cmd/chantools/rescueclosed.go index c8b11e9..b10dffd 100644 --- a/cmd/chantools/rescueclosed.go +++ b/cmd/chantools/rescueclosed.go @@ -173,7 +173,7 @@ func (c *rescueClosedCommand) Execute(_ *cobra.Command, _ []string) error { return rescueClosedChannels(extendedKey, entries, commitPoints) default: - return fmt.Errorf("you either need to specify --channeldb and " + + return errors.New("you either need to specify --channeldb and " + "--fromsummary or --force_close_addr and " + "--commit_point but not a mixture of them") } @@ -333,7 +333,7 @@ func rescueClosedChannel(extendedKey *hdkeychain.ExtendedKey, "hash %x\n", addr.ScriptAddress()) default: - return fmt.Errorf("address: must be a bech32 P2WPKH address") + return errors.New("address: must be a bech32 P2WPKH address") } err := fillCache(extendedKey) @@ -380,13 +380,13 @@ func addrInCache(addr string, perCommitPoint *btcec.PublicKey) (string, error) { return "", fmt.Errorf("error parsing addr: %w", err) } if scriptHash { - return "", fmt.Errorf("address must be a P2WPKH address") + return "", errors.New("address must be a P2WPKH address") } // If the commit point is nil, we try with plain private keys to match // static_remote_key outputs. if perCommitPoint == nil { - for i := 0; i < cacheSize; i++ { + for i := range cacheSize { cacheEntry := cache[i] hashedPubKey := btcutil.Hash160( cacheEntry.pubKey.SerializeCompressed(), @@ -415,7 +415,7 @@ func addrInCache(addr string, perCommitPoint *btcec.PublicKey) (string, error) { // Loop through all cached payment base point keys, tweak each of it // with the per_commit_point and see if the hashed public key // corresponds to the target pubKeyHash of the given address. - for i := 0; i < cacheSize; i++ { + for i := range cacheSize { cacheEntry := cache[i] basePoint := cacheEntry.pubKey tweakedPubKey := input.TweakPubKey(basePoint, perCommitPoint) @@ -449,7 +449,7 @@ func addrInCache(addr string, perCommitPoint *btcec.PublicKey) (string, error) { func fillCache(extendedKey *hdkeychain.ExtendedKey) error { cache = make([]*cacheEntry, cacheSize) - for i := 0; i < cacheSize; i++ { + for i := range cacheSize { key, err := lnd.DeriveChildren(extendedKey, []uint32{ lnd.HardenedKeyStart + uint32(keychain.BIP0043Purpose), lnd.HardenedKeyStart + chainParams.HDCoinType, diff --git a/cmd/chantools/rescuefunding.go b/cmd/chantools/rescuefunding.go index 753904f..bb89f38 100644 --- a/cmd/chantools/rescuefunding.go +++ b/cmd/chantools/rescuefunding.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -153,7 +154,7 @@ func (c *rescueFundingCommand) Execute(_ *cobra.Command, _ []string) error { case (c.ChannelDB == "" || c.DBChannelPoint == "") && c.RemotePubKey == "": - return fmt.Errorf("need to specify either channel DB and " + + return errors.New("need to specify either channel DB and " + "channel point or both local and remote pubkey") case c.ChannelDB != "" && c.DBChannelPoint != "": @@ -179,11 +180,11 @@ func (c *rescueFundingCommand) Execute(_ *cobra.Command, _ []string) error { } if pendingChan.LocalChanCfg.MultiSigKey.PubKey == nil { - return fmt.Errorf("invalid channel data in DB, local " + + return errors.New("invalid channel data in DB, local " + "multisig pubkey is nil") } if pendingChan.LocalChanCfg.MultiSigKey.PubKey == nil { - return fmt.Errorf("invalid channel data in DB, remote " + + return errors.New("invalid channel data in DB, remote " + "multisig pubkey is nil") } @@ -297,7 +298,7 @@ func rescueFunding(localKeyDesc *keychain.KeyDescriptor, // Some last sanity check that we're working with the correct data. if !bytes.Equal(fundingTxOut.PkScript, utxo.PkScript) { - return fmt.Errorf("funding output script does not match UTXO") + return errors.New("funding output script does not match UTXO") } // Now the rest of the known data for the PSBT. diff --git a/cmd/chantools/rescuetweakedkey.go b/cmd/chantools/rescuetweakedkey.go index 08507b1..0b7ed23 100644 --- a/cmd/chantools/rescuetweakedkey.go +++ b/cmd/chantools/rescuetweakedkey.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -15,7 +16,7 @@ import ( ) var ( - ErrAddrNotFound = fmt.Errorf("address not found") + ErrAddrNotFound = errors.New("address not found") ) type rescueTweakedKeyCommand struct { @@ -66,7 +67,7 @@ func (c *rescueTweakedKeyCommand) Execute(_ *cobra.Command, _ []string) error { } if c.Path == "" { - return fmt.Errorf("path is required") + return errors.New("path is required") } childKey, _, _, err := lnd.DeriveKey(extendedKey, c.Path, chainParams) diff --git a/cmd/chantools/root.go b/cmd/chantools/root.go index 2e3a3b8..ba23f8f 100644 --- a/cmd/chantools/root.go +++ b/cmd/chantools/root.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -58,7 +59,7 @@ funds locked in lnd channels in case lnd itself cannot run properly anymore. Complete documentation is available at https://github.com/lightninglabs/chantools/.`, Version: fmt.Sprintf("v%s, commit %s", version, Commit), - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(_ *cobra.Command, _ []string) { switch { case Testnet: chainParams = &chaincfg.TestNet3Params @@ -282,7 +283,7 @@ func (f *inputFlags) parseInputType() ([]*dataformat.SummaryEntry, error) { return target.AsSummaryEntries() default: - return nil, fmt.Errorf("an input file must be specified") + return nil, errors.New("an input file must be specified") } if err != nil { diff --git a/cmd/chantools/signmessage.go b/cmd/chantools/signmessage.go index 06c3ba5..da74bb3 100644 --- a/cmd/chantools/signmessage.go +++ b/cmd/chantools/signmessage.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" chantools_lnd "github.com/lightninglabs/chantools/lnd" @@ -41,7 +42,7 @@ func newSignMessageCommand() *cobra.Command { func (c *signMessageCommand) Execute(_ *cobra.Command, _ []string) error { if c.Msg == "" { - return fmt.Errorf("please enter a valid msg") + return errors.New("please enter a valid msg") } extendedKey, err := c.rootKey.read() diff --git a/cmd/chantools/signpsbt.go b/cmd/chantools/signpsbt.go index 927881b..39b1cf1 100644 --- a/cmd/chantools/signpsbt.go +++ b/cmd/chantools/signpsbt.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "encoding/binary" + "errors" "fmt" "os" @@ -93,7 +94,7 @@ func (c *signPSBTCommand) Execute(_ *cobra.Command, _ []string) error { } default: - return fmt.Errorf("either the PSBT or the raw PSBT file " + + return errors.New("either the PSBT or the raw PSBT file " + "must be set") } @@ -222,5 +223,5 @@ func findMatchingDerivationPath(rootKey *hdkeychain.ExtendedKey, } } - return nil, 0, fmt.Errorf("no matching derivation path found") + return nil, 0, errors.New("no matching derivation path found") } diff --git a/cmd/chantools/signrescuefunding.go b/cmd/chantools/signrescuefunding.go index 9380ae3..ebc093f 100644 --- a/cmd/chantools/signrescuefunding.go +++ b/cmd/chantools/signrescuefunding.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -115,11 +116,11 @@ func signRescueFunding(rootKey *hdkeychain.ExtendedKey, return fmt.Errorf("could not find local multisig key: %w", err) } if len(packet.Inputs[0].WitnessScript) == 0 { - return fmt.Errorf("invalid PSBT, missing witness script") + return errors.New("invalid PSBT, missing witness script") } witnessScript := packet.Inputs[0].WitnessScript if packet.Inputs[0].WitnessUtxo == nil { - return fmt.Errorf("invalid PSBT, witness UTXO missing") + return errors.New("invalid PSBT, witness UTXO missing") } utxo := packet.Inputs[0].WitnessUtxo @@ -157,7 +158,7 @@ func findLocalMultisigKey(multisigBranch *hdkeychain.ExtendedKey, targetPubkey *btcec.PublicKey) (*keychain.KeyDescriptor, error) { // Loop through the local multisig keys to find the target key. - for index := uint32(0); index < MaxChannelLookup; index++ { + for index := range uint32(MaxChannelLookup) { currentKey, err := multisigBranch.DeriveNonStandard(index) if err != nil { return nil, fmt.Errorf("error deriving child key: %w", @@ -183,5 +184,5 @@ func findLocalMultisigKey(multisigBranch *hdkeychain.ExtendedKey, }, nil } - return nil, fmt.Errorf("no matching pubkeys found") + return nil, errors.New("no matching pubkeys found") } diff --git a/cmd/chantools/sweepremoteclosed.go b/cmd/chantools/sweepremoteclosed.go index 133bcd1..a64ddd9 100644 --- a/cmd/chantools/sweepremoteclosed.go +++ b/cmd/chantools/sweepremoteclosed.go @@ -145,7 +145,7 @@ func sweepRemoteClosed(extendedKey *hdkeychain.ExtendedKey, apiURL, targets []*targetAddr api = newExplorerAPI(apiURL) ) - for index := uint32(0); index < recoveryWindow; index++ { + for index := range recoveryWindow { path := fmt.Sprintf("m/1017'/%d'/%d'/0/%d", chainParams.HDCoinType, keychain.KeyFamilyPaymentBase, index) diff --git a/cmd/chantools/sweeptimelockmanual.go b/cmd/chantools/sweeptimelockmanual.go index 6d04197..ee7d16e 100644 --- a/cmd/chantools/sweeptimelockmanual.go +++ b/cmd/chantools/sweeptimelockmanual.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/hex" + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -179,7 +180,7 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error case c.ChannelBackup != "": if c.ChannelPoint == "" { - return fmt.Errorf("channel point is required with " + + return errors.New("channel point is required with " + "--frombackup") } @@ -211,11 +212,11 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error maxNumChannelsTotal = startNumChannelsTotal + 1 case c.ChannelBackup != "" && c.RemoteRevocationBasePoint != "": - return fmt.Errorf("cannot use both --frombackup and " + + return errors.New("cannot use both --frombackup and " + "--remoterevbasepoint at the same time") default: - return fmt.Errorf("either --frombackup or " + + return errors.New("either --frombackup or " + "--remoterevbasepoint is required") } @@ -318,7 +319,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string, // Did we find what we looked for or did we just exhaust all // possibilities? if script == nil || delayDesc == nil { - return fmt.Errorf("target script not derived") + return errors.New("target script not derived") } // We now know everything we need to construct the sweep transaction, @@ -564,7 +565,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey, }, nil } - return 0, nil, nil, nil, nil, fmt.Errorf("target script not derived") + return 0, nil, nil, nil, nil, errors.New("target script not derived") } func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey, @@ -572,7 +573,7 @@ func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey, startCsvTimeout, maxCsvTimeout uint16, maxChanUpdates uint64) (int32, []byte, []byte, *btcec.PublicKey, error) { - for i := uint64(0); i < maxChanUpdates; i++ { + for i := range maxChanUpdates { revPreimage, err := revRoot.AtIndex(i) if err != nil { return 0, nil, nil, nil, err @@ -592,5 +593,5 @@ func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey, return csvTimeout, script, scriptHash, commitPoint, nil } - return 0, nil, nil, nil, fmt.Errorf("target script not derived") + return 0, nil, nil, nil, errors.New("target script not derived") } diff --git a/cmd/chantools/testdata/wallet.db b/cmd/chantools/testdata/wallet.db index 0c5f4dd5037df965d39da1e65af4967711c6de38..6c6002f05453990b962eaee6d96dcec9a7a23cda 100644 GIT binary patch delta 61 zcmZoTz}9epZGwZq9tH?_EcD()XeQ^c&5j2)@J|wO5ZDWqsFY~@^Z5|#3a~_z!ZHQM F1^{dX6x{#- delta 61 zcmZoTz}9epZGwZqDh3EJ^*r=*%kM3wKl6`e5m=&0VVMGB F0|06^6fyt+ diff --git a/cmd/chantools/vanitygen.go b/cmd/chantools/vanitygen.go index ff1da21..ef4a6bd 100644 --- a/cmd/chantools/vanitygen.go +++ b/cmd/chantools/vanitygen.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/rand" "encoding/hex" + "errors" "fmt" "math" "runtime" @@ -71,14 +72,14 @@ func (c *vanityGenCommand) Execute(_ *cobra.Command, _ []string) error { } if len(prefixBytes) < 2 { - return fmt.Errorf("prefix must be at least 2 bytes") + return errors.New("prefix must be at least 2 bytes") } if len(prefixBytes) > 8 { - return fmt.Errorf("prefix too long, unlikely to find a key " + + return errors.New("prefix too long, unlikely to find a key " + "within billions of years") } if !(prefixBytes[0] == 0x02 || prefixBytes[0] == 0x03) { - return fmt.Errorf("prefix must start with 02 or 03 because " + + return errors.New("prefix must start with 02 or 03 because " + "it's an EC public key") } @@ -103,7 +104,7 @@ func (c *vanityGenCommand) Execute(_ *cobra.Command, _ []string) error { start = time.Now() ) - for i := uint8(0); i < c.Threads; i++ { + for range c.Threads { go func() { var ( entropy [16]byte diff --git a/cmd/chantools/walletinfo.go b/cmd/chantools/walletinfo.go index 7715136..9458df0 100644 --- a/cmd/chantools/walletinfo.go +++ b/cmd/chantools/walletinfo.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -79,7 +80,7 @@ or simply press without entering a password when being prompted.`, func (c *walletInfoCommand) Execute(_ *cobra.Command, _ []string) error { // Check that we have a wallet DB. if c.WalletDB == "" { - return fmt.Errorf("wallet DB is required") + return errors.New("wallet DB is required") } w, privateWalletPw, cleanup, err := lnd.OpenWallet( @@ -163,7 +164,7 @@ func walletInfo(w *wallet.Wallet, dumpAddrs bool) (*btcec.PublicKey, string, printAddr := func(a waddrmgr.ManagedAddress) error { pka, ok := a.(waddrmgr.ManagedPubKeyAddress) if !ok { - return fmt.Errorf("key is not a managed pubkey") + return errors.New("key is not a managed pubkey") } privKey, err := pka.PrivKey() diff --git a/cmd/chantools/zombierecovery_findmatches.go b/cmd/chantools/zombierecovery_findmatches.go index 0b33ffd..76188cf 100644 --- a/cmd/chantools/zombierecovery_findmatches.go +++ b/cmd/chantools/zombierecovery_findmatches.go @@ -298,7 +298,7 @@ func (c *zombieRecoveryFindMatchesCommand) Execute(_ *cobra.Command, Node1: node1, } - folder := fmt.Sprintf("results/match-%s", node1) + folder := "results/match-" + node1 today := time.Now().Format("2006-01-02") for node2, match := range node1map { err = os.MkdirAll(folder, 0755) diff --git a/cmd/chantools/zombierecovery_makeoffer.go b/cmd/chantools/zombierecovery_makeoffer.go index 99a40b3..dc52611 100644 --- a/cmd/chantools/zombierecovery_makeoffer.go +++ b/cmd/chantools/zombierecovery_makeoffer.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "errors" "fmt" "os" "strconv" @@ -111,49 +112,49 @@ func (c *zombieRecoveryMakeOfferCommand) Execute(_ *cobra.Command, // Make sure the key files were filled correctly. if keys1.Node1 == nil || keys1.Node2 == nil { - return fmt.Errorf("invalid node1 file, node info missing") + return errors.New("invalid node1 file, node info missing") } if keys2.Node1 == nil || keys2.Node2 == nil { - return fmt.Errorf("invalid node2 file, node info missing") + return errors.New("invalid node2 file, node info missing") } if keys1.Node1.PubKey != keys2.Node1.PubKey { - return fmt.Errorf("invalid files, node 1 pubkey doesn't match") + return errors.New("invalid files, node 1 pubkey doesn't match") } if keys1.Node2.PubKey != keys2.Node2.PubKey { - return fmt.Errorf("invalid files, node 2 pubkey doesn't match") + return errors.New("invalid files, node 2 pubkey doesn't match") } if len(keys1.Node1.MultisigKeys) == 0 && len(keys1.Node2.MultisigKeys) == 0 { - return fmt.Errorf("invalid node1 file, missing multisig keys") + return errors.New("invalid node1 file, missing multisig keys") } if len(keys2.Node1.MultisigKeys) == 0 && len(keys2.Node2.MultisigKeys) == 0 { - return fmt.Errorf("invalid node2 file, missing multisig keys") + return errors.New("invalid node2 file, missing multisig keys") } if len(keys1.Node1.MultisigKeys) == len(keys2.Node1.MultisigKeys) { - return fmt.Errorf("invalid files, channel info incorrect") + return errors.New("invalid files, channel info incorrect") } if len(keys1.Node2.MultisigKeys) == len(keys2.Node2.MultisigKeys) { - return fmt.Errorf("invalid files, channel info incorrect") + return errors.New("invalid files, channel info incorrect") } if len(keys1.Channels) != len(keys2.Channels) { - return fmt.Errorf("invalid files, channels don't match") + return errors.New("invalid files, channels don't match") } for idx, node1Channel := range keys1.Channels { if keys2.Channels[idx].ChanPoint != node1Channel.ChanPoint { - return fmt.Errorf("invalid files, channels don't match") + return errors.New("invalid files, channels don't match") } if keys2.Channels[idx].Address != node1Channel.Address { - return fmt.Errorf("invalid files, channels don't match") + return errors.New("invalid files, channels don't match") } if keys2.Channels[idx].Address == "" || node1Channel.Address == "" { - return fmt.Errorf("invalid files, channel address " + + return errors.New("invalid files, channel address " + "missing") } } @@ -221,10 +222,10 @@ func (c *zombieRecoveryMakeOfferCommand) Execute(_ *cobra.Command, theirPayoutAddr = keys1.Node1.PayoutAddr } if len(ourKeys) == 0 || len(theirKeys) == 0 { - return fmt.Errorf("couldn't find necessary keys") + return errors.New("couldn't find necessary keys") } if ourPayoutAddr == "" || theirPayoutAddr == "" { - return fmt.Errorf("payout address missing") + return errors.New("payout address missing") } ourPubKeys, err := parseKeys(ourKeys) @@ -315,7 +316,7 @@ func (c *zombieRecoveryMakeOfferCommand) Execute(_ *cobra.Command, theirSum -= totalFee default: - return fmt.Errorf("error distributing fees, unhandled case") + return errors.New("error distributing fees, unhandled case") } // Our output. diff --git a/cmd/chantools/zombierecovery_preparekeys.go b/cmd/chantools/zombierecovery_preparekeys.go index ad4b48f..269776d 100644 --- a/cmd/chantools/zombierecovery_preparekeys.go +++ b/cmd/chantools/zombierecovery_preparekeys.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -72,7 +73,7 @@ func (c *zombieRecoveryPrepareKeysCommand) Execute(_ *cobra.Command, _, err = lnd.GetP2WPKHScript(c.PayoutAddr, chainParams) if err != nil { - return fmt.Errorf("invalid payout address, must be P2WPKH") + return errors.New("invalid payout address, must be P2WPKH") } matchFileBytes, err := ioutil.ReadFile(c.MatchFile) @@ -90,7 +91,7 @@ func (c *zombieRecoveryPrepareKeysCommand) Execute(_ *cobra.Command, // Make sure the match file was filled correctly. if match.Node1 == nil || match.Node2 == nil { - return fmt.Errorf("invalid match file, node info missing") + return errors.New("invalid match file, node info missing") } _, pubKey, _, err := lnd.DeriveKey( @@ -116,7 +117,7 @@ func (c *zombieRecoveryPrepareKeysCommand) Execute(_ *cobra.Command, } // Derive all 2500 keys now, this might take a while. - for index := uint32(0); index < c.NumKeys; index++ { + for index := range c.NumKeys { _, pubKey, _, err := lnd.DeriveKey( extendedKey, lnd.MultisigPath(chainParams, int(index)), chainParams, diff --git a/cmd/chantools/zombierecovery_signoffer.go b/cmd/chantools/zombierecovery_signoffer.go index 9298038..4541e64 100644 --- a/cmd/chantools/zombierecovery_signoffer.go +++ b/cmd/chantools/zombierecovery_signoffer.go @@ -3,6 +3,7 @@ package main import ( "bufio" "bytes" + "errors" "fmt" "os" @@ -151,12 +152,12 @@ func signOffer(rootKey *hdkeychain.ExtendedKey, "%w", err) } if len(packet.Inputs[idx].WitnessScript) == 0 { - return fmt.Errorf("invalid PSBT, missing witness " + + return errors.New("invalid PSBT, missing witness " + "script") } witnessScript := packet.Inputs[idx].WitnessScript if packet.Inputs[idx].WitnessUtxo == nil { - return fmt.Errorf("invalid PSBT, witness UTXO missing") + return errors.New("invalid PSBT, witness UTXO missing") } utxo := packet.Inputs[idx].WitnessUtxo diff --git a/lnd/aezeed.go b/lnd/aezeed.go index 5c45266..9c293bf 100644 --- a/lnd/aezeed.go +++ b/lnd/aezeed.go @@ -49,7 +49,7 @@ var ( ) func noConsole() ([]byte, error) { - return nil, fmt.Errorf("wallet db requires console access") + return nil, errors.New("wallet db requires console access") } // ReadAezeed reads an aezeed from the console or the environment variable. @@ -112,7 +112,7 @@ func ReadAezeed(params *chaincfg.Params) (*hdkeychain.ExtendedKey, time.Time, } rootKey, err := hdkeychain.NewMaster(cipherSeed.Entropy[:], params) if err != nil { - return nil, time.Unix(0, 0), fmt.Errorf("failed to derive " + + return nil, time.Unix(0, 0), errors.New("failed to derive " + "master extended key") } return rootKey, cipherSeed.BirthdayTime(), nil @@ -229,7 +229,7 @@ func OpenWallet(walletDbPath string, DefaultOpenTimeout, ) if errors.Is(err, bbolt.ErrTimeout) { - return nil, nil, nil, fmt.Errorf("error opening wallet " + + return nil, nil, nil, errors.New("error opening wallet " + "database, make sure lnd is not running and holding " + "the exclusive lock on the wallet") } diff --git a/lnd/brontide.go b/lnd/brontide.go index 5f073fc..9b45a48 100644 --- a/lnd/brontide.go +++ b/lnd/brontide.go @@ -1,6 +1,7 @@ package lnd import ( + "errors" "fmt" "os" "time" @@ -103,14 +104,14 @@ func ConnectPeer(conn *brontide.Conn, connReq *connmgr.ConnReq, gossiper := discovery.New(discovery.Config{ ChainHash: *netParams.GenesisHash, - Broadcast: func(skips map[route.Vertex]struct{}, - msg ...lnwire.Message) error { + Broadcast: func(_ map[route.Vertex]struct{}, + _ ...lnwire.Message) error { return nil }, NotifyWhenOnline: func([33]byte, chan<- lnpeer.Peer) { }, - NotifyWhenOffline: func(peerPubKey [33]byte) <-chan struct{} { + NotifyWhenOffline: func(_ [33]byte) <-chan struct{} { return make(chan struct{}) }, FetchSelfAnnouncement: func() lnwire.NodeAnnouncement { @@ -137,24 +138,24 @@ func ConnectPeer(conn *brontide.Conn, connReq *connmgr.ConnReq, SignAliasUpdate: func( *lnwire.ChannelUpdate) (*ecdsa.Signature, error) { - return nil, fmt.Errorf("unimplemented") + return nil, errors.New("unimplemented") }, FindBaseByAlias: func( lnwire.ShortChannelID) (lnwire.ShortChannelID, error) { return lnwire.ShortChannelID{}, - fmt.Errorf("unimplemented") + errors.New("unimplemented") }, - GetAlias: func(id lnwire.ChannelID) (lnwire.ShortChannelID, + GetAlias: func(_ lnwire.ChannelID) (lnwire.ShortChannelID, error) { return lnwire.ShortChannelID{}, - fmt.Errorf("unimplemented") + errors.New("unimplemented") }, FindChannel: func(*btcec.PublicKey, lnwire.ChannelID) (*channeldb.OpenChannel, error) { - return nil, fmt.Errorf("unimplemented") + return nil, errors.New("unimplemented") }, }, &keychain.KeyDescriptor{ KeyLocator: keychain.KeyLocator{}, @@ -181,22 +182,21 @@ func ConnectPeer(conn *brontide.Conn, connReq *connmgr.ConnReq, key.SerializeCompressed()) return nil }, - GenNodeAnnouncement: func( - modifier ...netann.NodeAnnModifier) ( + GenNodeAnnouncement: func(_ ...netann.NodeAnnModifier) ( lnwire.NodeAnnouncement, error) { return lnwire.NodeAnnouncement{}, - fmt.Errorf("unimplemented") + errors.New("unimplemented") }, PongBuf: pongBuf, - PrunePersistentPeerConnection: func(bytes [33]byte) {}, + PrunePersistentPeerConnection: func(_ [33]byte) {}, - FetchLastChanUpdate: func(id lnwire.ShortChannelID) ( + FetchLastChanUpdate: func(_ lnwire.ShortChannelID) ( *lnwire.ChannelUpdate, error) { - return nil, fmt.Errorf("unimplemented") + return nil, errors.New("unimplemented") }, Hodl: &hodl.Config{}, @@ -216,16 +216,14 @@ func ConnectPeer(conn *brontide.Conn, connReq *connmgr.ConnReq, return nil }, GetAliases: func( - base lnwire.ShortChannelID) []lnwire.ShortChannelID { + _ lnwire.ShortChannelID) []lnwire.ShortChannelID { return nil }, RequestAlias: func() (lnwire.ShortChannelID, error) { return lnwire.ShortChannelID{}, nil }, - AddLocalAlias: func(alias, base lnwire.ShortChannelID, - gossip bool) error { - + AddLocalAlias: func(_, _ lnwire.ShortChannelID, _ bool) error { return nil }, Quit: make(chan struct{}), diff --git a/lnd/chanbackup.go b/lnd/chanbackup.go index 21e130c..f0d73fe 100644 --- a/lnd/chanbackup.go +++ b/lnd/chanbackup.go @@ -58,8 +58,6 @@ func ExtractChannel(extendedKey *hdkeychain.ExtendedKey, channels := dump.BackupDump(multi, chainParams) for _, channel := range channels { - channel := channel - if channel.FundingOutpoint == channelPoint { return &channel, nil } diff --git a/lnd/channel.go b/lnd/channel.go index 160bb4f..18eb7ac 100644 --- a/lnd/channel.go +++ b/lnd/channel.go @@ -1,6 +1,7 @@ package lnd import ( + "errors" "fmt" "strconv" "strings" @@ -90,7 +91,7 @@ func (lc *LightningChannel) SignedCommitTx() (*wire.MsgTx, error) { func ParseOutpoint(s string) (*wire.OutPoint, error) { split := strings.Split(s, ":") if len(split) != 2 { - return nil, fmt.Errorf("expecting channel point to be in " + + return nil, errors.New("expecting channel point to be in " + "format of: txid:index") } diff --git a/lnd/hdkeychain.go b/lnd/hdkeychain.go index 51caeb4..fd95c17 100644 --- a/lnd/hdkeychain.go +++ b/lnd/hdkeychain.go @@ -2,6 +2,7 @@ package lnd import ( "crypto/sha256" + "errors" "fmt" "strconv" "strings" @@ -79,10 +80,10 @@ func DeriveChildren(key *hdkeychain.ExtendedKey, path []uint32) ( func ParsePath(path string) ([]uint32, error) { path = strings.TrimSpace(path) if len(path) == 0 { - return nil, fmt.Errorf("path cannot be empty") + return nil, errors.New("path cannot be empty") } if !strings.HasPrefix(path, "m/") { - return nil, fmt.Errorf("path must start with m/") + return nil, errors.New("path must start with m/") } parts := strings.Split(path, "/") indices := make([]uint32, len(parts)-1) @@ -250,7 +251,7 @@ func DecodeAddressHash(addr string, chainParams *chaincfg.Params) ([]byte, bool, targetHash = targetAddr.ScriptAddress() default: - return nil, false, fmt.Errorf("address: must be a bech32 " + + return nil, false, errors.New("address: must be a bech32 " + "P2WPKH or P2WSH address") } return targetHash, isScriptHash, nil @@ -589,7 +590,7 @@ func (r *HDKeyRing) CheckDescriptor( // A check doesn't make sense if there is no public key set. if keyDesc.PubKey == nil { - return fmt.Errorf("no public key provided to check") + return errors.New("no public key provided to check") } // Performance fix, derive static path only once. @@ -604,7 +605,7 @@ func (r *HDKeyRing) CheckDescriptor( } // Scan the same key range as lnd would do on channel restore. - for i := 0; i < keychain.MaxKeyRangeScan; i++ { + for i := range keychain.MaxKeyRangeScan { child, err := DeriveChildren(familyKey, []uint32{uint32(i)}) if err != nil { return err diff --git a/lnd/signer.go b/lnd/signer.go index 328eb67..2173a43 100644 --- a/lnd/signer.go +++ b/lnd/signer.go @@ -2,6 +2,7 @@ package lnd import ( "crypto/sha256" + "errors" "fmt" "github.com/btcsuite/btcd/btcec/v2" @@ -119,7 +120,7 @@ func (s *Signer) SignOutputRawWithPrivateKey(tx *wire.MsgTx, func (s *Signer) ComputeInputScript(_ *wire.MsgTx, _ *input.SignDescriptor) ( *input.Script, error) { - return nil, fmt.Errorf("unimplemented") + return nil, errors.New("unimplemented") } func (s *Signer) FetchPrivateKey(descriptor *keychain.KeyDescriptor) ( diff --git a/tools/Dockerfile b/tools/Dockerfile index 2af87c5..c85bb99 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.4-buster +FROM golang:1.22.3-bookworm RUN apt-get update && apt-get install -y git ENV GOCACHE=/tmp/build/.cache @@ -11,7 +11,7 @@ RUN cd /tmp \ && mkdir -p /tmp/build/.cache \ && mkdir -p /tmp/build/.modcache \ && cd /tmp/tools \ - && go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint \ + && go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 \ && chmod -R 777 /tmp/build/ WORKDIR /build