forked from ComposableFi/picasso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ComposableFi#244 from notional-labs/fork-upgrade-c…
…lient Fork upgrade client
- Loading branch information
Showing
3 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package v5_2_0 | ||
|
||
import "github.com/notional-labs/centauri/v5/app/upgrades" | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name for the Composable v5 upgrade. | ||
UpgradeName = "v5_2_0" | ||
|
||
// UpgradeHeight defines the block height at which the Composable v6 upgrade is | ||
// triggered. | ||
UpgradeHeight = 1769900 | ||
) | ||
|
||
var Fork = upgrades.Fork{ | ||
UpgradeName: UpgradeName, | ||
UpgradeHeight: UpgradeHeight, | ||
BeginForkLogic: RunForkLogic, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package v5_2_0 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" | ||
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" | ||
"github.com/cosmos/ibc-go/v7/modules/core/exported" | ||
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" | ||
wasm08types "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types" | ||
|
||
"github.com/notional-labs/centauri/v5/app/keepers" | ||
) | ||
|
||
const ( | ||
newWasmCodeID = "ad84ee3292e28b4e46da16974c118d40093e1a6e28a083f2f045f68fde7fb575" | ||
clientId = "08-wasm-05" | ||
substituteClientId = "08-wasm-132" | ||
) | ||
|
||
func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) { | ||
ctx.Logger().Info("Applying v5_2_0 upgrade" + | ||
"Upgrade 08-wasm contract", | ||
) | ||
|
||
UpdateWasmContract(ctx, keepers.IBCKeeper) | ||
|
||
err := ClientUpdate(ctx, keepers.IBCKeeper.Codec(), keepers.IBCKeeper, clientId, substituteClientId) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func UpdateWasmContract(ctx sdk.Context, ibckeeper *ibckeeper.Keeper) { | ||
unknownClientState, found := ibckeeper.ClientKeeper.GetClientState(ctx, clientId) | ||
if !found { | ||
panic("cannot update client with ID") | ||
} | ||
|
||
clientState, ok := unknownClientState.(*wasm08types.ClientState) | ||
if !ok { | ||
panic("cannot update client with ID") | ||
} | ||
|
||
code, err := transfertypes.ParseHexHash(newWasmCodeID) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientState.CodeId = code | ||
|
||
ibckeeper.ClientKeeper.SetClientState(ctx, clientId, clientState) | ||
} | ||
|
||
func ClientUpdate(ctx sdk.Context, codec codec.BinaryCodec, ibckeeper *ibckeeper.Keeper, subjectClientId string, substituteClientId string) error { | ||
subjectClientState, found := ibckeeper.ClientKeeper.GetClientState(ctx, subjectClientId) | ||
if !found { | ||
return sdkerrors.Wrapf(clienttypes.ErrClientNotFound, "subject client with ID %s", subjectClientId) | ||
} | ||
|
||
subjectClientStore := ibckeeper.ClientKeeper.ClientStore(ctx, subjectClientId) | ||
|
||
substituteClientState, found := ibckeeper.ClientKeeper.GetClientState(ctx, substituteClientId) | ||
if !found { | ||
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 { | ||
return sdkerrors.Wrapf(clienttypes.ErrClientNotActive, "substitute client is not Active, status is %s", status) | ||
} | ||
|
||
if err := subjectClientState.CheckSubstituteAndUpdateState(ctx, codec, subjectClientStore, substituteClientStore, substituteClientState); err != nil { | ||
return err | ||
} | ||
|
||
ctx.Logger().Info("client updated after hark fork passed", "client-id", subjectClientId) | ||
|
||
return nil | ||
} |