Skip to content

Commit

Permalink
feat: hard fork v2 code
Browse files Browse the repository at this point in the history
* add schedule plain in beginBlock
  • Loading branch information
fx0x55 committed Dec 7, 2022
1 parent c4a33e7 commit f54bf29
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"

v2 "github.com/pundix/pundix/app/fork/v2"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"

Expand Down Expand Up @@ -455,6 +458,15 @@ func (app *App) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
// hard-fork
// v2 - fork
ctx.Logger().With("app/beginBlock").Info("beginBlock", "height", ctx.BlockHeight())
if ctx.BlockHeight() == int64(pxtypes.V2HardForkHeight()) {
err := v2.Upgrade(ctx, app.UpgradeKeeper)
if err != nil {
panic(fmt.Sprintf("failed to hard fork v2: %v", err))
}
}
return app.mm.BeginBlock(ctx, req)
}

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

import (
sdk "github.com/cosmos/cosmos-sdk/types"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"

pxtypes "github.com/pundix/pundix/types"
)

const (
name = "pxv2"
info = `'{"binaries":{"darwin/arm64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Darwin_arm64.tar.gz","darwin/amd64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Darwin_amd64.tar.gz","linux/arm64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Linux_arm64.tar.gz","linux/amd64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Linux_amd64.tar.gz","windows/x86_64":"https://github.com/pundix/pundix/releases/download/v0.2.0/pundix_0.2.0_Windows_x86_64.zip"}}'`
)

func Upgrade(ctx sdk.Context, upgradeKeeper upgradekeeper.Keeper) error {
plan := types.Plan{
Name: name,
Height: int64(pxtypes.V2SoftwareUpgradeHeight()),
Info: info,
}
ctx.Logger().With("fork/v2").Info("schedule upgrade begin", "plan", plan)
err := upgradeKeeper.ScheduleUpgrade(ctx, plan)
ctx.Logger().With("fork/v2").Info("schedule upgrade done", "err", err)
return err
}
21 changes: 21 additions & 0 deletions types/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"math"
"os"
"sync"

Expand All @@ -12,13 +13,19 @@ const (
TestnetChainId = "payalebar"
testnetMintDenom = "bsc0x0BEdB58eC8D603E71556ef8aA4014c68DBd57AD7"
testnetStakingBondDenom = "ibc/169A52CA4862329131348484982CE75B3D6CC78AFB94C3107026C70CB66E7B2E"

testnetV2HardForkHeight = math.MaxUint64
testnetV2UpgradeHeight = math.MaxUint64
)

// mainnet constant
const (
MainnetChainId = "PUNDIX"
mainnetMintDenom = "bsc0x29a63F4B209C29B4DC47f06FFA896F32667DAD2C"
mainnetStakingBondDenom = "ibc/55367B7B6572631B78A93C66EF9FDFCE87CDE372CC4ED7848DA78C1EB1DCDD78"

mainnetV2HardForkHeight = math.MaxUint64
mainnetV2UpgradeHeight = math.MaxUint64
)

var (
Expand Down Expand Up @@ -62,3 +69,17 @@ func StakingBondDenom() string {
}
return mainnetStakingBondDenom
}

func V2HardForkHeight() uint64 {
if TestnetChainId == ChainId() {
return testnetV2HardForkHeight
}
return mainnetV2HardForkHeight
}

func V2SoftwareUpgradeHeight() uint64 {
if TestnetChainId == ChainId() {
return testnetV2UpgradeHeight
}
return mainnetV2UpgradeHeight
}

0 comments on commit f54bf29

Please sign in to comment.