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

Standalone to consumer changeover - recycle existing transfer channel #832

Merged
merged 95 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
40f3fdd
on-chain upgrade to consumer chain wip
jstr1121 Dec 19, 2022
aa566c9
add preCCV store and use it on democracy staking
jstr1121 Dec 19, 2022
dc9768d
add TODOs and one more packet possibility
jstr1121 Dec 19, 2022
473e467
status update
jstr1121 Dec 28, 2022
c6803f1
Resolve hermes start issue for trusted validator set by changing revi…
jstr1121 Jan 5, 2023
15265ad
remove intermediary logs
jstr1121 Jan 6, 2023
2806d6f
remove further unused codebase
jstr1121 Jan 6, 2023
c3ae9a4
updates for endblocker test, existing test fixes, get last validators
jstr1121 Jan 18, 2023
67aa39b
update for slashing sovereign validators for the fault made before co…
jstr1121 Jan 19, 2023
09f7b61
resolve comments on github and slack communication
jstr1121 Jan 31, 2023
d7b5a7f
Merge branch 'main' of github.com:Stride-Labs/interchain-security int…
jstr1121 Feb 21, 2023
8aea5bf
update sovereign app to use v4 ibc from v3 & resolve consumer module …
jstr1121 Feb 21, 2023
62da0d2
Update app/sovereign/upgrades/v3/upgrades.go
jstr1121 Feb 21, 2023
1cbd9d8
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 9, 2023
d46d6ef
rm sovereign chain and tests. Will be replaced by simapp and integrat…
shaspitz Mar 9, 2023
a8e8f4f
duplicate module name
shaspitz Mar 9, 2023
85b7be5
add comment
shaspitz Mar 10, 2023
a651abc
small rename
shaspitz Mar 10, 2023
1269163
remove democracy staking changes
shaspitz Mar 10, 2023
68515d9
consumer ccv beginblock, endblock, and initgenesis order shouldn't ma…
shaspitz Mar 11, 2023
48d64f4
add mock calls to compile
shaspitz Mar 13, 2023
95d11e7
adjust tests for new keeper field
shaspitz Mar 13, 2023
be3fda8
add registerDemocConsumer method
shaspitz Mar 13, 2023
e3a35ce
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 14, 2023
331f206
split out preCCV flag and initial valset
shaspitz Mar 14, 2023
08bb06b
cleanup consumer module
shaspitz Mar 14, 2023
91d7bee
cleanup
shaspitz Mar 14, 2023
110d710
more cleanup
shaspitz Mar 14, 2023
3584537
temp changes to validators.go
shaspitz Mar 14, 2023
1107280
comment out test
shaspitz Mar 14, 2023
fa5a6eb
rm bad code from merge
shaspitz Mar 14, 2023
4b5fd84
comment
shaspitz Mar 15, 2023
00a78ef
Update app.go
shaspitz Mar 15, 2023
e09066d
UTs for CRUD
shaspitz Mar 15, 2023
772c09c
UTs for keys
shaspitz Mar 15, 2023
2dc79e4
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 16, 2023
c0847e1
use make for mocks
shaspitz Mar 16, 2023
e0e5699
todo
shaspitz Mar 16, 2023
a7982de
changeover method and test
shaspitz Mar 16, 2023
aa6da31
resolve #783
shaspitz Mar 17, 2023
53dd6ea
comment
shaspitz Mar 17, 2023
3651164
comments
shaspitz Mar 17, 2023
45453b8
add appropriate TODOs, restore changes to main
shaspitz Mar 17, 2023
7fa624b
final nits before non-draft
shaspitz Mar 17, 2023
a07e84b
comment on ChangeoverToConsumer
shaspitz Mar 17, 2023
541aeb2
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 17, 2023
0ce68ce
more clear comment
shaspitz Mar 17, 2023
4f31546
Merge branch 'feature/onchain_upgrade_to_consumer_chain_840' of https…
shaspitz Mar 17, 2023
3652b2a
small comment change
shaspitz Mar 17, 2023
4f2e77e
update InitGenesis comment
shaspitz Mar 17, 2023
6b63b7e
sovereign -> standalone
shaspitz Mar 20, 2023
b80fe0f
missed a file
shaspitz Mar 20, 2023
17f020a
builds now
shaspitz Mar 20, 2023
f395584
Merge branch 'main' into feature/onchain_upgrade_to_consumer_chain_840
shaspitz Mar 20, 2023
2a76cd1
update comment after debug
shaspitz Mar 20, 2023
d091971
ChangeoverIsComplete method
shaspitz Mar 20, 2023
751acb7
small refactors, comments, slash and jail code
shaspitz Mar 21, 2023
8cf1da3
naming refactor
shaspitz Mar 21, 2023
9b50a64
Merge branch 'feature/onchain_upgrade_to_consumer_chain_840' into cha…
shaspitz Mar 21, 2023
b032f91
fix last standalone height
shaspitz Mar 21, 2023
e0f6bc3
Merge branch 'main' into changeover-staking
shaspitz Apr 6, 2023
df86b2a
Update module.go
shaspitz Apr 6, 2023
71af3a1
needed refactors
shaspitz Apr 6, 2023
14f8876
rm unneeded diffs
shaspitz Apr 6, 2023
b3156de
two UTs
shaspitz Apr 6, 2023
f804281
sanity check integration test
shaspitz Apr 6, 2023
edb491f
gofumpt
shaspitz Apr 6, 2023
d0640e1
last standalone height -> init genesis height
shaspitz Apr 7, 2023
134e8e6
wiring
shaspitz Apr 7, 2023
21fb417
integration test and refactor to enable it
shaspitz Apr 8, 2023
5b3896b
sanity check
shaspitz Apr 8, 2023
c31efc7
Update changeover.go
shaspitz Apr 8, 2023
80a6da2
Merge branch 'main' into changeover-staking
shaspitz Apr 8, 2023
e153a37
Use ValidatorUpdateDelay
shaspitz Apr 11, 2023
7cae263
Merge branch 'main' into changeover-staking
shaspitz Apr 11, 2023
0bcc0f2
Merge branch 'main' into changeover-staking
shaspitz Apr 12, 2023
cb9a1ec
for loop
shaspitz Apr 13, 2023
e78e078
Merge branch 'main' into changeover-staking
shaspitz Apr 13, 2023
d514989
Merge branch 'main' into changeover-staking
shaspitz Apr 13, 2023
098d704
Merge branch 'changeover-staking' into recycle-transfer-channel
shaspitz Apr 13, 2023
861c484
fix key name
shaspitz Apr 13, 2023
7f4c49f
Merge branch 'main' into changeover-staking
shaspitz Apr 14, 2023
02b4f75
Update x/ccv/consumer/keeper/changeover.go
shaspitz Apr 14, 2023
0147229
Update x/ccv/consumer/keeper/validators.go
shaspitz Apr 14, 2023
256bbd3
fix test
shaspitz Apr 14, 2023
7a37933
Merge branch 'changeover-staking' into recycle-transfer-channel
shaspitz Apr 14, 2023
1c76219
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 14, 2023
9f36094
rm dup method
shaspitz Apr 14, 2023
7b48350
Update keys_test.go
shaspitz Apr 14, 2023
95ed1b3
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 18, 2023
866f79d
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 18, 2023
692fb65
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 19, 2023
031283b
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 19, 2023
09fd740
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 19, 2023
aa68fc5
Merge branch 'main' into recycle-transfer-channel
shaspitz Apr 19, 2023
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
6 changes: 6 additions & 0 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,12 @@ func New(
// upgrade handler code is application specific. However, as an example, standalone to consumer
// changeover chains should utilize customized upgrade handler code similar to below.

// Setting the standalone transfer channel ID is only needed for standalone to consumer changeover chains
// who wish to preserve existing IBC transfer denoms. Here's an example.
//
// Note: This setter needs to execute before the ccv channel handshake is initiated.
app.ConsumerKeeper.SetStandaloneTransferChannelID(ctx, "hardcoded-existing-channel-id")

// TODO: should have a way to read from current node home
userHomeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
53 changes: 53 additions & 0 deletions tests/integration/changeover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package integration

import (
transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
)

func (suite *CCVTestSuite) TestRecycleTransferChannel() {
consumerKeeper := suite.consumerApp.GetConsumerKeeper()

// Only create a connection between consumer and provider
suite.coordinator.CreateConnections(suite.path)

// Confirm transfer channel has not been persisted
transChan := consumerKeeper.GetDistributionTransmissionChannel(suite.consumerCtx())
suite.Require().Empty(transChan)

// Create transfer channel manually
distrTransferMsg := channeltypes.NewMsgChannelOpenInit(
transfertypes.PortID,
transfertypes.Version,
channeltypes.UNORDERED,
[]string{suite.path.EndpointA.ConnectionID},
transfertypes.PortID,
"", // signer unused
)
resp, err := consumerKeeper.ChannelOpenInit(suite.consumerCtx(), distrTransferMsg)
suite.Require().NoError(err)

// Confirm transfer channel still not persisted
transChan = consumerKeeper.GetDistributionTransmissionChannel(suite.consumerCtx())
suite.Require().Empty(transChan)

// Setup state s.t. the consumer keeper emulates a consumer that was previously standalone
consumerKeeper.MarkAsPrevStandaloneChain(suite.consumerCtx())
suite.Require().True(consumerKeeper.IsPrevStandaloneChain(suite.consumerCtx()))
suite.consumerApp.GetConsumerKeeper().SetStandaloneTransferChannelID(suite.consumerCtx(), resp.ChannelId)

// Now finish setting up CCV channel
suite.ExecuteCCVChannelHandshake(suite.path)

// Confirm transfer channel is now persisted with expected channel id from open init response
transChan = consumerKeeper.GetDistributionTransmissionChannel(suite.consumerCtx())
suite.Require().Equal(resp.ChannelId, transChan)

// Confirm channel exists
found := consumerKeeper.TransferChannelExists(suite.consumerCtx(), transChan)
suite.Require().True(found)

// Sanity check, only two channels should exist, one transfer and one ccv
channels := suite.consumerApp.GetIBCKeeper().ChannelKeeper.GetAllChannels(suite.consumerCtx())
suite.Require().Len(channels, 2)
}
3 changes: 3 additions & 0 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ func (suite *CCVTestSuite) SetupAllCCVChannels() {

func (suite *CCVTestSuite) SetupCCVChannel(path *ibctesting.Path) {
suite.coordinator.CreateConnections(path)
suite.ExecuteCCVChannelHandshake(path)
}

func (suite *CCVTestSuite) ExecuteCCVChannelHandshake(path *ibctesting.Path) {
err := path.EndpointA.ChanOpenInit()
suite.Require().NoError(err)

Expand Down
8 changes: 8 additions & 0 deletions testutil/integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,11 @@ func TestPacketRoundtrip(t *testing.T) {
func TestQueueAndSendVSCMaturedPackets(t *testing.T) {
runCCVTestByName(t, "TestQueueAndSendVSCMaturedPackets")
}

//
// Changeover tests
//

func TestRecycleTransferChannel(t *testing.T) {
runCCVTestByName(t, "TestRecycleTransferChannel")
}
13 changes: 12 additions & 1 deletion x/ccv/consumer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ func (am AppModule) OnChanOpenAck(

///////////////////////////////////////////////////
// Initialize distribution token transfer channel
//

// First check if an existing transfer channel exists, if this consumer was a previously standalone chain.
if am.keeper.IsPrevStandaloneChain(ctx) {
transChannelID := am.keeper.GetStandaloneTransferChannelID(ctx)
found := am.keeper.TransferChannelExists(ctx, transChannelID)
if found {
// If existing transfer channel is found, persist that channel ID and return
am.keeper.SetDistributionTransmissionChannel(ctx, transChannelID)
return nil
}
}

// NOTE The handshake for this channel is handled by the ibc-go/transfer
// module. If the transfer-channel fails here (unlikely) then the transfer
// channel should be manually created and ccv parameters set accordingly.
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/consumer/keeper/changeover.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// ChangeoverIsComplete returns whether the standalone to consumer changeover process is complete.
func (k Keeper) ChangeoverIsComplete(ctx sdk.Context) bool {
if !k.IsPrevStandaloneChain() {
if !k.IsPrevStandaloneChain(ctx) {
panic("ChangeoverIsComplete should only be called on previously standalone consumers")
}
return ctx.BlockHeight() >= k.FirstConsumerHeight(ctx)
Expand Down
5 changes: 5 additions & 0 deletions x/ccv/consumer/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (k Keeper) ChannelOpenInit(ctx sdk.Context, msg *channeltypes.MsgChannelOpe
return k.ibcCoreKeeper.ChannelOpenInit(sdk.WrapSDKContext(ctx), msg)
}

func (k Keeper) TransferChannelExists(ctx sdk.Context, channelID string) bool {
_, found := k.channelKeeper.GetChannel(ctx, transfertypes.PortID, channelID)
return found
}

func (k Keeper) GetConnectionHops(ctx sdk.Context, srcPort, srcChan string) ([]string, error) {
ch, found := k.channelKeeper.GetChannel(ctx, srcPort, srcChan)
if !found {
Expand Down
1 change: 1 addition & 0 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState)
// stick around for slashing/jailing purposes.
if state.PreCCV {
k.SetPreCCVTrue(ctx)
k.MarkAsPrevStandaloneChain(ctx)
k.SetInitialValSet(ctx, state.InitialValSet)
}
k.SetInitGenesisHeight(ctx, ctx.BlockHeight()) // Usually 0, but not the case for changeover chains
Expand Down
32 changes: 26 additions & 6 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ func (k *Keeper) SetStandaloneStakingKeeper(sk ccv.StakingKeeper) {
k.standaloneStakingKeeper = sk
}

func (k Keeper) IsPrevStandaloneChain() bool {
return k.standaloneStakingKeeper != nil
}

// Validates that the consumer keeper is initialized with non-zero and
// non-nil values for all its fields. Otherwise this method will panic.
func (k Keeper) mustValidateFields() {
Expand Down Expand Up @@ -261,7 +257,7 @@ func (k Keeper) DeletePendingChanges(ctx sdk.Context) {

func (k Keeper) GetInitGenesisHeight(ctx sdk.Context) int64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.LastStandaloneHeightKey())
bz := store.Get(types.InitGenesisHeightKey())
if bz == nil {
panic("last standalone height not set")
}
Expand All @@ -272,7 +268,7 @@ func (k Keeper) GetInitGenesisHeight(ctx sdk.Context) int64 {
func (k Keeper) SetInitGenesisHeight(ctx sdk.Context, height int64) {
bz := sdk.Uint64ToBigEndian(uint64(height))
store := ctx.KVStore(k.storeKey)
store.Set(types.LastStandaloneHeightKey(), bz)
store.Set(types.InitGenesisHeightKey(), bz)
}

func (k Keeper) IsPreCCV(ctx sdk.Context) bool {
Expand Down Expand Up @@ -606,3 +602,27 @@ func (k Keeper) AppendPendingPacket(ctx sdk.Context, packet ...ccv.ConsumerPacke
list := append(pending.GetList(), packet...)
k.SetPendingPackets(ctx, ccv.ConsumerPacketDataList{List: list})
}

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

func (k Keeper) IsPrevStandaloneChain(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.PrevStandaloneChainKey())
}

// SetStandaloneTransferChannelID sets the channelID of an existing transfer channel,
// for a chain which used to be a standalone chain.
func (k Keeper) SetStandaloneTransferChannelID(ctx sdk.Context, channelID string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.StandaloneTransferChannelIDKey(), []byte(channelID))
}

// GetStandaloneTransferChannelID returns the channelID of an existing transfer channel,
// for a chain which used to be a standalone chain.
func (k Keeper) GetStandaloneTransferChannelID(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
return string(store.Get(types.StandaloneTransferChannelIDKey()))
}
25 changes: 25 additions & 0 deletions x/ccv/consumer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,28 @@ func TestGetAllOutstandingDowntimes(t *testing.T) {
require.Len(t, result, len(addresses))
require.Equal(t, result, expectedGetAllOrder)
}

// TestStandaloneTransferChannelID tests the getter and setter for the existing transfer channel id
func TestStandaloneTransferChannelID(t *testing.T) {
ck, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

// Test that the default value is empty
require.Equal(t, "", ck.GetStandaloneTransferChannelID(ctx))

// Test that the value can be set and retrieved
ck.SetStandaloneTransferChannelID(ctx, "channelID1234")
require.Equal(t, "channelID1234", ck.GetStandaloneTransferChannelID(ctx))
}

func TestPrevStandaloneChainFlag(t *testing.T) {
ck, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

// Test that the default value is false
require.False(t, ck.IsPrevStandaloneChain(ctx))

// Test that the value can be set and retrieved
ck.MarkAsPrevStandaloneChain(ctx)
require.True(t, ck.IsPrevStandaloneChain(ctx))
}
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (k Keeper) Validator(ctx sdk.Context, addr sdk.ValAddress) stakingtypes.Val
func (k Keeper) IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool {
// if the changeover is not complete for prev standalone chain,
// return the standalone staking keeper's jailed status
if k.IsPrevStandaloneChain() && !k.ChangeoverIsComplete(ctx) {
if k.IsPrevStandaloneChain(ctx) && !k.ChangeoverIsComplete(ctx) {
return k.standaloneStakingKeeper.IsValidatorJailed(ctx, addr)
}
// Otherwise, return the ccv consumer keeper's notion of a validator being jailed
Expand Down Expand Up @@ -111,7 +111,7 @@ func (k Keeper) Slash(ctx sdk.Context, addr sdk.ConsAddress, infractionHeight, p

// If this is a previously standalone chain and infraction happened before the changeover was completed,
// slash only on the standalone staking keeper.
if k.IsPrevStandaloneChain() && infractionHeight < k.FirstConsumerHeight(ctx) {
if k.IsPrevStandaloneChain(ctx) && infractionHeight < k.FirstConsumerHeight(ctx) {
k.standaloneStakingKeeper.Slash(ctx, addr, infractionHeight, power, slashFactor, stakingtypes.InfractionEmpty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to dig into how exactly consumer chains using the democracy module or other things will populate standaloneStakingKeeper

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? That's the staking module with the native token from when the chain was a standalone chain.

return
}
Expand Down
16 changes: 10 additions & 6 deletions x/ccv/consumer/keeper/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestIsValidatorJailed(t *testing.T) {
defer ctrl.Finish()

// Consumer keeper from test setup should return false for IsPrevStandaloneChain()
require.False(t, consumerKeeper.IsPrevStandaloneChain())
require.False(t, consumerKeeper.IsPrevStandaloneChain(ctx))

// IsValidatorJailed should return false for an arbitrary consensus address
consAddr := []byte{0x01, 0x02, 0x03}
Expand All @@ -123,9 +123,11 @@ func TestIsValidatorJailed(t *testing.T) {
// Now confirm IsValidatorJailed returns true
require.True(t, consumerKeeper.IsValidatorJailed(ctx, consAddr))

// Next, we set a value for the standalone staking keeper so IsPrevStandaloneChain() returns true
// Next, we set a value for the standalone staking keeper,
// and mark the consumer keeper as being from a previous standalone chain
consumerKeeper.SetStandaloneStakingKeeper(mocks.MockStakingKeeper)
require.True(t, consumerKeeper.IsPrevStandaloneChain())
consumerKeeper.MarkAsPrevStandaloneChain(ctx)
require.True(t, consumerKeeper.IsPrevStandaloneChain(ctx))

// Set init genesis height to current block height so that ChangeoverIsComplete() is false
consumerKeeper.SetInitGenesisHeight(ctx, ctx.BlockHeight())
Expand All @@ -150,7 +152,7 @@ func TestSlash(t *testing.T) {
require.Len(t, pendingPackets.List, 0)

// Consumer keeper from test setup should return false for IsPrevStandaloneChain()
require.False(t, consumerKeeper.IsPrevStandaloneChain())
require.False(t, consumerKeeper.IsPrevStandaloneChain(ctx))

// Now setup a value for vscID mapped to infraction height
consumerKeeper.SetHeightValsetUpdateID(ctx, 5, 6)
Expand All @@ -160,9 +162,11 @@ func TestSlash(t *testing.T) {
pendingPackets = consumerKeeper.GetPendingPackets(ctx)
require.Len(t, pendingPackets.List, 1)

// Next, we set a value for the standalone staking keeper so IsPrevStandaloneChain() returns true
// Next, we set a value for the standalone staking keeper,
// and mark the consumer keeper as being from a previous standalone chain
consumerKeeper.SetStandaloneStakingKeeper(mocks.MockStakingKeeper)
require.True(t, consumerKeeper.IsPrevStandaloneChain())
consumerKeeper.MarkAsPrevStandaloneChain(ctx)
require.True(t, consumerKeeper.IsPrevStandaloneChain(ctx))

// At this point, the state of the consumer keeper is s.t.
// Slash() calls the standalone staking keeper's Slash()
Expand Down
26 changes: 22 additions & 4 deletions x/ccv/consumer/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,19 @@ const (
// InitialValSetByteKey is the byte to store the initial validator set for a consumer
InitialValSetByteKey

// LastStandaloneHeightByteKey is the byte that will store last standalone height
LastStandaloneHeightByteKey
// InitGenesisHeightByteKey is the byte that will store the init genesis height
InitGenesisHeightByteKey

// SmallestNonOptOutPowerByteKey is the byte that will store the smallest val power that cannot opt out
SmallestNonOptOutPowerByteKey

// StandaloneTransferChannelIDByteKey is the byte storing the channelID of transfer channel
// that existed from a standalone chain changing over to a consumer
StandaloneTransferChannelIDByteKey

// PrevStandaloneChainByteKey is the byte storing the flag marking whether this chain was previously standalone
PrevStandaloneChainByteKey

// HistoricalInfoKey is the byte prefix that will store the historical info for a given height
HistoricalInfoBytePrefix

Expand Down Expand Up @@ -134,14 +141,25 @@ func InitialValSetKey() []byte {
return []byte{InitialValSetByteKey}
}

func LastStandaloneHeightKey() []byte {
return []byte{LastStandaloneHeightByteKey}
func InitGenesisHeightKey() []byte {
return []byte{InitGenesisHeightByteKey}
}

func SmallestNonOptOutPowerKey() []byte {
return []byte{SmallestNonOptOutPowerByteKey}
}

// StandaloneTransferChannelIDKey returns the key to the transfer channelID that existed from a standalone chain
// changing over to a consumer
func StandaloneTransferChannelIDKey() []byte {
return []byte{StandaloneTransferChannelIDByteKey}
}

// PrevStandaloneChainKey returns the key to the flag marking whether this chain was previously standalone
func PrevStandaloneChainKey() []byte {
return []byte{PrevStandaloneChainByteKey}
}

// HistoricalInfoKey returns the key to historical info to a given block height
func HistoricalInfoKey(height int64) []byte {
hBytes := make([]byte, 8)
Expand Down
8 changes: 6 additions & 2 deletions x/ccv/consumer/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ func getAllKeyPrefixes() []byte {
PendingDataPacketsByteKey,
PreCCVByteKey,
InitialValSetByteKey,
LastStandaloneHeightByteKey,
InitGenesisHeightByteKey,
SmallestNonOptOutPowerByteKey,
StandaloneTransferChannelIDByteKey,
PrevStandaloneChainByteKey,
HistoricalInfoBytePrefix,
PacketMaturityTimeBytePrefix,
HeightValsetUpdateIDBytePrefix,
Expand Down Expand Up @@ -62,8 +64,10 @@ func getAllFullyDefinedKeys() [][]byte {
PendingDataPacketsKey(),
PreCCVKey(),
InitialValSetKey(),
LastStandaloneHeightKey(),
InitGenesisHeightKey(),
SmallestNonOptOutPowerKey(),
StandaloneTransferChannelIDKey(),
PrevStandaloneChainKey(),
HistoricalInfoKey(0),
PacketMaturityTimeKey(0, time.Time{}),
HeightValsetUpdateIDKey(0),
Expand Down