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: export InitTimeoutTimestamps and VscSendTimestamps to genesis #1076

Merged
merged 11 commits into from
Jul 19, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

Add an entry to the unreleased section whenever merging a PR to main that is not targeted at a specific release. These entries will eventually be included in a release.
* `[x/ccv/provider]` (fix) [#1076](https://github.com/cosmos/interchain-security/pull/1076) Add `InitTimeoutTimestamps` and `ExportedVscSendTimestamps` to exported genesis.

* (fix!) revert consumer packet data changes from #1037 [#1150](https://github.com/cosmos/interchain-security/pull/1150)
* (fix!) proper deletion of pending packets [#1146](https://github.com/cosmos/interchain-security/pull/1146)
Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/consumer/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ message HeightToValsetUpdateID {

// OutstandingDowntime defines the genesis information for each validator
// flagged with an outstanding downtime slashing.
message OutstandingDowntime { string validator_consensus_address = 1; }
message OutstandingDowntime { string validator_consensus_address = 1; }
6 changes: 6 additions & 0 deletions proto/interchain_security/ccv/provider/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ message GenesisState {
// empty for a new chain
repeated ConsumerAddrsToPrune consumer_addrs_to_prune = 11
[ (gogoproto.nullable) = false ];

repeated interchain_security.ccv.provider.v1.InitTimeoutTimestamp init_timeout_timestamps = 12
[ (gogoproto.nullable) = false ];

repeated interchain_security.ccv.provider.v1.ExportedVscSendTimestamp exported_vsc_send_timestamps = 13
[ (gogoproto.nullable) = false ];
}

// consumer chain
Expand Down
7 changes: 7 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ message VscSendTimestamp {
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
}

// ExportedVscSendTimestamps is VscSendTimestamp with chainID info for exporting to genesis
message ExportedVscSendTimestamp {
shaspitz marked this conversation as resolved.
Show resolved Hide resolved
string chain_id = 1;
repeated VscSendTimestamp vsc_send_timestamps = 2
[ (gogoproto.nullable) = false ];
}

//
// Key assignment section
//
Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ message MsgRegisterConsumerRewardDenom {

// MsgRegisterConsumerRewardDenomResponse defines the
// Msg/RegisterConsumerRewardDenom response type.
message MsgRegisterConsumerRewardDenomResponse {}
message MsgRegisterConsumerRewardDenomResponse {}
15 changes: 15 additions & 0 deletions x/ccv/provider/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
}
}

for _, item := range genState.InitTimeoutTimestamps {
k.SetInitTimeoutTimestamp(ctx, item.ChainId, item.Timestamp)
}

for _, item := range genState.ExportedVscSendTimestamps {
for _, vscSendTimestamp := range item.VscSendTimestamps {
k.SetVscSendTimestamp(ctx, item.ChainId, vscSendTimestamp.VscId, vscSendTimestamp.Timestamp)
}
}

k.SetParams(ctx, genState.Params)
k.InitializeSlashMeter(ctx)
}
Expand All @@ -100,6 +110,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
// get a list of all registered consumer chains
registeredChains := k.GetAllConsumerChains(ctx)

var exportedVscSendTimestamps []types.ExportedVscSendTimestamp
// export states for each consumer chains
var consumerStates []types.ConsumerState
for _, chain := range registeredChains {
Expand Down Expand Up @@ -130,6 +141,8 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
cs.PendingValsetChanges = k.GetPendingVSCPackets(ctx, chain.ChainId)
consumerStates = append(consumerStates, cs)

vscSendTimestamps := k.GetAllVscSendTimestamps(ctx, chain.ChainId)
exportedVscSendTimestamps = append(exportedVscSendTimestamps, types.ExportedVscSendTimestamp{ChainId: chain.ChainId, VscSendTimestamps: vscSendTimestamps})
}

// ConsumerAddrsToPrune are added only for registered consumer chains
Expand All @@ -152,5 +165,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
k.GetAllValidatorConsumerPubKeys(ctx, nil),
k.GetAllValidatorsByConsumerAddr(ctx, nil),
consumerAddrsToPrune,
k.GetAllInitTimeoutTimestamps(ctx),
exportedVscSendTimestamps,
)
}
47 changes: 47 additions & 0 deletions x/ccv/provider/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"sort"
"testing"
"time"

