Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint #121

Merged
merged 4 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: golangci_lint

on:
push:

jobs:
golang_lint:
name: Golang Lint
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@f25a3a9f25bd5f4c5d77189cab02ff357b5aedeb # v2.4.1
- uses: smartcontractkit/[email protected]
id: tool-versions
- name: Setup go ${{ steps.tool-versions.outputs.golang_version }}
uses: actions/setup-go@v2
with:
go-version: ${{ steps.tool-versions.outputs.golang_version }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v${{ steps.tool-versions.outputs.golangci-lint_version }}

# Optional: working directory, useful for monorepos
working-directory: relayer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include all Go modules in the monorepo: golangci/golangci-lint#828 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted GH Issue: #122 (not blocking)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use matrix args or something even more automated to repeat for each module?


# Optional: golangci-lint command line arguments.
args: --enable=gofmt --tests=false --exclude-use-default

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
83 changes: 83 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
run:
timeout: 10m0s
linters:
enable:
- exhaustive
- exportloopref
- revive
- goimports
- gosec
- misspell
- rowserrcheck
- errorlint
linters-settings:
exhaustive:
default-signifies-exhaustive: true
goimports:
local-prefixes: github.com/smartcontractkit/chainlink-starknet
golint:
min-confidence: 1.0
gosec:
excludes:
- G101
- G104
# - G204
# - G304
# - G404
govet:
# report about shadowed variables
check-shadowing: true
errorlint:
# Allow formatting of errors without %w
errorf: false
revive:
confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: if-return
- name: increment-decrement
# - name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
# - name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
# - name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: waitgroup-by-value
- name: unconditional-recursion
- name: struct-tag
# - name: string-format
- name: string-of-int
# - name: range-val-address
- name: range-val-in-closure
- name: modifies-value-receiver
- name: modifies-parameter
- name: identical-branches
- name: get-return
# - name: flag-parameter
# - name: early-return
- name: defer
- name: constant-logical-expr
# - name: confusing-naming
# - name: confusing-results
- name: bool-literal-in-expr
- name: atomic
issues:
exclude-rules:
- path: test
text: "^G404:"
linters:
- gosec
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python 3.9.13
# Tools
ginkgo 2.1.3
mockery 2.13.0-beta.1
golangci-lint 1.45.2
golangci-lint 1.49.0
actionlint 1.6.12
shellcheck 0.8.0

Expand Down
1 change: 1 addition & 0 deletions relayer/pkg/chainlink/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/smartcontractkit/chainlink-relay/pkg/types"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/db"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/txm"
Expand Down
1 change: 1 addition & 0 deletions relayer/pkg/chainlink/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/smartcontractkit/chainlink-relay/pkg/logger"
"github.com/smartcontractkit/chainlink-relay/pkg/utils"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/db"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/txm"
Expand Down
3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/keys/mocks/keystore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/keys/ocr2key.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2/medianreport"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"

"github.com/smartcontractkit/libocr/offchainreporting2/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
)
Expand Down Expand Up @@ -38,7 +39,7 @@ func ReportToSigData(reportCtx ocrtypes.ReportContext, report ocrtypes.Report) (
dataArray = append(dataArray, new(big.Int).SetBytes(rawReportContext[1][:]))
dataArray = append(dataArray, new(big.Int).SetBytes(starknet.EnsureFelt(rawReportContext[2]))) // convert 32 byte extraHash to 31 bytes

// split report into seperate felts for hashing
// split report into separate felts for hashing
splitReport, err := medianreport.SplitReport(report)
if err != nil {
return &big.Int{}, err
Expand Down
1 change: 1 addition & 0 deletions relayer/pkg/chainlink/keys/ocr2key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestStarkNetKeyring_TestVector(t *testing.T) {

// check that report hash matches expected
msg, err := ReportToSigData(ctx, report)
require.NoError(t, err)

expected, err := caigo.HexToBytes("0x1332a8dabaabef63b03438ca50760cb9f5c0292cbf015b2395e50e6157df4e3")
require.NoError(t, err)
Expand Down
4 changes: 4 additions & 0 deletions relayer/pkg/chainlink/keys/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/NethermindEth/juno/pkg/crypto/pedersen"
"github.com/dontpanicdao/caigo"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
)

Expand Down Expand Up @@ -50,6 +51,9 @@ func GenerateKey(material io.Reader) (k Key, err error) {
}

k.pub.X, k.pub.Y, err = caigo.Curve.PrivateToPoint(k.priv)
if err != nil {
return k, err
}

if !caigo.Curve.IsOnCurve(k.pub.X, k.pub.Y) {
return k, fmt.Errorf("key gen is not on stark curve")
Expand Down
3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/ocr2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/pkg/errors"

caigotypes "github.com/dontpanicdao/caigo/types"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"

"github.com/smartcontractkit/chainlink-relay/pkg/logger"
)

Expand Down
3 changes: 1 addition & 2 deletions relayer/pkg/chainlink/ocr2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
"os"
"testing"
"time"

caigo "github.com/dontpanicdao/caigo"
"github.com/dontpanicdao/caigo/gateway"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-relay/pkg/logger"

"github.com/smartcontractkit/chainlink-starknet/ops"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/keys"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
Expand Down
3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/ocr2/config_digester.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (

"github.com/NethermindEth/juno/pkg/crypto/pedersen"

"github.com/smartcontractkit/libocr/offchainreporting2/types"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2/medianreport"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
)

// TODO: use libocr constant
Expand Down
5 changes: 3 additions & 2 deletions relayer/pkg/chainlink/ocr2/config_digester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"strings"
"testing"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
)

var testConfig = types.ContractConfig{
Expand Down
3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/ocr2/contract_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package ocr2

import (
"context"
"github.com/pkg/errors"
"math/big"
"time"

"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-relay/pkg/logger"
"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
Expand Down
37 changes: 19 additions & 18 deletions relayer/pkg/chainlink/ocr2/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

caigotypes "github.com/dontpanicdao/caigo/types"

"github.com/smartcontractkit/libocr/offchainreporting2/types"

"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2/medianreport"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
)

var (
Expand Down Expand Up @@ -46,24 +47,24 @@ func ParseNewTransmissionEvent(eventData []*caigotypes.Felt) (NewTransmissionEve
roundId := uint32(eventData[index].Uint64())

// answer
index += 1
index++
latestAnswer := starknet.HexToSignedBig(eventData[index].String())

// transmitter
index += 1
index++
transmitter := eventData[index]

// observation_timestamp
index += 1
index++
unixTime := eventData[index].Int64()
latestTimestamp := time.Unix(unixTime, 0)

// observers (raw) max 31
index += 1
index++
observersRaw := starknet.PadBytes(eventData[index].Big().Bytes(), MaxObservers)

// observation_len
index += 1
index++
observationsLen := uint32(eventData[index].Uint64())

// observers (based on observationsLen)
Expand All @@ -83,22 +84,22 @@ func ParseNewTransmissionEvent(eventData []*caigotypes.Felt) (NewTransmissionEve
juelsPerFeeCoin := eventData[index].Big()

// juels_per_fee_coin
index += 1
index++
gasPrice := eventData[index].Big()

// config digest
index += 1
index++
digest, err := types.BytesToConfigDigest(starknet.PadBytes(eventData[index].Bytes(), len(types.ConfigDigest{})))
if err != nil {
return NewTransmissionEvent{}, errors.Wrap(err, "couldn't convert bytes to ConfigDigest")
}

// epoch_and_round
index += 1
index++
epoch, round := parseEpochAndRound(eventData[index].Big())

// reimbursement
index += 1
index++
reimbursement := eventData[index].Big()

return NewTransmissionEvent{
Expand All @@ -124,22 +125,22 @@ func ParseConfigSetEvent(eventData []*caigotypes.Felt) (types.ContractConfig, er
// previous_config_block_number - skip

// latest_config_digest
index += 1
index++
digest, err := types.BytesToConfigDigest(starknet.PadBytes(eventData[index].Bytes(), len(types.ConfigDigest{})))
if err != nil {
return types.ContractConfig{}, errors.Wrap(err, "couldn't convert bytes to ConfigDigest")
}

// config_count
index += 1
index++
configCount := eventData[index].Uint64()

// oracles_len
index += 1
index++
oraclesLen := eventData[index].Uint64()

// oracles
index += 1
index++
oracleMembers := eventData[index:(index + int(oraclesLen)*2)]
var signers []types.OnchainPublicKey
var transmitters []types.Account
Expand All @@ -156,11 +157,11 @@ func ParseConfigSetEvent(eventData []*caigotypes.Felt) (types.ContractConfig, er
f := eventData[index].Uint64()

// onchain_config length
index += 1
index++
onchainConfigLen := eventData[index].Uint64()

// onchain_config (version=1, min, max)
index += 1
index++
onchainConfigFelts := eventData[index:(index + int(onchainConfigLen))]
onchainConfig, err := medianreport.OnchainConfigCodec{}.EncodeFromFelt(
onchainConfigFelts[0].Big(),
Expand All @@ -176,11 +177,11 @@ func ParseConfigSetEvent(eventData []*caigotypes.Felt) (types.ContractConfig, er
offchainConfigVersion := eventData[index].Uint64()

// offchain_config_len
index += 1
index++
offchainConfigLen := eventData[index].Uint64()

// offchain_config
index += 1
index++
offchainConfigFelts := eventData[index:(index + int(offchainConfigLen))]
// todo: get rid of caigoToJuno workaround
offchainConfig, err := starknet.DecodeFelts(starknet.FeltsToBig(offchainConfigFelts))
Expand Down
Loading