Skip to content

Commit

Permalink
Merge branch 'master' into ty/3729-tx_block
Browse files Browse the repository at this point in the history
  • Loading branch information
technicallyty committed Jan 6, 2022
2 parents 4666d08 + fbcca26 commit d3749f8
Show file tree
Hide file tree
Showing 22 changed files with 504 additions and 229 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/atlas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand All @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand All @@ -45,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v3.5.0
- uses: amannn/action-semantic-pull-request@v3.6.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-go@v2.1.5
with:
go-version: 1.17
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@master
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
PATTERNS: |
**/**.proto
Expand All @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
PATTERNS: |
**/**.proto
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
PATTERNS: |
**/**.go
Expand All @@ -72,7 +72,7 @@ jobs:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
SUFFIX_FILTER: |
**/**.go
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
SUFFIX_FILTER: |
**/**.go
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
SUFFIX_FILTER: |
**/**.go
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- uses: actions/setup-go@v2.1.5
with:
go-version: 1.17
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand All @@ -54,7 +54,7 @@ jobs:
- uses: actions/setup-go@v2.1.5
with:
go-version: 1.17
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
- uses: actions/setup-go@v2.1.5
with:
go-version: 1.17
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
PATTERNS: |
**/**.go
Expand All @@ -132,7 +132,7 @@ jobs:
needs: tests
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
PATTERNS: |
**/**.go
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:
- uses: actions/setup-go@v2.1.5
with:
go-version: 1.17
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
with:
PATTERNS: |
**/**.go
Expand All @@ -214,7 +214,7 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand All @@ -234,7 +234,7 @@ jobs:
- uses: actions/setup-go@v2.1.5
with:
go-version: 1.17
- uses: technote-space/get-diff-action@v5
- uses: technote-space/get-diff-action@v6.0.1
id: git_diff
with:
PATTERNS: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#10507](https://github.com/cosmos/cosmos-sdk/pull/10507) Add middleware for tx priority.
* [\#10311](https://github.com/cosmos/cosmos-sdk/pull/10311) Adds cli to use tips transactions. It adds an `--aux` flag to all CLI tx commands to generate the aux signer data (with optional tip), and a new `tx aux-to-fee` subcommand to let the fee payer gather aux signer data and broadcast the tx
* [\#10430](https://github.com/cosmos/cosmos-sdk/pull/10430) ADR-040: Add store/v2 `MultiStore` implementation
* [\#10614](https://github.com/cosmos/cosmos-sdk/pull/10614) Support in-place migration ordering

### API Breaking Changes

Expand Down
8 changes: 0 additions & 8 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sort"
"strings"
"syscall"
"time"

"github.com/gogo/protobuf/proto"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -18,7 +17,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx"
Expand Down Expand Up @@ -137,7 +135,6 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")

if app.cms.TracingEnabled() {
app.cms.SetTracingContext(sdk.TraceContext(
Expand Down Expand Up @@ -204,7 +201,6 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg

// EndBlock implements the ABCI interface.
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "end_block")

if app.deliverState.ms.TracingEnabled() {
app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore)
Expand Down Expand Up @@ -236,7 +232,6 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc
// will contain releveant error information. Regardless of tx execution outcome,
// the ResponseCheckTx will contain relevant gas execution context.
func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
defer telemetry.MeasureSince(time.Now(), "abci", "check_tx")

var mode runTxMode

Expand Down Expand Up @@ -271,7 +266,6 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
// Regardless of tx execution outcome, the ResponseDeliverTx will contain relevant
// gas execution context.
func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx")

var abciRes abci.ResponseDeliverTx
defer func() {
Expand Down Expand Up @@ -306,7 +300,6 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx
// against that height and gracefully halt if it matches the latest committed
// height.
func (app *BaseApp) Commit() (res abci.ResponseCommit) {
defer telemetry.MeasureSince(time.Now(), "abci", "commit")

header := app.deliverState.ctx.BlockHeader()
retainHeight := app.GetBlockRetentionHeight(header.Height)
Expand Down Expand Up @@ -410,7 +403,6 @@ func (app *BaseApp) snapshot(height int64) {
// Query implements the ABCI interface. It delegates to CommitMultiStore if it
// implements Queryable.
func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
defer telemetry.MeasureSince(time.Now(), "abci", "query")

// Add panic recovery for all queries.
// ref: https://github.com/cosmos/cosmos-sdk/pull/8039
Expand Down
8 changes: 0 additions & 8 deletions docs/core/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ The following examples expose too much cardinality and may not even prove to be
| `tx_msg_ibc_recv_packet` | Total number of IBC packets received | packet | counter |
| `tx_msg_ibc_acknowledge_packet` | Total number of IBC packets acknowledged | acknowledgement | counter |
| `ibc_timeout_packet` | Total number of IBC timeout packets | timeout | counter |
| `abci_check_tx` | Duration of ABCI `CheckTx` | ms | summary |
| `abci_deliver_tx` | Duration of ABCI `DeliverTx` | ms | summary |
| `abci_commit` | Duration of ABCI `Commit` | ms | summary |
| `abci_query` | Duration of ABCI `Query` | ms | summary |
| `abci_begin_block` | Duration of ABCI `BeginBlock` | ms | summary |
| `abci_end_block` | Duration of ABCI `EndBlock` | ms | summary |
| `begin_blocker` | Duration of `BeginBlock` for a given module | ms | summary |
| `end_blocker` | Duration of `EndBlock` for a given module | ms | summary |
| `store_iavl_get` | Duration of an IAVL `Store#Get` call | ms | summary |
| `store_iavl_set` | Duration of an IAVL `Store#Set` call | ms | summary |
| `store_iavl_has` | Duration of an IAVL `Store#Has` call | ms | summary |
Expand Down
84 changes: 44 additions & 40 deletions docs/core/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,13 @@ This document provides steps to use the In-Place Store Migrations upgrade method

Each module gets assigned a consensus version by the module developer. The consensus version serves as the breaking change version of the module. The Cosmos SDK keeps track of all module consensus versions in the x/upgrade `VersionMap` store. During an upgrade, the difference between the old `VersionMap` stored in state and the new `VersionMap` is calculated by the Cosmos SDK. For each identified difference, the module-specific migrations are run and the respective consensus version of each upgraded module is incremented.

## Genesis State

When starting a new chain, the consensus version of each module must be saved to state during the application's genesis. To save the consensus version, add the following line to the `InitChainer` method in `app.go`:

```diff
func (app *MyApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
...
+ app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
...
}
```

This information is used by the Cosmos SDK to detect when modules with newer versions are introduced to the app.

### Consensus Version

The consensus version is defined on each app module by the module developer and serves as the breaking change version of the module. The consensus version informs the Cosmos SDK on which modules need to be upgraded. For example, if the bank module was version 2 and an upgrade introduces bank module 3, the Cosmos SDK upgrades the bank module and runs the "version 2 to 3" migration script.

### Version Map

The version map is a mapping of module names to consensus versions. The map is persisted to x/upgrade's state for use during in-place migrations. When migrations finish, the updated version map is persisted to state.
The version map is a mapping of module names to consensus versions. The map is persisted to x/upgrade's state for use during in-place migrations. When migrations finish, the updated version map is persisted in the state.

## Upgrade Handlers

Expand All @@ -60,24 +46,29 @@ Inside these functions, you must perform any upgrade logic to include in the pro

## Running Migrations

Migrations are run inside of an `UpgradeHandler` using `app.mm.RunMigrations(ctx, cfg, vm)`. The `UpgradeHandler` functions describe the functionality to occur during an upgrade. The `RunMigration` function loops through the `VersionMap` argument and runs the migration scripts for all versions that are less than the versions of the new binary app module. After the migrations are finished, a new `VersionMap` is returned to persist the upgraded module versions to state.
Migrations are run inside of an `UpgradeHandler` using `app.mm.RunMigrations(ctx, cfg, vm)`. The `UpgradeHandler` functions describe the functionality to occur during an upgrade. The `RunMigration` function loops through the `VersionMap` argument and runs the migration scripts for all versions that are less than the versions of the new binary app module. After the migrations are finished, a new `VersionMap` is returned to persist the upgraded module versions to state.

```go
cfg := module.NewConfigurator(...)
app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

// ...
// do upgrade logic
// additional upgrade logic
// ...

// RunMigrations returns the VersionMap
// with the updated module ConsensusVersions
return app.mm.RunMigrations(ctx, vm)
// returns a VersionMap with the updated module ConsensusVersions
return app.mm.RunMigrations(ctx, fromVM)
})
```

To learn more about configuring migration scripts for your modules, see the [Module Upgrade Guide](../building-modules/upgrade.md).

### Order Of Migrations

By default, all migrations are run in module name alphabetical ascending order, except `x/auth` which is run last. The reason is state dependencies between x/auth and other modules (you can read more in [issue #10606](https://github.com/cosmos/cosmos-sdk/issues/10606)).

If you want to change the order of migration then you should call `app.mm.SetOrderMigrations(module1, module2, ...)` in your app.go file. The function will panic if you forget to include a module in the argument list.

## Adding New Modules During Upgrades

You can introduce entirely new modules to the application during an upgrade. New modules are recognized because they have not yet been registered in `x/upgrade`'s `VersionMap` store. In this case, `RunMigrations` calls the `InitGenesis` function from the corresponding module to set up its initial state.
Expand Down Expand Up @@ -105,7 +96,35 @@ if upgradeInfo.Name == "my-plan" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.
}
```

## Overwriting Genesis Functions
## Genesis State

When starting a new chain, the consensus version of each module MUST be saved to state during the application's genesis. To save the consensus version, add the following line to the `InitChainer` method in `app.go`:

```diff
func (app *MyApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
...
+ app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
...
}
```

This information is used by the Cosmos SDK to detect when modules with newer versions are introduced to the app.

For a new module `foo`, `InitGenesis` is called by `RunMigration` only when `foo` is registered in the module manager but it's not set in the `fromVM`. Therefore, if you want to skip `InitGenesis` when a new module is added to the app, then you should set its module version in `fromVM` to the module consensus version:

```go
app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// ...

// Set foo's version to the latest ConsensusVersion in the VersionMap.
// This will skip running InitGenesis on Foo
fromVM[foo.ModuleName] = foo.AppModule{}.ConsensusVersion()

return app.mm.RunMigrations(ctx, fromVM)
})
```

### Overwriting Genesis Functions

The Cosmos SDK offers modules that the application developer can import in their app. These modules often have an `InitGenesis` function already defined.

Expand All @@ -118,32 +137,17 @@ You MUST manually set the consensus version in the version map passed to the `Up
```go
import foo "github.com/my/module/foo"

app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

// Register the consensus version in the version map
// to avoid the SDK from triggering the default
// InitGenesis function.
vm["foo"] = foo.AppModule{}.ConsensusVersion()
fromVM["foo"] = foo.AppModule{}.ConsensusVersion()

// Run custom InitGenesis for foo
app.mm["foo"].InitGenesis(ctx, app.appCodec, myCustomGenesisState)

return app.mm.RunMigrations(ctx, cfg, vm)
})
```

If you do not have a custom genesis function and want to skip the module's default genesis function, you can simply register the module with the version map in the `UpgradeHandler` as shown in the example:

```go
import foo "github.com/my/module/foo"

app.UpgradeKeeper.SetUpgradeHandler("my-plan", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {

// Set foo's version to the latest ConsensusVersion in the VersionMap.
// This will skip running InitGenesis on Foo
vm["foo"] = foo.AppModule{}.ConsensusVersion()

return app.mm.RunMigrations(ctx, cfg, vm)
return app.mm.RunMigrations(ctx, cfg, fromVM)
})
```

Expand Down
Loading

0 comments on commit d3749f8

Please sign in to comment.