-
Notifications
You must be signed in to change notification settings - Fork 751
feat: clientv2 module #7936
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
Merged
Merged
feat: clientv2 module #7936
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
71a3e9f
init
128c373
move logic
9973f79
fix all tests and types
ee51649
genesis proto and gen
21fac15
gen
290837a
godoc
2e3d279
core genesis
f7d8b45
core genesis wiring
796236a
wire and test
2dbfaed
lint fix
034b18e
fmt
0620d48
fmt
801fa99
Merge branch 'main' into feat/client-v2-module
640d996
add defensive checks
687b196
fix all
b3615be
Merge branch 'main' into feat/client-v2-module
69624f7
Merge branch 'main' into feat/client-v2-module
8bf8a63
Merge branch 'main' into feat/client-v2-module
AdityaSripal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package clientv2 | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/keeper" | ||
| "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" | ||
| ) | ||
|
|
||
| // InitGenesis initializes the ibc client/v2 submodule's state from a provided genesis | ||
| // state. | ||
| func InitGenesis(ctx context.Context, k *keeper.Keeper, gs types.GenesisState) { | ||
| sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
|
||
| if err := gs.Validate(); err != nil { | ||
| panic(fmt.Errorf("invalid genesis state: %w", err)) | ||
| } | ||
|
|
||
| for _, info := range gs.CounterpartyInfos { | ||
| k.SetClientCounterparty(sdkCtx, info.ClientId, info.CounterpartyInfo) | ||
| } | ||
| } | ||
|
|
||
| // ExportGenesis returns the ibc client/v2 submodule's exported genesis. | ||
| func ExportGenesis(ctx context.Context, k *keeper.Keeper) types.GenesisState { | ||
| sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
|
||
| clients := k.ClientV1Keeper.GetAllGenesisClients(ctx) | ||
| gs := types.GenesisState{ | ||
| CounterpartyInfos: make([]types.GenesisCounterpartyInfo, 0), | ||
| } | ||
| for _, client := range clients { | ||
| counterpartyInfo, found := k.GetClientCounterparty(sdkCtx, client.ClientId) | ||
| if found { | ||
| gs.CounterpartyInfos = append(gs.CounterpartyInfos, types.GenesisCounterpartyInfo{ | ||
| ClientId: client.ClientId, | ||
| CounterpartyInfo: counterpartyInfo, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return gs | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package clientv2_test | ||
|
|
||
| import ( | ||
| clientv2 "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2" | ||
| "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" | ||
| ibctesting "github.com/cosmos/ibc-go/v9/testing" | ||
| ) | ||
|
|
||
| // TestInitExportGenesis tests the import and export flow for the channel v2 keeper. | ||
| func (suite *ModuleTestSuite) TestInitExportGenesis() { | ||
| path := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
| path.SetupV2() | ||
|
|
||
| path2 := ibctesting.NewPath(suite.chainA, suite.chainC) | ||
| path2.SetupV2() | ||
|
|
||
| path3 := ibctesting.NewPath(suite.chainB, suite.chainC) | ||
| path3.SetupV2() | ||
|
|
||
| app := suite.chainA.App | ||
|
|
||
| emptyGenesis := types.DefaultGenesisState() | ||
|
|
||
| // create a valid genesis state that uses the counterparty info set during setup | ||
| existingGS := clientv2.ExportGenesis(suite.chainA.GetContext(), app.GetIBCKeeper().ClientV2Keeper) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| genState types.GenesisState | ||
| expectedState types.GenesisState | ||
| }{ | ||
| { | ||
| name: "no modifications genesis", | ||
| genState: emptyGenesis, | ||
| expectedState: existingGS, | ||
| }, | ||
| { | ||
| name: "valid - default genesis", | ||
| genState: types.DefaultGenesisState(), | ||
| expectedState: existingGS, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| suite.Run(tt.name, func() { | ||
| clientV2Keeper := app.GetIBCKeeper().ClientV2Keeper | ||
|
|
||
| clientv2.InitGenesis(suite.chainA.GetContext(), clientV2Keeper, tt.genState) | ||
|
|
||
| exported := clientv2.ExportGenesis(suite.chainA.GetContext(), clientV2Keeper) | ||
| suite.Require().Equal(tt.expectedState, exported) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
|
||
| "github.com/cosmos/ibc-go/v9/modules/core/02-client/v2/types" | ||
| host "github.com/cosmos/ibc-go/v9/modules/core/24-host" | ||
| ) | ||
|
|
||
| var _ types.QueryServer = (*queryServer)(nil) | ||
|
|
||
| // queryServer implements the 02-client/v2 types.QueryServer interface. | ||
| // It embeds the client keeper to leverage store access while limiting the api of the client keeper. | ||
| type queryServer struct { | ||
| *Keeper | ||
| } | ||
|
|
||
| // NewQueryServer returns a new 02-client/v2 types.QueryServer implementation. | ||
| func NewQueryServer(k *Keeper) types.QueryServer { | ||
| return &queryServer{ | ||
| Keeper: k, | ||
| } | ||
| } | ||
|
|
||
| // CounterpartyInfo gets the CounterpartyInfo from the store corresponding to the request client ID. | ||
| func (q queryServer) CounterpartyInfo(ctx context.Context, req *types.QueryCounterpartyInfoRequest) (*types.QueryCounterpartyInfoResponse, error) { | ||
| if req == nil { | ||
| return nil, status.Error(codes.InvalidArgument, "empty request") | ||
| } | ||
|
|
||
| if err := host.ClientIdentifierValidator(req.ClientId); err != nil { | ||
| return nil, status.Error(codes.InvalidArgument, err.Error()) | ||
| } | ||
|
|
||
| sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally do a bit more validation before the grpc directly gets from store. Would be good to follow the same. See the v1 chanKeeper grpc implementation |
||
| info, found := q.GetClientCounterparty(sdkCtx, req.ClientId) | ||
| if !found { | ||
| return nil, status.Error(codes.NotFound, fmt.Sprintf("client %s counterparty not found", req.ClientId)) | ||
| } | ||
|
|
||
| return &types.QueryCounterpartyInfoResponse{CounterpartyInfo: &info}, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a test file for this as well.