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

Dev #36

Closed
wants to merge 24 commits into from
Closed

Dev #36

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fa22154
Merge pull request #22 from onomyprotocol/dev
laloquidity Apr 27, 2024
83ec3b9
Merge pull request #24 from onomyprotocol/dev
laloquidity Apr 27, 2024
1897d35
Added DistributionTransmissionChannel to Whitelist
May 14, 2024
d789ddc
Change upgrade version
May 15, 2024
8fe963d
Add in upgrade handler
May 16, 2024
70ccf85
Merge pull request #35 from cgdusek/dev
cgdusek May 16, 2024
113be77
Add in Market v1.1.3-dev dependency and pool reset
May 26, 2024
0ec6b50
Merge pull request #39 from onomyprotocol/bug-fix
cgdusek May 26, 2024
74ef7c5
Add in reclaimation of pool funds
May 26, 2024
c26e1cd
Add in fork logic
May 26, 2024
c722453
Add store upgrade handler
May 26, 2024
05d925c
Prepare for v1.1.6 and update Market Module
May 26, 2024
c63775a
Updated genesis-with-ccv to correct version
May 27, 2024
97f59db
Merge pull request #41 from onomyprotocol/genesis-upddate
cgdusek May 27, 2024
39d27a7
Return funds upgrade
May 29, 2024
bfb3b7a
Merge branch 'release/v1.1.6-fh' into release/v1.1.6
cgdusek Jun 3, 2024
1cbb9de
Merge pull request #43 from onomyprotocol/release/v1.1.6
cgdusek Jun 3, 2024
6d35a5f
Merge pull request #44 from onomyprotocol/release/v1.1.7
cgdusek Jun 3, 2024
3365ec3
Add in v1.2.0-dev market module and upgrade
Jun 14, 2024
4173972
Update v1.2.0 upgrade code
Jun 14, 2024
d530352
Gofumpt
Jun 15, 2024
e7774b9
Update market version to v1.2.0
Jun 15, 2024
9fa34af
Merge pull request #45 from cgdusek/dev
cgdusek Jun 15, 2024
aecd576
Merge branch 'release/v1.2.0-fh' into dev
cgdusek Jun 17, 2024
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
55 changes: 34 additions & 21 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"os"
"path/filepath"

// v0 "github.com/onomyprotocol/onex/app/upgrades/"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand All @@ -20,7 +18,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -120,15 +117,22 @@ import (
marketclient "github.com/pendulum-labs/market/x/market/client"
marketkeeper "github.com/pendulum-labs/market/x/market/keeper"
markettypes "github.com/pendulum-labs/market/x/market/types"

"github.com/onomyprotocol/onex/app/upgrades"
v1_1_6 "github.com/onomyprotocol/onex/app/upgrades/v1.1.6"
v1_1_7 "github.com/onomyprotocol/onex/app/upgrades/v1.1.7"
v1_2_0 "github.com/onomyprotocol/onex/app/upgrades/v1.2.0"
)

const (
AppName = "onex"
upgradeName = "v1.1.0"
AccountAddressPrefix = "onomy"
)

var (
Upgrades = []upgrades.Upgrade{v1_1_7.Upgrade, v1_2_0.Upgrade}
Forks = []upgrades.Fork{v1_1_6.Fork}

// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

Expand Down Expand Up @@ -554,6 +558,7 @@ func New(
consumertypes.ModuleName,
)
app.MM.SetOrderEndBlockers(
upgradetypes.ModuleName,
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
Expand All @@ -567,7 +572,6 @@ func New(
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
Expand All @@ -582,6 +586,7 @@ func New(
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
app.MM.SetOrderInitGenesis(
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand All @@ -595,7 +600,6 @@ func New(
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -659,7 +663,8 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

app.setupUpgradeHandlers(app.configurator)
app.setupUpgradeStoreLoaders()
app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand All @@ -679,6 +684,7 @@ func (app *App) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
BeginBlockForks(ctx, app)
return app.MM.BeginBlock(ctx, req)
}

Expand Down Expand Up @@ -918,29 +924,36 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
return paramsKeeper
}

func (app *App) setupUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return app.MM.RunMigrations(ctx, cfg, vm)
})

func (app *App) setupUpgradeStoreLoaders() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

var storeUpgrades *storetypes.StoreUpgrades

switch upgradeInfo.Name {
default:
// no store upgrades
for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
}
}

if storeUpgrades != nil {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
func (app *App) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgrade.CreateUpgradeHandler(
app.MM,
app.configurator,
&upgrades.UpgradeKeepers{
BankKeeper: app.BankKeeper,
MarketKeeper: app.MarketKeeper,
AccountKeeper: app.AccountKeeper,
},
),
)
}
}
19 changes: 19 additions & 0 deletions app/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/onomyprotocol/onex/app/upgrades"
)

