From 98d6a8a47021e527f04b370fc02f669ebe71d2ec Mon Sep 17 00:00:00 2001 From: Tyler Ruppert <{ID}+{username}@users.noreply.github.com> Date: Thu, 1 Jun 2023 07:25:04 -0600 Subject: [PATCH 1/6] Linting and formatting * Adding the github actions to lint and fmt on each PR * Initial linting changes * Initial formatting changes --- .github/workflows/ci-test.yml | 14 ++++ .golangci.yml | 16 ++++- chain/evm/client.go | 5 +- chain/evm/client_test.go | 1 - chain/evm/compass.go | 4 -- chain/evm/compass_test.go | 6 +- chain/evm/factory.go | 1 - chain/evm/health_check_test.go | 1 - chain/evm/processor.go | 1 - chain/paloma/client.go | 7 +- chain/paloma/client_test.go | 10 +-- chain/paloma/collision/zero_collision.go | 3 +- chain/paloma/wrappers.go | 4 +- cmd/pigeon/cmd_config.go | 3 +- cmd/pigeon/cmd_health_check_verify.go | 20 +++--- cmd/pigeon/cmd_init.go | 75 ++++++++++----------- cmd/pigeon/cmd_root.go | 32 +++++---- cmd/pigeon/cmd_start.go | 84 ++++++++++++------------ cmd/pigeon/cmd_version.go | 21 +++--- config/config.go | 1 - health/server.go | 1 - health/wait_for_chain_test.go | 2 - relayer/health_check.go | 5 +- relayer/health_check_test.go | 5 +- relayer/process.go | 1 - relayer/relayer.go | 2 +- util/slice/all.go | 1 - 27 files changed, 159 insertions(+), 167 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index c68feb3d..f796637d 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -15,3 +15,17 @@ jobs: go-version: '1.20' - name: Run tests run: go test -v ./... + - name: Go lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.51.2 + args: --verbose + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: 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 diff --git a/.golangci.yml b/.golangci.yml index bf2909b3..0579c166 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,6 +13,14 @@ linters: disable-all: true enable: - errcheck + - gci + - gofmt + - gofumpt + - goimports + - govet + - misspell + - unused + - gosec fast: false issues: @@ -20,7 +28,13 @@ issues: max-same-issues: 0 max-issues-per-linter: 0 exclude-rules: - # disabling some linters for test files + # disabling some linters for test files - path: _test\.go linters: - errcheck + - gosec + # disabling some linters rules + exclude: + # gosec + - G101 # Potential hardcoded credentials + - G114 # Use of net/http serve function that has no support for setting timeouts diff --git a/chain/evm/client.go b/chain/evm/client.go index 36ef54c4..54ac6ca0 100644 --- a/chain/evm/client.go +++ b/chain/evm/client.go @@ -15,6 +15,7 @@ import ( "time" "github.com/VolumeFi/whoops" + "github.com/cosmos/gogoproto/proto" "github.com/ethereum/go-ethereum" etherum "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts" @@ -27,7 +28,6 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/event" - "github.com/cosmos/gogoproto/proto" compassABI "github.com/palomachain/pigeon/chain/evm/abi/compass" "github.com/palomachain/pigeon/config" "github.com/palomachain/pigeon/errors" @@ -161,7 +161,6 @@ type CompassBinding interface { func (c *Client) init() error { return whoops.Try(func() { - if !ethcommon.IsHexAddress(c.config.SigningKey) { whoops.Assert(errors.Unrecoverable(ErrInvalidAddress.Format(c.config.SigningKey))) } @@ -362,7 +361,6 @@ func (c *Client) sign(ctx context.Context, bytes []byte) ([]byte, error) { // splitting the possible set in two, recursively. func (c *Client) FilterLogs(ctx context.Context, fq etherum.FilterQuery, currBlockHeight *big.Int, fn func(logs []ethtypes.Log) bool) (bool, error) { found, err := filterLogs(ctx, c.conn, fq, currBlockHeight, true, fn) - if err != nil { log.WithError(err).Error("error filtering logs") } @@ -385,7 +383,6 @@ type ethClientToFilterLogs interface { } func shouldDoBinarySearchFromError(err error) bool { - switch { case strings.Contains(err.Error(), "query returned more than 10000 results"): return true diff --git a/chain/evm/client_test.go b/chain/evm/client_test.go index 210576b7..e6d3de8c 100644 --- a/chain/evm/client_test.go +++ b/chain/evm/client_test.go @@ -300,7 +300,6 @@ func TestFilterLogs(t *testing.T) { } func TestFindingTheBlockNearestToTime(t *testing.T) { - type ethHeader struct { height uint64 time uint64 diff --git a/chain/evm/compass.go b/chain/evm/compass.go index 7093e6e0..da34cb6f 100644 --- a/chain/evm/compass.go +++ b/chain/evm/compass.go @@ -206,7 +206,6 @@ func (t compass) submitLogicCall( new(big.Int).SetInt64(int64(origMessage.ID)), new(big.Int).SetInt64(msg.GetDeadline()), }) - if err != nil { isSmartContractError := whoops.Must(t.tryProvidingEvidenceIfSmartContractErr(ctx, queueTypeName, origMessage.ID, err)) if isSmartContractError { @@ -274,7 +273,6 @@ func (t compass) uploadSmartContract( msg.GetBytecode(), constructorInput, ) - if err != nil { logger. WithField("error", err.Error()). @@ -310,7 +308,6 @@ func (t compass) tryProvidingEvidenceIfSmartContractErr(ctx context.Context, que err := t.paloma.AddMessageEvidence(ctx, queueTypeName, msgID, &types.SmartContractExecutionErrorProof{ ErrorMessage: jsonRpcErr.Error(), }) - if err != nil { return false, err } @@ -334,7 +331,6 @@ func (t compass) findLastValsetMessageID(ctx context.Context) (uint64, error) { func (t compass) isArbitraryCallAlreadyExecuted(ctx context.Context, messageID uint64) (bool, error) { blockNumber, err := t.evm.FindCurrentBlockNumber(ctx) - if err != nil { return false, err } diff --git a/chain/evm/compass_test.go b/chain/evm/compass_test.go index 0ef66399..5e20232a 100644 --- a/chain/evm/compass_test.go +++ b/chain/evm/compass_test.go @@ -608,7 +608,8 @@ func TestMessageProcessing(t *testing.T) { return evm, paloma }, expErr: nil, - }, { + }, + { name: "upload_smart_contract/when smart contract returns an error and sending it to paloma fails, it returns it back", msgs: []chain.MessageWithSignatures{ { @@ -710,7 +711,6 @@ func TestProcessingvalidatorBalancesRequest(t *testing.T) { } func TestProvidingEvidenceForAMessage(t *testing.T) { - addValidSignature := func(pk *ecdsa.PrivateKey) chain.ValidatorSignature { return signMessage(ethCompatibleBytesToSign, pk) } @@ -799,8 +799,8 @@ func TestProvidingEvidenceForAMessage(t *testing.T) { }) } } -func TestIfTheConsensusHasBeenReached(t *testing.T) { +func TestIfTheConsensusHasBeenReached(t *testing.T) { addValidSignature := func(pk *ecdsa.PrivateKey) chain.ValidatorSignature { return signMessage(ethCompatibleBytesToSign, pk) } diff --git a/chain/evm/factory.go b/chain/evm/factory.go index 34ee92f4..35a8ca96 100644 --- a/chain/evm/factory.go +++ b/chain/evm/factory.go @@ -32,7 +32,6 @@ func (f *Factory) Build( blockHeightHash common.Hash, minOnChainBalance *big.Int, ) (chain.Processor, error) { - var smartContractABI *abi.ABI if len(smartContractABIJson) > 0 { aabi, err := abi.JSON(strings.NewReader(smartContractABIJson)) diff --git a/chain/evm/health_check_test.go b/chain/evm/health_check_test.go index 38e786e4..640576b7 100644 --- a/chain/evm/health_check_test.go +++ b/chain/evm/health_check_test.go @@ -90,5 +90,4 @@ var _ = Describe("health check", func() { }) }) }) - }) diff --git a/chain/evm/processor.go b/chain/evm/processor.go index afba953f..50410aa9 100644 --- a/chain/evm/processor.go +++ b/chain/evm/processor.go @@ -78,7 +78,6 @@ func (p Processor) SignMessages(ctx context.Context, queueTypeName string, messa }, nil }, ) - } func (p Processor) ProcessMessages(ctx context.Context, queueTypeName string, msgs []chain.MessageWithSignatures) error { diff --git a/chain/paloma/client.go b/chain/paloma/client.go index 5bc8a59b..864782a8 100644 --- a/chain/paloma/client.go +++ b/chain/paloma/client.go @@ -6,15 +6,13 @@ import ( "time" "github.com/VolumeFi/whoops" + coretypes "github.com/cometbft/cometbft/rpc/core/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/gogoproto/grpc" "github.com/cosmos/gogoproto/proto" - "github.com/strangelove-ventures/lens/client/query" - - coretypes "github.com/cometbft/cometbft/rpc/core/types" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/palomachain/pigeon/chain" "github.com/palomachain/pigeon/config" consensus "github.com/palomachain/pigeon/types/paloma/x/consensus/types" @@ -23,6 +21,7 @@ import ( valset "github.com/palomachain/pigeon/types/paloma/x/valset/types" "github.com/palomachain/pigeon/util/slice" log "github.com/sirupsen/logrus" + "github.com/strangelove-ventures/lens/client/query" ) type ResultStatus = coretypes.ResultStatus diff --git a/chain/paloma/client_test.go b/chain/paloma/client_test.go index d584003d..9bb8a60e 100644 --- a/chain/paloma/client_test.go +++ b/chain/paloma/client_test.go @@ -6,8 +6,10 @@ import ( "net" "testing" + "github.com/VolumeFi/whoops" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/gogoproto/proto" "github.com/palomachain/pigeon/chain" clientmocks "github.com/palomachain/pigeon/chain/paloma/mocks" @@ -20,12 +22,8 @@ import ( lens "github.com/strangelove-ventures/lens/client" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - - "google.golang.org/grpc/test/bufconn" - - "github.com/VolumeFi/whoops" - "github.com/cosmos/cosmos-sdk/types/module" "google.golang.org/grpc" + "google.golang.org/grpc/test/bufconn" ) var ( @@ -305,6 +303,7 @@ func TestGetMessagesInQueue(t *testing.T) { }) } } + func TestQueryValidatorInfo(t *testing.T) { fakeErr := errors.New("something") fakeExternalInfo := []*valset.ExternalChainInfo{ @@ -443,6 +442,7 @@ type mockMsgSender func(context.Context, sdk.Msg, string) (*sdk.TxResponse, erro func (m mockMsgSender) SendMsg(ctx context.Context, msg sdk.Msg, memo string) (*sdk.TxResponse, error) { return m(ctx, msg, memo) } + func TestBroadcastingMessageSignatures(t *testing.T) { ctx := context.Background() for _, tt := range []struct { diff --git a/chain/paloma/collision/zero_collision.go b/chain/paloma/collision/zero_collision.go index 17afdec9..127ff901 100644 --- a/chain/paloma/collision/zero_collision.go +++ b/chain/paloma/collision/zero_collision.go @@ -1,4 +1,4 @@ -// Zero collision strategy ensures that all pigeons are using the same way of determinig if they can execute a message or not. +// Zero collision strategy ensures that all pigeons are using the same way of determining if they can execute a message or not. // That way we can distribute the jobs without having to write data to paloma so that paloma could do it, as it could be slow. // Of course, paloma does not care about the strategy pigeons are using. Somebody could rewrite pigeon to do send all the messages, // but then they would be "fighting" with paloma and they (and other pigeons) would spend gas unceccecary. @@ -143,7 +143,6 @@ func pickWinner(seed []byte, dump []byte, vals []sdk.ValAddress) sdk.ValAddress } return possibleWinners[0] } - } // rounds down the block height to the nearest 10 diff --git a/chain/paloma/wrappers.go b/chain/paloma/wrappers.go index b913cc8e..aa42a32a 100644 --- a/chain/paloma/wrappers.go +++ b/chain/paloma/wrappers.go @@ -2,12 +2,12 @@ package paloma import ( "context" + "time" + "github.com/VolumeFi/whoops" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/grpc" log "github.com/sirupsen/logrus" - "time" - ggrpc "google.golang.org/grpc" ) diff --git a/cmd/pigeon/cmd_config.go b/cmd/pigeon/cmd_config.go index 780d41e9..018d5db3 100644 --- a/cmd/pigeon/cmd_config.go +++ b/cmd/pigeon/cmd_config.go @@ -1,8 +1,8 @@ package main import ( - "github.com/spf13/cobra" "github.com/palomachain/pigeon/app" + "github.com/spf13/cobra" ) var ( @@ -14,7 +14,6 @@ var ( Use: "validate", Short: "validates configuration", RunE: func(cmd *cobra.Command, args []string) error { - _, err := app.PalomaClient().Keyring().List() if err != nil { return err diff --git a/cmd/pigeon/cmd_health_check_verify.go b/cmd/pigeon/cmd_health_check_verify.go index a3c79f3d..eb0c658a 100644 --- a/cmd/pigeon/cmd_health_check_verify.go +++ b/cmd/pigeon/cmd_health_check_verify.go @@ -5,17 +5,15 @@ import ( "github.com/spf13/cobra" ) -var ( - healthCheckVerify = &cobra.Command{ - Use: "health-check", - Short: "Verifies the health of pigeon.", - RunE: func(cmd *cobra.Command, args []string) error { - app.HealthCheckService().BootChecker(cmd.Context()) - app.HealthCheckService().Check(cmd.Context()) - return nil - }, - } -) +var healthCheckVerify = &cobra.Command{ + Use: "health-check", + Short: "Verifies the health of pigeon.", + RunE: func(cmd *cobra.Command, args []string) error { + app.HealthCheckService().BootChecker(cmd.Context()) + app.HealthCheckService().Check(cmd.Context()) + return nil + }, +} func init() { rootCmd.AddCommand(healthCheckVerify) diff --git a/cmd/pigeon/cmd_init.go b/cmd/pigeon/cmd_init.go index cc1ffda5..7d869779 100644 --- a/cmd/pigeon/cmd_init.go +++ b/cmd/pigeon/cmd_init.go @@ -2,53 +2,50 @@ package main import ( "fmt" - "github.com/cosmos/cosmos-sdk/codec" "os" - + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" ) -var ( - initCmd = &cobra.Command{ - Use: "init [keyring-backend] [keyring-location]", - Short: "initializes the pigeon", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - // check if the signing key exists, - // if it does not, it creates one which it reads from the passed in config. - key := "signing-key" - - legacyAmino := codec.NewLegacyAmino() - aminoCodec := codec.NewAminoCodec(legacyAmino) - - kr, err := keyring.New("pigeon", args[0], args[1], os.Stdin, aminoCodec) - if err != nil { - return err - } - _, err = kr.Key(key) - if err == nil { - // nothing to do - // TODO; there could be other things that need to be initialised, - // so this message might go away from this line of code. - fmt.Println("nothing to do for me") - return nil - } - - fmt.Println("Adding a new signing key to the keyring") - info, _, err := kr.NewMnemonic(key, keyring.English, types.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) - if err != nil { - return err - } - fmt.Printf("key '%s' added to the keyring in %s\n", key, args[1]) - fmt.Println(info) - +var initCmd = &cobra.Command{ + Use: "init [keyring-backend] [keyring-location]", + Short: "initializes the pigeon", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + // check if the signing key exists, + // if it does not, it creates one which it reads from the passed in config. + key := "signing-key" + + legacyAmino := codec.NewLegacyAmino() + aminoCodec := codec.NewAminoCodec(legacyAmino) + + kr, err := keyring.New("pigeon", args[0], args[1], os.Stdin, aminoCodec) + if err != nil { + return err + } + _, err = kr.Key(key) + if err == nil { + // nothing to do + // TODO; there could be other things that need to be initialised, + // so this message might go away from this line of code. + fmt.Println("nothing to do for me") return nil - }, - } -) + } + + fmt.Println("Adding a new signing key to the keyring") + info, _, err := kr.NewMnemonic(key, keyring.English, types.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + if err != nil { + return err + } + fmt.Printf("key '%s' added to the keyring in %s\n", key, args[1]) + fmt.Println(info) + + return nil + }, +} func init() { rootCmd.AddCommand(initCmd) diff --git a/cmd/pigeon/cmd_root.go b/cmd/pigeon/cmd_root.go index 525a56ae..afdf3b2b 100644 --- a/cmd/pigeon/cmd_root.go +++ b/cmd/pigeon/cmd_root.go @@ -11,24 +11,22 @@ var ( configRequiredCmds []*cobra.Command ) -var ( - rootCmd = &cobra.Command{ - Use: "pigeon", - SilenceUsage: true, - PersistentPreRun: func(cmd *cobra.Command, args []string) { - found := false - for _, curr := range configRequiredCmds { - if curr == cmd { - found = true - break - } - } - if found { - app.SetConfigPath(flagConfigPath) +var rootCmd = &cobra.Command{ + Use: "pigeon", + SilenceUsage: true, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + found := false + for _, curr := range configRequiredCmds { + if curr == cmd { + found = true + break } - }, - } -) + } + if found { + app.SetConfigPath(flagConfigPath) + } + }, +} func configRequired(cmd *cobra.Command) { for _, curr := range configRequiredCmds { diff --git a/cmd/pigeon/cmd_start.go b/cmd/pigeon/cmd_start.go index 51e06306..cc526bfd 100644 --- a/cmd/pigeon/cmd_start.go +++ b/cmd/pigeon/cmd_start.go @@ -14,54 +14,52 @@ import ( "github.com/spf13/cobra" ) -var ( - startCmd = &cobra.Command{ - Use: "start", - Short: "starts the pigeon server", - RunE: func(cmd *cobra.Command, args []string) error { - pid := os.Getpid() - fmt.Println("*coo! coo!*") - log.WithFields( - log.Fields{ - "PID": pid, - "version": app.Version(), - "commit": app.Commit(), - }, - ).Info("app info") +var startCmd = &cobra.Command{ + Use: "start", + Short: "starts the pigeon server", + RunE: func(cmd *cobra.Command, args []string) error { + pid := os.Getpid() + fmt.Println("*coo! coo!*") + log.WithFields( + log.Fields{ + "PID": pid, + "version": app.Version(), + "commit": app.Commit(), + }, + ).Info("app info") - ctx := catchKillSignal(cmd.Context(), 30*time.Second) + ctx := catchKillSignal(cmd.Context(), 30*time.Second) - // start healthcheck server - go func() { - health.StartHTTPServer( - ctx, - app.Config().HealthCheckPort(), - pid, - app.Version(), - app.Commit(), - ) - }() + // start healthcheck server + go func() { + health.StartHTTPServer( + ctx, + app.Config().HealthCheckPort(), + pid, + app.Version(), + app.Commit(), + ) + }() - // wait for paloma to get online - waitCtx, cancelFnc := context.WithTimeout(ctx, 2*time.Minute) - err := health.WaitForPaloma(waitCtx, app.PalomaClient()) - cancelFnc() - if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) { - log.WithError(err).Fatal("exiting as paloma was not detected to be running") - return err - } + // wait for paloma to get online + waitCtx, cancelFnc := context.WithTimeout(ctx, 2*time.Minute) + err := health.WaitForPaloma(waitCtx, app.PalomaClient()) + cancelFnc() + if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) { + log.WithError(err).Fatal("exiting as paloma was not detected to be running") + return err + } - // build a context that will get canceled if paloma ever goes offline - ctx = health.CancelContextIfPalomaIsDown(ctx, app.PalomaClient()) + // build a context that will get canceled if paloma ever goes offline + ctx = health.CancelContextIfPalomaIsDown(ctx, app.PalomaClient()) - err = app.Relayer().Start(ctx) - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { - return nil - } - return err - }, - } -) + err = app.Relayer().Start(ctx) + if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + return nil + } + return err + }, +} func init() { rootCmd.AddCommand(startCmd) diff --git a/cmd/pigeon/cmd_version.go b/cmd/pigeon/cmd_version.go index 28261692..f2809667 100644 --- a/cmd/pigeon/cmd_version.go +++ b/cmd/pigeon/cmd_version.go @@ -7,19 +7,16 @@ import ( "github.com/spf13/cobra" ) -var ( - versionCmd = &cobra.Command{ - Use: "version", - Short: "prints version info", - RunE: func(cmd *cobra.Command, args []string) error { - fmt.Println("App version:", app.Version()) - fmt.Println("Build commit hash:", app.Commit()) - return nil - }, - } -) +var versionCmd = &cobra.Command{ + Use: "version", + Short: "prints version info", + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Println("App version:", app.Version()) + fmt.Println("Build commit hash:", app.Commit()) + return nil + }, +} func init() { rootCmd.AddCommand(versionCmd) - } diff --git a/config/config.go b/config/config.go index a271b7ed..545129b2 100644 --- a/config/config.go +++ b/config/config.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/VolumeFi/whoops" - "gopkg.in/yaml.v2" ) diff --git a/health/server.go b/health/server.go index 3a7b82d3..7a8607df 100644 --- a/health/server.go +++ b/health/server.go @@ -48,5 +48,4 @@ func StartHTTPServer( log.WithError(err).Error("error starting healtcheck server") panic(err) } - } diff --git a/health/wait_for_chain_test.go b/health/wait_for_chain_test.go index 3e2f68f9..a90112f4 100644 --- a/health/wait_for_chain_test.go +++ b/health/wait_for_chain_test.go @@ -49,7 +49,6 @@ var _ = Describe("waiting for paloma", func() { }) }) Context("paloma is online after second loop", func() { - It("returns context error", func() { m.On("PalomaStatus", mock.Anything).Return(whoops.String("doesnt matter")).Times(1) m.On("PalomaStatus", mock.Anything).Return(nil).Times(1) @@ -95,5 +94,4 @@ var _ = Describe("canceling context if paloma is down", func() { }) }) }) - }) diff --git a/relayer/health_check.go b/relayer/health_check.go index 03551415..cfba8132 100644 --- a/relayer/health_check.go +++ b/relayer/health_check.go @@ -6,14 +6,12 @@ import ( "strings" "github.com/VolumeFi/whoops" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/palomachain/pigeon/chain/evm" log "github.com/sirupsen/logrus" - - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) func (r *Relayer) isStaking(ctx context.Context) error { - val, err := r.palomaClient.GetValidator(ctx) if err != nil { if !strings.Contains(err.Error(), "NotFound") { @@ -38,7 +36,6 @@ func (r *Relayer) isStaking(ctx context.Context) error { func (r *Relayer) HealthCheck(ctx context.Context) error { chainsInfos, err := r.palomaClient.QueryGetEVMChainInfos(ctx) - if err != nil { return err } diff --git a/relayer/health_check_test.go b/relayer/health_check_test.go index b2d580c7..a39663b7 100644 --- a/relayer/health_check_test.go +++ b/relayer/health_check_test.go @@ -11,9 +11,8 @@ import ( chainmocks "github.com/palomachain/pigeon/chain/mocks" "github.com/palomachain/pigeon/config" "github.com/palomachain/pigeon/relayer/mocks" - "github.com/stretchr/testify/mock" - evmtypes "github.com/palomachain/pigeon/types/paloma/x/evm/types" + "github.com/stretchr/testify/mock" ) func TestGinkgo(t *testing.T) { @@ -44,7 +43,7 @@ var _ = Describe("health check", func() { BeforeEach(func() { cfg.EVM = map[string]config.EVM{ - "test": config.EVM{}, + "test": {}, } }) diff --git a/relayer/process.go b/relayer/process.go index 2527794e..32324c5f 100644 --- a/relayer/process.go +++ b/relayer/process.go @@ -124,7 +124,6 @@ func (r *Relayer) Process(ctx context.Context, processors []chain.Processor) err // todo randomise for _, p := range processors { - // todo randomise for _, queueName := range p.SupportedQueues() { logger := log.WithFields(log.Fields{ diff --git a/relayer/relayer.go b/relayer/relayer.go index 2e21d8c1..a4f6003d 100644 --- a/relayer/relayer.go +++ b/relayer/relayer.go @@ -7,8 +7,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ethereum/go-ethereum/common" proto "github.com/cosmos/gogoproto/proto" + "github.com/ethereum/go-ethereum/common" "github.com/palomachain/pigeon/chain" "github.com/palomachain/pigeon/chain/paloma" "github.com/palomachain/pigeon/config" diff --git a/util/slice/all.go b/util/slice/all.go index 79b255f9..9bd1409e 100644 --- a/util/slice/all.go +++ b/util/slice/all.go @@ -5,4 +5,3 @@ func All[A any, B any](in []A, f func(A)) { f(el) } } - From 1f024abcef1f10bad7d31a647d6e84846519190c Mon Sep 17 00:00:00 2001 From: Tyler Ruppert <{ID}+{username}@users.noreply.github.com> Date: Thu, 1 Jun 2023 07:27:18 -0600 Subject: [PATCH 2/6] One more linted file --- cmd/pigeon/cmd_init.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/pigeon/cmd_init.go b/cmd/pigeon/cmd_init.go index 7d869779..023b1627 100644 --- a/cmd/pigeon/cmd_init.go +++ b/cmd/pigeon/cmd_init.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" From b2436be630af3930a5d88696adc32f7011cd8035 Mon Sep 17 00:00:00 2001 From: Tyler Ruppert <{ID}+{username}@users.noreply.github.com> Date: Thu, 1 Jun 2023 07:38:44 -0600 Subject: [PATCH 3/6] Remove unused code --- chain/client_test.go | 27 --------------------------- chain/evm/client.go | 4 ---- chain/evm/compass.go | 2 -- chain/evm/compass_test.go | 16 ---------------- chain/evm/deploy_contract.go | 14 -------------- chain/evm/processor.go | 4 +--- chain/paloma/client_test.go | 14 +------------- cmd/pigeon/cmd_evm.go | 4 ---- cmd/pigeon/read_stdin.go | 14 -------------- relayer/start.go | 6 +----- 10 files changed, 3 insertions(+), 102 deletions(-) delete mode 100644 chain/client_test.go diff --git a/chain/client_test.go b/chain/client_test.go deleted file mode 100644 index 82f542c7..00000000 --- a/chain/client_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package chain - -import ( - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/strangelove-ventures/lens/client" -) - -func newClient() *LensClient { - return &LensClient{ - ChainClient: client.ChainClient{ - Config: &client.ChainClientConfig{ - ChainID: "random-chain", - }, - Codec: client.MakeCodec(testModules(), []string{}), - }, - } -} - -func testModules() []module.AppModuleBasic { - return append( - client.ModuleBasics[:], - // byop.NewModule( - // "testModule", - // (&types.SimpleMessage)(nil), - // ), - ) -} diff --git a/chain/evm/client.go b/chain/evm/client.go index 54ac6ca0..632be15e 100644 --- a/chain/evm/client.go +++ b/chain/evm/client.go @@ -36,10 +36,6 @@ import ( log "github.com/sirupsen/logrus" ) -const ( - smartContractFilename = "compass-evm" -) - type StoredContract struct { ABI abi.ABI Source []byte diff --git a/chain/evm/compass.go b/chain/evm/compass.go index da34cb6f..8973b23b 100644 --- a/chain/evm/compass.go +++ b/chain/evm/compass.go @@ -27,8 +27,6 @@ const ( maxPower uint64 = 1 << 32 powerThreshold uint64 = 2_863_311_530 SignedMessagePrefix = "\x19Ethereum Signed Message:\n32" - - valsetUpdatedABISignature = "ValsetUpdated(bytes32,uint256)" ) //go:generate mockery --name=evmClienter --inpackage --testonly diff --git a/chain/evm/compass_test.go b/chain/evm/compass_test.go index 5e20232a..b8597c10 100644 --- a/chain/evm/compass_test.go +++ b/chain/evm/compass_test.go @@ -69,22 +69,6 @@ func powerFromPercentage(p float64) uint64 { return uint64(float64(maxPower) * p) } -func valsetUpdatedEvent(blockNumber uint64, checkpoint string, valsetID int64) etherumtypes.Log { - compassABI := StoredContracts()["compass-evm"].ABI - // checkpoint bytes32 - // valset_id uint256 - var cp32 [32]byte - copy(cp32[:], []byte(checkpoint)) - data, err := compassABI.Events["ValsetUpdated"].Inputs.Pack(cp32, big.NewInt(valsetID)) - if err != nil { - panic(err) - } - return etherumtypes.Log{ - BlockNumber: blockNumber, - Data: data, - } -} - func TestIsArbitraryCallAlreadyExecuted(t *testing.T) { tests := []struct { name string diff --git a/chain/evm/deploy_contract.go b/chain/evm/deploy_contract.go index 070bf6df..87e1b893 100644 --- a/chain/evm/deploy_contract.go +++ b/chain/evm/deploy_contract.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" log "github.com/sirupsen/logrus" ) @@ -153,16 +152,3 @@ func deployContract( }) return } - -func rawDeploy(opts *bind.TransactOpts, abi abi.ABI, bytecode []byte, backend bind.ContractBackend, packedConstructorInput []byte) (common.Address, *ethtypes.Transaction, error) { - // Otherwise try to deploy the contract - c := bind.NewBoundContract(common.Address{}, abi, backend, backend, backend) - - tx, err := c.RawTransact(opts, append(bytecode, packedConstructorInput...)) - logger := log.WithField("constructor-input", packedConstructorInput) - logger.Info("raw deploy") - if err != nil { - return common.Address{}, nil, err - } - return crypto.CreateAddress(opts.From, tx.Nonce()), tx, nil -} diff --git a/chain/evm/processor.go b/chain/evm/processor.go index 50410aa9..7d6cd713 100644 --- a/chain/evm/processor.go +++ b/chain/evm/processor.go @@ -26,15 +26,13 @@ type Processor struct { chainType string chainReferenceID string - turnstoneEVMContract common.Address + turnstoneEVMContract common.Address //nolint:unused blockHeight int64 blockHeightHash common.Hash minOnChainBalance *big.Int } -var _ chain.Processor = Processor{} - func (p Processor) SupportedQueues() []string { return slice.Map( []string{ diff --git a/chain/paloma/client_test.go b/chain/paloma/client_test.go index 9bb8a60e..3b5b3edc 100644 --- a/chain/paloma/client_test.go +++ b/chain/paloma/client_test.go @@ -26,19 +26,7 @@ import ( "google.golang.org/grpc/test/bufconn" ) -var ( - errTestErr = errors.New("sample error") - simpleMessageTestData1 = &testdata.SimpleMessage{ - Sender: "bob", - Hello: "mars", - World: "!", - } - simpleMessageTestData2 = &testdata.SimpleMessage{ - Sender: "alice", - Hello: "jupiter", - World: "!", - } -) +var errTestErr = errors.New("sample error") func consensusQueryServerDialer(t *testing.T, msgsrv *consensusmocks.QueryServer) func(context.Context, string) (net.Conn, error) { listener := bufconn.Listen(1024 * 1024) diff --git a/cmd/pigeon/cmd_evm.go b/cmd/pigeon/cmd_evm.go index 6cfed317..ec5511a7 100644 --- a/cmd/pigeon/cmd_evm.go +++ b/cmd/pigeon/cmd_evm.go @@ -17,10 +17,6 @@ import ( "github.com/spf13/cobra" ) -const ( - signaturePrefix = "\x19Ethereum Signed Message:\n32" -) - var ( evmCmd = &cobra.Command{ Use: "evm", diff --git a/cmd/pigeon/read_stdin.go b/cmd/pigeon/read_stdin.go index 78d0b0d5..303b7a0f 100644 --- a/cmd/pigeon/read_stdin.go +++ b/cmd/pigeon/read_stdin.go @@ -34,20 +34,6 @@ func readLineFromStdin(isPassword bool) string { return text } -func readNTimes(n int, fnc func(string) bool) func(string) bool { - count := 0 - return func(input string) bool { - if count >= n { - return true - } - if fnc(input) { - return true - } - count++ - return false - } -} - func doubleReadInput(prefix string, isPassword bool, failedAttempts int) string { for i := failedAttempts; i > 0; i-- { fmt.Print(prefix) diff --git a/relayer/start.go b/relayer/start.go index 2025b133..a2e4a343 100644 --- a/relayer/start.go +++ b/relayer/start.go @@ -12,11 +12,7 @@ import ( log "github.com/sirupsen/logrus" ) -const ( - defaultErrorCountToExit = 5 - - defaultLoopTimeout = 1 * time.Minute -) +const defaultLoopTimeout = 1 * time.Minute func (r *Relayer) waitUntilStaking(ctx context.Context) error { for { From 660da7f316363de33c936af66c08168ba0f54990 Mon Sep 17 00:00:00 2001 From: Tyler Ruppert <{ID}+{username}@users.noreply.github.com> Date: Thu, 1 Jun 2023 07:49:32 -0600 Subject: [PATCH 4/6] Add ReadHeaderTimeout * Addresses gosec linting: G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server --- health/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/health/server.go b/health/server.go index 7a8607df..7df2fc3c 100644 --- a/health/server.go +++ b/health/server.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "os" + "time" log "github.com/sirupsen/logrus" ) @@ -42,6 +43,7 @@ func StartHTTPServer( BaseContext: func(_ net.Listener) context.Context { return ctx }, + ReadHeaderTimeout: 5 * time.Second, } log.Info("Starting healthcheck server") if err := server.ListenAndServe(); err != nil { From c1c8b21498e0bacfe6bf4dfc08d55fdd367a08f6 Mon Sep 17 00:00:00 2001 From: Tyler Ruppert <{ID}+{username}@users.noreply.github.com> Date: Thu, 1 Jun 2023 07:55:38 -0600 Subject: [PATCH 5/6] Use tmpfile * Addresses gosec linting: G303: File creation in shared tmp directory without using ioutil.Tempfile --- cmd/pigeon/cmd_evm.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/pigeon/cmd_evm.go b/cmd/pigeon/cmd_evm.go index ec5511a7..c9fcd77c 100644 --- a/cmd/pigeon/cmd_evm.go +++ b/cmd/pigeon/cmd_evm.go @@ -72,7 +72,15 @@ var ( return err } - if err := os.WriteFile("/tmp/ooo.hex", []byte(common.Bytes2Hex(b)), 0o666); err != nil { + tmpF, err := os.CreateTemp("/tmp", "ooo.hex") + if err != nil { + return err + } + + defer os.Remove(tmpF.Name()) + + _, err = tmpF.Write([]byte(common.Bytes2Hex(b))) + if err != nil { return err } From 1f24d89b2b3e90bc5b33e4445255f311f62aa194 Mon Sep 17 00:00:00 2001 From: Tyler Ruppert <{ID}+{username}@users.noreply.github.com> Date: Thu, 8 Jun 2023 14:16:50 -0600 Subject: [PATCH 6/6] Fix unlinted section from master rebase --- relayer/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relayer/start.go b/relayer/start.go index a2e4a343..5f3e17ee 100644 --- a/relayer/start.go +++ b/relayer/start.go @@ -3,11 +3,11 @@ package relayer import ( "context" goerrors "errors" - "github.com/palomachain/pigeon/errors" "sync" "time" "github.com/VolumeFi/whoops" + "github.com/palomachain/pigeon/errors" "github.com/palomachain/pigeon/util/channels" log "github.com/sirupsen/logrus" )