Skip to content

Commit

Permalink
Fix Stakeibc Init/Export Genesis (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Jan 20, 2023
1 parent eadc3e7 commit ea5a9a4
Show file tree
Hide file tree
Showing 30 changed files with 139 additions and 1,762 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ upgrade-init:
PART=1 bash $(DOCKERNET_HOME)/tests/run_tests_upgrade.sh

upgrade-submit:
UPGRADE_HEIGHT=750 bash $(DOCKERNET_HOME)/upgrades/submit_upgrade.sh
UPGRADE_HEIGHT=400 bash $(DOCKERNET_HOME)/upgrades/submit_upgrade.sh

upgrade-validate:
PART=2 bash $(DOCKERNET_HOME)/tests/run_tests_upgrade.sh
Expand Down
2 changes: 1 addition & 1 deletion dockernet/upgrades/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bash dockernet/upgrades/submit_upgrade.sh
* **WARNING**: The integration tests may change between versions - the following only works if there were not breaking changes. If there are breaking changes, you can replace the GAIA and OSMO integration test files with those from the old version.
* Start the network, run the integration tests on the old binary, and then propose and vote on the upgrade:
```
make start-docker-all && make upgrade-init && make upgrade-submit
make start-docker-all && make upgrade-init && make upgrade-submit
```
* Once the integration tests pass and the upgrade has been proposed, wait for the upgrade to occur at block 750. Check the stride logs to confirm the upgrade passes successfully
* Finally, run the remaining integration tests
Expand Down
7 changes: 1 addition & 6 deletions proto/stride/stakeibc/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package stride.stakeibc;

import "gogoproto/gogo.proto";
import "stride/stakeibc/params.proto";
import "stride/stakeibc/ica_account.proto";
import "stride/stakeibc/host_zone.proto";
import "stride/stakeibc/epoch_tracker.proto";
// this line is used by starport scaffolding # genesis/proto/import
Expand All @@ -15,13 +14,9 @@ message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
string port_id = 2;
// list of zones that are registered by the protocol
ICAAccount ica_account = 4;
repeated HostZone host_zone_list = 5 [ (gogoproto.nullable) = false ];
uint64 host_zone_count = 6;
// stores a map from hostZone base denom to hostZone
map<string, string> denom_to_host_zone = 9;
repeated EpochTracker epoch_tracker_list = 10
[ (gogoproto.nullable) = false ];
// this line is used by starport scaffolding # genesis/proto/state
reserved 3, 11;
reserved 3, 4, 6, 9, 11;
}
9 changes: 0 additions & 9 deletions proto/stride/stakeibc/min_validator_requirements.proto

This file was deleted.

