Skip to content

Commit

Permalink
fix: proper consumer key prefix ordering (backport #991) (#1011)
Browse files Browse the repository at this point in the history
fix: proper consumer key prefix ordering (#991)

* Update keys.go

* tests

* fix another bug

* fix comments

(cherry picked from commit a1e18d0)

Co-authored-by: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com>
  • Loading branch information
mergify[bot] and shaspitz authored Jun 13, 2023
1 parent 8ce740f commit e8230bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
39 changes: 22 additions & 17 deletions x/ccv/consumer/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ const (
// received over CCV channel but not yet flushed over ABCI
PendingChangesByteKey

// NOTE: This prefix is depreciated, but left in place to avoid consumer state migrations
// [DEPRECATED]
PendingDataPacketsByteKey

// PreCCVByteKey is the byte to store the consumer is running on democracy staking module without consumer
PreCCVByteKey

// InitialValSetByteKey is the byte to store the initial validator set for a consumer
InitialValSetByteKey

// NOTE: This prefix is depreciated, but left in place to avoid consumer state migrations
// [DEPRECATED]
LastStandaloneHeightByteKey

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

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

Expand All @@ -61,30 +78,18 @@ const (
// 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
// PendingDataPacketsBytePrefix is the byte prefix 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
PendingDataPacketsByteKey

// PreCCVByteKey is the byte to store the consumer is running on democracy staking module without consumer
PreCCVByteKey
PendingDataPacketsBytePrefix

// InitialValSetByteKey is the byte to store the initial validator set for a consumer
InitialValSetByteKey
// CrossChainValidatorPrefix is the byte prefix that will store cross-chain validators by consensus address
CrossChainValidatorBytePrefix

// 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
Expand Down Expand Up @@ -170,7 +175,7 @@ func CrossChainValidatorKey(addr []byte) []byte {
// 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}
return []byte{PendingDataPacketsBytePrefix}
}

func PreCCVKey() []byte {
Expand Down
20 changes: 12 additions & 8 deletions x/ccv/consumer/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ func getAllKeyPrefixes() []byte {
ProviderClientByteKey,
ProviderChannelByteKey,
PendingChangesByteKey,
PendingDataPacketsByteKey,
PreCCVByteKey,
InitialValSetByteKey,
LastStandaloneHeightByteKey,
SmallestNonOptOutPowerByteKey,
HistoricalInfoBytePrefix,
PacketMaturityTimeBytePrefix,
HeightValsetUpdateIDBytePrefix,
OutstandingDowntimeBytePrefix,
PendingDataPacketsBytePrefix,
CrossChainValidatorBytePrefix,
PendingDataPacketsByteKey,
PreCCVByteKey,
InitialValSetByteKey,
InitGenesisHeightByteKey,
SmallestNonOptOutPowerByteKey,
StandaloneTransferChannelIDByteKey,
PrevStandaloneChainByteKey,
}
Expand All @@ -61,16 +63,18 @@ func getAllFullyDefinedKeys() [][]byte {
ProviderClientIDKey(),
ProviderChannelKey(),
PendingChangesKey(),
// PendingDataPacketsKey() does not use duplicated prefix with value of 0x06
PreCCVKey(),
InitialValSetKey(),
// LastStandaloneHeightKey() is depreciated
SmallestNonOptOutPowerKey(),
HistoricalInfoKey(0),
PacketMaturityTimeKey(0, time.Time{}),
HeightValsetUpdateIDKey(0),
OutstandingDowntimeKey([]byte{}),
CrossChainValidatorKey([]byte{}),
PendingDataPacketsKey(),
PreCCVKey(),
InitialValSetKey(),
CrossChainValidatorKey([]byte{}),
InitGenesisHeightKey(),
SmallestNonOptOutPowerKey(),
StandaloneTransferChannelIDKey(),
PrevStandaloneChainKey(),
}
Expand Down

0 comments on commit e8230bc

Please sign in to comment.