// BeginBlockForks is intended to be ran in a chain upgrade.
func BeginBlockForks(ctx sdk.Context, app *App) {
for _, fork := range Forks {
if ctx.BlockHeight() == fork.UpgradeHeight {
fork.BeginForkLogic(ctx, &upgrades.ForkKeepers{
BankKeeper: app.BankKeeper,
MarketKeeper: app.MarketKeeper,
})
return
}
}
}
1 change: 1 addition & 0 deletions app/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var WhitelistedParams = map[paramChangeKey]struct{}{
// ccv params (note: some CCV params should not be configurable or require special coordination with the provider chain)
{Subspace: consumertypes.ModuleName, Key: "ProviderRewardDenoms"}: {},
{Subspace: consumertypes.ModuleName, Key: "RewardDenoms"}: {},
{Subspace: consumertypes.ModuleName, Key: "DistributionTransmissionChannel"}: {},
{Subspace: consumertypes.ModuleName, Key: "ConsumerRedistributionFraction"}: {},
{Subspace: consumertypes.ModuleName, Key: "BlocksPerDistributionTransmission"}: {},
{Subspace: consumertypes.ModuleName, Key: "TransferTimeoutPeriod"}: {},
Expand Down
54 changes: 54 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package upgrades

import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
marketkeeper "github.com/pendulum-labs/market/x/market/keeper"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
// must have written, in order for the state migration to go smoothly.
// An upgrade must implement this struct, and then set it in the app.go.
// The app.go will then define the handler.
type Upgrade struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator, *UpgradeKeepers) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

type UpgradeKeepers struct {
// keepers
BankKeeper bankkeeper.Keeper
MarketKeeper marketkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper
}

// Fork defines a struct containing the requisite fields for a non-software upgrade proposal
// Hard Fork at a given height to implement.
// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`.
// Any other change in the code should be height-gated, if the goal is to have old and new binaries
// to be compatible prior to the upgrade height.
type Fork struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// height the upgrade occurs at
UpgradeHeight int64

// Function that runs some custom state transition code at the beginning of a fork.
BeginForkLogic func(ctx sdk.Context, keepers *ForkKeepers)
}

type ForkKeepers struct {
// keepers
BankKeeper bankkeeper.Keeper
MarketKeeper marketkeeper.Keeper
}
17 changes: 17 additions & 0 deletions app/upgrades/v1.1.6/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v1_1_6

import (
"github.com/onomyprotocol/onex/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrades name.
UpgradeName = "v1_1_6"
UpgradeHeight = 389310
)

var Fork = upgrades.Fork{
UpgradeName: UpgradeName,
UpgradeHeight: UpgradeHeight,
BeginForkLogic: RunForkLogic,
}
59 changes: 59 additions & 0 deletions app/upgrades/v1.1.6/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Package v1_1_6 is contains chain fork of the corresponding version.
package v1_1_6 //nolint:revive,stylecheck // app version

import (
"github.com/onomyprotocol/onex/app/upgrades"

sdk "github.com/cosmos/cosmos-sdk/types"
markettypes "github.com/pendulum-labs/market/x/market/types"
)

