Skip to content

Commit

Permalink
feat!: migrations for permissionless (#2174)
Browse files Browse the repository at this point in the history
* migrations for permissionless -- wip

* feat!: migrations for permissionless (#2177)

* initial commit

* took into account comments

* removed deprecated queries

* fix error due to rebase

* remove fields from provider genesis

* remove commented code

---------

Co-authored-by: insumity <[email protected]>
  • Loading branch information
mpoke and insumity authored Aug 29, 2024
1 parent 4ed2723 commit 7aa6db9
Show file tree
Hide file tree
Showing 28 changed files with 746 additions and 3,322 deletions.
12 changes: 6 additions & 6 deletions proto/interchain_security/ccv/provider/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ message GenesisState {
// Reserve 4th slot for removed mature_unbonding_ops field
reserved 4;

// Reserve 6th slot for removed consumer_addition_proposals field
reserved 6;

// Reserve 7th slot for removed consumer_removal_proposals field
reserved 7;

// Reserve 11th slot for consumer_addrs_to_prune field
reserved 11;

Expand All @@ -36,12 +42,6 @@ message GenesisState {
// empty for a new chain
repeated ValsetUpdateIdToHeight valset_update_id_to_height = 5
[ (gogoproto.nullable) = false ];
// empty for a new chain
repeated ConsumerAdditionProposal consumer_addition_proposals = 6
[ (gogoproto.nullable) = false ];
// empty for a new chain
repeated ConsumerRemovalProposal consumer_removal_proposals = 7
[ (gogoproto.nullable) = false ];
Params params = 8 [ (gogoproto.nullable) = false ];
// empty for a new chain
repeated ValidatorConsumerPubKey validator_consumer_pubkeys = 9
Expand Down
49 changes: 0 additions & 49 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ service Query {
"/interchain_security/ccv/provider/consumer_chains";
}

// QueryConsumerChainStarts queries consumer chain start proposals.
rpc QueryConsumerChainStarts(QueryConsumerChainStartProposalsRequest)
returns (QueryConsumerChainStartProposalsResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/consumer_chain_start_proposals";
}

// QueryConsumerChainStops queries consumer chain stop proposals.
rpc QueryConsumerChainStops(QueryConsumerChainStopProposalsRequest)
returns (QueryConsumerChainStopProposalsResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/consumer_chain_stop_proposals";
}

// QueryValidatorConsumerAddr queries the address
// assigned by a validator for a consumer chain.
rpc QueryValidatorConsumerAddr(QueryValidatorConsumerAddrRequest)
Expand Down Expand Up @@ -82,15 +68,6 @@ service Query {
"/interchain_security/ccv/provider/registered_consumer_reward_denoms";
}

// QueryProposedConsumerChainIDs returns the chain IDs of the proposed consumer chain addition proposals
// that are still in the voting period
rpc QueryProposedConsumerChainIDs(
QueryProposedChainIDsRequest)
returns (QueryProposedChainIDsResponse) {
option (google.api.http).get =
"/interchain_security/ccv/provider/proposed_consumer_chains";
}

// QueryAllPairsValConAddrByConsumerChainID returns a list of pair valconsensus address
// between provider and consumer chain
rpc QueryAllPairsValConAddrByConsumerChainID (
Expand Down Expand Up @@ -210,18 +187,6 @@ message QueryConsumerChainsRequest {

message QueryConsumerChainsResponse { repeated Chain chains = 1; }

message QueryConsumerChainStartProposalsRequest {}

message QueryConsumerChainStartProposalsResponse {
ConsumerAdditionProposals proposals = 1;
}

message QueryConsumerChainStopProposalsRequest {}

message QueryConsumerChainStopProposalsResponse {
ConsumerRemovalProposals proposals = 1;
}

message Chain {
string chain_id = 1;
string client_id = 2;
Expand Down Expand Up @@ -302,20 +267,6 @@ message QueryRegisteredConsumerRewardDenomsResponse {
repeated string denoms = 1;
}

message QueryProposedChainIDsRequest {}

message QueryProposedChainIDsResponse {
repeated ProposedChain proposedChains = 1
[ (gogoproto.nullable) = false ];
}

message ProposedChain {
// [DEPRECATED] use `consumer_id` instead
string chainID = 1 [deprecated = true];
uint64 proposalID = 2;
string consumer_id = 3;
}

message QueryAllPairsValConAddrByConsumerChainIDRequest {
// [DEPRECATED] use `consumer_id` instead
string chain_id = 1 [deprecated = true];
Expand Down
92 changes: 0 additions & 92 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ func NewQueryCmd() *cobra.Command {

cmd.AddCommand(CmdConsumerGenesis())
cmd.AddCommand(CmdConsumerChains())
cmd.AddCommand(CmdConsumerStartProposals())
cmd.AddCommand(CmdConsumerStopProposals())
cmd.AddCommand(CmdConsumerValidatorKeyAssignment())
cmd.AddCommand(CmdProviderValidatorKey())
cmd.AddCommand(CmdThrottleState())
cmd.AddCommand(CmdRegisteredConsumerRewardDenoms())
cmd.AddCommand(CmdProposedConsumerChains())
cmd.AddCommand(CmdAllPairsValConAddrByConsumerChainID())
cmd.AddCommand(CmdProviderParameters())
cmd.AddCommand(CmdConsumerChainOptedInValidators())
Expand Down Expand Up @@ -121,95 +118,6 @@ func CmdConsumerChains() *cobra.Command {
return cmd
}

func CmdProposedConsumerChains() *cobra.Command {
cmd := &cobra.Command{
Use: "list-proposed-consumer-chains",
Short: "Query chainIDs in consumer addition proposal before voting finishes",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryProposedChainIDsRequest{}
res, err := queryClient.QueryProposedConsumerChainIDs(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdConsumerStartProposals() *cobra.Command {
cmd := &cobra.Command{
Use: "list-start-proposals",
Short: "Query consumer chains start proposals on provider chain.",
Long: `Query mature and pending consumer chains start proposals on provider chain.
Matured proposals will be executed on the next block - their spawn_time has passed
Pending proposals are waiting for their spawn_time to pass.
`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryConsumerChainStartProposalsRequest{}
res, err := queryClient.QueryConsumerChainStarts(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdConsumerStopProposals() *cobra.Command {
cmd := &cobra.Command{
Use: "list-stop-proposals",
Short: "Query consumer chains stop proposals on provider chain.",
Long: `Query mature and pending consumer chains stop proposals on provider chain.
Matured proposals will be executed on the next block - their stop_time has passed
Pending proposals are waiting for their stop_time to pass.
`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryConsumerChainStopProposalsRequest{}
res, err := queryClient.QueryConsumerChainStops(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// TODO: fix naming
func CmdConsumerValidatorKeyAssignment() *cobra.Command {
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix()
Expand Down
13 changes: 1 addition & 12 deletions x/ccv/provider/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) []abc
k.SetValsetUpdateBlockHeight(ctx, v2h.ValsetUpdateId, v2h.Height)
}

for _, prop := range genState.ConsumerAdditionProposals {
// prevent implicit memory aliasing
p := prop
k.SetPendingConsumerAdditionProp(ctx, &p)
}
for _, prop := range genState.ConsumerRemovalProposals {
p := prop
k.SetPendingConsumerRemovalProp(ctx, &p)
}

// Set initial state for each consumer chain
for _, cs := range genState.ConsumerStates {
chainID := cs.ChainId
Expand Down Expand Up @@ -173,12 +163,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {

params := k.GetParams(ctx)

// TODO (PERMISSIONLESS)
return types.NewGenesisState(
k.GetValidatorSetUpdateId(ctx),
k.GetAllValsetUpdateBlockHeights(ctx),
consumerStates,
k.GetAllPendingConsumerAdditionProps(ctx),
k.GetAllPendingConsumerRemovalProps(ctx),
params,
k.GetAllValidatorConsumerPubKeys(ctx, nil),
k.GetAllValidatorsByConsumerAddr(ctx, nil),
Expand Down
12 changes: 0 additions & 12 deletions x/ccv/provider/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ func TestInitAndExportGenesis(t *testing.T) {
nil,
),
},
[]providertypes.ConsumerAdditionProposal{{
ChainId: cChainIDs[0],
SpawnTime: oneHourFromNow,
}},
[]providertypes.ConsumerRemovalProposal{{
ChainId: cChainIDs[0],
StopTime: oneHourFromNow,
}},
params,
[]providertypes.ValidatorConsumerPubKey{
{
Expand Down Expand Up @@ -139,10 +131,6 @@ func TestInitAndExportGenesis(t *testing.T) {
height, found := pk.GetValsetUpdateBlockHeight(ctx, vscID)
require.True(t, found)
require.Equal(t, initHeight, height)
addProp, found := pk.GetPendingConsumerAdditionProp(ctx, oneHourFromNow, cChainIDs[0])
require.True(t, found)
require.Equal(t, provGenesis.ConsumerAdditionProposals[0], addProp)
require.True(t, pk.PendingConsumerRemovalPropExists(ctx, cChainIDs[0], oneHourFromNow))
require.Equal(t, provGenesis.Params, pk.GetParams(ctx))

providerConsensusValSet, err := pk.GetLastProviderConsensusValSet(ctx)
Expand Down
47 changes: 0 additions & 47 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,39 +160,6 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, consumerId string) (types.Chai
}, nil
}

func (k Keeper) QueryConsumerChainStarts(goCtx context.Context, req *types.QueryConsumerChainStartProposalsRequest) (*types.QueryConsumerChainStartProposalsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
var props []*types.ConsumerAdditionProposal

for _, prop := range k.GetAllPendingConsumerAdditionProps(ctx) {
// prevent implicit memory aliasing
p := prop
props = append(props, &p)
}

return &types.QueryConsumerChainStartProposalsResponse{Proposals: &types.ConsumerAdditionProposals{Pending: props}}, nil
}

func (k Keeper) QueryConsumerChainStops(goCtx context.Context, req *types.QueryConsumerChainStopProposalsRequest) (*types.QueryConsumerChainStopProposalsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
var props []*types.ConsumerRemovalProposal
for _, prop := range k.GetAllPendingConsumerRemovalProps(ctx) {
// prevent implicit memory aliasing
p := prop
props = append(props, &p)
}

return &types.QueryConsumerChainStopProposalsResponse{Proposals: &types.ConsumerRemovalProposals{Pending: props}}, nil
}

func (k Keeper) QueryValidatorConsumerAddr(goCtx context.Context, req *types.QueryValidatorConsumerAddrRequest) (*types.QueryValidatorConsumerAddrResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
Expand Down Expand Up @@ -285,20 +252,6 @@ func (k Keeper) QueryRegisteredConsumerRewardDenoms(goCtx context.Context, req *
}, nil
}

func (k Keeper) QueryProposedConsumerChainIDs(goCtx context.Context, req *types.QueryProposedChainIDsRequest) (*types.QueryProposedChainIDsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

chains := k.GetAllProposedConsumerChainIDs(ctx)

return &types.QueryProposedChainIDsResponse{
ProposedChains: chains,
}, nil
}

func (k Keeper) QueryAllPairsValConAddrByConsumerChainID(goCtx context.Context, req *types.QueryAllPairsValConAddrByConsumerChainIDRequest) (*types.QueryAllPairsValConAddrByConsumerChainIDResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
Expand Down
Loading

0 comments on commit 7aa6db9

Please sign in to comment.