From b9ba1ec1c26a9b886b65e17181dc5897920f5969 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Sat, 28 Jan 2023 00:34:23 +0000 Subject: [PATCH] Linting. --- .golangci.yml | 170 ++++++++++++++++++ cmd/account.go | 2 +- cmd/accountkey.go | 2 +- cmd/attestation.go | 2 +- cmd/attester.go | 2 +- cmd/attester/inclusion/process.go | 5 +- cmd/block.go | 2 +- cmd/block/analyze/process.go | 4 +- cmd/chain.go | 2 +- .../signedcontributionandproof/process.go | 5 +- cmd/chainverify.go | 2 +- cmd/deposit.go | 2 +- cmd/depositverify.go | 2 +- cmd/epoch.go | 2 +- cmd/epoch/summary/process.go | 1 - cmd/err.go | 6 +- cmd/exit.go | 2 +- cmd/exitverify.go | 2 +- cmd/node.go | 2 +- cmd/proposer.go | 2 +- cmd/root.go | 2 +- cmd/signature.go | 2 +- cmd/signatureaggregate.go | 2 +- cmd/signaturesign.go | 2 +- cmd/signatureverify.go | 2 +- cmd/slot.go | 2 +- cmd/synccommittee.go | 2 +- cmd/validator.go | 2 +- cmd/validator/credentials/set/process.go | 1 - cmd/validator/duties/output.go | 1 - cmd/validator/yield/process.go | 1 - cmd/validatorcredentials.go | 2 +- cmd/validatordepositdata.go | 2 +- cmd/validatorduties.go | 2 +- cmd/validatorinfo.go | 16 +- cmd/version.go | 2 +- cmd/wallet.go | 2 +- services/chaintime/service.go | 1 + shamir/shamir.go | 10 +- shamir/tables.go | 4 +- util/attestations.go | 4 +- util/signing.go | 2 +- 42 files changed, 230 insertions(+), 55 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..7c5d64f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,170 @@ +# This file contains all available configuration options +# with their default values (in comments). +# +# This file is not a configuration example, +# it contains the exhaustive configuration with explanations of the options. + +# Options for analysis running. +run: + # The default concurrency value is the number of available CPU. + # concurrency: 4 + + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 10m + + # Exit code when at least one issue was found. + # Default: 1 + # issues-exit-code: 2 + + # Include test files or not. + # Default: true + tests: false + + # List of build tags, all linters use it. + # Default: []. + # build-tags: + # - mytag + + # Which dirs to skip: issues from them won't be reported. + # Can use regexp here: `generated.*`, regexp is applied on full path. + # Default value is empty list, + # but default dirs are skipped independently of this option's value (see skip-dirs-use-default). + # "/" will be replaced by current OS file path separator to properly work on Windows. + # skip-dirs: + # - autogenerated_by_my_lib + + # Enables skipping of directories: + # - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + # Default: true + # skip-dirs-use-default: false + + # Which files to skip: they will be analyzed, but issues from them won't be reported. + # Default value is empty list, + # but there is no need to include all autogenerated files, + # we confidently recognize autogenerated files. + # If it's not please let us know. + # "/" will be replaced by current OS file path separator to properly work on Windows. + skip-files: + - ".*_ssz\\.go$" + + # If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + # + # Allowed values: readonly|vendor|mod + # By default, it isn't set. + modules-download-mode: readonly + + # Allow multiple parallel golangci-lint instances running. + # If false (default) - golangci-lint acquires file lock on start. + allow-parallel-runners: true + + # Define the Go version limit. + # Mainly related to generics support since go1.18. + # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18 + go: '1.19' + + +# output configuration options +output: + # Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions + # + # Multiple can be specified by separating them by comma, output can be provided + # for each of them by separating format name and path by colon symbol. + # Output path can be either `stdout`, `stderr` or path to the file to write to. + # Example: "checkstyle:report.json,colored-line-number" + # + # Default: colored-line-number + # format: json + + # Print lines of code with issue. + # Default: true + # print-issued-lines: false + + # Print linter name in the end of issue text. + # Default: true + # print-linter-name: false + + # Make issues output unique by line. + # Default: true + # uniq-by-line: false + + # Add a prefix to the output file references. + # Default is no prefix. + # path-prefix: "" + + # Sort results by: filepath, line and column. + # sort-results: true + + +# All available settings of specific linters. +linters-settings: + lll: + line-length: 132 + + stylecheck: + checks: [ "all", "-ST1000" ] + + tagliatelle: + case: + # use-field-name: true + rules: + json: snake + yaml: snake + +linters: + # Enable all available linters. + # Default: false + enable-all: true + # Disable specific linter + # https://golangci-lint.run/usage/linters/#disabled-by-default + disable: + - contextcheck + - cyclop + - deadcode + - dupl + - errorlint + - exhaustive + - exhaustivestruct + - exhaustruct + - forbidigo + - forcetypeassert + - funlen + - gci + - gochecknoglobals + - gochecknoinits + - gocognit + - goconst + - goerr113 + - gofumpt + - goheader + - golint + - gomnd + - ifshort + - interfacer + - ireturn + - lll + - maintidx + - maligned + - nestif + - nilnil + - nlreturn + - nolintlint + - nosnakecase + - promlinter + - rowserrcheck + - scopelint + - sqlclosecheck + - structcheck + - unparam + - varcheck + - varnamelen + - wastedassign + - wrapcheck + - wsl diff --git a/cmd/account.go b/cmd/account.go index 762c979..fad5dd9 100644 --- a/cmd/account.go +++ b/cmd/account.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// accountCmd represents the account command +// accountCmd represents the account command. var accountCmd = &cobra.Command{ Use: "account", Short: "Manage account", diff --git a/cmd/accountkey.go b/cmd/accountkey.go index 9d3b3c0..b3ebc6c 100644 --- a/cmd/accountkey.go +++ b/cmd/accountkey.go @@ -21,7 +21,7 @@ import ( accountkey "github.com/wealdtech/ethdo/cmd/account/key" ) -// accountKeyCmd represents the account key command +// accountKeyCmd represents the account key command. var accountKeyCmd = &cobra.Command{ Use: "key", Short: "Obtain the private key of an account.", diff --git a/cmd/attestation.go b/cmd/attestation.go index 0efe437..0953829 100644 --- a/cmd/attestation.go +++ b/cmd/attestation.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// attestationCmd represents the attestation command +// attestationCmd represents the attestation command. var attestationCmd = &cobra.Command{ Use: "attestation", Short: "Obtain information about an Ethereum 2 attestation", diff --git a/cmd/attester.go b/cmd/attester.go index 5c07f6f..244aefd 100644 --- a/cmd/attester.go +++ b/cmd/attester.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// attesterCmd represents the attester command +// attesterCmd represents the attester command. var attesterCmd = &cobra.Command{ Use: "attester", Short: "Obtain information about Ethereum 2 attesters", diff --git a/cmd/attester/inclusion/process.go b/cmd/attester/inclusion/process.go index f3e7223..e6654ff 100644 --- a/cmd/attester/inclusion/process.go +++ b/cmd/attester/inclusion/process.go @@ -100,7 +100,6 @@ func process(ctx context.Context, data *dataIn) (*dataOut, error) { if attestation.Data.Slot == duty.Slot && attestation.Data.Index == duty.CommitteeIndex && attestation.AggregationBits.BitAt(duty.ValidatorCommitteeIndex) { - headCorrect := false targetCorrect := false if data.verbose { @@ -138,7 +137,7 @@ func calcHeadCorrect(ctx context.Context, data *dataIn, attestation *phase0.Atte for { header, err := data.eth2Client.(eth2client.BeaconBlockHeadersProvider).BeaconBlockHeader(ctx, fmt.Sprintf("%d", slot)) if err != nil { - return false, nil + return false, err } if header == nil { // No block. @@ -160,7 +159,7 @@ func calcTargetCorrect(ctx context.Context, data *dataIn, attestation *phase0.At for { header, err := data.eth2Client.(eth2client.BeaconBlockHeadersProvider).BeaconBlockHeader(ctx, fmt.Sprintf("%d", slot)) if err != nil { - return false, nil + return false, err } if header == nil { // No block. diff --git a/cmd/block.go b/cmd/block.go index 3532e11..0f11312 100644 --- a/cmd/block.go +++ b/cmd/block.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// blockCmd represents the block command +// blockCmd represents the block command. var blockCmd = &cobra.Command{ Use: "block", Short: "Obtain information about an Ethereum 2 block", diff --git a/cmd/block/analyze/process.go b/cmd/block/analyze/process.go index 4c25542..c82e7a0 100644 --- a/cmd/block/analyze/process.go +++ b/cmd/block/analyze/process.go @@ -363,7 +363,7 @@ func (c *command) calcHeadCorrect(ctx context.Context, attestation *phase0.Attes for { header, err := c.blockHeadersProvider.BeaconBlockHeader(ctx, fmt.Sprintf("%d", slot)) if err != nil { - return false, nil + return false, err } if header == nil { // No block. @@ -392,7 +392,7 @@ func (c *command) calcTargetCorrect(ctx context.Context, attestation *phase0.Att for { header, err := c.blockHeadersProvider.BeaconBlockHeader(ctx, fmt.Sprintf("%d", slot)) if err != nil { - return false, nil + return false, err } if header == nil { // No block. diff --git a/cmd/chain.go b/cmd/chain.go index e3a8c67..5a56fb3 100644 --- a/cmd/chain.go +++ b/cmd/chain.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// chainCmd represents the chain command +// chainCmd represents the chain command. var chainCmd = &cobra.Command{ Use: "chain", Short: "Obtain information about an Ethereum 2 chain", diff --git a/cmd/chain/verify/signedcontributionandproof/process.go b/cmd/chain/verify/signedcontributionandproof/process.go index dfc683e..5fcb146 100644 --- a/cmd/chain/verify/signedcontributionandproof/process.go +++ b/cmd/chain/verify/signedcontributionandproof/process.go @@ -38,6 +38,7 @@ func (c *command) process(ctx context.Context) error { err := json.Unmarshal([]byte(c.data), c.item) if err != nil { c.additionalInfo = err.Error() + //nolint:nilerr return nil } c.itemStructureValid = true @@ -124,7 +125,7 @@ func (c *command) setup(ctx context.Context) error { return nil } -// isAggregator returns true if the given +// isAggregator returns true if the given. func (c *command) isAggregator(ctx context.Context) (bool, error) { // Calculate the modulo. specProvider, isProvider := c.eth2Client.(eth2client.SpecProvider) @@ -204,6 +205,7 @@ func (c *command) confirmContributionSignature(ctx context.Context) error { _, err := e2types.BLSSignatureFromBytes(sigBytes) if err != nil { c.additionalInfo = err.Error() + //nolint:nilerr return nil } c.contributionSignatureValidFormat = true @@ -256,6 +258,7 @@ func (c *command) confirmContributionAndProofSignature(ctx context.Context) erro sig, err := e2types.BLSSignatureFromBytes(sigBytes) if err != nil { c.additionalInfo = err.Error() + //nolint:nilerr return nil } c.contributionAndProofSignatureValidFormat = true diff --git a/cmd/chainverify.go b/cmd/chainverify.go index 71f0030..b23f43f 100644 --- a/cmd/chainverify.go +++ b/cmd/chainverify.go @@ -18,7 +18,7 @@ import ( "github.com/spf13/viper" ) -// chainVerifyCmd represents the chain verify command +// chainVerifyCmd represents the chain verify command. var chainVerifyCmd = &cobra.Command{ Use: "verify", Short: "Verify a beacon chain signature", diff --git a/cmd/deposit.go b/cmd/deposit.go index 4717fd8..2fce72e 100644 --- a/cmd/deposit.go +++ b/cmd/deposit.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// depositCmd represents the deposit command +// depositCmd represents the deposit command. var depositCmd = &cobra.Command{ Use: "deposit", Short: "Manage Ethereum 2 deposits", diff --git a/cmd/depositverify.go b/cmd/depositverify.go index 89f5632..d4449d1 100644 --- a/cmd/depositverify.go +++ b/cmd/depositverify.go @@ -45,7 +45,7 @@ var depositVerifyCmd = &cobra.Command{ The deposit data is compared to the supplied withdrawal account/public key, validator public key, and value to ensure they match. -In quiet mode this will return 0 if the the data is verified correctly, otherwise 1.`, +In quiet mode this will return 0 if the data is verified correctly, otherwise 1.`, Run: func(cmd *cobra.Command, args []string) { assert(depositVerifyData != "", "--data is required") var data []byte diff --git a/cmd/epoch.go b/cmd/epoch.go index 80db1e4..37f43c7 100644 --- a/cmd/epoch.go +++ b/cmd/epoch.go @@ -18,7 +18,7 @@ import ( "github.com/spf13/viper" ) -// epochCmd represents the epoch command +// epochCmd represents the epoch command. var epochCmd = &cobra.Command{ Use: "epoch", Short: "Obtain information about Ethereum 2 epochs", diff --git a/cmd/epoch/summary/process.go b/cmd/epoch/summary/process.go index 8f45dcb..c88b9dc 100644 --- a/cmd/epoch/summary/process.go +++ b/cmd/epoch/summary/process.go @@ -202,7 +202,6 @@ func (c *command) processSlots(ctx context.Context, Slot: beaconCommittee.Slot, Committee: beaconCommittee.Index, } - } } slotCommittees = allCommittees[attestation.Data.Slot] diff --git a/cmd/err.go b/cmd/err.go index a53574d..062a334 100644 --- a/cmd/err.go +++ b/cmd/err.go @@ -18,7 +18,7 @@ import ( "os" ) -// errCheck checks for an error and quits if it is present +// errCheck checks for an error and quits if it is present. func errCheck(err error, msg string) { if err != nil { if !quiet { @@ -48,14 +48,14 @@ func errCheck(err error, msg string) { // } // } -// assert checks a condition and quits if it is false +// assert checks a condition and quits if it is false. func assert(condition bool, msg string) { if !condition { die(msg) } } -// die prints an error and quits +// die prints an error and quits. func die(msg string) { if msg != "" && !quiet { fmt.Fprintf(os.Stderr, "%s\n", msg) diff --git a/cmd/exit.go b/cmd/exit.go index 02d5bb7..e71ddbc 100644 --- a/cmd/exit.go +++ b/cmd/exit.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// exitCmd represents the exit command +// exitCmd represents the exit command. var exitCmd = &cobra.Command{ Use: "exit", Short: "Manage Ethereum 2 voluntary exits", diff --git a/cmd/exitverify.go b/cmd/exitverify.go index 2b36bf5..237deb1 100644 --- a/cmd/exitverify.go +++ b/cmd/exitverify.go @@ -41,7 +41,7 @@ var exitVerifyCmd = &cobra.Command{ ethdo exit verify --data=exitdata.json --account=primary/current -In quiet mode this will return 0 if the the exit is verified correctly, otherwise 1.`, +In quiet mode this will return 0 if the exit is verified correctly, otherwise 1.`, Run: func(cmd *cobra.Command, args []string) { ctx := context.Background() diff --git a/cmd/node.go b/cmd/node.go index e977535..980d5ef 100644 --- a/cmd/node.go +++ b/cmd/node.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// nodeCmd represents the node command +// nodeCmd represents the node command. var nodeCmd = &cobra.Command{ Use: "node", Short: "Obtain information about an Ethereum 2 node", diff --git a/cmd/proposer.go b/cmd/proposer.go index 9a34021..ffc5066 100644 --- a/cmd/proposer.go +++ b/cmd/proposer.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// proposerCmd represents the proposer command +// proposerCmd represents the proposer command. var proposerCmd = &cobra.Command{ Use: "proposer", Short: "Obtain information about Ethereum 2 proposers", diff --git a/cmd/root.go b/cmd/root.go index cc2aace..8efb163 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -38,7 +38,7 @@ var quiet bool var verbose bool var debug bool -// RootCmd represents the base command when called without any subcommands +// RootCmd represents the base command when called without any subcommands. var RootCmd = &cobra.Command{ Use: "ethdo", Short: "Ethereum 2 CLI", diff --git a/cmd/signature.go b/cmd/signature.go index f33a87f..ff8c1e2 100644 --- a/cmd/signature.go +++ b/cmd/signature.go @@ -19,7 +19,7 @@ import ( "github.com/spf13/viper" ) -// signatureCmd represents the signature command +// signatureCmd represents the signature command. var signatureCmd = &cobra.Command{ Use: "signature", Aliases: []string{"sig"}, diff --git a/cmd/signatureaggregate.go b/cmd/signatureaggregate.go index 71b7941..db27eb7 100644 --- a/cmd/signatureaggregate.go +++ b/cmd/signatureaggregate.go @@ -28,7 +28,7 @@ import ( var signatureAggregateSignatures []string -// signatureAggregateCmd represents the signature aggregate command +// signatureAggregateCmd represents the signature aggregate command. var signatureAggregateCmd = &cobra.Command{ Use: "aggregate", Short: "Aggregate signatures", diff --git a/cmd/signaturesign.go b/cmd/signaturesign.go index 90256d2..29f3cbb 100644 --- a/cmd/signaturesign.go +++ b/cmd/signaturesign.go @@ -27,7 +27,7 @@ import ( e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2" ) -// signatureSignCmd represents the signature sign command +// signatureSignCmd represents the signature sign command. var signatureSignCmd = &cobra.Command{ Use: "sign", Short: "Sign a 32-byte piece of data", diff --git a/cmd/signatureverify.go b/cmd/signatureverify.go index 2af0d2c..35f52a8 100644 --- a/cmd/signatureverify.go +++ b/cmd/signatureverify.go @@ -30,7 +30,7 @@ import ( var signatureVerifySignature string var signatureVerifySigner string -// signatureVerifyCmd represents the signature verify command +// signatureVerifyCmd represents the signature verify command. var signatureVerifyCmd = &cobra.Command{ Use: "verify", Short: "Verify signed data", diff --git a/cmd/slot.go b/cmd/slot.go index 8797b83..98d342b 100644 --- a/cmd/slot.go +++ b/cmd/slot.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// slotCmd represents the slot command +// slotCmd represents the slot command. var slotCmd = &cobra.Command{ Use: "slot", Short: "Obtain information about an Ethereum 2 slot", diff --git a/cmd/synccommittee.go b/cmd/synccommittee.go index 7e085f1..a4b54bd 100644 --- a/cmd/synccommittee.go +++ b/cmd/synccommittee.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// synccommitteeCmd represents the synccommittee command +// synccommitteeCmd represents the synccommittee command. var synccommitteeCmd = &cobra.Command{ Use: "synccommittee", Short: "Obtain information about Ethereum 2 sync committees", diff --git a/cmd/validator.go b/cmd/validator.go index 41fbc4a..c994702 100644 --- a/cmd/validator.go +++ b/cmd/validator.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// validatorCmd represents the validator command +// validatorCmd represents the validator command. var validatorCmd = &cobra.Command{ Use: "validator", Short: "Manage Ethereum 2 validators", diff --git a/cmd/validator/credentials/set/process.go b/cmd/validator/credentials/set/process.go index da4e6fc..b76d9bd 100644 --- a/cmd/validator/credentials/set/process.go +++ b/cmd/validator/credentials/set/process.go @@ -426,7 +426,6 @@ func (c *command) generateOperationFromSeedAndPath(ctx context.Context, if err != nil { return false, errors.Wrap(err, "failed to create withdrawal account") } - } else { // Need the withdrawal credentials from the private key. withdrawalAccount, err = util.ParseAccount(ctx, c.privateKey, nil, true) diff --git a/cmd/validator/duties/output.go b/cmd/validator/duties/output.go index 9bbd4c1..a6e674b 100644 --- a/cmd/validator/duties/output.go +++ b/cmd/validator/duties/output.go @@ -65,7 +65,6 @@ func output(ctx context.Context, data *dataOut) (string, error) { } else { builder.WriteString("\n") } - } } diff --git a/cmd/validator/yield/process.go b/cmd/validator/yield/process.go index 6ee8825..b4507f1 100644 --- a/cmd/validator/yield/process.go +++ b/cmd/validator/yield/process.go @@ -46,7 +46,6 @@ var epochsPerYear = decimal.New(225*365, 0) // calculateYield calculates yield from the number of active validators. func (c *command) calculateYield(ctx context.Context) error { - spec, err := c.eth2Client.(eth2client.SpecProvider).Spec(ctx) if err != nil { return err diff --git a/cmd/validatorcredentials.go b/cmd/validatorcredentials.go index d78452d..9ca85ac 100644 --- a/cmd/validatorcredentials.go +++ b/cmd/validatorcredentials.go @@ -17,7 +17,7 @@ import ( "github.com/spf13/cobra" ) -// validatorCredentialsCmd represents the validator credentials command +// validatorCredentialsCmd represents the validator credentials command. var validatorCredentialsCmd = &cobra.Command{ Use: "credentials", Short: "Manage Ethereum consensus validator credentials", diff --git a/cmd/validatordepositdata.go b/cmd/validatordepositdata.go index 541d3cd..e25d72d 100644 --- a/cmd/validatordepositdata.go +++ b/cmd/validatordepositdata.go @@ -32,7 +32,7 @@ If validatoraccount is provided with an account path it will generate deposit da The information generated can be passed to ethereal to create a deposit from the Ethereum 1 chain. -In quiet mode this will return 0 if the the data can be generated correctly, otherwise 1.`, +In quiet mode this will return 0 if the data can be generated correctly, otherwise 1.`, RunE: func(cmd *cobra.Command, args []string) error { res, err := validatordepositdata.Run(cmd) if err != nil { diff --git a/cmd/validatorduties.go b/cmd/validatorduties.go index dbeaae8..deb8b82 100644 --- a/cmd/validatorduties.go +++ b/cmd/validatorduties.go @@ -30,7 +30,7 @@ var validatorDutiesCmd = &cobra.Command{ Attester duties are known for the current and next epoch. Proposer duties are known for the current epoch. -In quiet mode this will return 0 if the the duties have been obtained, otherwise 1.`, +In quiet mode this will return 0 if the duties have been obtained, otherwise 1.`, RunE: func(cmd *cobra.Command, args []string) error { res, err := validatorduties.Run(cmd) if err != nil { diff --git a/cmd/validatorinfo.go b/cmd/validatorinfo.go index eb4e0d4..2c27781 100644 --- a/cmd/validatorinfo.go +++ b/cmd/validatorinfo.go @@ -109,7 +109,7 @@ In quiet mode this will return 0 if the validator information can be obtained, o }, } -// graphData returns data from the graph about number and amount of deposits +// graphData returns data from the graph about number and amount of deposits. func graphData(network string, validatorPubKey []byte) (uint64, spec.Gwei, error) { subgraph := "" if network == "Mainnet" { @@ -119,8 +119,12 @@ func graphData(network string, validatorPubKey []byte) (uint64, spec.Gwei, error } query := fmt.Sprintf(`{"query": "{deposits(where: {validatorPubKey:\"%#x\"}) { id amount withdrawalCredentials }}"}`, validatorPubKey) url := fmt.Sprintf("https://api.thegraph.com/subgraphs/name/%s", subgraph) - // #nosec G107 - graphResp, err := http.Post(url, "application/json", bytes.NewBufferString(query)) + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, bytes.NewBufferString(query)) + if err != nil { + return 0, 0, errors.Wrap(err, "failed to start request") + } + req.Header.Set("Accept", "application/json") + graphResp, err := http.DefaultClient.Do(req) if err != nil { return 0, 0, errors.Wrap(err, "failed to check if there is already a deposit for this validator") } @@ -131,8 +135,10 @@ func graphData(network string, validatorPubKey []byte) (uint64, spec.Gwei, error } type graphDeposit struct { - Index string `json:"index"` - Amount string `json:"amount"` + Index string `json:"index"` + Amount string `json:"amount"` + // Using graph API JSON names in camel case. + //nolint:tagliatelle WithdrawalCredentials string `json:"withdrawalCredentials"` } type graphData struct { diff --git a/cmd/version.go b/cmd/version.go index d4d9447..c7dbcd2 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -26,7 +26,7 @@ import ( // Usually overridden by tag names when building binaries. var ReleaseVersion = "local build (latest release 1.27.1)" -// versionCmd represents the version command +// versionCmd represents the version command. var versionCmd = &cobra.Command{ Use: "version", Short: "Version of ethdo", diff --git a/cmd/wallet.go b/cmd/wallet.go index 67455af..98d349f 100644 --- a/cmd/wallet.go +++ b/cmd/wallet.go @@ -19,7 +19,7 @@ import ( "github.com/spf13/viper" ) -// walletCmd represents the wallet command +// walletCmd represents the wallet command. var walletCmd = &cobra.Command{ Use: "wallet", Short: "Manage wallets", diff --git a/services/chaintime/service.go b/services/chaintime/service.go index 6934f0d..3fc1490 100644 --- a/services/chaintime/service.go +++ b/services/chaintime/service.go @@ -20,6 +20,7 @@ import ( ) // Service provides a number of functions for calculating chain-related times. +//nolint:interfacebloat type Service interface { // GenesisTime provides the time of the chain's genesis. GenesisTime() time.Time diff --git a/shamir/shamir.go b/shamir/shamir.go index 5b50bb2..dc1545a 100644 --- a/shamir/shamir.go +++ b/shamir/shamir.go @@ -15,7 +15,7 @@ const ( ShareOverhead = 1 ) -// polynomial represents a polynomial of arbitrary degree +// polynomial represents a polynomial of arbitrary degree. type polynomial struct { coefficients []uint8 } @@ -53,7 +53,7 @@ func makePolynomial(intercept, degree uint8) (polynomial, error) { return p, nil } -// evaluate returns the value of the polynomial for the given x +// evaluate returns the value of the polynomial for the given x. func (p *polynomial) evaluate(x uint8) uint8 { // Special case the origin if x == 0 { @@ -92,7 +92,7 @@ func interpolatePolynomial(xSamples, ySamples []uint8, x uint8) uint8 { return result } -// div divides two numbers in GF(2^8) +// div divides two numbers in GF(2^8). func div(a, b uint8) uint8 { if b == 0 { // leaks some timing information but we don't care anyways as this @@ -111,8 +111,8 @@ func div(a, b uint8) uint8 { return uint8(ret) } -// mult multiplies two numbers in GF(2^8) -func mult(a, b uint8) (out uint8) { +// mult multiplies two numbers in GF(2^8). +func mult(a, b uint8) uint8 { logA := logTable[a] logB := logTable[b] sum := (int(logA) + int(logB)) % 255 diff --git a/shamir/tables.go b/shamir/tables.go index 07ec4e5..724b316 100644 --- a/shamir/tables.go +++ b/shamir/tables.go @@ -4,7 +4,7 @@ package shamir // They use 0xe5 (229) as the generator var ( - // logTable provides the log(X)/log(g) at each index X + // logTable provides the log(X)/log(g) at each index X. logTable = [256]uint8{ 0x00, 0xff, 0xc8, 0x08, 0x91, 0x10, 0xd0, 0x36, 0x5a, 0x3e, 0xd8, 0x43, 0x99, 0x77, 0xfe, 0x18, @@ -41,7 +41,7 @@ var ( } // expTable provides the anti-log or exponentiation value - // for the equivalent index + // for the equivalent index. expTable = [256]uint8{ 0x01, 0xe5, 0x4c, 0xb5, 0xfb, 0x9f, 0xfc, 0x12, 0x03, 0x34, 0xd4, 0xc4, 0x16, 0xba, 0x1f, 0x36, diff --git a/util/attestations.go b/util/attestations.go index 5c95ec6..c73da84 100644 --- a/util/attestations.go +++ b/util/attestations.go @@ -33,7 +33,7 @@ func AttestationHeadCorrect(ctx context.Context, for { header, err := headersCache.Fetch(ctx, slot) if err != nil { - return false, nil + return false, err } if header == nil { // No block. @@ -63,7 +63,7 @@ func AttestationTargetCorrect(ctx context.Context, for { header, err := headersCache.Fetch(ctx, slot) if err != nil { - return false, nil + return false, err } if header == nil { // No block. diff --git a/util/signing.go b/util/signing.go index 34cf247..0e29e5e 100644 --- a/util/signing.go +++ b/util/signing.go @@ -24,7 +24,7 @@ import ( e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2" ) -// SignRoot signs the hash tree root of a data structure +// SignRoot signs the hash tree root of a data structure. func SignRoot(account e2wtypes.Account, root spec.Root, domain spec.Domain) (e2types.Signature, error) { if _, isProtectingSigner := account.(e2wtypes.AccountProtectingSigner); isProtectingSigner { // Signer builds the signing data.