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

Problem: don't support hardfork style upgrades #1258

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
}

Check warning on line 30 in app/forks.go

View check run for this annotation

Codecov / codecov/patch

app/forks.go#L25-L30

Added lines #L25 - L30 were not covered by tests
}
}
Loading