Skip to content

Commit

Permalink
Merge branch 'main' into aka/fixTestGenesisAccountValidate
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Dec 20, 2024
2 parents 135ac7e + bb670d2 commit b76a712
Show file tree
Hide file tree
Showing 38 changed files with 1,048 additions and 1,060 deletions.
12 changes: 6 additions & 6 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

* @AdityaSripal @damiannolan @DimitrisJim @gjermundgaraba
* @AdityaSripal @damiannolan @gjermundgaraba

# Our appreciation and gratitude to past code owners: @fedekunze @seantking @tmsdkeys @charleenfei @crodriguezvega @colin-axner @chatton @bznein
# Our appreciation and gratitude to past code owners: @fedekunze @seantking @tmsdkeys @charleenfei @crodriguezvega @colin-axner @chatton @bznein @DimitrisJim

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
Expand All @@ -25,12 +25,12 @@

# CODEOWNERS for 08-wasm light client module

/modules/light-clients/08-wasm/ @AdityaSripal @damiannolan @DimitrisJim @srdtrk
/modules/light-clients/08-wasm/ @AdityaSripal @damiannolan @srdtrk

# CODEOWNERS for ICS 20

/modules/apps/transfer/ @AdityaSripal @damiannolan @DimitrisJim
/proto/ibc/applications/transfer/ @AdityaSripal @damiannolan @DimitrisJim
/modules/apps/transfer/ @AdityaSripal @damiannolan
/proto/ibc/applications/transfer/ @AdityaSripal @damiannolan

# CODEOWNERS for interchain-accounts module

Expand All @@ -48,5 +48,5 @@

# CODEOWNERS for docs

/docs/ @AdityaSripal @damiannolan @DimitrisJim @srdtrk
/docs/ @AdityaSripal @damiannolan @srdtrk

2 changes: 1 addition & 1 deletion .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pull_request_rules:
actions:
backport:
branches:
- 08-wasm/release/v0.5.x+ibc-go-v8.4.x-wasmvm-v2.0.x
- 08-wasm/release/v0.5.x+ibc-go-v8.4.x-wasmvm-v2.1.x
- name: backport patches to v0.5.x wasm ibc-go v9.0.x & wasmvm 2.1.x branch
conditions:
- base=main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{
"success",
func() {},
true,
nil,
},
{
"failed to validate active channel - invalid port identifier",
Expand All @@ -236,7 +236,7 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {

genesisState = genesistypes.NewHostGenesisState(activeChannels, []genesistypes.RegisteredInterchainAccount{}, icatypes.HostPortID, hosttypes.DefaultParams())
},
false,
host.ErrInvalidID,
},
{
"failed to validate active channel - invalid channel identifier",
Expand All @@ -250,7 +250,7 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {

genesisState = genesistypes.NewHostGenesisState(activeChannels, []genesistypes.RegisteredInterchainAccount{}, icatypes.HostPortID, hosttypes.DefaultParams())
},
false,
host.ErrInvalidID,
},
{
"failed to validate registered account - invalid port identifier",
Expand All @@ -271,7 +271,7 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {

genesisState = genesistypes.NewHostGenesisState(activeChannels, registeredAccounts, icatypes.HostPortID, hosttypes.DefaultParams())
},
false,
host.ErrInvalidID,
},
{
"failed to validate registered account - invalid owner address",
Expand All @@ -292,7 +292,7 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {

genesisState = genesistypes.NewHostGenesisState(activeChannels, registeredAccounts, icatypes.HostPortID, hosttypes.DefaultParams())
},
false,
icatypes.ErrInvalidAccountAddress,
},
{
"failed to validate controller ports - invalid port identifier",
Expand All @@ -313,7 +313,7 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {

genesisState = genesistypes.NewHostGenesisState(activeChannels, registeredAccounts, "invalid|port", hosttypes.DefaultParams())
},
false,
host.ErrInvalidID,
},
}

