Skip to content

Commit

Permalink
fix: permissionless query (#2191)
Browse files Browse the repository at this point in the history
* fix implementation

* addressed comments

* cleanup

* keep metadata and powershaping data for stopped consumer chains

* addressed comments

* adapt unit-tests
  • Loading branch information
bermuell authored Aug 30, 2024
1 parent b874510 commit 9bbd274
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
11 changes: 8 additions & 3 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func SetupForStoppingConsumerChain(t *testing.T, ctx sdk.Context,
// TestProviderStateIsCleanedAfterConsumerChainIsStopped executes test assertions for the provider's state being cleaned
// after a stopped consumer chain.
func TestProviderStateIsCleanedAfterConsumerChainIsStopped(t *testing.T, ctx sdk.Context, providerKeeper providerkeeper.Keeper,
consumerId, expectedChannelID string,
consumerId, expectedChannelID string, expErr bool,
) {
t.Helper()
_, found := providerKeeper.GetConsumerClientId(ctx, consumerId)
Expand All @@ -262,8 +262,13 @@ func TestProviderStateIsCleanedAfterConsumerChainIsStopped(t *testing.T, ctx sdk
require.Empty(t, acks)

// in case the chain was successfully stopped, it should not contain a Top N associated to it
_, err := providerKeeper.GetConsumerPowerShapingParameters(ctx, consumerId)
require.Error(t, err)
ps, err := providerKeeper.GetConsumerPowerShapingParameters(ctx, consumerId)
if expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
require.Empty(t, ps)

// test key assignment state is cleaned
require.Empty(t, providerKeeper.GetAllValidatorConsumerPubKeys(ctx, &consumerId))
Expand Down
73 changes: 73 additions & 0 deletions x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,42 @@ changed by updating the consumer chain.
Example:
%s tx provider create-consumer [path/to/create_consumer.json] --from node0 --home ../node0 --chain-id $CID
where create_consumer.json content:
{
"chain_id": "consu",
"metadata": {
"name": "chain consumer",
"description": "no description",
"metadata": "no metadata"
},
"initialization_parameters": {
"initial_height": {
"revision_number": "0",
"revision_height": "1"
},
"genesis_hash": "Z2VuX2hhc2g=",
"binary_hash": "YmluX2hhc2g=",
"spawn_time": "2024-08-29T12:26:16.529913Z",
"unbonding_period": "1209600s",
"ccv_timeout_period": "2419200s",
"transfer_timeout_period": "3600s",
"consumer_redistribution_fraction": "0.75",
"blocks_per_distribution_transmission": "1000",
"historical_entries": "10000",
"distribution_transmission_channel": ""
},
"power_shaping_parameters": {
"top_N": 100,
"validators_power_cap": 0,
"validator_set_cap": 0,
"allowlist": [],
"denylist": [],
"min_stake": "0",
"allow_inactive_vals": false
}
}
`, version.AppName)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -278,6 +314,43 @@ Note that only the owner of the chain can initialize it.
Example:
%s tx provider update-consumer [path/to/consumer-update.json] --from node0 --home ../node0 --chain-id $CID
where consumer-update.json contains parameters for 'power_shaping', 'initialization' and 'metadata':
{
"consumer_id": "0",
"new_owner_address": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
"metadata": {
"name": "chain consumer",
"description": "no description",
"metadata": "no metadata"
},
"initialization_parameters": {
"initial_height": {
"revision_number": "0",
"revision_height": "1"
},
"genesis_hash": "Z2VuX2hhc2g=",
"binary_hash": "YmluX2hhc2g=",
"spawn_time": "2024-08-29T12:26:16.529913Z",
"unbonding_period": "1209600s",
"ccv_timeout_period": "2419200s",
"transfer_timeout_period": "3600s",
"consumer_redistribution_fraction": "0.75",
"blocks_per_distribution_transmission": "1000",
"historical_entries": "10000",
"distribution_transmission_channel": ""
},
"power_shaping_parameters": {
"top_N": 100,
"validators_power_cap": 0,
"validator_set_cap": 0,
"allowlist": [],
"denylist": [],
"min_stake": "0",
"allow_inactive_vals": false
}
}
`, version.AppName)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 1 addition & 4 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, consumerId string) (types.Chai
strDenylist[i] = addr.String()
}

metadata, err := k.GetConsumerMetadata(ctx, consumerId)
if err != nil {
return types.Chain{}, fmt.Errorf("cannot get metadata for consumer (%s): %w", consumerId, err)
}
metadata, _ := k.GetConsumerMetadata(ctx, consumerId)

return types.Chain{
ChainId: chainID,
Expand Down
3 changes: 0 additions & 3 deletions x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ func (k Keeper) StopConsumerChain(ctx sdk.Context, consumerId string, closeChan
k.DeleteSlashAcks(ctx, consumerId)
k.DeletePendingVSCPackets(ctx, consumerId)

k.DeleteConsumerMetadata(ctx, consumerId)
k.DeleteConsumerPowerShapingParameters(ctx, consumerId)
k.DeleteConsumerPowerShapingParameters(ctx, consumerId)
k.DeleteAllowlist(ctx, consumerId)
k.DeleteDenylist(ctx, consumerId)
k.DeleteAllOptedIn(ctx, consumerId)
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestStopConsumerChain(t *testing.T) {
require.NoError(t, err)
}

testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsStopped(t, ctx, providerKeeper, consumerId, "channelID")
testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsStopped(t, ctx, providerKeeper, consumerId, "channelID", tc.expErr)

ctrl.Finish()
}
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func TestOnTimeoutPacketStopsChain(t *testing.T) {
}
err := providerKeeper.OnTimeoutPacket(ctx, packet)

testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsStopped(t, ctx, providerKeeper, "consumerId", "channelID")
testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsStopped(t, ctx, providerKeeper, "consumerId", "channelID", false)
require.NoError(t, err)
}

Expand Down Expand Up @@ -578,7 +578,7 @@ func TestOnAcknowledgementPacketWithAckError(t *testing.T) {

err = providerKeeper.OnAcknowledgementPacket(ctx, packet, ackError)

testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsStopped(t, ctx, providerKeeper, "consumerId", "channelID")
testkeeper.TestProviderStateIsCleanedAfterConsumerChainIsStopped(t, ctx, providerKeeper, "consumerId", "channelID", false)
require.NoError(t, err)
}

Expand Down

0 comments on commit 9bbd274

Please sign in to comment.