Skip to content

Commit

Permalink
Merge branch 'dev' into yxq/add-commit-mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiD authored Jul 17, 2023
2 parents e6188c6 + 39c86b1 commit a660794
Show file tree
Hide file tree
Showing 101 changed files with 3,077 additions and 871 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ commands:
jobs:
build:
docker:
- image: circleci/golang:1.17
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
- image: cimg/go:1.20
working_directory: /home/circleci/go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
steps:
- checkout
- restore_cache:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci-exchain-ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.20"

- name: Run Test exchain/app
id: first-attempt
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.20"

- name: Run Test exchain/x
id: first-attempt
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.20"

- name: Go Test exchain/libs/tm
id: first-attempt
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.20"

- name: Go Test exchain/libs/ibc-go
id: first-attempt
Expand All @@ -149,7 +149,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.20"

- name: Go Test exchain/libs/cosmos-sdk/x
id: first-attempt
Expand All @@ -175,7 +175,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: "1.20"

- name: Go Test exchain/libs/other
id: first-attempt
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# > docker build -t exchain .
# > docker run -it -p 36657:36657 -p 36656:36656 -v ~/.exchaind:/root/.exchaind -v ~/.exchaincli:/root/.exchaincli exchain exchaind init mynode
# > docker run -it -p 36657:36657 -p 36656:36656 -v ~/.exchaind:/root/.exchaind -v ~/.exchaincli:/root/.exchaincli exchain exchaind start
FROM golang:1.17.2-alpine AS build-env
FROM golang:1.20.2-alpine AS build-env

# Install minimum necessary dependencies, remove packages
RUN apk add --no-cache curl make git libc-dev bash gcc linux-headers eudev-dev
Expand Down
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export GO111MODULE=on

GithubTop=github.com

GO_VERSION=1.17
GO_VERSION=1.20
ROCKSDB_VERSION=6.27.3
IGNORE_CHECK_GO=false
install_rocksdb_version:=$(ROCKSDB_VERSION)


Version=v1.7.5
Version=v1.7.8
CosmosSDK=v0.39.2
Tendermint=v0.33.9
Iavl=v0.14.3
Expand Down Expand Up @@ -71,6 +71,18 @@ endif

build_tags = netgo

system=$(shell $(shell pwd)/libs/scripts/system.sh)
ifeq ($(system),alpine)
ifeq ($(LINK_STATICALLY),false)
$(warning Your system is alpine. It must be compiled statically. Now we start compile statically.)
endif
LINK_STATICALLY=true
else
ifeq ($(LINK_STATICALLY),true)
$(error your system is $(system) which can not be complied statically. please set LINK_STATICALLY=false)
endif
endif

ifeq ($(WITH_ROCKSDB),true)
CGO_ENABLED=1
build_tags += rocksdb
Expand All @@ -82,8 +94,10 @@ else
ROCKSDB_VERSION=0
endif


ifeq ($(LINK_STATICALLY),true)
build_tags += muslc
build_tags += muslc
dummy := $(shell $(shell pwd)/libs/scripts/wasm_static_install.sh)
endif

build_tags += $(BUILD_TAGS)
Expand Down Expand Up @@ -118,7 +132,7 @@ ifeq ($(MAKECMDGOALS),testnet)
endif

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif

ifeq ($(OKCMALLOC),tcmalloc)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Infrastructure of Decentralized Exchange

