Skip to content

Commit

Permalink
progress save
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Aug 14, 2023
1 parent ea1bb3e commit 4a5a561
Show file tree
Hide file tree
Showing 32 changed files with 484 additions and 307 deletions.
8 changes: 0 additions & 8 deletions proto/interchain_security/ccv/consumer/v1/consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ message CrossChainValidator {
];
}

// ConsumerPacketDataList is a list of consumer packet data packets.
//
// Note this type is is only used internally to the consumer CCV module
// for exporting / importing state in InitGenesis and ExportGenesis.
message ConsumerPacketDataList {
repeated interchain_security.ccv.v1.ConsumerPacketData list = 1 [ (gogoproto.nullable) = false ];
}

// A record storing the state of a slash packet sent to the provider chain
// which may bounce back and forth until handled by the provider.
//
Expand Down
12 changes: 11 additions & 1 deletion proto/interchain_security/ccv/v1/shared_consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ message GenesisState {
repeated OutstandingDowntime outstanding_downtime_slashing = 10
[ (gogoproto.nullable) = false ];
// PendingConsumerPackets nil on new chain, filled in on restart.
interchain_security.ccv.consumer.v1.ConsumerPacketDataList pending_consumer_packets =
ConsumerPacketDataList pending_consumer_packets =
11 [ (gogoproto.nullable) = false ];
// LastTransmissionBlockHeight nil on new chain, filled in on restart.
LastTransmissionBlockHeight
Expand Down Expand Up @@ -145,3 +145,13 @@ message MaturingVSCPacket {
google.protobuf.Timestamp maturity_time = 2
[ (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
}

// ConsumerPacketDataList is a list of consumer packet data packets.
//
// Note this type is is used internally to the consumer CCV module
// for exporting / importing state in InitGenesis and ExportGenesis,
// AND included in the consumer genesis type (reffed by provider and consumer modules),
// hence this is a shared type.
message ConsumerPacketDataList {
repeated interchain_security.ccv.v1.ConsumerPacketData list = 1 [ (gogoproto.nullable) = false ];
}
10 changes: 5 additions & 5 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal {
[]byte("gen_hash"),
[]byte("bin_hash"),
time.Now(),
consumertypes.DefaultConsumerRedistributeFrac,
consumertypes.DefaultBlocksPerDistributionTransmission,
types.DefaultConsumerRedistributeFrac,
types.DefaultBlocksPerDistributionTransmission,
"",
consumertypes.DefaultHistoricalEntries,
types.DefaultHistoricalEntries,
types.DefaultCCVTimeoutPeriod,
consumertypes.DefaultTransferTimeoutPeriod,
consumertypes.DefaultConsumerUnbondingPeriod,
types.DefaultTransferTimeoutPeriod,
types.DefaultConsumerUnbondingPeriod,
).(*providertypes.ConsumerAdditionProposal)

return prop
Expand Down
3 changes: 1 addition & 2 deletions x/ccv/consumer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
"github.com/cosmos/interchain-security/v3/x/ccv/types"
)

Expand Down Expand Up @@ -127,7 +126,7 @@ func (am AppModule) OnChanOpenAck(
"provider channel: %s already established", providerChannel)
}

var md providertypes.HandshakeMetadata
var md types.HandshakeMetadata
if err := (&md).Unmarshal([]byte(counterpartyMetadata)); err != nil {
return errorsmod.Wrapf(types.ErrInvalidHandshakeMetadata,
"error unmarshalling ibc-ack metadata: \n%v; \nmetadata: %v", err, counterpartyMetadata)
Expand Down
5 changes: 2 additions & 3 deletions x/ccv/consumer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
"github.com/cosmos/interchain-security/v3/x/ccv/consumer"
consumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

Expand Down Expand Up @@ -262,7 +261,7 @@ func TestOnChanOpenAck(t *testing.T) {
{
"invalid: mismatched serialized version",
func(keeper *consumerkeeper.Keeper, params *params, mocks testkeeper.MockedKeepers) {
md := providertypes.HandshakeMetadata{
md := ccv.HandshakeMetadata{
ProviderFeePoolAddr: "", // dummy address used
Version: "bunkVersion",
}
Expand All @@ -288,7 +287,7 @@ func TestOnChanOpenAck(t *testing.T) {
counterpartyChannelID: "providerCCVChannelID",
}

metadata := providertypes.HandshakeMetadata{
metadata := ccv.HandshakeMetadata{
ProviderFeePoolAddr: "someAcct",
Version: ccv.Version,
}
Expand Down
8 changes: 4 additions & 4 deletions x/ccv/consumer/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (k Keeper) EndBlockRD(ctx sdk.Context) {
}

// Update LastTransmissionBlockHeight
newLtbh := types.LastTransmissionBlockHeight{
newLtbh := ccv.LastTransmissionBlockHeight{
Height: ctx.BlockHeight(),
}
k.SetLastTransmissionBlockHeight(ctx, newLtbh)
Expand Down Expand Up @@ -190,10 +190,10 @@ func (k Keeper) AllowedRewardDenoms(ctx sdk.Context) []string {
return rewardDenoms
}

func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) types.LastTransmissionBlockHeight {
func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmissionBlockHeight {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.LastDistributionTransmissionKey())
ltbh := types.LastTransmissionBlockHeight{}
ltbh := ccv.LastTransmissionBlockHeight{}
if bz != nil {
if err := ltbh.Unmarshal(bz); err != nil {
panic(fmt.Errorf("failed to unmarshal LastTransmissionBlockHeight: %w", err))
Expand All @@ -202,7 +202,7 @@ func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) types.LastTransm
return ltbh
}

func (k Keeper) SetLastTransmissionBlockHeight(ctx sdk.Context, ltbh types.LastTransmissionBlockHeight) {
func (k Keeper) SetLastTransmissionBlockHeight(ctx sdk.Context, ltbh ccv.LastTransmissionBlockHeight) {
store := ctx.KVStore(k.storeKey)
bz, err := ltbh.Marshal()
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/consumer/keeper/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

// TestGetEstimatedNextFeeDistribution tests next fee distribution parameters.
Expand All @@ -25,7 +26,7 @@ func TestGetEstimatedNextFeeDistribution(t *testing.T) {
mockAccountKeeper := mocks.MockAccountKeeper
mockBankKeeper := mocks.MockBankKeeper
consumerKeeper := testkeeper.NewInMemConsumerKeeper(keeperParams, mocks)
consumerKeeper.SetParams(ctx, types.DefaultParams())
consumerKeeper.SetParams(ctx, ccvtypes.DefaultParams())

// Setup mock account balance
fracParam := consumerKeeper.GetConsumerRedistributionFrac(ctx)
Expand Down Expand Up @@ -76,7 +77,7 @@ func TestAllowedRewardDenoms(t *testing.T) {
defer ctrl.Finish()
mocks := testkeeper.NewMockedKeepers(ctrl)
consumerKeeper := testkeeper.NewInMemConsumerKeeper(keeperParams, mocks)
params := types.DefaultParams()
params := ccvtypes.DefaultParams()
params.RewardDenoms = []string{"ustake"}
params.ProviderRewardDenoms = []string{"uatom"}
consumerKeeper.SetParams(ctx, params)
Expand Down
15 changes: 7 additions & 8 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

abci "github.com/cometbft/cometbft/abci/types"

consumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

Expand All @@ -17,7 +16,7 @@ import (
// 1. A client to the provider was never created, i.e. a new consumer chain is started for the first time.
// 2. A consumer chain restarts after a client to the provider was created, but the CCV channel handshake is still in progress
// 3. A consumer chain restarts after the CCV channel handshake was completed.
func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate {
func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.GenesisState) []abci.ValidatorUpdate {
// PreCCV is true during the process of a standalone to consumer changeover.
// At the PreCCV point in the process, the standalone chain has just been upgraded to include
// the consumer ccv module, but the standalone staking keeper is still managing the validator set.
Expand Down Expand Up @@ -116,10 +115,10 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState)
}

// ExportGenesis returns the CCV consumer module's exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisState) {
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) {
params := k.GetConsumerParams(ctx)
if !params.Enabled {
return consumertypes.DefaultGenesisState()
return ccv.DefaultGenesisState()
}

// export the current validator set
Expand All @@ -138,7 +137,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt
panic("provider client does not exist although provider channel does exist")
}

genesis = consumertypes.NewRestartGenesisState(
genesis = ccv.NewRestartGenesisState(
clientID,
channelID,
k.GetAllPacketMaturityTimes(ctx),
Expand All @@ -154,19 +153,19 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt
// if provider clientID and channelID don't exist on the consumer chain,
// then CCV protocol is disabled for this chain return a default genesis state
if !ok {
return consumertypes.DefaultGenesisState()
return ccv.DefaultGenesisState()
}

// export client states and pending slashing requests into a new chain genesis
genesis = consumertypes.NewRestartGenesisState(
genesis = ccv.NewRestartGenesisState(
clientID,
"",
nil,
valset,
k.GetAllHeightToValsetUpdateIDs(ctx),
pendingPacketsDepreciated,
nil,
consumertypes.LastTransmissionBlockHeight{},
ccv.LastTransmissionBlockHeight{},
params,
)
}
Expand Down
Loading

0 comments on commit 4a5a561

Please sign in to comment.