Skip to content

Commit

Permalink
split upgrade heights
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed May 31, 2023
1 parent e7af0de commit 0eac8a5
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 92 deletions.
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP173, upgradeConfig.BEP173Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.FixDoubleSignChainId, upgradeConfig.FixDoubleSignChainIdHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP126, upgradeConfig.BEP126Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.SecurityEnhancement, upgradeConfig.SecurityEnhancementHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.EnableReconciliation, upgradeConfig.EnableReconciliationHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.DisableMessagesPhase1, upgradeConfig.DisableMessagesPhase1Height)

// register store keys of upgrade
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name())
Expand Down Expand Up @@ -967,7 +968,7 @@ func (app *BinanceChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) a
// match may end with transaction failure, which is better to save into
// the EndBlock response. However, current cosmos doesn't support this.

if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
if sdk.IsUpgrade(upgrade.EnableReconciliation) {
app.reconBalance(ctx)
}

Expand Down
12 changes: 8 additions & 4 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ BEP173Height = {{ .UpgradeConfig.BEP173Height }}
FixDoubleSignChainIdHeight = {{ .UpgradeConfig.FixDoubleSignChainIdHeight }}
# Block height of BEP126 upgrade
BEP126Height = {{ .UpgradeConfig.BEP126Height }}
# Block height of security enhancement upgrade
SecurityEnhancementHeight = {{ .UpgradeConfig.SecurityEnhancementHeight }}
# Block height of reconciliation upgrade
EnableReconciliationHeight = {{ .UpgradeConfig.EnableReconciliationHeight }}
# Block height of disable messages phase1 upgrade
DisableMessagesPhase1Height = {{ .UpgradeConfig.DisableMessagesPhase1Height }}
[query]
# ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"]
Expand Down Expand Up @@ -551,7 +553,8 @@ type UpgradeConfig struct {
BEP173Height int64 `mapstructure:"BEP173Height"`
FixDoubleSignChainIdHeight int64 `mapstructure:"FixDoubleSignChainIdHeight"`
BEP126Height int64 `mapstructure:"BEP126Height"`
SecurityEnhancementHeight int64 `mapstructure:"SecurityEnhancementHeight"`
EnableReconciliationHeight int64 `mapstructure:"EnableReconciliationHeight"`
DisableMessagesPhase1Height int64 `mapstructure:"DisableMessagesPhase1Height"`
}

func defaultUpgradeConfig() *UpgradeConfig {
Expand Down Expand Up @@ -586,7 +589,8 @@ func defaultUpgradeConfig() *UpgradeConfig {
BEP171Height: math.MaxInt64,
FixFailAckPackageHeight: math.MaxInt64,
EnableAccountScriptsForCrossChainTransferHeight: math.MaxInt64,
SecurityEnhancementHeight: math.MaxInt64,
EnableReconciliationHeight: math.MaxInt64,
DisableMessagesPhase1Height: math.MaxInt64,
}
}

Expand Down
6 changes: 4 additions & 2 deletions app/reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package app

import (
"fmt"
"github.com/bnb-chain/node/common"
"github.com/bnb-chain/node/common/types"

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

"github.com/bnb-chain/node/common"
"github.com/bnb-chain/node/common/types"
)

const globalAccountNumber = "globalAccountNumber"
Expand Down
3 changes: 2 additions & 1 deletion common/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const (
BEP171 = sdk.BEP171 // https://github.com/bnb-chain/BEPs/pull/171 Security Enhancement for Cross-Chain Module
BEP173 = sdk.BEP173 // https://github.com/bnb-chain/BEPs/pull/173 Text Proposal
FixDoubleSignChainId = sdk.FixDoubleSignChainId
SecurityEnhancement = sdk.SecurityEnhancement
EnableReconciliation = sdk.EnableReconciliation
DisableMessagesPhase1 = sdk.DisableMessagesPhase1
)

func UpgradeBEP10(before func(), after func()) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230529063008-dbf47b51db49
github.com/cosmos/cosmos-sdk => github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230531023724-2e22c6326b67
github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2
github.com/tendermint/iavl => github.com/bnb-chain/bnc-tendermint-iavl v0.12.0-binance.5
github.com/tendermint/tendermint => github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM=
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230529063008-dbf47b51db49 h1:0cpB5uSk7BUyauTtg23pDctUrInfT33g2zYF72b0sq0=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230529063008-dbf47b51db49/go.mod h1:XiDYVT+XqECR+AyCBO4KBsrbL/d1x2UTsVU36SvHxI8=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230531023724-2e22c6326b67 h1:yysn9/l3K9jEcdJ4Nd25tvPLHQxw1J9PkS4a3RyNRNM=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230531023724-2e22c6326b67/go.mod h1:XiDYVT+XqECR+AyCBO4KBsrbL/d1x2UTsVU36SvHxI8=
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
Expand Down
15 changes: 8 additions & 7 deletions plugins/bridge/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"strings"
"time"

