-
Notifications
You must be signed in to change notification settings - Fork 625
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
feat: add automatic in-place migrations for 02-client-refactor (v7) #2819
Changes from all commits
0f90c1e
9d7c048
fa08b63
ae2b1c2
bf2a11b
af99600
ee02a0b
cd6b54d
df50f0e
8881fdc
da0ae8e
5d9d6a1
9013ef2
8e2b93a
a3a3490
478d694
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
package v7 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copied from Needed in order to unmarshal the existing types which no longer register solomachine v2 on the codec. The SDK codec will prematurely try to lookup type registration against the interface (even if the cdc isn't supposed to unpack the interface). |
||
|
||
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/v6/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 v2 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. | ||
|
||
// Interface implementation checks. | ||
var ( | ||
_, _ codectypes.UnpackInterfacesMessage = &ClientState{}, &ConsensusState{} | ||
_ exported.ClientState = (*ClientState)(nil) | ||
_ exported.ConsensusState = &ConsensusState{} | ||
) | ||
|
||
// RegisterInterfaces registers the solomachine v2 ClientState and ConsensusState types in the interface registry. | ||
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!") | ||
} | ||
|
||
// CheckForMisbehaviour panics! | ||
func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// UpdateStateOnMisbehaviour panics! | ||
func (cs *ClientState) UpdateStateOnMisbehaviour( | ||
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, | ||
) { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// VerifyClientMessage panics! | ||
func (cs *ClientState) VerifyClientMessage( | ||
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, | ||
) error { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// UpdateState panis! | ||
func (cs *ClientState) UpdateState(_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage) []exported.Height { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// CheckHeaderAndUpdateState panics! | ||
func (cs *ClientState) CheckHeaderAndUpdateState( | ||
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, | ||
) (exported.ClientState, exported.ConsensusState, error) { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// CheckMisbehaviourAndUpdateState panics! | ||
func (cs ClientState) CheckMisbehaviourAndUpdateState( | ||
_ sdk.Context, _ codec.BinaryCodec, _ sdk.KVStore, _ exported.ClientMessage, | ||
) (exported.ClientState, error) { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// CheckSubstituteAndUpdateState panics! | ||
func (cs ClientState) CheckSubstituteAndUpdateState( | ||
ctx sdk.Context, _ codec.BinaryCodec, _, _ sdk.KVStore, | ||
_ 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, | ||
) 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!") | ||
} | ||
|
||
// GetTimestampAtHeight panics! | ||
func (cs ClientState) GetTimestampAtHeight( | ||
sdk.Context, sdk.KVStore, codec.BinaryCodec, exported.Height, | ||
) (uint64, error) { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// VerifyMembership panics! | ||
func (cs *ClientState) VerifyMembership( | ||
ctx sdk.Context, | ||
clientStore sdk.KVStore, | ||
cdc codec.BinaryCodec, | ||
height exported.Height, | ||
delayTimePeriod uint64, | ||
delayBlockPeriod uint64, | ||
proof []byte, | ||
path exported.Path, | ||
value []byte, | ||
) error { | ||
panic("legacy solo machine is deprecated!") | ||
} | ||
|
||
// VerifyNonMembership panics! | ||
func (cs *ClientState) VerifyNonMembership( | ||
ctx sdk.Context, | ||
clientStore sdk.KVStore, | ||
cdc codec.BinaryCodec, | ||
height exported.Height, | ||
delayTimePeriod uint64, | ||
delayBlockPeriod uint64, | ||
proof []byte, | ||
path exported.Path, | ||
) 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!") | ||
} | ||
|
||
// ValidateBasic panics! | ||
func (cs ConsensusState) ValidateBasic() error { | ||
panic("legacy solo machine is deprecated!") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question about the
Migrator
struct, do we need to this to be a struct (maybe implementing some interface?)It looks like we only use 2 fields from the keeper and don't actually use any of the other keeper functionality. (cdc/storeKey)
I'm happy to stick with the pattern of adding functions, just curious if we need this struct!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good question. This was the approach documented by the SDK
I think it makes sense for the Keeper not to expose
Migrate2to3
, but I'm totally open to a different design