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

Implement new begin blocker interface #4563

Merged
merged 11 commits into from
Sep 6, 2023
Merged
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.0-beta.2 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc3 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR
github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y=
github.com/cosmos/iavl v1.0.0-beta.2 h1:XOsIM80Yyml/KifCXEYOy9tWCXwMAbLa91n6pReW07Y=
github.com/cosmos/iavl v1.0.0-beta.2/go.mod h1:EA97dJ07TBktRlG/iGzK6g1eCXNj1q3MGoFYkVzrwHE=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc3 h1:jEq48O/lE7dT34U6dJLLl8PaHSwerFrRqgaVVPg7J4A=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc3/go.mod h1:h+HXgDnFpzthSy7mKw3xCeOG1QZDiwlz7Vuw8eSevjg=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5 h1:OwYsRIM2gwe3ifuvi2sriEvDBd3t43vTF2GEi1SOchM=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5/go.mod h1:YriReKrNl7ZKBW6FSmgV7v4BhrN84tm672YjU0Y2C2I=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/interchain-accounts v0.5.1 h1:J5ZaYsMc2u4DekKXbDPzv8nu4YD/RSmT0F8dmN7G1oM=
Expand Down
8 changes: 8 additions & 0 deletions e2e/tests/transfer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() {

s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")

t.Run("ensure capability module BeginBlock is executed", func(t *testing.T) {
// by restarting the chain we ensure that the capability module's BeginBlocker is executed.
s.Require().NoError(chainA.StopAllNodes(ctx))
s.Require().NoError(chainA.StartAllNodes(ctx))
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA), "failed to wait for blocks")
s.InitGRPCClients(chainA)
})
Comment on lines +60 to +66
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the best place to do this. This is happening in every transfer test now?

Seems like it would make more sense to have a dedicated test in genesis_test which covered tearing down nodes and restarting with some existing channel being reused post restart to ensure capabilities are populated

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me

Copy link
Contributor Author

@chatton chatton Sep 5, 2023

Choose a reason for hiding this comment

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

think the naming is a bit misleading with base_test.go, this is actually just happening in the TestMsgTransfer_Succeeds_Nonincentivized. Happy to move it to its own separate test though.

I might do in a follow up though so we can get closer to tagging v8


chainAVersion := chainA.Config().Images[0].Version
chainBVersion := chainB.Config().Images[0].Version

Expand Down
13 changes: 13 additions & 0 deletions e2e/tests/transfer/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() {

s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks")

t.Run("verify begin blocker was executed", func(t *testing.T) {
cs, err := s.QueryClientState(ctx, chainA, exported.LocalhostClientID)
s.Require().NoError(err)
originalHeight := cs.GetLatestHeight()

s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA), "failed to wait for blocks")

cs, err = s.QueryClientState(ctx, chainA, exported.LocalhostClientID)
s.Require().NoError(err)
s.Require().True(cs.GetLatestHeight().GT(originalHeight), "client state height was not incremented")
chatton marked this conversation as resolved.
Show resolved Hide resolved
})

t.Run("channel open init localhost", func(t *testing.T) {
msgChanOpenInit := channeltypes.NewMsgChannelOpenInit(
transfertypes.PortID, transfertypes.Version,
Expand Down Expand Up @@ -159,4 +171,5 @@ func (s *LocalhostTransferTestSuite) TestMsgTransfer_Localhost() {
expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})

}
2 changes: 2 additions & 0 deletions e2e/testsuite/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
localhost "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost"
simappparams "github.com/cosmos/ibc-go/v7/testing/simapp/params"
)

