Skip to content

Commit

Permalink
Problem: don't support hardfork style upgrades (#1258)
Browse files Browse the repository at this point in the history
* Problem: don't support hardfork style upgrades

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

* check chain-id

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored Dec 14, 2023
1 parent 29cdd9d commit 7ee87f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## UNRELEASED

- [#1258](https://github.com/crypto-org-chain/cronos/pull/1258) Support hard-fork style upgrades.

*December 11, 2023*

## v1.1.0-rc2
Expand Down
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ const (
FlagBlockedAddresses = "blocked-addresses"
)

var Forks = []Fork{}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down Expand Up @@ -983,6 +985,7 @@ func (app *App) PreBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (sdk.Res

// 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
32 changes: 32 additions & 0 deletions app/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package app

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

// 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.
//
// Adapted from osmosis: https://github.com/osmosis-labs/osmosis/blob/057192c2c0949fde5673a5f314bf41816f808fd9/app/upgrades/types.go#L40
type Fork struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// height the upgrade occurs at
UpgradeHeight int64
// chain-id the upgrade occurs at
UpgradeChainId string

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

// 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 && ctx.ChainID() == fork.UpgradeChainId {
fork.BeginForkLogic(ctx, app)
return
}
}
}

0 comments on commit 7ee87f0

Please sign in to comment.