Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix ibc error #654

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import (
ibc "github.com/cosmos/ibc-go/v2/modules/core"
ibcclient "github.com/cosmos/ibc-go/v2/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v2/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v2/modules/core/keeper"
Expand Down Expand Up @@ -206,6 +207,8 @@ type RegenApp struct {

// module configurator
configurator module.Configurator

bte *BlockTimerExecutor
}

// NewRegenApp returns a reference to an initialized RegenApp.
Expand Down Expand Up @@ -245,6 +248,8 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
keys: keys,
tkeys: tkeys,
memKeys: memKeys,

bte: NewBlockTimerExecutor(),
}

app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
Expand Down Expand Up @@ -491,6 +496,12 @@ func NewRegenApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
// note replicate if you do not need to test core IBC or light clients.
app.ScopedIBCMockKeeper = scopedIBCMockKeeper

// TODO: update height once proposal is passed
app.AddPatch(3038452, func(ctx sdk.Context) error {
app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())
return nil
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, this is a hack to get consensus breaking change without doing a SoftwareUpgrade proposal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct


return app
}

Expand All @@ -507,9 +518,14 @@ func (app *RegenApp) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *RegenApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
app.bte.Start(ctx)
return app.mm.BeginBlock(ctx, req)
}

func (app *RegenApp) AddPatch(height int64, patch Execute) {
app.bte.add(height, patch)
}

// EndBlocker application updates every end block
func (app *RegenApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
Expand Down
33 changes: 33 additions & 0 deletions app/patch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Execute is responsible for checking the permission to execute patches
type Execute = func(ctx sdk.Context) error

// BlockTimerExecutor is responsible for checking the permission to execute patches
type BlockTimerExecutor struct {
patches map[int64]Execute
}

func NewBlockTimerExecutor() *BlockTimerExecutor {
return &BlockTimerExecutor{
patches: make(map[int64]Execute),
}
}

func (bte *BlockTimerExecutor) add(height int64, patch Execute) {
bte.patches[height] = patch
}

func (bte *BlockTimerExecutor) Start(ctx sdk.Context) {
exec := bte.patches[ctx.BlockHeight()]
if exec != nil {
ctx.Logger().Info("Execute patch", "height", ctx.BlockHeight())
if err := exec(ctx); err != nil {
panic(err)
}
}
}