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

feat: add automatic in-place migrations for 02-client-refactor (v7) #2819

Merged
merged 16 commits into from
Nov 29, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: use coventional unmarshal/marshal format
Remove pointer var declaration and pass the derefenced value into the unmarshal and marshal functions
  • Loading branch information
colin-axner committed Nov 29, 2022
commit 8881fdc9f8a77d9a03e984bd42c5b1c2dfb4215d
14 changes: 7 additions & 7 deletions modules/core/02-client/migrations/v7/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ func handleSolomachineMigration(ctx sdk.Context, store sdk.KVStore, cdc codec.Bi
return clienttypes.ErrClientNotFound
}

any := &codectypes.Any{}
if err := cdc.Unmarshal(bz, any); err != nil {
var any codectypes.Any
if err := cdc.Unmarshal(bz, &any); err != nil {
return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state")
}

clientState := &ClientState{}
if err := cdc.Unmarshal(any.Value, clientState); err != nil {
var clientState ClientState
if err := cdc.Unmarshal(any.Value, &clientState); err != nil {
return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state")
}

updatedClientState := migrateSolomachine(clientState)

bz, err := clienttypes.MarshalClientState(cdc, updatedClientState)
bz, err := clienttypes.MarshalClientState(cdc, &updatedClientState)
if err != nil {
return sdkerrors.Wrap(err, "failed to unmarshal client state bytes into solo machine client state")
}
Expand Down Expand Up @@ -200,14 +200,14 @@ func removeAllClientConsensusStates(clientStore sdk.KVStore) {

// migrateSolomachine migrates the solomachine from v2 to v3 solo machine protobuf definition.
// Notably it drops the AllowUpdateAfterProposal field.
func migrateSolomachine(clientState *ClientState) *solomachine.ClientState {
func migrateSolomachine(clientState ClientState) solomachine.ClientState {
consensusState := &solomachine.ConsensusState{
PublicKey: clientState.ConsensusState.PublicKey,
Diversifier: clientState.ConsensusState.Diversifier,
Timestamp: clientState.ConsensusState.Timestamp,
}

return &solomachine.ClientState{
return solomachine.ClientState{
Sequence: clientState.Sequence,
IsFrozen: clientState.IsFrozen,
ConsensusState: consensusState,
Expand Down