Skip to content

Commit

Permalink
Merge PR: disable msg of dex && order with block height (#818)
Browse files Browse the repository at this point in the history
* FINISH: disable msg of dex && order with block height

* OPTIMIZE: typo

* OPTIMIZE: msg text

* OPTIMIZE: update MercuryHeight in Makefile
  • Loading branch information
RevelationOfTuring authored Apr 15, 2021
1 parent 0ed74b4 commit 2ff92b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ServerName=okexchaind
ClientName=okexchaincli
# the height of the 1st block is GenesisHeight+1
GenesisHeight=0
MercuryHeight=2100000

# process linker flags
ifeq ($(VERSION),)
Expand All @@ -40,6 +41,7 @@ ldflags = -X $(GithubTop)/cosmos/cosmos-sdk/version.Version=$(Version) \
-X $(GithubTop)/cosmos/cosmos-sdk/version.Tendermint=$(Tendermint) \
-X $(GithubTop)/cosmos/cosmos-sdk/version.BuildTags=$(build_tags) \
-X $(GithubTop)/tendermint/tendermint/types.startBlockHeightStr=$(GenesisHeight) \
-X $(GithubTop)/cosmos/cosmos-sdk/types.MILESTONE_MERCURY_HEIGHT=$(MercuryHeight) \


ldflags += $(LDFLAGS)
Expand Down
10 changes: 7 additions & 3 deletions x/dex/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import (
"fmt"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/okex/exchain/x/common"

"github.com/okex/exchain/x/common/perf"
"github.com/okex/exchain/x/dex/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
)

// NewHandler handles all "dex" type messages.
func NewHandler(k IKeeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
// disable dex tx handler
if sdk.HigherThanMercury(ctx.BlockHeight()) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "dex message has been disabled")
}

ctx = ctx.WithEventManager(sdk.NewEventManager())
logger := ctx.Logger().With("module", ModuleName)

Expand Down
16 changes: 10 additions & 6 deletions x/order/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ package order
import (
"encoding/json"
"fmt"
"github.com/okex/exchain/x/common"
"math"

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

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
"github.com/willf/bitset"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/okex/exchain/x/common"
"github.com/okex/exchain/x/common/perf"
"github.com/okex/exchain/x/order/keeper"
"github.com/okex/exchain/x/order/types"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
"github.com/willf/bitset"
)

func CalculateGas(msg sdk.Msg, params *types.Params) (gas uint64) {
Expand All @@ -34,6 +33,11 @@ func CalculateGas(msg sdk.Msg, params *types.Params) (gas uint64) {
// NewOrderHandler returns the handler with version 0.
func NewOrderHandler(keeper keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
// disable order tx handler
if sdk.HigherThanMercury(ctx.BlockHeight()) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "order message has been disabled")
}

gas := CalculateGas(msg, keeper.GetParams(ctx))

// consume gas that msg required, it will panic if gas is insufficient
Expand Down

0 comments on commit 2ff92b3

Please sign in to comment.