Skip to content
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

refactor: move democracy consumer code to /x/ccv/consumer #883

Merged
merged 28 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
ibctestingcore "github.com/cosmos/interchain-security/legacy_ibc_testing/core"
ibctesting "github.com/cosmos/interchain-security/legacy_ibc_testing/testing"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -90,16 +91,16 @@ import (
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
testutil "github.com/cosmos/interchain-security/testutil/integration"
ccvdistr "github.com/cosmos/interchain-security/x/ccv/democracy/distribution"
ccvdistr "github.com/cosmos/interchain-security/x/ccv/consumer/democracy/distribution"

stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ccvstaking "github.com/cosmos/interchain-security/x/ccv/democracy/staking"
ccvstaking "github.com/cosmos/interchain-security/x/ccv/consumer/democracy/staking"

gov "github.com/cosmos/cosmos-sdk/x/gov"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
ccvgov "github.com/cosmos/interchain-security/x/ccv/democracy/governance"
ccvgov "github.com/cosmos/interchain-security/x/ccv/consumer/democracy/governance"

// add mint
mint "github.com/cosmos/cosmos-sdk/x/mint"
Expand Down Expand Up @@ -660,7 +661,7 @@ func New(
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

consumerGenesis := consumertypes.GenesisState{}
consumerGenesis := ccvtypes.ConsumerGenesisState{}
appCodec.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis)

consumerGenesis.PreCCV = true
Expand Down
3 changes: 2 additions & 1 deletion app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
ibctestingcore "github.com/cosmos/interchain-security/legacy_ibc_testing/core"
ibctesting "github.com/cosmos/interchain-security/legacy_ibc_testing/testing"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -422,7 +423,7 @@ func New(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(app.ProviderKeeper)).
AddRoute(ccvtypes.RouterKey, ibcprovider.NewProviderProposalHandler(app.ProviderKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

app.GovKeeper = govkeeper.NewKeeper(
Expand Down
6 changes: 3 additions & 3 deletions proto/interchain_security/ccv/consumer/v1/consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package interchain_security.ccv.consumer.v1;

import "interchain_security/ccv/v1/ccv.proto";

option go_package = "github.com/cosmos/interchain-security/x/ccv/consumer/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

// Params defines the parameters for CCV consumer module
message Params {
// ConsumerParams defines the parameters for CCV consumer module
message ConsumerParams {
// TODO: Remove enabled flag and find a better way to setup integration tests
// See: https://github.com/cosmos/interchain-security/issues/339
bool enabled = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package interchain_security.ccv.consumer.v1;

option go_package = "github.com/cosmos/interchain-security/x/ccv/consumer/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "interchain_security/ccv/v1/ccv.proto";
import "interchain_security/ccv/consumer/v1/consumer.proto";
Expand All @@ -12,9 +12,9 @@ import "ibc/core/channel/v1/channel.proto";
import "google/protobuf/duration.proto";
import "gogoproto/gogo.proto";

// GenesisState defines the CCV consumer chain genesis state
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
// ConsumerGenesisState defines the CCV consumer chain genesis state
message ConsumerGenesisState {
ConsumerParams params = 1 [ (gogoproto.nullable) = false ];
string provider_client_id = 2; // empty for a new chain, filled in on restart.
string provider_channel_id = 3; // empty for a new chain, filled in on restart.
bool new_chain = 4; // true for new chain GenesisState, false for chain restart.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
syntax = "proto3";

package interchain_security.ccv.consumer.v1;
option go_package = "github.com/cosmos/interchain-security/x/ccv/consumer/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "interchain_security/ccv/consumer/v1/consumer.proto";

service Query {
service ConsumerQuery {
// ConsumerGenesis queries the genesis state needed to start a consumer chain
// whose proposal has been accepted
rpc QueryNextFeeDistribution(QueryNextFeeDistributionEstimateRequest)
Expand Down Expand Up @@ -50,5 +50,5 @@ message QueryParamsRequest {}
// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
ConsumerParams params = 1 [(gogoproto.nullable) = false];
}
6 changes: 3 additions & 3 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package interchain_security.ccv.provider.v1;

option go_package = "github.com/cosmos/interchain-security/x/ccv/provider/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
Expand Down Expand Up @@ -107,8 +107,8 @@ message GlobalSlashEntry {
ProviderConsAddress provider_val_cons_addr = 4;
}

// Params defines the parameters for CCV Provider module
message Params {
// ProviderParams defines the parameters for CCV Provider module
message ProviderParams {
ibc.lightclients.tendermint.v1.ClientState template_client = 1;
// TrustingPeriodFraction is used to compute the consumer and provider IBC client's TrustingPeriod from the chain defined UnbondingPeriod
string trusting_period_fraction = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ syntax = "proto3";

package interchain_security.ccv.provider.v1;

option go_package = "github.com/cosmos/interchain-security/x/ccv/provider/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "gogoproto/gogo.proto";
import "interchain_security/ccv/v1/ccv.proto";
import "interchain_security/ccv/provider/v1/provider.proto";
import "interchain_security/ccv/consumer/v1/consumer.proto";
import "interchain_security/ccv/consumer/v1/genesis.proto";
import "interchain_security/ccv/consumer/v1/consumer_genesis.proto";
import "tendermint/crypto/keys.proto";


// GenesisState defines the CCV provider chain genesis state
message GenesisState {
// ProviderGenesisState defines the CCV provider chain genesis state
message ProviderGenesisState {
// strictly positive and set to 1 (DefaultValsetUpdateID) for a new chain
uint64 valset_update_id = 1;
// empty for a new chain
Expand All @@ -35,7 +35,7 @@ message GenesisState {
// empty for a new chain
repeated ConsumerRemovalProposal consumer_removal_proposals = 7
[ (gogoproto.nullable) = false ];
Params params = 8
ProviderParams params = 8
[ (gogoproto.nullable) = false ];
// empty for a new chain
repeated ValidatorConsumerPubKey validator_consumer_pubkeys = 9
Expand All @@ -59,7 +59,7 @@ message ConsumerState {
// InitalHeight defines the initial block height for the consumer chain
uint64 initial_height = 4;
// ConsumerGenesis defines the initial consumer chain genesis states
interchain_security.ccv.consumer.v1.GenesisState consumer_genesis = 5
interchain_security.ccv.consumer.v1.ConsumerGenesisState consumer_genesis = 5
[ (gogoproto.nullable) = false ];
// PendingValsetChanges defines the pending validator set changes for the consumer chain
repeated interchain_security.ccv.v1.ValidatorSetChangePacketData pending_valset_changes = 6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
syntax = "proto3";
package interchain_security.ccv.provider.v1;

option go_package = "github.com/cosmos/interchain-security/x/ccv/provider/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "interchain_security/ccv/v1/ccv.proto";
import "interchain_security/ccv/consumer/v1/genesis.proto";
import "interchain_security/ccv/consumer/v1/consumer_genesis.proto";
import "interchain_security/ccv/provider/v1/provider.proto";


service Query {
service ProviderQuery {
// ConsumerGenesis queries the genesis state needed to start a consumer chain
// whose proposal has been accepted
rpc QueryConsumerGenesis(QueryConsumerGenesisRequest)
Expand Down Expand Up @@ -73,7 +73,7 @@ service Query {
message QueryConsumerGenesisRequest { string chain_id = 1; }

message QueryConsumerGenesisResponse {
interchain_security.ccv.consumer.v1.GenesisState genesis_state = 1
interchain_security.ccv.consumer.v1.ConsumerGenesisState genesis_state = 1
[ (gogoproto.nullable) = false ];
}

Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package interchain_security.ccv.provider.v1;

option go_package = "github.com/cosmos/interchain-security/x/ccv/provider/types";
option go_package = "github.com/cosmos/interchain-security/x/ccv/types";

import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
Expand Down
13 changes: 6 additions & 7 deletions tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
icstestingutils "github.com/cosmos/interchain-security/testutil/ibc_testing"
simibc "github.com/cosmos/interchain-security/testutil/simibc"
consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
providerkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"

ccv "github.com/cosmos/interchain-security/x/ccv/types"
Expand Down Expand Up @@ -499,23 +498,23 @@ func (b *Builder) createConsumersLocalClientGenesis() *ibctmtypes.ClientState {
)
}

func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *consumertypes.GenesisState {
func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *ccv.ConsumerGenesisState {
providerConsState := b.provider().LastHeader.ConsensusState()

valUpdates := tmtypes.TM2PB.ValidatorUpdates(b.provider().Vals)
params := consumertypes.NewParams(
params := ccv.NewConsumerParams(
true,
1000, // ignore distribution
"", // ignore distribution
"", // ignore distribution
ccv.DefaultCCVTimeoutPeriod,
consumertypes.DefaultTransferTimeoutPeriod,
consumertypes.DefaultConsumerRedistributeFrac,
consumertypes.DefaultHistoricalEntries,
ccv.DefaultTransferTimeoutPeriod,
ccv.DefaultConsumerRedistributeFrac,
ccv.DefaultHistoricalEntries,
b.initState.UnbondingC,
"0", // disable soft opt-out
)
return consumertypes.NewInitialGenesisState(client, providerConsState, valUpdates, params)
return ccv.NewInitialConsumerGenesisState(client, providerConsState, valUpdates, params)
}

// The state of the data returned is equivalent to the state of two chains
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (

evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"

"github.com/cosmos/interchain-security/x/ccv/provider/client"
"github.com/cosmos/interchain-security/x/ccv/provider/types"
"github.com/tidwall/gjson"
)

Expand Down Expand Up @@ -214,7 +213,7 @@ func (tr TestRun) submitConsumerAdditionProposal(
verbose bool,
) {
spawnTime := tr.containerConfig.now.Add(time.Duration(action.spawnTime) * time.Millisecond)
params := consumertypes.DefaultParams()
params := ccvtypes.DefaultConsumerParams()
prop := client.ConsumerAdditionProposalJSON{
Title: "Propose the addition of a new chain",
Description: "Gonna be a great chain",
Expand Down Expand Up @@ -417,7 +416,7 @@ func (tr TestRun) submitEquivocationProposal(action submitEquivocationProposalAc
providerChain := tr.chainConfigs[chainID("provi")]

prop := client.EquivocationProposalJSON{
EquivocationProposal: types.EquivocationProposal{
EquivocationProposal: ccvtypes.EquivocationProposal{
Title: "Validator equivocation!",
Description: fmt.Sprintf("Validator: %s has committed an equivocation infraction on chainID: %s", action.validator, action.chain),
Equivocations: []*evidencetypes.Equivocation{
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
ibctesting "github.com/cosmos/interchain-security/legacy_ibc_testing/testing"
icstestingutils "github.com/cosmos/interchain-security/testutil/ibc_testing"
testutil "github.com/cosmos/interchain-security/testutil/integration"
providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"
ccv "github.com/cosmos/interchain-security/x/ccv/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -548,7 +547,7 @@ func (suite *CCVTestSuite) CreateCustomClient(endpoint *ibctesting.Endpoint, unb
require.True(endpoint.Chain.T, ok)
tmConfig.UnbondingPeriod = unbondingPeriod

trustPeriod, err := ccv.CalculateTrustPeriod(unbondingPeriod, providertypes.DefaultTrustingPeriodFraction)
trustPeriod, err := ccv.CalculateTrustPeriod(unbondingPeriod, ccv.DefaultTrustingPeriodFraction)
require.NoError(endpoint.Chain.T, err)
tmConfig.TrustingPeriod = trustPeriod

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() {

// reward for the provider chain will be sent after each 2 blocks
consumerParams := s.consumerApp.GetSubspace(consumertypes.ModuleName)
consumerParams.Set(s.consumerCtx(), consumertypes.KeyBlocksPerDistributionTransmission, int64(2))
consumerParams.Set(s.consumerCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(2))
s.consumerChain.NextBlock()

consumerAccountKeeper := s.consumerApp.GetTestAccountKeeper()
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() {

// reward for the provider chain will be sent after each 1000 blocks
consumerParams := s.consumerApp.GetSubspace(consumertypes.ModuleName)
consumerParams.Set(s.consumerCtx(), consumertypes.KeyBlocksPerDistributionTransmission, int64(1000))
consumerParams.Set(s.consumerCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(1000))

// fill fee pool
fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)))
Expand Down Expand Up @@ -200,7 +200,7 @@ func (s *CCVTestSuite) TestEndBlockRD() {

// reward for the provider chain will be sent after each 1000 blocks
consumerParams := s.consumerApp.GetSubspace(consumertypes.ModuleName)
consumerParams.Set(s.consumerCtx(), consumertypes.KeyBlocksPerDistributionTransmission, int64(1000))
consumerParams.Set(s.consumerCtx(), ccv.KeyBlocksPerDistributionTransmission, int64(1000))

// fill fee pool
fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100)))
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/normal_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package integration

import (
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

Expand All @@ -21,7 +21,7 @@ func (k CCVTestSuite) TestHistoricalInfo() { //nolint:govet // this is a test so
createVal := func(k CCVTestSuite) { //nolint:govet // this is a test so we can copy locks
// add new validator to consumer states
pk := ed25519.GenPrivKey().PubKey()
cVal, err := consumertypes.NewCCValidator(pk.Address(), int64(1), pk)
cVal, err := ccvtypes.NewCCValidator(pk.Address(), int64(1), pk)
k.Require().NoError(err)

consumerKeeper.SetCCValidator(k.consumerChain.GetContext(), cVal)
Expand Down Expand Up @@ -71,7 +71,7 @@ func (k CCVTestSuite) TestHistoricalInfo() { //nolint:govet // this is a test so
expLen: 0,
},
{
height: initHeight + consumertypes.DefaultHistoricalEntries + 2,
height: initHeight + ccvtypes.DefaultHistoricalEntries + 2,
found: true,
expLen: initValsetLen + 2,
},
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
tmencoding "github.com/tendermint/tendermint/crypto/encoding"

icstestingutils "github.com/cosmos/interchain-security/testutil/ibc_testing"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
ccv "github.com/cosmos/interchain-security/x/ccv/types"

transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
Expand Down Expand Up @@ -152,7 +151,7 @@ func (suite *CCVTestSuite) SetupTest() {
func initConsumerChain(
s *CCVTestSuite,
chainID string,
genesisState *consumertypes.GenesisState,
genesisState *ccv.ConsumerGenesisState,
) {
providerKeeper := s.providerApp.GetProviderKeeper()
bundle := s.consumerBundles[chainID]
Expand Down
Loading