This repository hosts `OKTC`, the implementation of the OKTC based on the [Cosmos SDK](https://github.com/cosmos/cosmos-sdk).

**Note**: Requires [Go 1.17](https://golang.org/dl/)
**Note**: Requires [Go 1.20](https://golang.org/dl/)

## Getting Started
Refer to the [documentation](https://okexchain-docs.readthedocs.io/en/latest/index.html).
Expand Down
47 changes: 5 additions & 42 deletions app/ante/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package ante

import (
"bytes"
tmtypes "github.com/okex/exchain/libs/tendermint/types"
"math/big"
"strconv"
"strings"

tmtypes "github.com/okex/exchain/libs/tendermint/types"

"github.com/ethereum/go-ethereum/common"
ethcore "github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/okex/exchain/libs/cosmos-sdk/baseapp"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
sdkerrors "github.com/okex/exchain/libs/cosmos-sdk/types/errors"
"github.com/okex/exchain/libs/cosmos-sdk/types/innertx"
"github.com/okex/exchain/libs/cosmos-sdk/x/auth"
"github.com/okex/exchain/libs/cosmos-sdk/x/auth/exported"
"github.com/okex/exchain/libs/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -153,7 +153,7 @@ func nonceVerification(ctx sdk.Context, acc exported.Account, msgEthTx *evmtypes
return ctx, nil
}

func ethGasConsume(ek EVMKeeper, ak accountKeeperInterface, sk types.SupplyKeeper, ctx *sdk.Context, acc exported.Account, accGetGas sdk.Gas, msgEthTx *evmtypes.MsgEthereumTx, simulate bool) error {
func ethGasConsume(ek EVMKeeper, sk types.SupplyKeeper, ctx *sdk.Context, acc exported.Account, accGetGas sdk.Gas, msgEthTx *evmtypes.MsgEthereumTx, simulate bool) error {
gasLimit := msgEthTx.GetGas()

if shouldIntrinsicGas(ek, ctx, msgEthTx) {
Expand Down Expand Up @@ -182,7 +182,7 @@ func ethGasConsume(ek EVMKeeper, ak accountKeeperInterface, sk types.SupplyKeepe

ctx.UpdateFromAccountCache(acc, accGetGas)

err := deductFees(ek, ak, sk, *ctx, acc, feeAmt)
err := auth.DeductFees(sk, *ctx, acc, feeAmt)
if err != nil {
return err
}
Expand Down Expand Up @@ -212,43 +212,6 @@ func IsE2CTx(ek EVMKeeper, ctx *sdk.Context, msgEthTx *evmtypes.MsgEthereumTx) b
return false
}

func deductFees(ik innertx.InnerTxKeeper, ak accountKeeperInterface, sk types.SupplyKeeper, ctx sdk.Context, acc exported.Account, fees sdk.Coins) error {
blockTime := ctx.BlockTime()
coins := acc.GetCoins()

if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}

// verify the account has enough funds to pay for fees
balance, hasNeg := coins.SafeSub(fees)
if hasNeg {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds,
"insufficient funds to pay for fees; %s < %s", coins, fees)
}

// Validate the account has enough "spendable" coins as this will cover cases
// such as vesting accounts.
spendableCoins := acc.SpendableCoins(blockTime)
if _, hasNeg := spendableCoins.SafeSub(fees); hasNeg {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds,
"insufficient funds to pay for fees; %s < %s", spendableCoins, fees)
}

// set coins and record innertx
err := acc.SetCoins(balance)
if !ctx.IsCheckTx() {
toAcc := sk.GetModuleAddress(types.FeeCollectorName)
ik.UpdateInnerTx(ctx.TxBytes(), ctx.BlockHeight(), innertx.CosmosDepth, acc.GetAddress(), toAcc, innertx.CosmosCallType, innertx.SendCallName, fees, err)
}
if err != nil {
return err
}
ak.SetAccount(ctx, acc)

return nil
}

func incrementSeq(ctx sdk.Context, msgEthTx *evmtypes.MsgEthereumTx, accAddress sdk.AccAddress, ak auth.AccountKeeper, acc exported.Account) {
if ctx.IsCheckTx() && !ctx.IsReCheckTx() && !baseapp.IsMempoolEnableRecheck() && !ctx.IsTraceTx() {
return
Expand Down Expand Up @@ -339,7 +302,7 @@ func (avd AccountAnteDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

ctx.EnableAccountCache()
// account would be updated
err = ethGasConsume(avd.evmKeeper, avd.ak, avd.sk, &ctx, acc, getAccGasUsed, msgEthTx, simulate)
err = ethGasConsume(avd.evmKeeper, avd.sk, &ctx, acc, getAccGasUsed, msgEthTx, simulate)
acc = nil
acc, _ = ctx.GetFromAccountCacheData().(exported.Account)
ctx.DisableAccountCache()
Expand Down
24 changes: 20 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"fmt"
"github.com/okex/exchain/libs/cosmos-sdk/client/flags"
"io"
"os"
"runtime/debug"
Expand Down Expand Up @@ -50,6 +51,7 @@ import (
"github.com/okex/exchain/libs/cosmos-sdk/server"
"github.com/okex/exchain/libs/cosmos-sdk/simapp"
"github.com/okex/exchain/libs/cosmos-sdk/store/mpt"
stypes "github.com/okex/exchain/libs/cosmos-sdk/store/types"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/types/module"
upgradetypes "github.com/okex/exchain/libs/cosmos-sdk/types/upgrade"
Expand Down Expand Up @@ -758,13 +760,15 @@ func NewOKExChainApp(
app.SetMptCommitHandler(NewMptCommitHandler(app.EvmKeeper))
app.SetUpdateWasmTxCount(fixCosmosTxCountInWasmForParallelTx(app.WasmHandler.TXCounterStoreKey))
app.SetUpdateFeeCollectorAccHandler(updateFeeCollectorHandler(app.BankKeeper, app.SupplyKeeper))
app.SetGetFeeCollectorInfo(getFeeCollectorInfo(app.BankKeeper, app.SupplyKeeper))
app.SetParallelTxLogHandlers(fixLogForParallelTxHandler(app.EvmKeeper))
app.SetPreDeliverTxHandler(preDeliverTxHandler(app.AccountKeeper))
app.SetPartialConcurrentHandlers(getTxFeeAndFromHandler(app.AccountKeeper))
app.SetPartialConcurrentHandlers(getTxFeeAndFromHandler(app.EvmKeeper))
app.SetGetTxFeeHandler(getTxFeeHandler())
app.SetEvmSysContractAddressHandler(NewEvmSysContractAddressHandler(app.EvmKeeper))
app.SetEvmWatcherCollector(app.EvmKeeper.Watcher.Collect)
app.SetUpdateCMTxNonceHandler(NewUpdateCMTxNonceHandler())
app.SetGetGasConfigHandler(NewGetGasConfigHandler(app.ParamsKeeper))

if loadLatest {
err := app.LoadLatestVersion(app.keys[bam.MainStoreKey])
Expand Down Expand Up @@ -955,6 +959,8 @@ func NewAccNonceHandler(ak auth.AccountKeeper) sdk.AccNonceHandler {
}

func PreRun(ctx *server.Context, cmd *cobra.Command) error {
prepareSnapshotDataIfNeed(viper.GetString(server.FlagStartFromSnapshot), viper.GetString(flags.FlagHome), ctx.Logger)

// check start flag conflicts
err := sanity.CheckStart()
if err != nil {
Expand Down Expand Up @@ -1033,9 +1039,19 @@ func NewEvmSysContractAddressHandler(ak *evm.Keeper) sdk.EvmSysContractAddressHa

func NewUpdateCMTxNonceHandler() sdk.UpdateCMTxNonceHandler {
return func(tx sdk.Tx, nonce uint64) {
stdtx, ok := tx.(*authtypes.StdTx)
if ok && nonce != 0 {
stdtx.Nonce = nonce
if nonce != 0 {
switch v := tx.(type) {
case *authtypes.StdTx:
v.Nonce = nonce
case *authtypes.IbcTx:
v.Nonce = nonce
}
}
}
}

func NewGetGasConfigHandler(pk params.Keeper) sdk.GetGasConfigHandler {
return func(ctx sdk.Context) *stypes.GasConfig {
return pk.GetGasConfig(ctx)
}
}
Loading

0 comments on commit a660794

Please sign in to comment.