diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0d9867a0c89a..1c47eeca6b03 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,25 +1,43 @@ -name: golangci-lint +name: Lint +# Lint runs golangci-lint over the entire cosmos-sdk repository +# This workflow is run on every pull request and push to main +# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed. on: + pull_request: push: - tags: - - v* branches: - main - pull_request: permissions: contents: read + jobs: golangci: - name: lint + permissions: + pull-requests: read # for technote-space/get-diff-action to get git reference + name: golangci-lint runs-on: ubuntu-latest steps: - uses: actions/setup-go@v3 with: go-version: 1.19 - uses: actions/checkout@v3 - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + - uses: technote-space/get-diff-action@v6.1.0 + id: git_diff + with: + PATTERNS: | + **/**.go + go.mod + go.sum + - name: Get data from Go build cache + # if: env.GIT_DIFF + if: ${{ false }} + uses: actions/cache@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: latest - args: --timeout 10m + path: | + ~/go/pkg/mod + ~/.cache/golangci-lint + ~/.cache/go-build + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + - name: Run golangci-lint + if: env.GIT_DIFF + run: make lint diff --git a/.github/workflows/proto-docker.yml b/.github/workflows/proto-docker.yml index dbab7a21cc05..fb4af6ae130c 100644 --- a/.github/workflows/proto-docker.yml +++ b/.github/workflows/proto-docker.yml @@ -4,7 +4,10 @@ on: branches: - main paths: - - "contrib/devtools/dockerfile" + - "contrib/devtools/Dockerfile" + pull_request: + paths: + - "contrib/devtools/Dockerfile" permissions: contents: read @@ -31,16 +34,20 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Login to DockerHub - uses: docker/login-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + if: ${{ github.event_name != 'pull_request' }} with: - username: ${{ secrets.DOCKERHUBTM_USERNAME }} - password: ${{ secrets.DOCKERHUBTM_TOKEN }} + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - - name: Publish to Docker Hub + - name: Publish to GHCR uses: docker/build-push-action@v3 with: context: ./contrib/devtools platforms: linux/amd64,linux/arm64 - push: true + push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.prep.outputs.tags }} + name: ghcr.io/cosmos/proto-builder diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c9aa01bddce..2d4999c9a9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * (ci) [#12851](https://github.com/cosmos/cosmos-sdk/pull/12851) Use canonical golangci-lint github action and lint grandfathered issues +* (events) [#12850](https://github.com/cosmos/cosmos-sdk/pull/12850) Add a new `fee_payer` attribute to the `tx` event that is emitted from the `DeductFeeDecorator` AnteHandler decorator. +* (ci) [#12854](https://github.com/cosmos/cosmos-sdk/pull/12854) Use ghcr.io to host the proto builder image. Update proto builder image to go 1.19 * (x/bank) [#12706](https://github.com/cosmos/cosmos-sdk/pull/12706) Added the `chain-id` flag to the `AddTxFlagsToCmd` API. There is no longer a need to explicitly register this flag on commands whens `AddTxFlagsToCmd` is already called. * [#12791](https://github.com/cosmos/cosmos-sdk/pull/12791) Bump the math library used in the sdk and replace old usages of sdk.* * (x/params) [#12615](https://github.com/cosmos/cosmos-sdk/pull/12615) Add `GetParamSetIfExists` function to params `Subspace` to prevent panics on breaking changes. diff --git a/UPGRADING.md b/UPGRADING.md index 355d625d0c81..35d548ce00c5 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -123,3 +123,8 @@ As a result, it gives a good indication of the progress of the upgrade. There is also downgrade and re-upgrade protection. If a node operator chooses to downgrade to IAVL pre-fast index, and then upgrade again, the index is rebuilt from scratch. This implementation detail should not be relevant in most cases. It was added as a safeguard against operator mistakes. + +### Modules + +- The `x/param` module has been depreacted in favour of each module housing and providing way to modify their parameters. Each module that has parameters that are changable during runtime have an authority, the authority can be a module or user account. The Cosmos-SDK team recommends migrating modules away from using the param module. An example of how this could look like can be found [here](https://github.com/cosmos/cosmos-sdk/pull/12363). + - The Param module will be maintained until April 18, 2022. At this point the module will reach end of life and be removed from the Cosmos SDK. diff --git a/contrib/devtools/Dockerfile b/contrib/devtools/Dockerfile index 05bed5ac81bf..d5f4469dc435 100644 --- a/contrib/devtools/Dockerfile +++ b/contrib/devtools/Dockerfile @@ -4,7 +4,8 @@ FROM bufbuild/buf:1.1.0 as BUILDER -FROM golang:1.18-alpine +FROM golang:1.19-alpine + RUN apk add --no-cache \ nodejs \ diff --git a/docs/building-modules/keeper.md b/docs/building-modules/keeper.md index 78712a91b3d7..294ad48a5a4a 100644 --- a/docs/building-modules/keeper.md +++ b/docs/building-modules/keeper.md @@ -29,6 +29,8 @@ type Keeper struct { // Store key(s) // codec + + // authority } ``` @@ -40,7 +42,7 @@ Let us go through the different parameters: * An expected `keeper` is a `keeper` external to a module that is required by the internal `keeper` of said module. External `keeper`s are listed in the internal `keeper`'s type definition as interfaces. These interfaces are themselves defined in an `expected_keepers.go` file in the root of the module's folder. In this context, interfaces are used to reduce the number of dependencies, as well as to facilitate the maintenance of the module itself. * `storeKey`s grant access to the store(s) of the [multistore](../core/store.md) managed by the module. They should always remain unexposed to external modules. -* `cdc` is the [codec](../core/encoding.md) used to marshall and unmarshall structs to/from `[]byte`. The `cdc` can be any of `codec.BinaryCodec`, `codec.JSONCodec` or `codec.Codec` based on your requirements. It can be either a proto or amino codec as long as they implement these interfaces. +* `cdc` is the [codec](../core/encoding.md) used to marshall and unmarshall structs to/from `[]byte`. The `cdc` can be any of `codec.BinaryCodec`, `codec.JSONCodec` or `codec.Codec` based on your requirements. It can be either a proto or amino codec as long as they implement these interfaces. The authority listed is a module account or user account that has the right to change module level parameters. Previously this was handled by the param module, which has been deprecated. Of course, it is possible to define different types of internal `keeper`s for the same module (e.g. a read-only `keeper`). Each type of `keeper` comes with its own constructor function, which is called from the [application's constructor function](../basics/app-anatomy.md). This is where `keeper`s are instantiated, and where developers make sure to pass correct instances of modules' `keeper`s to other modules that require them. diff --git a/docs/core/baseapp.md b/docs/core/baseapp.md index 0144cbeeb36f..4172536bf504 100644 --- a/docs/core/baseapp.md +++ b/docs/core/baseapp.md @@ -69,7 +69,6 @@ First, the important parameters that are initialized during the bootstrapping of are relayed to the relevant module's gRPC `Query` service. * [`TxDecoder`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/types#TxDecoder): It is used to decode raw transaction bytes relayed by the underlying Tendermint engine. -* [`ParamStore`](#paramstore): The parameter store used to get and set application consensus parameters. * [`AnteHandler`](#antehandler): This handler is used to handle signature verification, fee payment, and other pre-message execution checks when a transaction is received. It's executed during [`CheckTx/RecheckTx`](#checktx) and [`DeliverTx`](#delivertx). @@ -182,8 +181,8 @@ newly committed state and `deliverState` is set to `nil` to be reset on `BeginBl During `InitChain`, the `RequestInitChain` provides `ConsensusParams` which contains parameters related to block execution such as maximum gas and size in addition to evidence parameters. If these parameters are non-nil, they are set in the BaseApp's `ParamStore`. Behind the scenes, the `ParamStore` -is actually managed by an `x/params` module `Subspace`. This allows the parameters to be tweaked via -on-chain governance. +is managed by an `x/consensus_params` module. This allows the parameters to be tweaked via + on-chain governance. ## Service Routers diff --git a/docs/core/store.md b/docs/core/store.md index 5852f3a89c38..b0f6390eeae6 100644 --- a/docs/core/store.md +++ b/docs/core/store.md @@ -148,7 +148,7 @@ The documentation on the IAVL Tree is located [here](https://github.com/cosmos/i `dbadapter.Store` embeds `dbm.DB`, meaning most of the `KVStore` interface functions are implemented. The other functions (mostly miscellaneous) are manually implemented. This store is primarily used within [Transient Stores](#transient-stores) -### `Transient` Store +### `Transient` Store `Transient.Store` is a base-layer `KVStore` which is automatically discarded at the end of the block. diff --git a/store/types/utils.go b/store/types/utils.go index f0cf469871d9..7b69dacca30f 100644 --- a/store/types/utils.go +++ b/store/types/utils.go @@ -41,21 +41,31 @@ func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []k if iterB.Valid() { kvB = kv.Pair{Key: iterB.Key(), Value: iterB.Value()} - - iterB.Next() } compareValue := true for _, prefix := range prefixesToSkip { // Skip value comparison if we matched a prefix - if bytes.HasPrefix(kvA.Key, prefix) || bytes.HasPrefix(kvB.Key, prefix) { + if bytes.HasPrefix(kvA.Key, prefix) { compareValue = false break } } - if compareValue && (!bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value)) { + if !compareValue { + // We're skipping this key due to an exclusion prefix. If it's present in B, iterate past it. If it's + // absent don't iterate. + if bytes.Equal(kvA.Key, kvB.Key) { + iterB.Next() + } + continue + } + + // always iterate B when comparing + iterB.Next() + + if !bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value) { kvAs = append(kvAs, kvA) kvBs = append(kvBs, kvB) } diff --git a/types/events.go b/types/events.go index dbff89ce2d02..322123b43299 100644 --- a/types/events.go +++ b/types/events.go @@ -217,6 +217,7 @@ const ( AttributeKeyAccountSequence = "acc_seq" AttributeKeySignature = "signature" AttributeKeyFee = "fee" + AttributeKeyFeePayer = "fee_payer" EventTypeMessage = "message" diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 73792d3e63dd..4ab9dda9ee1a 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -109,9 +109,13 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee } } - events := sdk.Events{sdk.NewEvent(sdk.EventTypeTx, - sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), - )} + events := sdk.Events{ + sdk.NewEvent( + sdk.EventTypeTx, + sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), + sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFrom.String()), + ), + } ctx.EventManager().EmitEvents(events) return nil diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 61a2c4759e03..bdd53e433f2f 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -413,7 +413,7 @@ func randomDeposit( return nil, false, err } - minAmount = sdk.NewDecFromInt(minDepositAmount).Mul(minDepositPercent).RoundInt() + minAmount = sdk.NewDecFromInt(minDepositAmount).Mul(minDepositPercent).TruncateInt() } amount, err := simtypes.RandPositiveInt(r, minDepositAmount.Sub(minAmount)) diff --git a/x/params/spec/README.md b/x/params/spec/README.md index 6f0387a01c9c..cdeeb1a66077 100644 --- a/x/params/spec/README.md +++ b/x/params/spec/README.md @@ -5,7 +5,9 @@ parent: title: "params" --> -# `params` +# `params` (Deprecated) + +> Note: The Params module has been depreacted in favour of each module housing its own parameters. ## Abstract diff --git a/x/staking/keeper/genesis.go b/x/staking/keeper/genesis.go index 908151c1d762..b990b600c5d8 100644 --- a/x/staking/keeper/genesis.go +++ b/x/staking/keeper/genesis.go @@ -3,9 +3,10 @@ package keeper import ( "fmt" - "cosmossdk.io/math" abci "github.com/tendermint/tendermint/abci/types" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -26,7 +27,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) (res []ab // genesis.json are in block 0. ctx = ctx.WithBlockHeight(1 - sdk.ValidatorUpdateDelay) - k.SetParams(ctx, data.Params) + if err := k.SetParams(ctx, data.Params); err != nil { + panic(err) + } k.SetLastTotalPower(ctx, data.LastTotalPower) for _, validator := range data.Validators { diff --git a/x/staking/simulation/decoder.go b/x/staking/simulation/decoder.go index eec0ce22a01a..7fd3aea49d61 100644 --- a/x/staking/simulation/decoder.go +++ b/x/staking/simulation/decoder.go @@ -57,6 +57,13 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { cdc.MustUnmarshal(kvB.Value, &redB) return fmt.Sprintf("%v\n%v", redA, redB) + case bytes.Equal(kvA.Key[:1], types.ParamsKey): + var paramsA, paramsB types.Params + + cdc.MustUnmarshal(kvA.Value, ¶msA) + cdc.MustUnmarshal(kvB.Value, ¶msB) + + return fmt.Sprintf("%v\n%v", paramsA, paramsB) default: panic(fmt.Sprintf("invalid staking key prefix %X", kvA.Key[:1])) }