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

fix!: consumer key prefix order to avoid complex migrations #963

Merged
merged 3 commits into from
May 17, 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
101 changes: 52 additions & 49 deletions x/ccv/consumer/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ const (
// received over CCV channel but not yet flushed over ABCI
PendingChangesByteKey

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

// PacketMaturityTimePrefix is the byte prefix that will store maturity time for each received VSC packet
PacketMaturityTimeBytePrefix

// HeightValsetUpdateIDPrefix is the byte prefix that will store the mapping from block height to valset update ID
HeightValsetUpdateIDBytePrefix

// OutstandingDowntimePrefix is the byte prefix that will store the validators outstanding downtime by consensus address
OutstandingDowntimeBytePrefix

// NOTE: This prefix is depreciated, but left in place to avoid consumer state migrations
PendingDataPacketsBytePrefix

// CrossChainValidatorPrefix is the byte prefix that will store cross-chain validators by consensus address
CrossChainValidatorBytePrefix

// PendingDataPacketsByteKey is the byte key for storing
// a list of data packets that cannot be sent yet to the provider
// chain either because the CCV channel is not established or
Expand All @@ -74,21 +92,6 @@ const (
// 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

// PacketMaturityTimePrefix is the byte prefix that will store maturity time for each received VSC packet
PacketMaturityTimeBytePrefix

// HeightValsetUpdateIDPrefix is the byte prefix that will store the mapping from block height to valset update ID
HeightValsetUpdateIDBytePrefix

// OutstandingDowntimePrefix is the byte prefix that will store the validators outstanding downtime by consensus address
OutstandingDowntimeBytePrefix

// CrossChainValidatorPrefix is the byte prefix that will store cross-chain validators by consensus address
CrossChainValidatorBytePrefix

// NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go
)

Expand Down Expand Up @@ -126,40 +129,6 @@ func PendingChangesKey() []byte {
return []byte{PendingChangesByteKey}
}

// PendingDataPacketsKey returns the key for storing a list of data packets
// that cannot be sent yet to the provider chain either because the CCV channel
// is not established or because the client is expired.
func PendingDataPacketsKey() []byte {
return []byte{PendingDataPacketsByteKey}
}

func PreCCVKey() []byte {
return []byte{PreCCVByteKey}
}

func InitialValSetKey() []byte {
return []byte{InitialValSetByteKey}
}

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 Expand Up @@ -197,6 +166,40 @@ func CrossChainValidatorKey(addr []byte) []byte {
return append([]byte{CrossChainValidatorBytePrefix}, addr...)
}

// PendingDataPacketsKey returns the key for storing a list of data packets
// that cannot be sent yet to the provider chain either because the CCV channel
// is not established or because the client is expired.
func PendingDataPacketsKey() []byte {
return []byte{PendingDataPacketsByteKey}
}

func PreCCVKey() []byte {
return []byte{PreCCVByteKey}
}

func InitialValSetKey() []byte {
return []byte{InitialValSetByteKey}
}

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}
}

// NOTE: DO NOT ADD FULLY DEFINED KEY FUNCTIONS WITHOUT ADDING THEM TO getAllFullyDefinedKeys() IN keys_test.go

//
Expand Down
20 changes: 10 additions & 10 deletions x/ccv/consumer/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ func getAllKeyPrefixes() []byte {
ProviderClientByteKey,
ProviderChannelByteKey,
PendingChangesByteKey,
HistoricalInfoBytePrefix,
PacketMaturityTimeBytePrefix,
HeightValsetUpdateIDBytePrefix,
OutstandingDowntimeBytePrefix,
CrossChainValidatorBytePrefix,
PendingDataPacketsByteKey,
PreCCVByteKey,
InitialValSetByteKey,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Diffs in the testing file only exist to make sure the prefixes are listed in these files in the same order they're defined in keys.go

InitGenesisHeightByteKey,
SmallestNonOptOutPowerByteKey,
StandaloneTransferChannelIDByteKey,
PrevStandaloneChainByteKey,
HistoricalInfoBytePrefix,
PacketMaturityTimeBytePrefix,
HeightValsetUpdateIDBytePrefix,
OutstandingDowntimeBytePrefix,
CrossChainValidatorBytePrefix,
}
}

Expand All @@ -61,17 +61,17 @@ func getAllFullyDefinedKeys() [][]byte {
ProviderClientIDKey(),
ProviderChannelKey(),
PendingChangesKey(),
HistoricalInfoKey(0),
PacketMaturityTimeKey(0, time.Time{}),
HeightValsetUpdateIDKey(0),
OutstandingDowntimeKey([]byte{}),
CrossChainValidatorKey([]byte{}),
PendingDataPacketsKey(),
PreCCVKey(),
InitialValSetKey(),
InitGenesisHeightKey(),
SmallestNonOptOutPowerKey(),
StandaloneTransferChannelIDKey(),
PrevStandaloneChainKey(),
HistoricalInfoKey(0),
PacketMaturityTimeKey(0, time.Time{}),
HeightValsetUpdateIDKey(0),
OutstandingDowntimeKey([]byte{}),
CrossChainValidatorKey([]byte{}),
}
}