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

V5 hardfork #787

Merged
merged 5 commits into from
Oct 20, 2024
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
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var (
Bech32Prefix = "bostrom"

Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade}
Forks = []upgrades.Fork{v5.Fork}
)

// These constants are derived from the above variables.
Expand Down Expand Up @@ -339,6 +340,7 @@ func (app *App) Name() string {

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
BeginBlockForks(ctx, app)
return app.ModuleManager.BeginBlock(ctx, req)
}

Expand Down
15 changes: 15 additions & 0 deletions app/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

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

// 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 {
fork.BeginForkLogic(ctx, &app.AppKeepers)
return
}
}
}
15 changes: 15 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ 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)
}
17 changes: 17 additions & 0 deletions app/upgrades/v5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v5

import (
"github.com/cybercongress/go-cyber/v5/app/upgrades"
)

const (
UpgradeName = "v5"

UpgradeHeight = 15_700_842
)

var Fork = upgrades.Fork{
UpgradeName: UpgradeName,
UpgradeHeight: UpgradeHeight,
BeginForkLogic: RunForkLogic,
}
25 changes: 25 additions & 0 deletions app/upgrades/v5/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v5

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cybercongress/go-cyber/v5/app/keepers"
)

func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) {
logger := ctx.Logger().With("upgrade", UpgradeName)

logger.Info("Applying emergency hard fork for v5")

liquidityParams := keepers.LiquidityKeeper.GetParams(ctx)
liquidityParams.CircuitBreakerEnabled = true
err := keepers.LiquidityKeeper.SetParams(ctx, liquidityParams)
if err != nil {
panic(err)
}
logger.Info("set liquidity circuit breaker enabled, disable dex")

keepers.BankKeeper.SetSendEnabled(ctx, "millivolt", false)
keepers.BankKeeper.SetSendEnabled(ctx, "milliampere", false)

logger.Info("set bank send disabled for millivolt and amperes")
}
7 changes: 3 additions & 4 deletions x/resources/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,10 @@ func (k Keeper) CalculateInvestmint(ctx sdk.Context, amt sdk.Coin, resource stri
case ctypes.VOLT:
cycles := sdk.NewDec(int64(length)).QuoInt64(int64(params.BaseInvestmintPeriodVolt))
base := sdk.NewDec(amt.Amount.Int64()).QuoInt64(params.BaseInvestmintAmountVolt.Amount.Int64())

// TODO double check when third halving will be applied?
// NOTE out of parametrization custom code is applied here in order to shift the FIRST HALVING 6M BLOCKS LATER but keep base halving parameter same

// NOTE out of parametrization, custom code is applied here in order to shift the HALVINGS START 6M BLOCKS LATER but keep base halving parameter same
if ctx.BlockHeight() > 15000000 {
halving = sdk.NewDecWithPrec(int64(math.Pow(0.5, float64((ctx.BlockHeight()-600000)/int64(params.HalvingPeriodVoltBlocks)))*10000), 4)
halving = sdk.NewDecWithPrec(int64(math.Pow(0.5, float64((ctx.BlockHeight()-6000000)/int64(params.HalvingPeriodVoltBlocks)))*10000), 4)
} else {
halving = sdk.OneDec()
}
Expand Down