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

Fork upgrade client #245

Merged
merged 5 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion app/upgrades/v5_2_0/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const (

// UpgradeHeight defines the block height at which the Composable v6 upgrade is
// triggered.
UpgradeHeight = 1769900
UpgradeHeight = 1771900
)

var Fork = upgrades.Fork{
Expand Down
18 changes: 7 additions & 11 deletions app/upgrades/v5_2_0/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

const (
newWasmCodeID = "ad84ee3292e28b4e46da16974c118d40093e1a6e28a083f2f045f68fde7fb575"
clientId = "08-wasm-05"
substituteClientId = "08-wasm-132"
subjectClientId = "08-wasm-5"
substituteClientId = "08-wasm-133"
)

func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) {
Expand All @@ -27,21 +27,21 @@ func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) {

UpdateWasmContract(ctx, keepers.IBCKeeper)

err := ClientUpdate(ctx, keepers.IBCKeeper.Codec(), keepers.IBCKeeper, clientId, substituteClientId)
err := ClientUpdate(ctx, keepers.IBCKeeper.Codec(), keepers.IBCKeeper, subjectClientId, substituteClientId)
if err != nil {
panic(err)
}
}

func UpdateWasmContract(ctx sdk.Context, ibckeeper *ibckeeper.Keeper) {
unknownClientState, found := ibckeeper.ClientKeeper.GetClientState(ctx, clientId)
unknownClientState, found := ibckeeper.ClientKeeper.GetClientState(ctx, subjectClientId)
if !found {
panic("cannot update client with ID")
panic("substitute client client not found ")
}

clientState, ok := unknownClientState.(*wasm08types.ClientState)
if !ok {
panic("cannot update client with ID")
panic("cannot update client")
}

code, err := transfertypes.ParseHexHash(newWasmCodeID)
Expand All @@ -51,7 +51,7 @@ func UpdateWasmContract(ctx sdk.Context, ibckeeper *ibckeeper.Keeper) {

clientState.CodeId = code

ibckeeper.ClientKeeper.SetClientState(ctx, clientId, clientState)
ibckeeper.ClientKeeper.SetClientState(ctx, substituteClientId, clientState)
}

func ClientUpdate(ctx sdk.Context, codec codec.BinaryCodec, ibckeeper *ibckeeper.Keeper, subjectClientId string, substituteClientId string) error {
Expand All @@ -67,10 +67,6 @@ func ClientUpdate(ctx sdk.Context, codec codec.BinaryCodec, ibckeeper *ibckeeper
return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "substitute client with ID %s", substituteClientId)
}

if subjectClientState.GetLatestHeight().GTE(substituteClientState.GetLatestHeight()) {
return sdkerrors.Wrapf(clienttypes.ErrInvalidHeight, "subject client state latest height is greater or equal to substitute client state latest height (%s >= %s)", subjectClientState.GetLatestHeight(), substituteClientState.GetLatestHeight())
}

substituteClientStore := ibckeeper.ClientKeeper.ClientStore(ctx, substituteClientId)

if status := ibckeeper.ClientKeeper.GetClientStatus(ctx, substituteClientState, substituteClientId); status != exported.Active {
Expand Down