Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into use-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Aug 9, 2022
2 parents f25f1eb + b6791b7 commit d0a8f88
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 34 deletions.
38 changes: 28 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 14 additions & 7 deletions .github/workflows/proto-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
branches:
- main
paths:
- "contrib/devtools/dockerfile"
- "contrib/devtools/Dockerfile"
pull_request:
paths:
- "contrib/devtools/Dockerfile"

permissions:
contents: read
Expand All @@ -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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion contrib/devtools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 3 additions & 1 deletion docs/building-modules/keeper.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Keeper struct {
// Store key(s)

// codec

// authority
}
```

Expand All @@ -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.

Expand Down
5 changes: 2 additions & 3 deletions docs/core/baseapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/core/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
18 changes: 14 additions & 4 deletions store/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const (
AttributeKeyAccountSequence = "acc_seq"
AttributeKeySignature = "signature"
AttributeKeyFee = "fee"
AttributeKeyFeePayer = "fee_payer"

EventTypeMessage = "message"

Expand Down
10 changes: 7 additions & 3 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/gov/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion x/params/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions x/staking/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions x/staking/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &paramsA)
cdc.MustUnmarshal(kvB.Value, &paramsB)

return fmt.Sprintf("%v\n%v", paramsA, paramsB)
default:
panic(fmt.Sprintf("invalid staking key prefix %X", kvA.Key[:1]))
}
Expand Down

0 comments on commit d0a8f88

Please sign in to comment.