"github.com/bnb-chain/node/common/log"
cmmtypes "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/plugins/bridge/types"
"github.com/cosmos/cosmos-sdk/bsc/rlp"
"github.com/cosmos/cosmos-sdk/pubsub"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"

"github.com/bnb-chain/node/common/log"
cmmtypes "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/common/upgrade"
"github.com/bnb-chain/node/plugins/bridge/types"
)

func NewHandler(keeper Keeper) sdk.Handler {
Expand All @@ -21,10 +23,9 @@ func NewHandler(keeper Keeper) sdk.Handler {
case TransferOutMsg:
return handleTransferOutMsg(ctx, keeper, msg)
case BindMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("BindMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("BindMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleBindMsg(ctx, keeper, msg)
case UnbindMsg:
return handleUnbindMsg(ctx, keeper, msg)
Expand Down
15 changes: 8 additions & 7 deletions plugins/tokens/freeze/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ import (
"reflect"
"strings"

"github.com/bnb-chain/node/common/log"
common "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/plugins/tokens/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"

"github.com/bnb-chain/node/common/log"
common "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/common/upgrade"
"github.com/bnb-chain/node/plugins/tokens/store"
)

// NewHandler creates a new token freeze message handler
func NewHandler(tokenMapper store.Mapper, accKeeper auth.AccountKeeper, keeper bank.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case FreezeMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("FreezeMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("FreezeMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleFreezeToken(ctx, tokenMapper, accKeeper, keeper, msg)
case UnfreezeMsg:
return handleUnfreezeToken(ctx, tokenMapper, accKeeper, keeper, msg)
Expand Down
32 changes: 15 additions & 17 deletions plugins/tokens/issue/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,42 @@ package issue
import (
"encoding/json"
"fmt"

"reflect"
"strconv"
"strings"

"github.com/bnb-chain/node/common/log"
"github.com/bnb-chain/node/common/types"
common "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/plugins/tokens/store"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
tmlog "github.com/tendermint/tendermint/libs/log"

"github.com/bnb-chain/node/common/log"
"github.com/bnb-chain/node/common/types"
common "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/common/upgrade"
"github.com/bnb-chain/node/plugins/tokens/store"
)

// NewHandler creates a new token issue message handler
func NewHandler(tokenMapper store.Mapper, keeper bank.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case IssueMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("IssueMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("IssueMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleIssueToken(ctx, tokenMapper, keeper, msg)
case MintMsg:
return handleMintToken(ctx, tokenMapper, keeper, msg)
case IssueMiniMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("IssueMiniMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("IssueMiniMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleIssueMiniToken(ctx, tokenMapper, keeper, msg)
case IssueTinyMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("IssueTinyMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("IssueTinyMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleIssueTinyToken(ctx, tokenMapper, keeper, msg)
default:
errMsg := "Unrecognized msg type: " + reflect.TypeOf(msg).Name()
Expand Down
12 changes: 6 additions & 6 deletions plugins/tokens/seturi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package seturi

import (
"fmt"

"reflect"
"strings"

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

"github.com/bnb-chain/node/common/log"
common "github.com/bnb-chain/node/common/types"
"github.com/bnb-chain/node/common/upgrade"
"github.com/bnb-chain/node/plugins/tokens/store"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func NewHandler(tokenMapper store.Mapper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case SetURIMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("SetURIMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("SetURIMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleSetURI(ctx, tokenMapper, msg)
default:
errMsg := "Unrecognized msg type: " + reflect.TypeOf(msg).Name()
Expand Down
9 changes: 5 additions & 4 deletions plugins/tokens/timelock/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
"time"

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

"github.com/bnb-chain/node/common/upgrade"
)

func NewHandler(keeper Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case TimeLockMsg:
// TODO: disable for recon testing
//if sdk.IsUpgrade(upgrade.SecurityEnhancement) {
// return sdk.ErrMsgNotSupported("TimeLockMsg disabled in SecurityEnhancement upgrade").Result()
//}
if sdk.IsUpgrade(upgrade.DisableMessagesPhase1) {
return sdk.ErrMsgNotSupported("TimeLockMsg disabled in DisableMessagesPhase1 upgrade").Result()
}
return handleTimeLock(ctx, keeper, msg)
case TimeUnlockMsg:
return handleTimeUnlock(ctx, keeper, msg)
Expand Down
Loading

0 comments on commit 0eac8a5

Please sign in to comment.