Skip to content

Commit

Permalink
Merge branch 'master' into dreamer/refator-evm
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer authored Jul 4, 2023
2 parents b4c0a37 + 9a4825f commit 3b18b0b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
28 changes: 14 additions & 14 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import (
)

var (
plans = []upgrades.Upgrade{
v110.Upgrade,
v120.Upgrade,
v130.Upgrade,
v140.Upgrade,
v200.Upgrade,
}
router = upgrades.NewUpgradeRouter().
Register(v110.Upgrade).
Register(v120.Upgrade).
Register(v130.Upgrade).
Register(v140.Upgrade).
Register(v200.Upgrade)
)

// RegisterUpgradePlans register a handler of upgrade plan
Expand Down Expand Up @@ -57,17 +56,18 @@ func (app *IrisApp) setupUpgradeStoreLoaders() {
return
}

for _, upgrade := range plans {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, upgrade.StoreUpgrades))
}
}
app.SetStoreLoader(
upgradetypes.UpgradeStoreLoader(
upgradeInfo.Height,
router.UpgradeInfo(upgradeInfo.Name).StoreUpgrades,
),
)
}

func (app *IrisApp) setupUpgradeHandlers() {
for _, upgrade := range plans {
for upgradeName, upgrade := range router.Routers() {
app.UpgradeKeeper.SetUpgradeHandler(
upgrade.UpgradeName,
upgradeName,
upgrade.UpgradeHandlerConstructor(
app.mm,
app.configurator,
Expand Down
24 changes: 24 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,27 @@ type AppKeepers struct {
TokenKeeper tokenkeeper.Keeper
ReaderWriter ConsensusParamsReaderWriter
}

type upgradeRouter struct {
mu map[string]Upgrade
}

func NewUpgradeRouter() *upgradeRouter {
return &upgradeRouter{make(map[string]Upgrade)}
}

func (r *upgradeRouter) Register(u Upgrade) *upgradeRouter {
if _, has := r.mu[u.UpgradeName]; has {
panic(u.UpgradeName + " already registered")
}
r.mu[u.UpgradeName] = u
return r
}

func (r *upgradeRouter) Routers() map[string]Upgrade {
return r.mu
}

func (r *upgradeRouter) UpgradeInfo(planName string) Upgrade {
return r.mu[planName]
}

0 comments on commit 3b18b0b

Please sign in to comment.