Skip to content

Commit 1d9709e

Browse files
author
HuangYi
committed
Problem: don't support hardfork style upgrades
1 parent 29cdd9d commit 1d9709e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## UNRELEASED
4+
5+
- [#]() Support hard-fork style upgrades.
6+
37
*December 11, 2023*
48

59
## v1.1.0-rc2

app/app.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ const (
175175
FlagBlockedAddresses = "blocked-addresses"
176176
)
177177

178+
var Forks = []Fork{}
179+
178180
// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
179181

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

984986
// BeginBlocker application updates every begin block
985987
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
988+
BeginBlockForks(ctx, app)
986989
return app.mm.BeginBlock(ctx, req)
987990
}
988991

app/forks.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package app
2+
3+
import sdk "github.com/cosmos/cosmos-sdk/types"
4+
5+
// Fork defines a struct containing the requisite fields for a non-software upgrade proposal
6+
// Hard Fork at a given height to implement.
7+
// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`.
8+
// Any other change in the code should be height-gated, if the goal is to have old and new binaries
9+
// to be compatible prior to the upgrade height.
10+
//
11+
// Adapted from osmosis: https://github.com/osmosis-labs/osmosis/blob/057192c2c0949fde5673a5f314bf41816f808fd9/app/upgrades/types.go#L40
12+
type Fork struct {
13+
// Upgrade version name, for the upgrade handler, e.g. `v7`
14+
UpgradeName string
15+
// height the upgrade occurs at
16+
UpgradeHeight int64
17+
18+
// Function that runs some custom state transition code at the beginning of a fork.
19+
BeginForkLogic func(ctx sdk.Context, app *App)
20+
}
21+
22+
// BeginBlockForks is intended to be ran in a chain upgrade.
23+
func BeginBlockForks(ctx sdk.Context, app *App) {
24+
for _, fork := range Forks {
25+
if ctx.BlockHeight() == fork.UpgradeHeight {
26+
fork.BeginForkLogic(ctx, app)
27+
return
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)