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

On-chain upgrade to consumer chain #1

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func New(
ccvmint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper),
ccvdistr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName),
ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
params.NewAppModule(app.ParamsKeeper),
Expand All @@ -506,6 +506,7 @@ func New(
ccvdistrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
ibcconsumertypes.ModuleName, // Note: consumer initiation before staking module
ccvstakingtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand All @@ -517,11 +518,11 @@ func New(
vestingtypes.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
ibcconsumertypes.ModuleName,
)
app.MM.SetOrderEndBlockers(
crisistypes.ModuleName,
ccvgovtypes.ModuleName,
ibcconsumertypes.ModuleName, // Note: consumer initiation before staking module
ccvstakingtypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
Expand All @@ -537,7 +538,6 @@ func New(
vestingtypes.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
ibcconsumertypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -550,6 +550,7 @@ func New(
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
ibcconsumertypes.ModuleName, // Note: consumer initiation before staking module
ccvdistrtypes.ModuleName,
ccvstakingtypes.ModuleName,
slashingtypes.ModuleName,
Expand All @@ -564,7 +565,6 @@ func New(
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcconsumertypes.ModuleName,
)

app.MM.RegisterInvariants(&app.CrisisKeeper)
Expand All @@ -584,7 +584,7 @@ func New(
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
ccvgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, IsProposalWhitelisted),
ccvmint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
ccvstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper),
ccvdistr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
params.NewAppModule(app.ParamsKeeper),
Expand Down
6 changes: 6 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ message GenesisState {
// LastTransmissionBlockHeight nil on new chain, filled in on restart.
interchain_security.ccv.consumer.v1.LastTransmissionBlockHeight last_transmission_block_height = 12
[ (gogoproto.nullable) = false ];
// TODO: preCCV could be replaced by params.Enabled
jstr1121 marked this conversation as resolved.
Show resolved Hide resolved
bool preCCV = 13; // flag indicating whether the consumer CCV module starts in pre-CCV state
google.protobuf.Duration unbonding_period = 14; // the unbonding period on the consumer chain.
string conn_id = 15; // the ID of the connection end on the consumer chain on top of which the CCV channel will be established.
string counterparty_client_id = 16; // the ID of the client of the consumer chain on the provider chain.
string transfer_channel_id = 17; // the ID of a token transfer channel used for the Reward Distribution sub-protocol.
}

// MaturingVSCPacket defines the genesis information for the
Expand Down
4 changes: 4 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ message ConsumerAdditionProposal {
// This param is a part of the cosmos sdk staking module. In the case of
// a ccv enabled consumer chain, the ccv module acts as the staking module.
int64 historical_entries = 13;
string conn_id = 15; // the ID of the connection end on the consumer chain on top of which the CCV channel will be established.
string transfer_channel_id = 16; // the ID of a token transfer channel used for the Reward Distribution sub-protocol.
// TODO: preCCV field shouldn't be added here? to make sure if it's a new chain with consumer initial validator set
jstr1121 marked this conversation as resolved.
Show resolved Hide resolved
// or if initial validator set will be provided from provider chain via packet
}

// ConsumerRemovalProposal is a governance proposal on the provider chain to remove (and stop) a consumer chain.
Expand Down
8 changes: 8 additions & 0 deletions proto/interchain_security/ccv/v1/ccv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import "cosmos/staking/v1beta1/staking.proto";
import "gogoproto/gogo.proto";
import "tendermint/abci/types.proto";

// This packet is to send for preCCV chain, and once it's received consumer chain sends VSCMaturedPacketData
// and consumer chain becomes preCCV chain as false, and provider chain record preCCV field as false on provider chain
message ReplaceWholeValidatorSet {
jstr1121 marked this conversation as resolved.
Show resolved Hide resolved
repeated .tendermint.abci.ValidatorUpdate initial_val_set = 1
[ (gogoproto.nullable) = false ];
uint64 valset_update_id = 2;
}

// This packet is sent from provider chain to consumer chain if the validator
// set for consumer chain changes (due to new bonding/unbonding messages or
// slashing events) A VSCMatured packet from consumer chain will be sent
Expand Down
1 change: 1 addition & 0 deletions x/ccv/consumer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (am AppModule) OnRecvPacket(
errAck := channeltypes.NewErrorAcknowledgement("cannot unmarshal CCV packet data")
ack = &errAck
} else {
// TODO: add possibility to receive ReplaceValidatorSet if it's the first time switching to consumer chain
jstr1121 marked this conversation as resolved.
Show resolved Hide resolved
ack = am.keeper.OnRecvVSCPacket(ctx, packet, data)
}

Expand Down
7 changes: 7 additions & 0 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import (
// 2. A consumer chain restarts after a client to the provider was created, but the CCV channel handshake is still in progress
// 3. A consumer chain restarts after the CCV channel handshake was completed.
func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate {
// PreCCV is true when consumer chain used to be running on non-consumer chain, and when it is in the progress of upgrading
// to consumer chain, where consumer chain upgrade is done.
if state.PreCCV {
k.SetPreCCV(ctx)
return []abci.ValidatorUpdate{}
}

k.SetParams(ctx, state.Params)
// TODO: Remove enabled flag and find a better way to setup e2e tests
// See: https://github.com/cosmos/interchain-security/issues/339
Expand Down
19 changes: 19 additions & 0 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ func (k Keeper) DeletePendingChanges(ctx sdk.Context) {
store.Delete(types.PendingChangesKey())
}

func (k Keeper) IsPreCCV(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.PreCCVKey())
if bz != nil {
return true
}
return false
}

func (k Keeper) SetPreCCV(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
store.Set(types.PreCCVKey(), []byte{1})
}

func (k Keeper) DeletePreCCV(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.PreCCVKey())
}

// IteratePacketMaturityTime iterates through the VSC packet maturity times set in the store
func (k Keeper) IteratePacketMaturityTime(ctx sdk.Context, cb func(vscId, timeNs uint64) (stop bool)) {
store := ctx.KVStore(k.storeKey)
Expand Down
1 change: 1 addition & 0 deletions x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
// Note: CCV uses an ordered IBC channel, meaning VSC packet changes will be accumulated (and later
// processed by ApplyCCValidatorChanges) s.t. more recent val power changes overwrite older ones.
func (k Keeper) OnRecvVSCPacket(ctx sdk.Context, packet channeltypes.Packet, newChanges ccv.ValidatorSetChangePacketData) exported.Acknowledgement {
// TODO: validator set update on receive packet
jstr1121 marked this conversation as resolved.
Show resolved Hide resolved
// get the provider channel
providerChannel, found := k.GetProviderChannel(ctx)
if found && providerChannel != packet.DestinationChannel {
Expand Down
Loading