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

Add in-place and genesis migrations #205

Merged
merged 27 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4f874d9
add in-place migrations
colin-axner May 31, 2021
f8ca013
update migrations
colin-axner Jun 2, 2021
29c1c48
migrate solomachine from v1 to v2 during in place migration
colin-axner Jun 7, 2021
db0db21
fix build
colin-axner Jun 7, 2021
972ca3c
add genesis migration
colin-axner Jun 7, 2021
314aaba
code cleanup
colin-axner Jun 8, 2021
40a30fa
Merge branch 'main' into colin/11-migration-scripts
colin-axner Jun 8, 2021
863fdbd
add store migration test for expired tendermint consensus states
colin-axner Jun 8, 2021
a36801f
Merge branch 'colin/11-migration-scripts' of github.com:cosmos/ibc-go…
colin-axner Jun 8, 2021
863b50a
finish adding in place migration store tests
colin-axner Jun 9, 2021
545056e
add genesis test for solo machines
colin-axner Jun 9, 2021
40484bb
fix genesis migration bug, add tendermint tests
colin-axner Jun 9, 2021
a24618d
test fix, changelog, migration docs
colin-axner Jun 9, 2021
6d9bcdd
Apply suggestions from code review
colin-axner Jun 9, 2021
6c6fc52
Merge branch 'main' into colin/11-migration-scripts
colin-axner Jun 9, 2021
a67102f
Update docs/migrations/ibc-migration-043.md
AdityaSripal Jun 9, 2021
7e1f40f
apply Aditya's review suggestions
colin-axner Jun 10, 2021
3896a2a
Merge branch 'colin/11-migration-scripts' of github.com:cosmos/ibc-go…
colin-axner Jun 10, 2021
7edac1e
fix tests
colin-axner Jun 10, 2021
e326f74
add genesis json unmarshal test
colin-axner Jun 10, 2021
a970700
Merge branch 'main' into colin/11-migration-scripts
colin-axner Jun 10, 2021
7ceca61
add migration support for max expected time per block
colin-axner Jun 15, 2021
ca070bd
Merge branch 'colin/11-migration-scripts' of github.com:cosmos/ibc-go…
colin-axner Jun 15, 2021
0fcd0c4
fix docs
colin-axner Jun 15, 2021
900b907
fix bug found by Aditya
colin-axner Jun 16, 2021
fed9443
remove unnecessary code
colin-axner Jun 16, 2021
e595b11
apply Aditya review suggestions, fix bug
colin-axner Jun 17, 2021
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
4 changes: 2 additions & 2 deletions docs/migrations/ibc-migration-043.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ import (
...

// add in migrate cmd function
newGenState, err = ibcv100.MigrateGenesis(clientCtx.InterfaceRegistry, newGenState, genDoc.GenesisTime)
newGenState, err = ibcv100.MigrateGenesis(clientCtx.InterfaceRegistry, newGenState, genDoc)
if err != nil {
return err
}
```

**NOTE:** The genesis time MUST be updated before migrating IBC, otherwise the tendermint consensus state will not be pruned.
**NOTE:** The genesis chain-id, time and height MUST be updated before migrating IBC, otherwise the tendermint consensus state will not be pruned.

## IBC Keeper Changes

Expand Down
11 changes: 5 additions & 6 deletions modules/core/02-client/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ func NewMigrator(keeper Keeper) Migrator {
}

// Migrate1to2 migrates from version 1 to 2.
// This migration prunes:
// - solo machine consensus states
// - expired tendermint consensus states
//
// This migration migrates:
// - solo machine client states from v1 to v2 protobuf definition
// This migration
// - migrates solo machine client states from v1 to v2 protobuf definition
// - prunes solo machine consensus states
// - prunes expired tendermint consensus states
// - adds iteration and processed height keys for unexpired tendermint consensus states
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v100.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
}
1 change: 1 addition & 0 deletions modules/core/02-client/legacy/v100/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// - Update solo machine client state protobuf definition (v1 to v2)
// - Remove all solo machine consensus states
// - Remove all expired tendermint consensus states
// - Adds ProcessedHeight and Iteration keys for unexpired tendermint consensus states
func MigrateGenesis(cdc codec.BinaryCodec, clientGenState *types.GenesisState, genesisBlockTime time.Time, selfHeight exported.Height) (*types.GenesisState, error) {
// To prune the consensus states, we will create new clientsConsensus
// and clientsMetadata. These slices will be filled up with consensus states
Expand Down
208 changes: 208 additions & 0 deletions modules/core/02-client/legacy/v100/solomachine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
package v100

import (
ics23 "github.com/confio/ics23/go"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/modules/core/exported"
)

// NOTE: this is a mock implmentation for exported.ClientState. This implementation
// should only be registered on the InterfaceRegistry during cli command genesis migration.
// This implementation is only used to successfully unmarshal the previous solo machine
// client state and consensus state and migrate them to the new implementations. When the proto
// codec unmarshals, it calls UnpackInterfaces() to create a cached value of the any. The
// UnpackInterfaces function for IdenitifiedClientState will attempt to unpack the any to
// exported.ClientState. If the solomachine v1 type is not registered against the exported.ClientState
// the unmarshal will fail. This implementation will panic on every interface function.
// The same is done for the ConsensusState.
Comment on lines +13 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's really no way around this. go semantic versioning will help a lot in the future


// Interface implementation checks.
var (
_, _ codectypes.UnpackInterfacesMessage = &ClientState{}, &ConsensusState{}
_ exported.ClientState = (*ClientState)(nil)
_ exported.ConsensusState = &ConsensusState{}
)

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*exported.ClientState)(nil),
&ClientState{},
)
registry.RegisterImplementations(
(*exported.ConsensusState)(nil),
&ConsensusState{},
)
}

// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (cs ClientState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return cs.ConsensusState.UnpackInterfaces(unpacker)
}

// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (cs ConsensusState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(cs.PublicKey, new(cryptotypes.PubKey))
}

// ClientType panics!
func (cs ClientState) ClientType() string {
panic("legacy solo machine is deprecated!")
}

// GetLatestHeight panics!
func (cs ClientState) GetLatestHeight() exported.Height {
panic("legacy solo machine is deprecated!")
}

// Status panics!
func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryCodec) exported.Status {
panic("legacy solo machine is deprecated!")
}

// Validate panics!
func (cs ClientState) Validate() error {
panic("legacy solo machine is deprecated!")
}

// GetProofSpecs panics!
func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
panic("legacy solo machine is deprecated!")
}

// ZeroCustomFields panics!
func (cs ClientState) ZeroCustomFields() exported.ClientState {
panic("legacy solo machine is deprecated!")
}

// Initialize panics!
func (cs ClientState) Initialize(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, consState exported.ConsensusState) error {
panic("legacy solo machine is deprecated!")
}

// ExportMetadata panics!
func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata {
panic("legacy solo machine is deprecated!")
}

// CheckHeaderAndUpdateState panics!
func (cs *ClientState) CheckHeaderAndUpdateState(
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.Header,
) (exported.ClientState, exported.ConsensusState, error) {
panic("legacy solo machine is deprecated!")
}

// CheckMisbehaviourAndUpdateState panics!
func (cs ClientState) CheckMisbehaviourAndUpdateState(
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.Misbehaviour,
) (exported.ClientState, error) {
panic("legacy solo machine is deprecated!")
}

// CheckSubstituteAndUpdateState panics!
func (cs ClientState) CheckSubstituteAndUpdateState(
ctx sdk.Context, _ codec.BinaryCodec, _, _ sdk.KVStore,
_ exported.ClientState,
) (exported.ClientState, error) {
panic("legacy solo machine is deprecated!")
}

// VerifyUpgradeAndUpdateState panics!
func (cs ClientState) VerifyUpgradeAndUpdateState(
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore,
_ exported.ClientState, _ exported.ConsensusState, _, _ []byte,
) (exported.ClientState, exported.ConsensusState, error) {
panic("legacy solo machine is deprecated!")
}

// VerifyClientState panics!
func (cs ClientState) VerifyClientState(
store sdk.KVStore, cdc codec.BinaryCodec,
_ exported.Height, _ exported.Prefix, _ string, _ []byte, clientState exported.ClientState,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyClientConsensusState panics!
func (cs ClientState) VerifyClientConsensusState(
sdk.KVStore, codec.BinaryCodec,
exported.Height, string, exported.Height, exported.Prefix,
[]byte, exported.ConsensusState,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyConnectionState panics!
func (cs ClientState) VerifyConnectionState(
sdk.KVStore, codec.BinaryCodec, exported.Height,
exported.Prefix, []byte, string, exported.ConnectionI,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyChannelState panics!
func (cs ClientState) VerifyChannelState(
sdk.KVStore, codec.BinaryCodec, exported.Height, exported.Prefix,
[]byte, string, string, exported.ChannelI,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyPacketCommitment panics!
func (cs ClientState) VerifyPacketCommitment(
sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64, []byte,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyPacketAcknowledgement panics!
func (cs ClientState) VerifyPacketAcknowledgement(
sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64, []byte,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyPacketReceiptAbsence panics!
func (cs ClientState) VerifyPacketReceiptAbsence(
sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64,
) error {
panic("legacy solo machine is deprecated!")
}

// VerifyNextSequenceRecv panics!
func (cs ClientState) VerifyNextSequenceRecv(
sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height,
uint64, uint64, exported.Prefix, []byte,
string, string, uint64,
) error {
panic("legacy solo machine is deprecated!")
}

// ClientType panics!
func (ConsensusState) ClientType() string {
panic("legacy solo machine is deprecated!")
}

// GetTimestamp panics!
func (cs ConsensusState) GetTimestamp() uint64 {
panic("legacy solo machine is deprecated!")
}

// GetRoot panics!
func (cs ConsensusState) GetRoot() exported.Root {
panic("legacy solo machine is deprecated!")
}

// ValidateBasic panics!
func (cs ConsensusState) ValidateBasic() error {
panic("legacy solo machine is deprecated!")
}
1 change: 1 addition & 0 deletions modules/core/02-client/legacy/v100/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
// - Migrating solo machine client states from v1 to v2 protobuf definition
// - Pruning all solo machine consensus states
// - Pruning expired tendermint consensus states
// - Adds ProcessedHeight and Iteration keys for unexpired tendermint consensus states
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) (err error) {
store := ctx.KVStore(storeKey)
iterator := sdk.KVStorePrefixIterator(store, host.KeyClientStorePrefix)
Expand Down
3 changes: 1 addition & 2 deletions modules/core/exported/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package exported

import (
ics23 "github.com/confio/ics23/go"
proto "github.com/gogo/protobuf/proto"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/gogo/protobuf/proto"
)

// Status represents the status of a client
Expand Down
9 changes: 4 additions & 5 deletions modules/core/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ func NewMigrator(keeper Keeper) Migrator {

// Migrate1to2 migrates from version 1 to 2.
// This migration prunes:
// - solo machine consensus states
// - expired tendermint consensus states
//
// This migration migrates:
// - solo machine client state from protobuf definition v1 to v2
// - migrates solo machine client state from protobuf definition v1 to v2
// - prunes solo machine consensus states
// - prunes expired tendermint consensus states
// - adds ProcessedHeight and Iteration keys for unexpired tendermint consensus states
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
clientMigrator := clientkeeper.NewMigrator(m.keeper.ClientKeeper)
if err := clientMigrator.Migrate1to2(ctx); err != nil {
Expand Down
11 changes: 7 additions & 4 deletions modules/core/legacy/v100/genesis.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package v100

import (
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
tmtypes "github.com/tendermint/tendermint/types"

clientv100 "github.com/cosmos/ibc-go/modules/core/02-client/legacy/v100"
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/modules/core/24-host"
"github.com/cosmos/ibc-go/modules/core/types"
)
Expand All @@ -17,13 +17,16 @@ import (
// - Update solo machine client state protobuf definition (v1 to v2)
// - Remove all solo machine consensus states
// - Remove all expired tendermint consensus states
func MigrateGenesis(appState genutiltypes.AppMap, clientCtx client.Context, genesisBlockTime time.Time) (genutiltypes.AppMap, error) {
func MigrateGenesis(appState genutiltypes.AppMap, clientCtx client.Context, genDoc tmtypes.GenesisDoc) (genutiltypes.AppMap, error) {
if appState[host.ModuleName] != nil {
// ensure legacy solo machines are registered
clientv100.RegisterInterfaces(clientCtx.InterfaceRegistry)

// unmarshal relative source genesis application state
ibcGenState := &types.GenesisState{}
clientCtx.JSONCodec.MustUnmarshalJSON(appState[host.ModuleName], ibcGenState)

clientGenState, err := clientv100.MigrateGenesis(codec.NewProtoCodec(clientCtx.InterfaceRegistry), &ibcGenState.ClientGenesis, genesisBlockTime)
clientGenState, err := clientv100.MigrateGenesis(codec.NewProtoCodec(clientCtx.InterfaceRegistry), &ibcGenState.ClientGenesis, genDoc.GenesisTime, clienttypes.NewHeight(clienttypes.ParseChainID(genDoc.ChainID), uint64(genDoc.InitialHeight)))
if err != nil {
return nil, err
}
Expand Down
Loading