Skip to content

Commit

Permalink
fix: add ibc migration (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleem1314 authored Nov 23, 2021
1 parent 4803705 commit 446a7cf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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
})

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)
}
}
}

0 comments on commit 446a7cf

Please sign in to comment.