18 changes: 1 addition & 17 deletions proto/stride/stakeibc/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "stride/stakeibc/params.proto";
import "stride/stakeibc/validator.proto";
import "stride/stakeibc/ica_account.proto";
import "stride/stakeibc/host_zone.proto";
import "stride/stakeibc/epoch_tracker.proto";
// this line is used by starport scaffolding # 1
Expand All @@ -25,11 +24,6 @@ service Query {
option (google.api.http).get =
"/Stride-Labs/stride/stakeibc/validators/{chain_id}";
}
// Queries a ICAAccount by index.
rpc ICAAccount(QueryGetICAAccountRequest)
returns (QueryGetICAAccountResponse) {
option (google.api.http).get = "/Stride-Labs/stride/stakeibc/ica_account";
}
// Queries a HostZone by id.
rpc HostZone(QueryGetHostZoneRequest) returns (QueryGetHostZoneResponse) {
option (google.api.http).get =
Expand Down Expand Up @@ -95,11 +89,6 @@ message QueryGetValidatorsRequest { string chain_id = 1; }

message QueryGetValidatorsResponse { repeated Validator validators = 1; }

message QueryGetICAAccountRequest {}

message QueryGetICAAccountResponse {
ICAAccount ica_account = 1 [ (gogoproto.nullable) = false ];
}
message QueryGetHostZoneRequest { string chain_id = 1; }

message QueryGetHostZoneResponse {
Expand All @@ -125,13 +114,8 @@ message QueryGetEpochTrackerResponse {
EpochTracker epoch_tracker = 1 [ (gogoproto.nullable) = false ];
}

message QueryAllEpochTrackerRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}
message QueryAllEpochTrackerRequest {}

message QueryAllEpochTrackerResponse {
repeated EpochTracker epoch_tracker = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// this line is used by starport scaffolding # 3
2 changes: 1 addition & 1 deletion testutil/localstride/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ If you are only running the validator for a short time (< 24 hours) you will not
### Testing the upgrade
* Once localstride starts churning blocks, you are ready to test the upgrade. Run the following to submit and vote on the upgrade:
```bash
# Check the localstride logs to determine the current block and propose the upgrade at a height at least 100 blocks in the future
# Check the localstride logs to determine the current block and propose the upgrade at a height at least 75 blocks in the future
make localnet-state-export-upgrade upgrade_name={upgrade_name} upgrade_height={upgrade_height}
# Ex: make localnet-state-export-upgrade upgrade_name=v5 upgrade_height=1956500
```
Expand Down
2 changes: 0 additions & 2 deletions x/stakeibc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ Governance
- `QueryParamsResponse`
- `QueryGetValidatorsRequest`
- `QueryGetValidatorsResponse`
- `QueryGetICAAccountRequest`
- `QueryGetICAAccountResponse`
- `QueryGetHostZoneRequest`
- `QueryGetHostZoneResponse`
- `QueryAllHostZoneRequest`
Expand Down
1 change: 0 additions & 1 deletion x/stakeibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command {

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdShowValidators())
cmd.AddCommand(CmdShowICAAccount())
cmd.AddCommand(CmdListHostZone())
cmd.AddCommand(CmdShowHostZone())
cmd.AddCommand(CmdModuleAddress())
Expand Down
10 changes: 1 addition & 9 deletions x/stakeibc/client/cli/query_epoch_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ func CmdListEpochTracker() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAllEpochTrackerRequest{
Pagination: pageReq,
}
params := &types.QueryAllEpochTrackerRequest{}

res, err := queryClient.EpochTrackerAll(context.Background(), params)
if err != nil {
Expand All @@ -37,7 +30,6 @@ func CmdListEpochTracker() *cobra.Command {
},
}

flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand Down
37 changes: 0 additions & 37 deletions x/stakeibc/client/cli/query_ica_account.go

This file was deleted.

73 changes: 0 additions & 73 deletions x/stakeibc/client/cli/query_ica_account_test.go

This file was deleted.

37 changes: 6 additions & 31 deletions x/stakeibc/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,23 @@ import (
// InitGenesis initializes the capability module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// TODO: TEST-10
// Set if defined
if genState.IcaAccount != nil {
k.SetICAAccount(ctx, *genState.IcaAccount)
for _, hostZone := range genState.HostZoneList {
k.SetHostZone(ctx, hostZone)
}
// Set all the hostZone
for _, elem := range genState.HostZoneList {
k.SetHostZone(ctx, elem)
for _, epochTracker := range genState.EpochTrackerList {
k.SetEpochTracker(ctx, epochTracker)
}

// Set hostZone count
k.SetHostZoneCount(ctx, genState.HostZoneCount)
// this line is used by starport scaffolding # genesis/module/init
// TODO(TEST-22): Set ports
// k.SetPort(ctx, genState.PortId)
// // Only try to bind to port if it is not already bound, since we may already own
// // port capability from capability InitGenesis
// if !k.IsBound(ctx, genState.PortId) {
// // module binds to the port on InitChain
// // and claims the returned capability
// err := k.BindPort(ctx, genState.PortId)
// if err != nil {
// panic("could not claim port capability: " + err.Error())
// }
// }
k.SetParams(ctx, genState.Params)
}

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)

// ibc v2 scaffolded code
// genesis.PortId = k.GetPort(ctx)
// Get all iCAAccount
iCAAccount, found := k.GetICAAccount(ctx)
if found {
genesis.IcaAccount = &iCAAccount
}
genesis.Params = k.GetParams(ctx)
genesis.HostZoneList = k.GetAllHostZone(ctx)
genesis.EpochTrackerList = k.GetAllEpochTracker(ctx)
// this line is used by starport scaffolding # genesis/module/export

return genesis
}
4 changes: 0 additions & 4 deletions x/stakeibc/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),
PortId: types.PortID,
IcaAccount: &types.ICAAccount{
Address: "78",
},
EpochTrackerList: []types.EpochTracker{
{EpochIdentifier: "stride_epoch"},
},
Expand All @@ -33,7 +30,6 @@ func TestGenesis(t *testing.T) {
nullify.Fill(got)

require.Equal(t, genesisState.PortId, got.PortId)
require.Equal(t, genesisState.IcaAccount, got.IcaAccount)
require.Equal(t, genesisState.EpochTrackerList, got.EpochTrackerList)
require.Equal(t, genesisState.Params, got.Params)
// this line is used by starport scaffolding # genesis/test/assert
Expand Down
22 changes: 2 additions & 20 deletions x/stakeibc/keeper/grpc_query_epoch_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package keeper
import (
"context"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -17,26 +15,10 @@ func (k Keeper) EpochTrackerAll(c context.Context, req *types.QueryAllEpochTrack
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

var epochTrackers []types.EpochTracker
ctx := sdk.UnwrapSDKContext(c)
epochTrackers := k.GetAllEpochTracker(ctx)

store := ctx.KVStore(k.storeKey)
epochTrackerStore := prefix.NewStore(store, types.KeyPrefix(types.EpochTrackerKeyPrefix))

pageRes, err := query.Paginate(epochTrackerStore, req.Pagination, func(key []byte, value []byte) error {
var epochTracker types.EpochTracker
if err := k.cdc.Unmarshal(value, &epochTracker); err != nil {
return err
}

epochTrackers = append(epochTrackers, epochTracker)
return nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryAllEpochTrackerResponse{EpochTracker: epochTrackers, Pagination: pageRes}, nil
return &types.QueryAllEpochTrackerResponse{EpochTracker: epochTrackers}, nil
}

func (k Keeper) EpochTracker(c context.Context, req *types.QueryGetEpochTrackerRequest) (*types.QueryGetEpochTrackerResponse, error) {
Expand Down
Loading

0 comments on commit ea5a9a4

Please sign in to comment.