-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to audit tag version with upgrade (#459)
* added migration functions to add new fields to bridge keeper. Set upgrade name to match software upgrade plan name * pushing up a change that was missed * made changes to deal with circular import * branch is now building with no circular import errors * removed migrations.go file in keeper and am just importing the v2 migration package into module.go * fixed migration function to use right context * fixed typo * changed format around to desired format * saving changes before branching to old tag to test * rebased from main to hopefully solve some git issues with merge * lint fixes
- Loading branch information
1 parent
09cb346
commit 9129e14
Showing
10 changed files
with
182 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ build/* | |
secrets.yaml | ||
.env | ||
prod-sim | ||
/layerd_new | ||
|
||
dist/ | ||
|
||
|
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,53 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tellor-io/layer/app/upgrades" | ||
v_2_0 "github.com/tellor-io/layer/app/upgrades/v2.0.0-alpha2" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
) | ||
|
||
var ( | ||
// `Upgrades` defines the upgrade handlers and store loaders for the application. | ||
// New upgrades should be added to this slice after they are implemented. | ||
Upgrades = []*upgrades.Upgrade{ | ||
&v_2_0.Upgrade, | ||
} | ||
Forks = []upgrades.Fork{} | ||
) | ||
|
||
// setupUpgradeHandlers registers the upgrade handlers to perform custom upgrade | ||
// logic and state migrations for software upgrades. | ||
func (app *App) setupUpgradeHandlers() { | ||
if app.UpgradeKeeper.HasHandler(v_2_0.UpgradeName) { | ||
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v_2_0.UpgradeName)) | ||
} | ||
app.UpgradeKeeper.SetUpgradeHandler( | ||
v_2_0.UpgradeName, | ||
v_2_0.CreateUpgradeHandler( | ||
app.ModuleManager(), | ||
app.configurator, | ||
), | ||
) | ||
} | ||
|
||
// setUpgradeStoreLoaders sets custom store loaders to customize the rootMultiStore | ||
// initialization for software upgrades. | ||
func (app *App) setupUpgradeStoreLoaders() { | ||
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) | ||
} | ||
|
||
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { | ||
return | ||
} | ||
|
||
for _, upgrade := range Upgrades { | ||
if upgradeInfo.Name == upgrade.UpgradeName { | ||
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades)) | ||
} | ||
} | ||
} |
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,26 @@ | ||
package upgrades | ||
|
||
import ( | ||
store "cosmossdk.io/store/types" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/module" | ||
) | ||
|
||
type Upgrade struct { | ||
UpgradeName string | ||
CreateUpgradeHandler func(*module.Manager, module.Configurator) upgradetypes.UpgradeHandler | ||
// Store Upgrades, should be used for any new modules introduced, deleted, or store names renamed | ||
StoreUpgrades store.StoreUpgrades | ||
} | ||
|
||
type Fork struct { | ||
// Upgrade version name, for the upgrade handler, e.g. `v2.0.0-audit` | ||
UpgradeName string | ||
|
||
// Height the upgrade occurs at | ||
UpgradeHeight func(*module.Manager, module.Configurator) upgradetypes.UpgradeHandler | ||
|
||
// Upgrade info for this fork | ||
UpgradeInfo string | ||
} |
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,16 @@ | ||
package v_2_0_0_alpha2 | ||
|
||
import ( | ||
"github.com/tellor-io/layer/app/upgrades" | ||
|
||
store "cosmossdk.io/store/types" | ||
) | ||
|
||
const ( | ||
UpgradeName = "v2.0.0-audit" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: store.StoreUpgrades{}, | ||
} |
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,23 @@ | ||
package v_2_0_0_alpha2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName)) | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} |
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,42 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/tellor-io/layer/x/bridge/keeper" | ||
bridgetypes "github.com/tellor-io/layer/x/bridge/types" | ||
) | ||
|
||
type SnapshotLimit struct { | ||
Limit uint64 `protobuf:"varint,1,opt,name=limit,proto3"` | ||
} | ||
|
||
// func MigrateStoreFromV1ToV2(ctx context.Context, storeService store.KVStoreService) error { | ||
// kvStore := storeService.OpenKVStore(ctx) | ||
|
||
// limit := bridgetypes.SnapshotLimit{Limit: 1000} | ||
// data, err := json.Marshal(limit) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// key := []byte("SnapshotLimit") | ||
// err = kvStore.Set(key, data) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// return nil | ||
// } | ||
|
||
func MigrateStoreFromV1ToV2(ctx context.Context, keeper *keeper.Keeper) error { | ||
limit := bridgetypes.SnapshotLimit{Limit: 1000} | ||
err := keeper.SnapshotLimit.Set(ctx, limit) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println("Set snapshot limit in migration") | ||
|
||
return nil | ||
} |
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,9 @@ | ||
package v2_test | ||
|
||
// import ( | ||
// "testing" | ||
// ) | ||
|
||
// func TestMigrateStoreFromV1ToV2(t *testing.T) { | ||
|
||
// } |
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