Skip to content

Commit

Permalink
refactor: combine upgrades and migrations
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed May 2, 2023
1 parent 8157808 commit 016464c
Show file tree
Hide file tree
Showing 41 changed files with 345 additions and 373 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

apptypes "github.com/akash-network/node/app/types"
utypes "github.com/akash-network/node/upgrades/types"

// unnamed import of statik for swagger UI support
_ "github.com/akash-network/node/client/docs/statik"
Expand Down Expand Up @@ -515,7 +516,7 @@ func (app *AkashApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abc

// BeginBlocker is a function in which application updates every begin block
func (app *AkashApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
if fork, exists := apptypes.GetForksList()[ctx.BlockHeight()]; exists {
if fork, exists := utypes.GetForksList()[ctx.BlockHeight()]; exists {
app.Logger().Info(fmt.Sprintf("found hard-fork %s for current height %d. Applying...", fork.Name(), ctx.BlockHeight()))
fork.BeginForkLogic(ctx, &app.Keepers)
app.Logger().Info(fmt.Sprintf("hard-fork %s applied successfully at height %d", fork.Name(), ctx.BlockHeight()))
Expand Down
9 changes: 6 additions & 3 deletions app/app_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ import (
providertypes "github.com/akash-network/akash-api/go/node/provider/v1beta3"

"github.com/akash-network/node/x/audit"
akeeper "github.com/akash-network/node/x/audit/keeper"
"github.com/akash-network/node/x/cert"
ckeeper "github.com/akash-network/node/x/cert/keeper"
"github.com/akash-network/node/x/deployment"
"github.com/akash-network/node/x/escrow"
ekeeper "github.com/akash-network/node/x/escrow/keeper"
agov "github.com/akash-network/node/x/gov"
agovkeeper "github.com/akash-network/node/x/gov/keeper"
"github.com/akash-network/node/x/inflation"
ikeeper "github.com/akash-network/node/x/inflation/keeper"
"github.com/akash-network/node/x/market"
mhooks "github.com/akash-network/node/x/market/hooks"
"github.com/akash-network/node/x/provider"
Expand Down Expand Up @@ -118,17 +121,17 @@ func (app *AkashApp) setAkashKeepers() {
app.keys[provider.StoreKey],
)

app.Keepers.Akash.Audit = audit.NewKeeper(
app.Keepers.Akash.Audit = akeeper.NewKeeper(
app.appCodec,
app.keys[audit.StoreKey],
)

app.Keepers.Akash.Cert = cert.NewKeeper(
app.Keepers.Akash.Cert = ckeeper.NewKeeper(
app.appCodec,
app.keys[cert.StoreKey],
)

app.Keepers.Akash.Inflation = inflation.NewKeeper(
app.Keepers.Akash.Inflation = ikeeper.NewKeeper(
app.appCodec,
app.keys[inflation.StoreKey],
app.GetSubspace(inflation.ModuleName),
Expand Down
63 changes: 6 additions & 57 deletions app/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import (
"fmt"
"reflect"

"github.com/tendermint/tendermint/libs/log"

storetypes "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"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
Expand All @@ -24,47 +20,24 @@ import (
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

"github.com/akash-network/node/x/audit"
"github.com/akash-network/node/x/cert"
akeeper "github.com/akash-network/node/x/audit/keeper"
ckeeper "github.com/akash-network/node/x/cert/keeper"
dkeeper "github.com/akash-network/node/x/deployment/keeper"
escrowkeeper "github.com/akash-network/node/x/escrow/keeper"
agovkeeper "github.com/akash-network/node/x/gov/keeper"
"github.com/akash-network/node/x/inflation"
ikeeper "github.com/akash-network/node/x/inflation/keeper"
mkeeper "github.com/akash-network/node/x/market/keeper"
pkeeper "github.com/akash-network/node/x/provider/keeper"
astakingkeeper "github.com/akash-network/node/x/staking/keeper"
)

var (
upgrades = map[string]UpgradeInitFn{}
forks = map[int64]IFork{}
)

var (
ErrEmptyFieldName = errors.New("empty field name")
)

// IUpgrade defines an interface to run a SoftwareUpgradeProposal
type IUpgrade interface {
StoreLoader() *storetypes.StoreUpgrades
UpgradeHandler() upgradetypes.UpgradeHandler
}

// IFork defines an interface 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 IFork interface {
Name() string
BeginForkLogic(sdk.Context, *AppKeepers)
}

type UpgradeInitFn func(log.Logger, *App) (IUpgrade, error)

type AppKeepers struct {
Cosmos struct {
Acct authkeeper.AccountKeeper
Expand Down Expand Up @@ -92,9 +65,9 @@ type AppKeepers struct {
Deployment dkeeper.IKeeper
Market mkeeper.IKeeper
Provider pkeeper.IKeeper
Audit audit.Keeper
Cert cert.Keeper
Inflation inflation.Keeper
Audit akeeper.Keeper
Cert ckeeper.Keeper
Inflation ikeeper.IKeeper
Staking astakingkeeper.IKeeper
Gov agovkeeper.IKeeper
}
Expand All @@ -106,30 +79,6 @@ type App struct {
MM *module.Manager
}

func RegisterUpgrade(name string, fn UpgradeInitFn) {
if _, exists := upgrades[name]; exists {
panic(fmt.Sprintf("upgrade \"%s\" already registered", name))
}

upgrades[name] = fn
}

func RegisterFork(height int64, fork IFork) {
if _, exists := forks[height]; exists {
panic(fmt.Sprintf("fork \"%s\" for height %d already registered", fork.Name(), height))
}

forks[height] = fork
}

func GetUpgradesList() map[string]UpgradeInitFn {
return upgrades
}

func GetForksList() map[int64]IFork {
return forks
}

// FindStructField if an interface is either a struct or a pointer to a struct
// and has the defined member field, if error is nil, the given
// fieldName exists and is accessible with reflect.
Expand Down
13 changes: 3 additions & 10 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,9 @@ import (

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

apptypes "github.com/akash-network/node/app/types"

// nolint: revive
_ "github.com/akash-network/node/migrations"
// nolint: revive
_ "github.com/akash-network/node/app/upgrades/v0.24.0"
// nolint: revive
_ "github.com/akash-network/node/app/upgrades/v0.20.0"
utypes "github.com/akash-network/node/upgrades/types"
// nolint: revive
_ "github.com/akash-network/node/app/upgrades/v0.15.0"
_ "github.com/akash-network/node/upgrades"
)

func (app *AkashApp) registerUpgradeHandlers() error {
Expand All @@ -23,7 +16,7 @@ func (app *AkashApp) registerUpgradeHandlers() error {
return err
}

for name, fn := range apptypes.GetUpgradesList() {
for name, fn := range utypes.GetUpgradesList() {
app.Logger().Info(fmt.Sprintf("initializing upgrade `%s`", name))
upgrade, err := fn(app.Logger(), &app.App)
if err != nil {
Expand Down
30 changes: 0 additions & 30 deletions app/upgrades/readme.md

This file was deleted.

91 changes: 0 additions & 91 deletions migrations/consensus/consensus.go

This file was deleted.

9 changes: 0 additions & 9 deletions migrations/migrations.go

This file was deleted.

23 changes: 0 additions & 23 deletions migrations/v0.15.0/migrations.go

This file was deleted.

15 changes: 0 additions & 15 deletions migrations/v0.24.0/migrations.go

This file was deleted.

Empty file added upgrades/hardfork/.gitignore
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

av1beta2 "github.com/akash-network/akash-api/go/node/audit/v1beta2"

"github.com/akash-network/node/migrations/consensus"
utypes "github.com/akash-network/node/upgrades/types"
)

type auditMigrations struct {
consensus.Migrator
utypes.Migrator
}

func newAuditMigration(m consensus.Migrator) consensus.Migration {
func newAuditMigration(m utypes.Migrator) utypes.Migration {
return auditMigrations{Migrator: m}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

cv1beta2 "github.com/akash-network/akash-api/go/node/cert/v1beta2"

"github.com/akash-network/node/migrations/consensus"
utypes "github.com/akash-network/node/upgrades/types"
)

type certMigrations struct {
consensus.Migrator
utypes.Migrator
}

func newCertMigration(m consensus.Migrator) consensus.Migration {
func newCertMigration(m utypes.Migrator) utypes.Migration {
return certMigrations{Migrator: m}
}

Expand Down
Loading

0 comments on commit 016464c

Please sign in to comment.