Skip to content

Commit

Permalink
make changes to genesis import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Dec 23, 2022
1 parent da339ca commit a7ecaf7
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 76 deletions.
4 changes: 3 additions & 1 deletion proto/interchain_security/ccv/provider/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ message ConsumerState {
// UnbondingOpsIndex defines the unbonding operations waiting on this consumer chain
repeated interchain_security.ccv.provider.v1.VscUnbondingOps unbonding_ops_index = 8
[ (gogoproto.nullable) = false ];
// latest valset update id for which downtime slash packet was processed for this consumer chain
uint64 last_downtime_valset_update_id = 9;
}

// ValsetUpdateIdToHeight defines the genesis information for the mapping
Expand Down Expand Up @@ -99,4 +101,4 @@ message ConsumerAddrsToPrune {
string chain_id = 1;
uint64 vsc_id = 2;
AddressList consumer_addrs = 3;
}
}
10 changes: 6 additions & 4 deletions x/ccv/provider/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
k.SetChainToChannel(ctx, chainID, cs.ChannelId)
k.SetInitChainHeight(ctx, chainID, cs.InitialHeight)
k.SetSlashAcks(ctx, cs.ChainId, cs.SlashDowntimeAck)
k.SetLastDowntimeValsetUpdateId(ctx, chainID, cs.LastDowntimeValsetUpdateId)
} else {
k.AppendPendingVSCPackets(ctx, chainID, cs.PendingValsetChanges...)
}
Expand Down Expand Up @@ -102,10 +103,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {

// initial consumer chain states
cs := types.ConsumerState{
ChainId: chain.ChainId,
ClientId: chain.ClientId,
ConsumerGenesis: gen,
UnbondingOpsIndex: k.GetAllUnbondingOpIndexes(ctx, chain.ChainId),
ChainId: chain.ChainId,
ClientId: chain.ClientId,
ConsumerGenesis: gen,
UnbondingOpsIndex: k.GetAllUnbondingOpIndexes(ctx, chain.ChainId),
LastDowntimeValsetUpdateId: k.GetLastDowntimeValsetUpdateId(ctx, chain.ChainId),
}

// try to find channel id for the current consumer chain
Expand Down
3 changes: 3 additions & 0 deletions x/ccv/provider/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestInitAndExportGenesis(t *testing.T) {
},
[]ccv.ValidatorSetChangePacketData{},
[]string{"slashedValidatorConsAddress"},
111,
),
providertypes.NewConsumerStates(
cChainIDs[1],
Expand All @@ -60,6 +61,7 @@ func TestInitAndExportGenesis(t *testing.T) {
nil,
[]ccv.ValidatorSetChangePacketData{{ValsetUpdateId: vscID}},
nil,
0, // channel was not established, so there cannot be any matured VSCs or slash packets
),
},
[]providertypes.UnbondingOp{{
Expand Down Expand Up @@ -199,5 +201,6 @@ func assertConsumerChainStates(ctx sdk.Context, t *testing.T, pk keeper.Keeper,
}

require.Equal(t, cs.SlashDowntimeAck, pk.GetSlashAcks(ctx, chainID))
require.Equal(t, cs.LastDowntimeValsetUpdateId, pk.GetLastDowntimeValsetUpdateId(ctx, chainID))
}
}
18 changes: 10 additions & 8 deletions x/ccv/provider/types/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ func NewConsumerStates(
unbondingOpsIndexes []VscUnbondingOps,
pendingValsetChanges []ccv.ValidatorSetChangePacketData,
slashDowntimeAck []string,
lastDowntimeValsetUpdateId uint64,
) ConsumerState {
return ConsumerState{
ChainId: chainID,
ClientId: clientID,
ChannelId: channelID,
InitialHeight: initialHeight,
UnbondingOpsIndex: unbondingOpsIndexes,
PendingValsetChanges: pendingValsetChanges,
ConsumerGenesis: genesis,
SlashDowntimeAck: slashDowntimeAck,
ChainId: chainID,
ClientId: clientID,
ChannelId: channelID,
InitialHeight: initialHeight,
UnbondingOpsIndex: unbondingOpsIndexes,
PendingValsetChanges: pendingValsetChanges,
ConsumerGenesis: genesis,
SlashDowntimeAck: slashDowntimeAck,
LastDowntimeValsetUpdateId: lastDowntimeValsetUpdateId,
}
}
163 changes: 100 additions & 63 deletions x/ccv/provider/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7ecaf7

Please sign in to comment.