Expand Down Expand Up @@ -71,6 +72,7 @@ func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) {
channeltypes.RegisterInterfaces(cfg.InterfaceRegistry)
connectiontypes.RegisterInterfaces(cfg.InterfaceRegistry)
ibctmtypes.RegisterInterfaces(cfg.InterfaceRegistry)
localhost.RegisterInterfaces(cfg.InterfaceRegistry)

// all other types
upgradetypes.RegisterInterfaces(cfg.InterfaceRegistry)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230819070346-e8164be94954
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc3
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5
github.com/cosmos/ics23/go v0.10.0
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR
github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y=
github.com/cosmos/iavl v1.0.0-beta.2 h1:XOsIM80Yyml/KifCXEYOy9tWCXwMAbLa91n6pReW07Y=
github.com/cosmos/iavl v1.0.0-beta.2/go.mod h1:EA97dJ07TBktRlG/iGzK6g1eCXNj1q3MGoFYkVzrwHE=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc3 h1:jEq48O/lE7dT34U6dJLLl8PaHSwerFrRqgaVVPg7J4A=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc3/go.mod h1:h+HXgDnFpzthSy7mKw3xCeOG1QZDiwlz7Vuw8eSevjg=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5 h1:OwYsRIM2gwe3ifuvi2sriEvDBd3t43vTF2GEi1SOchM=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5/go.mod h1:YriReKrNl7ZKBW6FSmgV7v4BhrN84tm672YjU0Y2C2I=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s=
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/cosmos/cosmos-db v1.0.0
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230819070346-e8164be94954
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc4
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/callbacks/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ github.com/cosmos/gogoproto v1.4.11 h1:LZcMHrx4FjUgrqQSWeaGC1v/TeuVFqSLa43CC6aWR
github.com/cosmos/gogoproto v1.4.11/go.mod h1:/g39Mh8m17X8Q/GDEs5zYTSNaNnInBSohtaxzQnYq1Y=
github.com/cosmos/iavl v1.0.0-rc.1 h1:5+73BEWW1gZOIUJKlk/1fpD4lOqqeFBA8KuV+NpkCpU=
github.com/cosmos/iavl v1.0.0-rc.1/go.mod h1:CmTGqMnRnucjxbjduneZXT+0vPgNElYvdefjX2q9tYc=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc4 h1:SYxmGRCkpXUXxyb3eAQNomeSe26moo9XPfY5dC2HGTw=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc4/go.mod h1:YriReKrNl7ZKBW6FSmgV7v4BhrN84tm672YjU0Y2C2I=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5 h1:OwYsRIM2gwe3ifuvi2sriEvDBd3t43vTF2GEi1SOchM=
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5/go.mod h1:YriReKrNl7ZKBW6FSmgV7v4BhrN84tm672YjU0Y2C2I=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s=
Expand Down
12 changes: 8 additions & 4 deletions modules/capability/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package capability_test
import (
"testing"

dbm "github.com/cosmos/cosmos-db"
testifysuite "github.com/stretchr/testify/suite"

"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
testifysuite "github.com/stretchr/testify/suite"

dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
Expand Down Expand Up @@ -98,7 +99,8 @@ func (suite *CapabilityTestSuite) TestInitializeMemStore() {
prevBlockGas := ctx.BlockGasMeter().GasConsumed()

// call app module BeginBlock and ensure that no gas has been consumed
newModule.BeginBlock(ctx)
err = newModule.BeginBlock(ctx)
suite.Require().NoError(err)

gasUsed := ctx.GasMeter().GasConsumed()
blockGasUsed := ctx.BlockGasMeter().GasConsumed()
Expand All @@ -116,7 +118,9 @@ func (suite *CapabilityTestSuite) TestInitializeMemStore() {

// ensure capabilities do not get reinitialized on next BeginBlock by comparing capability pointers
// and assert that the in-memory store is still initialized
newModule.BeginBlock(ctx)
err = newModule.BeginBlock(ctx)
suite.Require().NoError(err)

refreshedCap, ok := scopedKeeper.GetCapability(ctx, "transfer")
suite.Require().True(ok)
suite.Require().Equal(cap1, refreshedCap, "capabilities got reinitialized after second BeginBlock")
Expand Down
2 changes: 1 addition & 1 deletion modules/capability/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (suite *CapabilityTestSuite) TestGenesis() {
// InitGenesis must be called in order to set the intial index to 1.
// InitGenesis must be called in order to set the initial index to 1.
capability.InitGenesis(suite.ctx, *suite.keeper, *types.DefaultGenesis())

sk1 := suite.keeper.ScopeToModule(banktypes.ModuleName)
Expand Down
24 changes: 12 additions & 12 deletions modules/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

"cosmossdk.io/core/appmodule"

abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -21,6 +19,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/ibc-go/modules/capability/keeper"
"github.com/cosmos/ibc-go/modules/capability/simulation"
"github.com/cosmos/ibc-go/modules/capability/types"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (AppModuleBasic) Name() string {
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}

// RegisterInterfaces registers the module's interface types
func (a AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}
func (AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}

// DefaultGenesis returns the capability module's default genesis state.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
Expand All @@ -72,11 +72,11 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the capability module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *gwruntime.ServeMux) {
}

// GetTxCmd returns the capability module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

// GetQueryCmd returns the capability module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil }
Expand All @@ -94,19 +94,19 @@ type AppModule struct {
sealKeeper bool
}

func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, sealKeeper bool) AppModule {
func NewAppModule(cdc codec.Codec, capabilityKeeper keeper.Keeper, sealKeeper bool) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
keeper: capabilityKeeper,
sealKeeper: sealKeeper,
}
}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}
func (AppModule) IsOnePerModuleType() {}

// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
func (AppModule) IsAppModule() {}

// Name returns the capability module's name.
func (am AppModule) Name() string {
Expand All @@ -115,10 +115,10 @@ func (am AppModule) Name() string {

// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(module.Configurator) {}
func (AppModule) RegisterServices(module.Configurator) {}

// RegisterInvariants registers the capability module's invariants.
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// InitGenesis performs the capability module's genesis initialization It returns
// no validator updates.
Expand Down Expand Up @@ -167,6 +167,6 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
}
6 changes: 4 additions & 2 deletions modules/core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)
_ appmodule.HasBeginBlocker = (*AppModule)(nil)
_ appmodule.AppModule = (*AppModule)(nil)
)

Expand Down Expand Up @@ -182,8 +183,9 @@
func (AppModule) ConsensusVersion() uint64 { return 5 }

// BeginBlock returns the begin blocker for the ibc module.
func (am AppModule) BeginBlock(ctx sdk.Context) {
ibcclient.BeginBlocker(ctx, am.keeper.ClientKeeper)
func (am AppModule) BeginBlock(ctx context.Context) error {
ibcclient.BeginBlocker(sdk.UnwrapSDKContext(ctx), am.keeper.ClientKeeper)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
return nil
}

// AppModuleSimulation functions
Expand Down
Loading