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

[WiP] Merger #381

Closed
Closed
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
69 changes: 54 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -86,7 +87,7 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
transfer "github.com/cosmos/ibc-go/v3/modules/apps/transfer"
"github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v3/modules/core"
Expand Down Expand Up @@ -216,6 +217,7 @@ type App struct {
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint
cudosPath string

// keys to access the substores
keys map[string]*sdk.KVStoreKey
Expand Down Expand Up @@ -256,7 +258,7 @@ type App struct {
// NewSimApp returns a reference to an initialized SimApp.
func New(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, enabledProposals []wasm.ProposalType,
skipUpgradeHeights map[int64]bool, homePath string, invCheckPeriod uint, cudosPath string, encodingConfig appparams.EncodingConfig, enabledProposals []wasm.ProposalType,
appOpts servertypes.AppOptions, wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp),
) *App {

Expand Down Expand Up @@ -285,6 +287,7 @@ func New(
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
cudosPath: cudosPath,
keys: keys,
tkeys: tkeys,
memKeys: memKeys,
Expand Down Expand Up @@ -369,7 +372,7 @@ func New(

app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
// register the governance hooks
),
)

Expand Down Expand Up @@ -718,41 +721,77 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
return subspace
}

func (app *App) PerformASIUpgradeTasks(ctx sdk.Context, networkInfo *NetworkConfig, manifest *UpgradeManifest) error {
err := app.DeleteContractStates(ctx, networkInfo, manifest)
if err != nil {
return err
}

// Call the separate function to handle the admin upgrade
err = app.UpgradeContractAdmins(ctx, networkInfo, manifest)
if err != nil {
return err
}

err = app.ProcessReconciliation(ctx, networkInfo, manifest)
if err != nil {
return err
}

err = app.ChangeContractLabels(ctx, networkInfo, manifest)
if err != nil {
return err
}

err = app.ChangeContractVersions(ctx, networkInfo, manifest)
if err != nil {
return err
}

return nil
}

func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler("v0.11.3", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, cfg, fromVM)
})

app.UpgradeKeeper.SetUpgradeHandler("v0.11.4", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.UpgradeKeeper.SetUpgradeHandler("fetchd-v0.11.3-8-g929563a", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

manifest := NewUpgradeManifest()

networkInfo, ok := NetworkInfos[ctx.ChainID()]
if !ok {
panic("Network info not found for chain id: " + ctx.ChainID())
}

err := app.DeleteContractStates(ctx, &networkInfo, manifest)
_, genDoc, err := genutiltypes.GenesisStateFromGenFile(app.cudosPath)
if err != nil {
return nil, err
panic(fmt.Sprintf("failed to unmarshal genesis state: %w", err))
}

// Call the separate function to handle the admin upgrade
err = app.UpgradeContractAdmins(ctx, &networkInfo, manifest)
if err != nil {
return nil, err
// unmarshal the app state
var jsonData map[string]interface{}
if err = json.Unmarshal(genDoc.AppState, &jsonData); err != nil {
panic(fmt.Sprintf("failed to unmarshal app state: %w", err))
}

err = app.ProcessReconciliation(ctx, &networkInfo, manifest)
convertedBalancesMap := getConvertedGenesisBalancesMap(jsonData)

err = withdrawGenesisStakingRewards(jsonData, convertedBalancesMap)
if err != nil {
return nil, err
panic(fmt.Sprintf("failed to withdraw genesis staking rewards: %w", err))
}

err = app.ChangeContractLabels(ctx, &networkInfo, manifest)
err = ProcessAccountsAndBalances(ctx, app, jsonData, networkInfo, manifest, convertedBalancesMap)
if err != nil {
return nil, err
panic(fmt.Sprintf("failed process accounts: %w", err))
}

err = app.ChangeContractVersions(ctx, &networkInfo, manifest)
panic("Debug interruption")

// Perform ASI upgrade tasks
err = app.PerformASIUpgradeTasks(ctx, &networkInfo, manifest)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading