Skip to content

Commit

Permalink
feat: add preblocker
Browse files Browse the repository at this point in the history
  • Loading branch information
duvbell committed Mar 29, 2024
1 parent ad1a374 commit fbd6f67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ func NewComposableApp(
app.basicModuleManger.RegisterLegacyAminoCodec(legacyAmino)
app.basicModuleManger.RegisterInterfaces(interfaceRegistry)

app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
Expand Down Expand Up @@ -557,6 +561,7 @@ func NewComposableApp(

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)

app.SetAnteHandler(ante.NewAnteHandler(
Expand Down Expand Up @@ -628,17 +633,24 @@ func (app *ComposableApp) GetTxConfig() client.TxConfig {

// BeginBlocker application updates every begin block
func (app *ComposableApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
fmt.Println("begin block")
BeginBlockForks(ctx, app)
return app.mm.BeginBlock(ctx)
}

// EndBlocker application updates every end block
func (app *ComposableApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
fmt.Println("end block")
return app.mm.EndBlock(ctx)
}

func (app *ComposableApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
return app.mm.PreBlock(ctx)
}

// InitChainer application update at chain initialization
func (app *ComposableApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) {
fmt.Println("init chainner")
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
Expand Down Expand Up @@ -760,6 +772,8 @@ func (app *ComposableApp) customPreUpgradeHandler(_ upgradetypes.Plan) {

func (app *ComposableApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
fmt.Println("setting upgrade handler for", upgrade.UpgradeName)

app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v7_0_0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v7_0_0

import (
"context"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand All @@ -18,7 +19,9 @@ func CreateUpgradeHandler(
_ codec.Codec,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
fmt.Println("upgrade: Creating upgrade handler for v7_0_0")
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
fmt.Println("Running upgrade handler for v7_0_0")
return mm.RunMigrations(ctx, configurator, vm)
}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,14 @@ require (

replace (
cosmossdk.io/core => cosmossdk.io/core v0.11.0

// Use the keyring specified by the cosmos-sdk
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
// lock wasmvm so we do not break the grandpa contract
// TODO: check wasm vm compatibility with grandpa contract
github.com/CosmWasm/wasmvm => github.com/CosmWasm/wasmvm v1.5.2

github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.5
github.com/cosmos/cosmos-sdk => /Users/kien6034/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.50.5

github.com/cosmos/ibc-go/modules/light-clients/08-wasm => github.com/notional-labs/ibc-go/modules/light-clients/08-wasm v0.0.0-20240328152744-0f9d4a916102
// github.com/cosmos/ibc-go/modules/light-clients/08-wasm => /Users/hoank/resource/notional/ibc-go/modules/light-clients/08-wasm
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@ cosmossdk.io/x/nft v0.1.0 h1:VhcsFiEK33ODN27kxKLa0r/CeFd8laBfbDBwYqCyYCM=
cosmossdk.io/x/nft v0.1.0/go.mod h1:ec4j4QAO4mJZ+45jeYRnW7awLHby1JZANqe1hNZ4S3g=
cosmossdk.io/x/tx v0.13.1 h1:Mg+EMp67Pz+NukbJqYxuo8uRp7N/a9uR+oVS9pONtj8=
cosmossdk.io/x/tx v0.13.1/go.mod h1:CBCU6fsRVz23QGFIQBb1DNX2DztJCf3jWyEkHY2nJQ0=
cosmossdk.io/x/upgrade v0.1.1 h1:aoPe2gNvH+Gwt/Pgq3dOxxQVU3j5P6Xf+DaUJTDZATc=
cosmossdk.io/x/upgrade v0.1.1/go.mod h1:MNLptLPcIFK9CWt7Ra//8WUZAxweyRDNcbs5nkOcQy0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
Expand Down Expand Up @@ -819,8 +817,6 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK
github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
github.com/cosmos/cosmos-proto v1.0.0-beta.4 h1:aEL7tU/rLOmxZQ9z4i7mzxcLbSCY48OdY7lIWTLG7oU=
github.com/cosmos/cosmos-proto v1.0.0-beta.4/go.mod h1:oeB+FyVzG3XrQJbJng0EnV8Vljfk9XvTIpGILNU/9Co=
github.com/cosmos/cosmos-sdk v0.50.5 h1:MOEi+DKYgW67YaPgB+Pf+nHbD3V9S/ayitRKJYLfGIA=
github.com/cosmos/cosmos-sdk v0.50.5/go.mod h1:oV/k6GJgXV9QPoM2fsYDPPsyPBgQbdotv532O6Mz1OQ=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
Expand Down

0 comments on commit fbd6f67

Please sign in to comment.