From 4e583cc7ca03b6449aaee01c988cc518afe8aff2 Mon Sep 17 00:00:00 2001 From: emidev98 <49301655+emidev98@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:41:35 +0200 Subject: [PATCH] Revert "Cleanup (#98)" (#115) This reverts commit a97277b3b51defb8a54e580cfaaf2608d2ae99fe. --- .github/workflows/lint.yml | 36 ++++++++++++++++++------------ .golangci.yml | 45 ++++++++++++++++++-------------------- app/ante/ante_test.go | 41 ++++++++++++++++++++++++++++++++++ app/ante/sigverify.go | 1 + app/app.go | 5 ++++- app/export.go | 3 +-- app/tx/broadcast.go | 6 ++--- client/docs/statik/init.go | 3 +++ cmd/terrad/root.go | 4 ++-- 9 files changed, 98 insertions(+), 46 deletions(-) create mode 100644 client/docs/statik/init.go diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1c0cc3a1..28eb3795 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,26 +1,34 @@ -name: golangci-lint +name: Lint +# Lint runs golangci-lint over the entire Gaia repository +# This workflow is run on every pull request and push to main +# The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified. on: + pull_request: push: - tags: - - v* branches: - - master - main - pull_request: -permissions: - contents: read - # Optional: allow read access to pull request. Use with `only-new-issues` option. - # pull-requests: read + - master + - "release/*" jobs: golangci: - name: lint + name: golangci-lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - name: Setup Go + uses: actions/setup-go@v3 with: go-version: 1.18 - uses: actions/checkout@v3 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + - uses: technote-space/get-diff-action@v4 + with: + PATTERNS: | + **/**.go + go.mod + go.sum + - uses: golangci/golangci-lint-action@v3 with: - version: latest + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.45.2 + args: --timeout 10m + github-token: ${{ secrets.github_token }} + if: "env.GIT_DIFF != ''" diff --git a/.golangci.yml b/.golangci.yml index 8c123360..b261ffbf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,29 +1,26 @@ -run: - tests: true - timeout: 10m - sort-results: true - allow-parallel-runners: true - concurrency: 4 - linters: disable-all: true enable: - - depguard - - dogsled - - exportloopref - - goconst - - gocritic - - gofumpt - - gosec - - gosimple - - govet + - errcheck + - golint - ineffassign - - misspell - - nakedret - - nolintlint - - staticcheck - - revive - - stylecheck - - typecheck - unconvert - - unused + - misspell + - govet + # - unused + # - deadcode + - goconst + - gosec + # - staticcheck +linters-settings: + gocyclo: + min-complexity: 11 + errcheck: + ignore: fmt:.*,io/ioutil:^Read.*,github.com/spf13/cobra:MarkFlagRequired,github.com/spf13/viper:BindPFlag + golint: + min-confidence: 1.1 +issues: + exclude: + - composite +run: + tests: false diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 0586ea4f..e6484a22 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -1,6 +1,8 @@ package ante_test import ( + "fmt" + "strings" "testing" "github.com/stretchr/testify/suite" @@ -11,12 +13,14 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" terraapp "github.com/terra-money/core/v2/app" @@ -113,3 +117,40 @@ func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums [] func TestAnteTestSuite(t *testing.T) { suite.Run(t, new(AnteTestSuite)) } + +func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptotypes.PubKey, signatures [][]byte) { + pubkeys = make([]cryptotypes.PubKey, n) + signatures = make([][]byte, n) + for i := 0; i < n; i++ { + var privkey cryptotypes.PrivKey = secp256k1.GenPrivKey() + + // TODO: also generate ed25519 keys as below when ed25519 keys are + // actually supported, https://github.com/cosmos/cosmos-sdk/issues/4789 + // for now this fails: + //if rand.Int63()%2 == 0 { + // privkey = ed25519.GenPrivKey() + //} else { + // privkey = secp256k1.GenPrivKey() + //} + + pubkeys[i] = privkey.PubKey() + signatures[i], _ = privkey.Sign(msg) + } + return +} + +func expectedGasCostByKeys(pubkeys []cryptotypes.PubKey) uint64 { + cost := uint64(0) + for _, pubkey := range pubkeys { + pubkeyType := strings.ToLower(fmt.Sprintf("%T", pubkey)) + switch { + case strings.Contains(pubkeyType, "ed25519"): + cost += types.DefaultParams().SigVerifyCostED25519 + case strings.Contains(pubkeyType, "secp256k1"): + cost += types.DefaultParams().SigVerifyCostSecp256k1 + default: + panic("unexpected key type") + } + } + return cost +} diff --git a/app/ante/sigverify.go b/app/ante/sigverify.go index b915dd56..62a29477 100644 --- a/app/ante/sigverify.go +++ b/app/ante/sigverify.go @@ -18,6 +18,7 @@ var ( // simulation signature values used to estimate gas consumption key = make([]byte, secp256k1.PubKeySize) simSecp256k1Pubkey = &secp256k1.PubKey{Key: key} + simSecp256k1Sig [64]byte _ authsigning.SigVerifiableTx = (*legacytx.StdTx)(nil) // assert StdTx implements SigVerifiableTx ) diff --git a/app/app.go b/app/app.go index 536fa162..354a654c 100644 --- a/app/app.go +++ b/app/app.go @@ -223,7 +223,9 @@ var ( } ) -var _ servertypes.Application = (*TerraApp)(nil) +var ( + _ servertypes.Application = (*TerraApp)(nil) +) func init() { userHomeDir, err := os.UserHomeDir() @@ -842,6 +844,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino // enforceStakingForVestingTokens enforce vesting tokens to be staked // CONTRACT: validator's gentx account must not be a vesting account func (app *TerraApp) enforceStakingForVestingTokens(ctx sdk.Context, genesisState GenesisState) { + var authState authtypes.GenesisState app.appCodec.MustUnmarshalJSON(genesisState[authtypes.ModuleName], &authState) diff --git a/app/export.go b/app/export.go index 5e507908..94837347 100644 --- a/app/export.go +++ b/app/export.go @@ -49,8 +49,7 @@ func (app *TerraApp) ExportAppStateAndValidators( // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated -// -// in favour of export at a block height +// in favour of export at a block height func (app *TerraApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { applyAllowedAddrs := false diff --git a/app/tx/broadcast.go b/app/tx/broadcast.go index ff7c566f..420c9cfa 100644 --- a/app/tx/broadcast.go +++ b/app/tx/broadcast.go @@ -3,7 +3,7 @@ package tx import ( "errors" "fmt" - "io" + "io/ioutil" "net/http" "github.com/cosmos/cosmos-sdk/client" @@ -43,7 +43,7 @@ func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req BroadcastReq - body, err := io.ReadAll(r.Body) + body, err := ioutil.ReadAll(r.Body) if rest.CheckBadRequestError(w, err) { return } @@ -96,7 +96,7 @@ func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc { // check the sequence nubmer is equal with the signature nubmer if len(signatures) != len(req.Sequences) { - rest.CheckBadRequestError(w, errors.New("must provide each signers's sequence number")) + rest.CheckBadRequestError(w, errors.New("Must provide each signers's sequence number")) return } diff --git a/client/docs/statik/init.go b/client/docs/statik/init.go new file mode 100644 index 00000000..9633aeb2 --- /dev/null +++ b/client/docs/statik/init.go @@ -0,0 +1,3 @@ +package statik + +//This just for fixing the error in importing empty github.com/cosmos/cosmos-sdk/client/lcd/statik diff --git a/cmd/terrad/root.go b/cmd/terrad/root.go index ea107b45..5f62a626 100644 --- a/cmd/terrad/root.go +++ b/cmd/terrad/root.go @@ -253,8 +253,8 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a func (a appCreator) appExport( logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailAllowedAddrs []string, - appOpts servertypes.AppOptions, -) (servertypes.ExportedApp, error) { + appOpts servertypes.AppOptions) (servertypes.ExportedApp, error) { + homePath, ok := appOpts.Get(flags.FlagHome).(string) if !ok || homePath == "" { return servertypes.ExportedApp{}, errors.New("application home not set")