Skip to content

Commit

Permalink
Merge pull request #245 from notional-labs/fork-upgrade-client
Browse files Browse the repository at this point in the history
Fork upgrade client
  • Loading branch information
vuong177 authored Oct 1, 2023
2 parents 8fdba09 + 89b897b commit e4eea8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
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"

Check failure on line 18 in app/upgrades/v5_2_0/fork.go

View workflow job for this annotation

GitHub Actions / lint

G101: Potential hardcoded credentials (gosec)

Check failure on line 18 in app/upgrades/v5_2_0/fork.go

View workflow job for this annotation

GitHub Actions / lint

G101: Potential hardcoded credentials (gosec)
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 {

Check failure on line 57 in app/upgrades/v5_2_0/fork.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 57 in app/upgrades/v5_2_0/fork.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
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)

Check failure on line 67 in app/upgrades/v5_2_0/fork.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: sdkerrors.Wrapf is deprecated: functionality of this package has been moved to it's own module: (staticcheck)

Check failure on line 67 in app/upgrades/v5_2_0/fork.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: sdkerrors.Wrapf is deprecated: functionality of this package has been moved to it's own module: (staticcheck)
}

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

0 comments on commit e4eea8a

Please sign in to comment.