Skip to content

Commit

Permalink
fix!: consumer key prefix order to avoid complex migrations (#963)
Browse files Browse the repository at this point in the history
proper order matching v1.0.0

Co-authored-by: Marius Poke <marius.poke@posteo.de>
  • Loading branch information
shaspitz and mpoke authored May 17, 2023
1 parent 11f5334 commit 82980f8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 59 deletions.
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,
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{}),
}
}

0 comments on commit 82980f8

Please sign in to comment.