Expand Down Expand Up @@ -36,6 +37,32 @@ func TestInitAndExportGenesis(t *testing.T) {
consumerTmPubKey := consumerCryptoId.TMProtoCryptoPublicKey()
consumerConsAddr := consumerCryptoId.ConsumerConsAddress()

initTimeoutTimeStamps := []providertypes.InitTimeoutTimestamp{
{ChainId: cChainIDs[0], Timestamp: uint64(time.Now().UTC().UnixNano()) + 10},
{ChainId: cChainIDs[1], Timestamp: uint64(time.Now().UTC().UnixNano()) + 15},
}

now := time.Now().UTC()
exportedVscSendTimeStampsC0 := providertypes.ExportedVscSendTimestamp{
ChainId: "c0",
VscSendTimestamps: []providertypes.VscSendTimestamp{
{VscId: 1, Timestamp: now.Add(time.Hour)},
{VscId: 2, Timestamp: now.Add(2 * time.Hour)},
},
}

exportedVscSendTimeStampsC1 := providertypes.ExportedVscSendTimestamp{
ChainId: "c1",
VscSendTimestamps: []providertypes.VscSendTimestamp{
{VscId: 1, Timestamp: now.Add(-time.Hour)},
{VscId: 2, Timestamp: now.Add(time.Hour)},
},
}

var exportedVscSendTimeStampsAll []providertypes.ExportedVscSendTimestamp
exportedVscSendTimeStampsAll = append(exportedVscSendTimeStampsAll, exportedVscSendTimeStampsC0)
exportedVscSendTimeStampsAll = append(exportedVscSendTimeStampsAll, exportedVscSendTimeStampsC1)

// create genesis struct
provGenesis := providertypes.NewGenesisState(vscID,
[]providertypes.ValsetUpdateIdToHeight{{ValsetUpdateId: vscID, Height: initHeight}},
Expand Down Expand Up @@ -98,6 +125,8 @@ func TestInitAndExportGenesis(t *testing.T) {
ConsumerAddrs: &providertypes.AddressList{Addresses: [][]byte{consumerConsAddr.ToSdkConsAddr()}},
},
},
initTimeoutTimeStamps,
exportedVscSendTimeStampsAll,
)

// Instantiate in-mem provider keeper with mocks
Expand Down Expand Up @@ -164,6 +193,24 @@ func TestInitAndExportGenesis(t *testing.T) {

// check the exported genesis
require.Equal(t, provGenesis, pk.ExportGenesis(ctx))

initTimeoutTimestampInStore := pk.GetAllInitTimeoutTimestamps(ctx)
sort.Slice(initTimeoutTimestampInStore, func(i, j int) bool {
return initTimeoutTimestampInStore[i].Timestamp < initTimeoutTimestampInStore[j].Timestamp
})
require.Equal(t, initTimeoutTimestampInStore, initTimeoutTimeStamps)

vscSendTimestampsC0InStore := pk.GetAllVscSendTimestamps(ctx, cChainIDs[0])
sort.Slice(vscSendTimestampsC0InStore, func(i, j int) bool {
return vscSendTimestampsC0InStore[i].VscId < vscSendTimestampsC0InStore[j].VscId
})
require.Equal(t, vscSendTimestampsC0InStore, exportedVscSendTimeStampsC0.VscSendTimestamps)

vscSendTimestampsC1InStore := pk.GetAllVscSendTimestamps(ctx, cChainIDs[1])
sort.Slice(vscSendTimestampsC1InStore, func(i, j int) bool {
return vscSendTimestampsC1InStore[i].VscId < vscSendTimestampsC1InStore[j].VscId
})
require.Equal(t, vscSendTimestampsC1InStore, exportedVscSendTimeStampsC1.VscSendTimestamps)
}

func assertConsumerChainStates(t *testing.T, ctx sdk.Context, pk keeper.Keeper, consumerStates ...providertypes.ConsumerState) {
Expand Down
2 changes: 2 additions & 0 deletions x/ccv/provider/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func TestInitGenesis(t *testing.T) {
nil,
nil,
nil,
nil,
nil,
)

cdc := keeperParams.Cdc
Expand Down
4 changes: 4 additions & 0 deletions x/ccv/provider/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func NewGenesisState(
validatorConsumerPubkeys []ValidatorConsumerPubKey,
validatorsByConsumerAddr []ValidatorByConsumerAddr,
consumerAddrsToPrune []ConsumerAddrsToPrune,
initTimeoutTimestamps []InitTimeoutTimestamp,
exportedVscSendTimestamps []ExportedVscSendTimestamp,
) *GenesisState {
return &GenesisState{
ValsetUpdateId: vscID,
Expand All @@ -37,6 +39,8 @@ func NewGenesisState(
ValidatorConsumerPubkeys: validatorConsumerPubkeys,
ValidatorsByConsumerAddr: validatorsByConsumerAddr,
ConsumerAddrsToPrune: consumerAddrsToPrune,
InitTimeoutTimestamps: initTimeoutTimestamps,
ExportedVscSendTimestamps: exportedVscSendTimestamps,
MSalopek marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading
Loading