Skip to content

Commit

Permalink
Merge branch 'feat/permissionless' into sainoe/consumer-chains-query-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Aug 28, 2024
2 parents 3b4feba + 50475e6 commit f2e9868
Show file tree
Hide file tree
Showing 36 changed files with 1,775 additions and 1,073 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Fix incorrect message defitions in the proto files of the provider module
- Fix incorrect message definitions in the proto files of the provider module
([\#2095](https://github.com/cosmos/interchain-security/pull/2095))
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Fix incorrect message defitions in the proto files of the provider module
- Fix incorrect message definitions in the proto files of the provider module
([\#2095](https://github.com/cosmos/interchain-security/pull/2095))
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
### API BREAKING

- [Provider](x/ccv/provider)
- Fix incorrect message defitions in the proto files of the provider module
- Fix incorrect message definitions in the proto files of the provider module
([\#2095](https://github.com/cosmos/interchain-security/pull/2095))

### STATE BREAKING

- [Provider](x/ccv/provider)
- Fix incorrect message defitions in the proto files of the provider module
- Fix incorrect message definitions in the proto files of the provider module
([\#2095](https://github.com/cosmos/interchain-security/pull/2095))

## v5.1.0
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/integrators/integrating_inactive_validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 1

# Inactive Validators Integration Guide

With the [inactive validators feature of Interchain Security](../adrs/adr-017-allowing-inactive-validators.md), validators outside of the active set on the provider chain can validate on consumer chains that allow this. Technically, this is achieved by *increasing* the MaxValidators paramater in the staking module, to let additional validators be part of the set of bonded validators. However, to keep the set of validators participating in consensus on the Cosmos Hub the same, we introduce the MaxProviderConsensusValidators parameter in the provider module, which will restrict the number of validators that actively validate on the provider chain.
With the [inactive validators feature of Interchain Security](../adrs/adr-017-allowing-inactive-validators.md), validators outside of the active set on the provider chain can validate on consumer chains that allow this. Technically, this is achieved by *increasing* the MaxValidators parameter in the staking module, to let additional validators be part of the set of bonded validators. However, to keep the set of validators participating in consensus on the Cosmos Hub the same, we introduce the MaxProviderConsensusValidators parameter in the provider module, which will restrict the number of validators that actively validate on the provider chain.

To clarify the terminology:

Expand Down
17 changes: 17 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,20 @@ message PowerShapingParameters {
// ConsumerIds contains consumer ids of chains
// Used so we can easily (de)serialize slices of strings
message ConsumerIds { repeated string ids = 1; }

// ConsumerPhase indicates the phases of a consumer chain according to ADR 019
enum ConsumerPhase {
// UNSPECIFIED defines an empty phase.
CONSUMER_PHASE_UNSPECIFIED = 0;
// REGISTERED defines the phase in which a consumer chain has been assigned a unique consumer id.
// A chain in this phase cannot yet launch.
CONSUMER_PHASE_REGISTERED = 1;
// INITIALIZED defines the phase in which a consumer chain has set all the needed parameters to launch but
// has not yet launched (e.g., because the `spawnTime` of the consumer chain has not yet been reached).
CONSUMER_PHASE_INITIALIZED = 2;
// LAUNCHED defines the phase in which a consumer chain is running and consuming a subset of the validator
// set of the provider.
CONSUMER_PHASE_LAUNCHED = 3;
// STOPPED defines the phase in which a previously-launched chain has stopped.
CONSUMER_PHASE_STOPPED = 4;
}
8 changes: 4 additions & 4 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ message QueryConsumerChainsRequest {
// the returned consumer chains
bool filter_by_phase = 1;
// The phase of the consumer chains returned (optional)
// Registered=0|Initialized=1|FailedToLaunch=2|Launched=3|Stopped=4
uint32 phase = 2;
// Registered=1|Initialized=2|Launched=3|Stopped=4
ConsumerPhase phase = 2;
// The limit of consumer chains returned (optional)
// default is 100
uint32 limit = 3;
int32 limit = 3;
}

message QueryConsumerChainsResponse { repeated Chain chains = 1; }
Expand Down Expand Up @@ -236,7 +236,7 @@ message Chain {
// Corresponds to a list of provider consensus addresses of validators that CANNOT validate the consumer chain.
repeated string denylist = 8;
// The phase the consumer chain (Registered=0|Initialized=1|FailedToLaunch=2|Launched=3|Stopped=4)
uint32 phase = 9;
ConsumerPhase phase = 9;
// The metadata of the consumer chain
ConsumerMetadata metadata = 10 [(gogoproto.nullable) = false ];
}
Expand Down
5 changes: 3 additions & 2 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ service Msg {
rpc ConsumerModification(MsgConsumerModification) returns (MsgConsumerModificationResponse) {
option deprecated = true;
}
rpc ChangeRewardDenoms(MsgChangeRewardDenoms) returns (MsgChangeRewardDenomsResponse);
}


Expand Down Expand Up @@ -223,7 +224,7 @@ message MsgConsumerRemovalResponse {}
// MsgRemoveConsumer defines the message used to remove (and stop) a consumer chain.
// If it passes, all the consumer chain's state is eventually removed from the provider chain.
message MsgRemoveConsumer {
option (cosmos.msg.v1.signer) = "authority";
option (cosmos.msg.v1.signer) = "signer";

// the consumer id of the consumer chain to be stopped
string consumer_id = 1;
Expand All @@ -232,7 +233,7 @@ message MsgRemoveConsumer {
google.protobuf.Timestamp stop_time = 2
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
// signer address
string authority = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string signer = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgRemoveConsumerResponse defines response type for MsgRemoveConsumer messages
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2227,8 +2227,8 @@ func (tr Chain) submitChangeRewardDenomsProposal(action SubmitChangeRewardDenoms
"messages": [
{
"@type": "/interchain_security.ccv.provider.v1.MsgChangeRewardDenoms",
"denoms_to_add": %s,
"denoms_to_remove": %s,
"denoms_to_add": ["%s"],
"denoms_to_remove": ["%s"],
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
}
],
Expand All @@ -2239,15 +2239,15 @@ func (tr Chain) submitChangeRewardDenomsProposal(action SubmitChangeRewardDenoms
"expedited": false
}`

denomsToAdd := []string{action.Denom}
denomsToRemove := []string{"stake"}
denomsToAdd := action.Denom
denomsToRemove := "stake"
jsonStr := fmt.Sprintf(template,
denomsToAdd,
denomsToRemove,
action.Deposit)

//#nosec G204 -- bypass unsafe quoting warning (no production code)
proposalFile := "/consumer-addition.proposal"
proposalFile := "/change-reward.proposal"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, proposalFile),
).CombinedOutput()
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/test_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func (td *DefaultDriver) runAction(action interface{}) error {
target.startConsumerEvidenceDetector(action, td.verbose)
case SubmitChangeRewardDenomsProposalAction:
target = td.getTargetDriver(action.Chain)
if semver.Compare(semver.Major(target.testConfig.providerVersion), "v5") < 0 {
version := target.testConfig.providerVersion
if semver.IsValid(version) && semver.Compare(semver.Major(version), "v5") < 0 {
target.submitChangeRewardDenomsLegacyProposal(action, td.verbose)
} else {
target.submitChangeRewardDenomsProposal(action, td.verbose)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package integration
import (
"context"
"fmt"
"github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
"testing"

transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
Expand All @@ -22,6 +21,7 @@ import (
icstestingutils "github.com/cosmos/interchain-security/v5/testutil/ibc_testing"
testutil "github.com/cosmos/interchain-security/v5/testutil/integration"
consumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types"
providertypes "github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
ccv "github.com/cosmos/interchain-security/v5/x/ccv/types"
)

Expand Down Expand Up @@ -150,7 +150,7 @@ func (suite *CCVTestSuite) SetupTest() {
// 2. MakeGenesis is called on the provider chain
// 3. ibc/testing sets the tendermint header for the consumer chain app

providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerId, keeper.Initialized)
providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
preProposalKeyAssignment(suite, icstestingutils.FirstConsumerId)

// start consumer chains
Expand Down
8 changes: 4 additions & 4 deletions testutil/ibc_testing/generic_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ibc_testing
import (
"encoding/json"
"fmt"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
"github.com/cosmos/interchain-security/v5/x/ccv/provider/keeper"
"testing"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"

ibctesting "github.com/cosmos/ibc-go/v8/testing"
testkeeper "github.com/cosmos/interchain-security/v5/testutil/keeper"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -158,8 +158,8 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata)
providerKeeper.SetConsumerInitializationParameters(providerChain.GetContext(), consumerId, initializationParameters)
providerKeeper.SetConsumerPowerShapingParameters(providerChain.GetContext(), consumerId, powerShapingParameters)
providerKeeper.SetConsumerPhase(providerChain.GetContext(), consumerId, keeper.Initialized)
providerKeeper.AppendSpawnTimeForConsumerToBeLaunched(providerChain.GetContext(), consumerId, coordinator.CurrentTime)
providerKeeper.SetConsumerPhase(providerChain.GetContext(), consumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
providerKeeper.AppendConsumerToBeLaunchedOnSpawnTime(providerChain.GetContext(), consumerId, coordinator.CurrentTime)

// opt-in all validators
lastVals, err := providerApp.GetProviderKeeper().GetLastBondedValidators(providerChain.GetContext())
Expand Down
4 changes: 2 additions & 2 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func SetupForStoppingConsumerChain(t *testing.T, ctx sdk.Context,
providerKeeper.SetConsumerMetadata(ctx, consumerId, GetTestConsumerMetadata())
providerKeeper.SetConsumerInitializationParameters(ctx, consumerId, GetTestInitializationParameters())
providerKeeper.SetConsumerPowerShapingParameters(ctx, consumerId, GetTestPowerShapingParameters())
providerKeeper.SetConsumerPhase(ctx, consumerId, providerkeeper.Initialized)
providerKeeper.SetConsumerPhase(ctx, consumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)

err := providerKeeper.CreateConsumerClient(ctx, consumerId)
require.NoError(t, err)
Expand Down Expand Up @@ -283,7 +283,7 @@ func GetTestConsumerMetadata() providertypes.ConsumerMetadata {

func GetTestInitializationParameters() providertypes.ConsumerInitializationParameters {
initialHeight := clienttypes.NewHeight(4, 5)
spawnTime := time.Now()
spawnTime := time.Now().UTC()
ccvTimeoutPeriod := types.DefaultCCVTimeoutPeriod
transferTimeoutPeriod := types.DefaultTransferTimeoutPeriod
unbondingPeriod := types.DefaultConsumerUnbondingPeriod
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ func CmdConsumerChains() *cobra.Command {
return err
}
req.FilterByPhase = true
req.Phase = uint32(phase)
req.Phase = types.ConsumerPhase(phase)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.
}

if args[1] != "" {
limit, err := strconv.Atoi(args[1])
if err != nil {
return err
}
req.Limit = uint32(limit)
req.Limit = int32(limit)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type int32 without an upper bound check.
}

res, err := queryClient.QueryConsumerChains(cmd.Context(), req)
Expand Down
10 changes: 5 additions & 5 deletions x/ccv/provider/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAssignConsensusKeyMsgHandling(t *testing.T) {
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
k.SetConsumerPhase(ctx, "consumerId", keeper.Initialized)
k.SetConsumerPhase(ctx, "consumerId", providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
gomock.InOrder(
mocks.MockStakingKeeper.EXPECT().GetValidator(
ctx, providerCryptoId.SDKValOpAddress(),
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestAssignConsensusKeyMsgHandling(t *testing.T) {
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
k.SetConsumerPhase(ctx, "consumerId", keeper.Initialized)
k.SetConsumerPhase(ctx, "consumerId", providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
gomock.InOrder(
mocks.MockStakingKeeper.EXPECT().GetValidator(
ctx, providerCryptoId.SDKValOpAddress(),
Expand All @@ -103,7 +103,7 @@ func TestAssignConsensusKeyMsgHandling(t *testing.T) {
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
k.SetConsumerPhase(ctx, "consumerId", keeper.Initialized)
k.SetConsumerPhase(ctx, "consumerId", providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)

// Use the consumer key already used by some other validator
k.SetValidatorByConsumerAddr(ctx, "consumerId", consumerConsAddr, providerConsAddr2)
Expand All @@ -127,7 +127,7 @@ func TestAssignConsensusKeyMsgHandling(t *testing.T) {
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
k.SetConsumerPhase(ctx, "consumerId", keeper.Initialized)
k.SetConsumerPhase(ctx, "consumerId", providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)

// Use the consumer key already
k.SetValidatorByConsumerAddr(ctx, "consumerId", consumerConsAddr, providerConsAddr)
Expand All @@ -149,7 +149,7 @@ func TestAssignConsensusKeyMsgHandling(t *testing.T) {
setup: func(ctx sdk.Context,
k keeper.Keeper, mocks testkeeper.MockedKeepers,
) {
k.SetConsumerPhase(ctx, "consumerId", keeper.Initialized)
k.SetConsumerPhase(ctx, "consumerId", providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)

// Use the consumer key already used by some other validator
k.SetValidatorByConsumerAddr(ctx, "consumerId", consumerConsAddr, providerConsAddr2)
Expand Down
22 changes: 11 additions & 11 deletions x/ccv/provider/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,33 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
return
}

// Iterate over all registered consumer chains
for _, consumerChainID := range k.GetAllRegisteredConsumerIds(ctx) {
// Iterate over all launched consumer chains
for _, consumerId := range k.GetAllRegisteredConsumerIds(ctx) {

// note that it's possible that no rewards are collected even though the
// reward pool isn't empty. This can happen if the reward pool holds some tokens
// of non-whitelisted denominations.
alloc := k.GetConsumerRewardsAllocation(ctx, consumerChainID)
alloc := k.GetConsumerRewardsAllocation(ctx, consumerId)
if alloc.Rewards.IsZero() {
continue
}

// temporary workaround to keep CanWithdrawInvariant happy
// general discussions here: https://github.com/cosmos/cosmos-sdk/issues/2906#issuecomment-441867634
if k.ComputeConsumerTotalVotingPower(ctx, consumerChainID) == 0 {
if k.ComputeConsumerTotalVotingPower(ctx, consumerId) == 0 {
rewardsToSend, rewardsChange := alloc.Rewards.TruncateDecimal()
err := k.distributionKeeper.FundCommunityPool(context.Context(ctx), rewardsToSend, k.accountKeeper.GetModuleAccount(ctx, types.ConsumerRewardsPool).GetAddress())
if err != nil {
k.Logger(ctx).Error(
"fail to allocate rewards from consumer chain %s to community pool: %s",
consumerChainID,
consumerId,
err,
)
}

// set the consumer allocation to the remaining reward decimals
alloc.Rewards = rewardsChange
k.SetConsumerRewardsAllocation(ctx, consumerChainID, alloc)
k.SetConsumerRewardsAllocation(ctx, consumerId, alloc)

return
}
Expand All @@ -112,7 +112,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
if err != nil {
k.Logger(ctx).Error(
"cannot get community tax while allocating rewards from consumer chain %s: %s",
consumerChainID,
consumerId,
err,
)
continue
Expand All @@ -132,7 +132,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
if err != nil {
k.Logger(ctx).Error(
"cannot send rewards to distribution module account %s: %s",
consumerChainID,
consumerId,
err,
)
continue
Expand All @@ -141,7 +141,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
// allocate tokens to consumer validators
k.AllocateTokensToConsumerValidators(
ctx,
consumerChainID,
consumerId,
sdk.NewDecCoinsFromCoins(validatorsRewardsTrunc...),
)

Expand All @@ -151,15 +151,15 @@ func (k Keeper) AllocateTokens(ctx sdk.Context) {
if err != nil {
k.Logger(ctx).Error(
"fail to allocate rewards from consumer chain %s to community pool: %s",
consumerChainID,
consumerId,
err,
)
continue
}

// set consumer allocations to the remaining rewards decimals
alloc.Rewards = validatorsRewardsChange.Add(remainingChanges...)
k.SetConsumerRewardsAllocation(ctx, consumerChainID, alloc)
k.SetConsumerRewardsAllocation(ctx, consumerId, alloc)
}
}

Expand Down
Loading

0 comments on commit f2e9868

Please sign in to comment.