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

imp: pass client store provider as arg to client modules #6028

Merged
merged 14 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,10 @@ func NewSimApp(

clientRouter := app.IBCKeeper.ClientKeeper.GetRouter()

tmLightClientModule := ibctm.NewLightClientModule(appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String())
tmLightClientModule := ibctm.NewLightClientModule(keys[ibcexported.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String())
clientRouter.AddRoute(ibctm.ModuleName, &tmLightClientModule)

smLightClientModule := solomachine.NewLightClientModule(appCodec)
smLightClientModule := solomachine.NewLightClientModule(keys[ibcexported.StoreKey], appCodec)
clientRouter.AddRoute(solomachine.ModuleName, &smLightClientModule)

// create evidence keeper with router
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Keeper struct {

// NewKeeper creates a new NewKeeper instance
func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace types.ParamSubspace, sk types.StakingKeeper, uk types.UpgradeKeeper) Keeper {
router := types.NewRouter(key)
router := types.NewRouter()
localhostModule := localhost.NewLightClientModule(cdc, key)
router.AddRoute(exported.Localhost, localhostModule)

Expand Down
17 changes: 4 additions & 13 deletions modules/core/02-client/types/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@ package types
import (
"fmt"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/ibc-go/v8/modules/core/exported"
)

// Router is a map from a clientType to a LightClientModule instance.
// The router has a reference to the client store provider (02-client keeper)
// and will register the store provider on a client module upon route registration.
type Router struct {
routes map[string]exported.LightClientModule
storeProvider exported.ClientStoreProvider
routes map[string]exported.LightClientModule
}

// NewRouter returns an instance of the Router.
func NewRouter(key storetypes.StoreKey) *Router {
func NewRouter() *Router {
return &Router{
routes: make(map[string]exported.LightClientModule),
storeProvider: NewStoreProvider(key),
routes: make(map[string]exported.LightClientModule),
}
}

// AddRoute adds LightClientModule for a given module name. It returns the Router
// so AddRoute calls can be linked. The store provider will be registered on the
// light client module. This function will panic if:
// so AddRoute calls can be linked. This function will panic if:
// - the Router is sealed,
// - or a module is already registered for the provided client type,
// - or the client type is invalid.
Expand All @@ -40,8 +33,6 @@ func (rtr *Router) AddRoute(clientType string, module exported.LightClientModule
}

rtr.routes[clientType] = module

module.RegisterStoreProvider(rtr.storeProvider)
Copy link
Contributor

Choose a reason for hiding this comment

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

For context: this was the main thing we wanted to remove with this PR!

return rtr
}

Expand Down
5 changes: 0 additions & 5 deletions modules/core/exported/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ type ClientStoreProvider interface {
// LightClientModule is an interface which core IBC uses to interact with light client modules.
// Light client modules must implement this interface to integrate with core IBC.
type LightClientModule interface {
// RegisterStoreProvider is called by core IBC when a LightClientModule is added to the router.
// It allows the LightClientModule to set a ClientStoreProvider which supplies isolated prefix client stores
// to IBC light client instances.
RegisterStoreProvider(storeProvider ClientStoreProvider)
Copy link
Contributor

Choose a reason for hiding this comment

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

And this!


// Initialize is called upon client creation, it allows the client to perform validation on the client state and initial consensus state.
// The light client module is responsible for setting any client-specific data in the store. This includes the client state,
// initial consensus state and any associated metadata.
Expand Down
13 changes: 4 additions & 9 deletions modules/light-clients/06-solomachine/light_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package solomachine

import (
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -19,19 +20,13 @@ type LightClientModule struct {
}

// NewLightClientModule creates and returns a new 06-solomachine LightClientModule.
func NewLightClientModule(cdc codec.BinaryCodec) LightClientModule {
func NewLightClientModule(key storetypes.StoreKey, cdc codec.BinaryCodec) LightClientModule {
return LightClientModule{
cdc: cdc,
cdc: cdc,
storeProvider: clienttypes.NewStoreProvider(key),
}
}

// RegisterStoreProvider is called by core IBC when a LightClientModule is added to the router.
// It allows the LightClientModule to set a ClientStoreProvider which supplies isolated prefix client stores
// to IBC light client instances.
func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) {
l.storeProvider = storeProvider
}

// Initialize unmarshals the provided client and consensus states and performs basic validation. It calls into the
// clientState.Initialize method.
//
Expand Down
13 changes: 4 additions & 9 deletions modules/light-clients/07-tendermint/light_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tendermint

import (
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -21,19 +22,13 @@ type LightClientModule struct {
}

// NewLightClientModule creates and returns a new 07-tendermint LightClientModule.
func NewLightClientModule(cdc codec.BinaryCodec, authority string) LightClientModule {
func NewLightClientModule(key storetypes.StoreKey, cdc codec.BinaryCodec, authority string) LightClientModule {
return LightClientModule{
keeper: keeper.NewKeeper(cdc, authority),
keeper: keeper.NewKeeper(cdc, authority),
storeProvider: clienttypes.NewStoreProvider(key),
}
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
}

// RegisterStoreProvider is called by core IBC when a LightClientModule is added to the router.
// It allows the LightClientModule to set a ClientStoreProvider which supplies isolated prefix client stores
// to IBC light client instances.
func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) {
l.storeProvider = storeProvider
}

// Initialize unmarshals the provided client and consensus states and performs basic validation. It calls into the
// clientState.Initialize method.
//
Expand Down
13 changes: 4 additions & 9 deletions modules/light-clients/08-wasm/light_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import (
errorsmod "cosmossdk.io/errors"

Check failure on line 5 in modules/light-clients/08-wasm/light_client_module.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
storetypes "cosmossdk.io/store/types"

Check failure on line 6 in modules/light-clients/08-wasm/light_client_module.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
sdk "github.com/cosmos/cosmos-sdk/types"

wasmkeeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
Expand All @@ -21,19 +22,13 @@
}

// NewLightClientModule creates and returns a new 08-wasm LightClientModule.
func NewLightClientModule(keeper wasmkeeper.Keeper) LightClientModule {
func NewLightClientModule(keeper wasmkeeper.Keeper, key storetypes.StoreKey) LightClientModule {
return LightClientModule{
keeper: keeper,
keeper: keeper,
storeProvider: clienttypes.NewStoreProvider(key),
}
}

// RegisterStoreProvider is called by core IBC when a LightClientModule is added to the router.
// It allows the LightClientModule to set a ClientStoreProvider which supplies isolated prefix client stores
// to IBC light client instances.
func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) {
l.storeProvider = storeProvider
}

// Initialize unmarshals the provided client and consensus states and performs basic validation. It calls into the
// clientState.Initialize method.
//
Expand Down
6 changes: 3 additions & 3 deletions modules/light-clients/08-wasm/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,13 @@ func NewSimApp(

clientRouter := app.IBCKeeper.ClientKeeper.GetRouter()

tmLightClientModule := ibctm.NewLightClientModule(appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String())
tmLightClientModule := ibctm.NewLightClientModule(keys[ibcexported.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String())
clientRouter.AddRoute(ibctm.ModuleName, &tmLightClientModule)

smLightClientModule := solomachine.NewLightClientModule(appCodec)
smLightClientModule := solomachine.NewLightClientModule(keys[ibcexported.StoreKey], appCodec)
clientRouter.AddRoute(solomachine.ModuleName, &smLightClientModule)

wasmLightClientModule := wasm.NewLightClientModule(app.WasmClientKeeper)
wasmLightClientModule := wasm.NewLightClientModule(app.WasmClientKeeper, keys[ibcexported.StoreKey])
clientRouter.AddRoute(wasmtypes.ModuleName, &wasmLightClientModule)

// create evidence keeper with router
Expand Down
12 changes: 3 additions & 9 deletions modules/light-clients/09-localhost/light_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ type LightClientModule struct {
// NewLightClientModule creates and returns a new 09-localhost LightClientModule.
func NewLightClientModule(cdc codec.BinaryCodec, key storetypes.StoreKey) *LightClientModule {
return &LightClientModule{
cdc: cdc,
key: key,
cdc: cdc,
key: key,
storeProvider: clienttypes.NewStoreProvider(key),
}
}

// RegisterStoreProvider is called by core IBC when a LightClientModule is added to the router.
// It allows the LightClientModule to set a ClientStoreProvider which supplies isolated prefix client stores
// to IBC light client instances.
func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientStoreProvider) {
l.storeProvider = storeProvider
}

// Initialize ensures that initial consensus state for localhost is nil.
//
// CONTRACT: clientID is validated in 02-client router, thus clientID is assumed here to be 09-localhost.
Expand Down
4 changes: 2 additions & 2 deletions testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ func NewSimApp(

clientRouter := app.IBCKeeper.ClientKeeper.GetRouter()

tmLightClientModule := ibctm.NewLightClientModule(appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String())
tmLightClientModule := ibctm.NewLightClientModule(keys[ibcexported.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String())
clientRouter.AddRoute(ibctm.ModuleName, &tmLightClientModule)

smLightClientModule := solomachine.NewLightClientModule(appCodec)
smLightClientModule := solomachine.NewLightClientModule(keys[ibcexported.StoreKey], appCodec)
clientRouter.AddRoute(solomachine.ModuleName, &smLightClientModule)

// create evidence keeper with router
Expand Down
Loading