Expand All @@ -327,10 +327,11 @@ func (suite *GenesisTypesTestSuite) TestValidateHostGenesisState() {

err := genesisState.Validate()

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err, tc.name)
} else {
suite.Require().Error(err, tc.name)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down
6 changes: 5 additions & 1 deletion modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), logger.With(log.ModuleKey, "x/upgrade"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), skipUpgradeHeights, appCodec, homePath, app.BaseApp, govModuleAddr, app.ConsensusParamsKeeper)

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec,
runtime.NewEnvironment(runtime.NewKVStoreService(keys[ibcexported.StoreKey]), logger.With(log.ModuleKey, "x/ibc")),
app.GetSubspace(ibcexported.ModuleName),
app.UpgradeKeeper,
govModuleAddr,
)

// NOTE: The mock ContractKeeper is only created for testing.
Expand Down
12 changes: 10 additions & 2 deletions modules/core/02-client/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v9/modules/core/02-client/keeper"
Expand All @@ -9,7 +11,11 @@ import (
)

// BeginBlocker is used to perform IBC client upgrades
func BeginBlocker(ctx sdk.Context, k *keeper.Keeper) {
func BeginBlocker(goCtx context.Context, k *keeper.Keeper) {
// TODO: In order to fully migrate away from sdk.Context here we will need to depend on comet service in order
// to consume the full block header as Env only contains header.Info (where we cannot access next vals hash)
ctx := sdk.UnwrapSDKContext(goCtx)

plan, err := k.GetUpgradePlan(ctx)
if err == nil {
// Once we are at the last block this chain will commit, set the upgraded consensus state
Expand All @@ -29,7 +35,9 @@ func BeginBlocker(ctx sdk.Context, k *keeper.Keeper) {
// SetUpgradedConsensusState always returns nil, hence the blank here.
_ = k.SetUpgradedConsensusState(ctx, plan.Height, bz)

keeper.EmitUpgradeChainEvent(ctx, plan.Height)
if err := k.EmitUpgradeChainEvent(ctx, plan.Height); err != nil {
k.Logger.Error("error in events emission", "error", err.Error())
}
}
}
}
42 changes: 18 additions & 24 deletions modules/core/02-client/keeper/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package keeper

import (
errorsmod "cosmossdk.io/errors"
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
Expand All @@ -15,7 +15,7 @@ import (
// client identifier. The light client module is responsible for setting any client-specific data in the store
// via the Initialize method. This includes the client state, initial consensus state and any associated
// metadata. The generated client identifier will be returned if a client was successfully initialized.
func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, consensusState []byte) (string, error) {
func (k *Keeper) CreateClient(ctx context.Context, clientType string, clientState, consensusState []byte) (string, error) {
if clientType == exported.Localhost {
return "", errorsmod.Wrapf(types.ErrInvalidClientType, "cannot create client of type: %s", clientType)
}
Expand All @@ -36,16 +36,18 @@ func (k *Keeper) CreateClient(ctx sdk.Context, clientType string, clientState, c
}

initialHeight := clientModule.LatestHeight(ctx, clientID)
k.Logger(ctx).Info("client created at height", "client-id", clientID, "height", initialHeight.String())
k.Logger.Info("client created at height", "client-id", clientID, "height", initialHeight.String())

defer telemetry.ReportCreateClient(clientType)
emitCreateClientEvent(ctx, clientID, clientType, initialHeight)
if err := k.emitCreateClientEvent(ctx, clientID, clientType, initialHeight); err != nil {
return "", err
}

return clientID, nil
}

// UpdateClient updates the consensus state and the state root from a provided header.
func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg exported.ClientMessage) error {
func (k *Keeper) UpdateClient(ctx context.Context, clientID string, clientMsg exported.ClientMessage) error {
clientModule, err := k.Route(ctx, clientID)
if err != nil {
return err
Expand All @@ -63,33 +65,27 @@ func (k *Keeper) UpdateClient(ctx sdk.Context, clientID string, clientMsg export
if foundMisbehaviour {
clientModule.UpdateStateOnMisbehaviour(ctx, clientID, clientMsg)

k.Logger(ctx).Info("client frozen due to misbehaviour", "client-id", clientID)
k.Logger.Info("client frozen due to misbehaviour", "client-id", clientID)

clientType := types.MustParseClientIdentifier(clientID)
defer telemetry.ReportUpdateClient(foundMisbehaviour, clientType, clientID)
emitSubmitMisbehaviourEvent(ctx, clientID, clientType)

return nil
return k.emitSubmitMisbehaviourEvent(ctx, clientID, clientType)
}

consensusHeights := clientModule.UpdateState(ctx, clientID, clientMsg)

k.Logger(ctx).Info("client state updated", "client-id", clientID, "heights", consensusHeights)
k.Logger.Info("client state updated", "client-id", clientID, "heights", consensusHeights)

clientType := types.MustParseClientIdentifier(clientID)
defer telemetry.ReportUpdateClient(foundMisbehaviour, clientType, clientID)
emitUpdateClientEvent(ctx, clientID, clientType, consensusHeights, k.cdc, clientMsg)

return nil
return k.emitUpdateClientEvent(ctx, clientID, clientType, consensusHeights, k.cdc, clientMsg)
}

// UpgradeClient upgrades the client to a new client state if this new client was committed to
// by the old client at the specified upgrade height
func (k *Keeper) UpgradeClient(
ctx sdk.Context,
clientID string,
upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof []byte,
) error {
func (k *Keeper) UpgradeClient(ctx context.Context, clientID string, upgradedClient, upgradedConsState, upgradeClientProof, upgradeConsensusStateProof []byte) error {
clientModule, err := k.Route(ctx, clientID)
if err != nil {
return err
Expand All @@ -104,21 +100,20 @@ func (k *Keeper) UpgradeClient(
}

latestHeight := clientModule.LatestHeight(ctx, clientID)
k.Logger(ctx).Info("client state upgraded", "client-id", clientID, "height", latestHeight.String())
k.Logger.Info("client state upgraded", "client-id", clientID, "height", latestHeight.String())

clientType := types.MustParseClientIdentifier(clientID)
defer telemetry.ReportUpgradeClient(clientType, clientID)
emitUpgradeClientEvent(ctx, clientID, clientType, latestHeight)

return nil
return k.emitUpgradeClientEvent(ctx, clientID, clientType, latestHeight)
}

// RecoverClient will invoke the light client module associated with the subject clientID requesting it to
// recover the subject client given a substitute client identifier. The light client implementation
// is responsible for validating the parameters of the substitute (ensuring they match the subject's parameters)
// as well as copying the necessary consensus states from the substitute to the subject client store.
// The substitute must be Active and the subject must not be Active.
func (k *Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClientID string) error {
func (k *Keeper) RecoverClient(ctx context.Context, subjectClientID, substituteClientID string) error {
clientModule, err := k.Route(ctx, subjectClientID)
if err != nil {
return errorsmod.Wrap(types.ErrRouteNotFound, subjectClientID)
Expand All @@ -142,11 +137,10 @@ func (k *Keeper) RecoverClient(ctx sdk.Context, subjectClientID, substituteClien
return err
}

k.Logger(ctx).Info("client recovered", "client-id", subjectClientID)
k.Logger.Info("client recovered", "client-id", subjectClientID)

clientType := types.MustParseClientIdentifier(subjectClientID)
defer telemetry.ReportRecoverClient(clientType, subjectClientID)
emitRecoverClientEvent(ctx, subjectClientID, clientType)

return nil
return k.emitRecoverClientEvent(ctx, subjectClientID, clientType)
}
Loading

0 comments on commit b76a712

Please sign in to comment.