func RunForkLogic(
ctx sdk.Context,
keepers *upgrades.ForkKeepers,
) {
ctx.Logger().Info("Starting fork...")

// Deactivate all drops
drops := keepers.MarketKeeper.GetAllDrop(ctx)
for _, drop := range drops {
drop.Active = false
keepers.MarketKeeper.SetDrop(ctx, drop)
}

// Set pool drops to zero and wipe leaders
pools := keepers.MarketKeeper.GetAllPool(ctx)
for _, pool := range pools {
pool.Drops = sdk.ZeroInt()
pool.Leaders = []*markettypes.Leader{}

keepers.MarketKeeper.SetPool(ctx, pool)
}

// Set member balances to zero
members := keepers.MarketKeeper.GetAllMember(ctx)
for _, member := range members {
member.Balance = sdk.ZeroInt()
keepers.MarketKeeper.SetMember(ctx, member)
}

onexAmount, _ := sdk.NewIntFromString("94784650277373001264452")

ibc1Amount, _ := sdk.NewIntFromString("998915079")

ibc2Amount, _ := sdk.NewIntFromString("28966246179579930912901")

ibc3Amount, _ := sdk.NewIntFromString("2952795016")

onexCoin := sdk.NewCoin("aonex", onexAmount)
ibc1 := sdk.NewCoin("ibc/30EDC220372A2C3D0FC1D987E19062E35375DECD1001A5EFA44EB92FF59D1867", ibc1Amount)
ibc2 := sdk.NewCoin("ibc/5BDD8875CC2AF7BC842BE44236ACD576EA4F53C36347F74903B852060D6BF29A", ibc2Amount)
ibc3 := sdk.NewCoin("ibc/CCCBD7307FEB70B0CF7ADF8503F711F6741F41623D25BAD8CB736E03BE384264", ibc3Amount)

reclaimCoins := sdk.NewCoins(onexCoin, ibc1, ibc2, ibc3)
reclaimer, _ := sdk.AccAddressFromBech32("onomy1yc0lg97cy5e80jyajtkz0zke2rr4734anugf9g")

keepers.BankKeeper.SendCoinsFromModuleToAccount(ctx, markettypes.ModuleName, reclaimer, reclaimCoins)

ctx.Logger().Info("Fork complete")
}
15 changes: 15 additions & 0 deletions app/upgrades/v1.1.7/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v1_1_7

import (
"github.com/onomyprotocol/onex/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrades name.
UpgradeName = "v1.1.7"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
}
42 changes: 42 additions & 0 deletions app/upgrades/v1.1.7/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Package v1_1_7 is contains chain upgrade of the corresponding version.
package v1_1_7 //nolint:revive,stylecheck // app version

import (
"github.com/onomyprotocol/onex/app/upgrades"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
markettypes "github.com/pendulum-labs/market/x/market/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *upgrades.UpgradeKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting module migrations...")

onexAmount, _ := sdk.NewIntFromString("65975935131986921086784")
ibc1Amount, _ := sdk.NewIntFromString("17216827458309103931141")
ibc2Amount, _ := sdk.NewIntFromString("20100000")

onexCoin := sdk.NewCoin("aonex", onexAmount)
ibc1 := sdk.NewCoin("ibc/5BDD8875CC2AF7BC842BE44236ACD576EA4F53C36347F74903B852060D6BF29A", ibc1Amount)
ibc2 := sdk.NewCoin("ibc/CCCBD7307FEB70B0CF7ADF8503F711F6741F41623D25BAD8CB736E03BE384264", ibc2Amount)

returnCoins := sdk.NewCoins(onexCoin, ibc1, ibc2)
returner, _ := sdk.AccAddressFromBech32("onomy1yc0lg97cy5e80jyajtkz0zke2rr4734anugf9g")

keepers.BankKeeper.SendCoinsFromAccountToModule(ctx, returner, markettypes.ModuleName, returnCoins)

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("Upgrade complete")
return vm, err
}
}
15 changes: 15 additions & 0 deletions app/upgrades/v1.2.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v1_2_0

import (
"github.com/onomyprotocol/onex/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrades name.
UpgradeName = "v1.2.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
}
Loading
Loading