Skip to content

Commit

Permalink
feat: add ceers fork
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoM committed Dec 18, 2024
1 parent ffe0ae0 commit 368dfb5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 17 deletions.
19 changes: 19 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import (

milkywayante "github.com/milkyway-labs/milkyway/v3/ante"
milkywayabci "github.com/milkyway-labs/milkyway/v3/app/abci"
"github.com/milkyway-labs/milkyway/v3/app/forks"
ceers2112 "github.com/milkyway-labs/milkyway/v3/app/forks/ceers-2112"
"github.com/milkyway-labs/milkyway/v3/app/keepers"
"github.com/milkyway-labs/milkyway/v3/app/upgrades"
v3 "github.com/milkyway-labs/milkyway/v3/app/upgrades/v3"
Expand All @@ -77,6 +79,10 @@ var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

Forks = []forks.Fork{
ceers2112.Fork,
}

Upgrades = []upgrades.Upgrade{
v3.Upgrade,
}
Expand Down Expand Up @@ -354,6 +360,7 @@ func NewMilkyWayApp(

app.setupUpgradeHandlers()
app.setupUpgradeStoreLoaders()
app.setupForksPreBlockers()

// At startup, after all modules have been registered, check that all prot
// annotations are correct.
Expand Down Expand Up @@ -547,6 +554,18 @@ func (app *MilkyWayApp) setupUpgradeHandlers() {
}
}

func (app *MilkyWayApp) setupForksPreBlockers() {
for _, fork := range Forks {
currentPreBlocker := app.PreBlocker()
app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) {
if req.Height == fork.ForkHeight {
fork.BeginForkLogic(ctx, &app.AppKeepers)
}
return currentPreBlocker(ctx, req)
})
}
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down
10 changes: 10 additions & 0 deletions app/forks/ceers-2112/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ceers2112

import (
"github.com/milkyway-labs/milkyway/v3/app/forks"
)

var Fork = forks.Fork{
ForkHeight: 301230,
BeginForkLogic: BeginFork,
}
29 changes: 29 additions & 0 deletions app/forks/ceers-2112/fork.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ceers2112

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/milkyway-labs/milkyway/v3/app/keepers"
)

func BeginFork(ctx sdk.Context, keepers *keepers.AppKeepers) {
ctx.Logger().Debug(`
===================================================================================================
==== Forking chain state
===================================================================================================
`)

// Update the gov params to make sure the min deposit amount is set to stake
params, err := keepers.GovKeeper.Params.Get(ctx)
if err != nil {
panic(err)
}

params.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin("stake", 1000000))
params.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin("stake", 5000000))

err = keepers.GovKeeper.Params.Set(ctx, params)
if err != nil {
panic(err)
}
}
20 changes: 20 additions & 0 deletions app/forks/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package forks

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/milkyway-labs/milkyway/v3/app/keepers"
)

// 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 {
// ForkHeight represents the height the upgrade occurs at
ForkHeight int64

// Function that runs some custom state transition code at the beginning of a fork.
BeginForkLogic func(ctx sdk.Context, keepers *keepers.AppKeepers)
}
17 changes: 0 additions & 17 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package upgrades
import (
store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/milkyway-labs/milkyway/v3/app/keepers"
Expand All @@ -24,18 +22,3 @@ type Upgrade struct {
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

// 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 *keepers.AppKeepers)
}

0 comments on commit 368dfb5

Please sign in to comment.