Skip to content

Commit

Permalink
Merge PR: Dynamic GP compatible with Tx parallel (#2795)
Browse files Browse the repository at this point in the history
* version 1

* bug fix

* rename mode and set MinimalGpMode for default

* rewrite ut

* delete the invalid annotations

* improve code

* enable dynamic config

* improve code

* improve code

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
LeoGuo621 and KamiD authored Dec 1, 2022
1 parent 6771448 commit 082ebe8
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 454 deletions.
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ func NewOKExChainApp(
app.SetEvmSysContractAddressHandler(NewEvmSysContractAddressHandler(app.EvmKeeper))
app.SetEvmWatcherCollector(app.EvmKeeper.Watcher.Collect)

gpoConfig := gasprice.NewGPOConfig(appconfig.GetOecConfig().GetDynamicGpWeight(), appconfig.GetOecConfig().GetDynamicGpCheckBlocks())
app.gpo = gasprice.NewOracle(gpoConfig)
app.SetUpdateGPOHandler(updateGPOHandler(app.gpo))

if loadLatest {
err := app.LoadLatestVersion(app.keys[bam.MainStoreKey])
if err != nil {
Expand All @@ -669,10 +673,6 @@ func NewOKExChainApp(
enableAnalyzer := sm.DeliverTxsExecMode(viper.GetInt(sm.FlagDeliverTxsExecMode)) == sm.DeliverTxsExecModeSerial
trace.EnableAnalyzer(enableAnalyzer)

if appconfig.GetOecConfig().GetDynamicGpMode() != types.CloseMode {
gpoConfig := gasprice.NewGPOConfig(appconfig.GetOecConfig().GetDynamicGpWeight(), appconfig.GetOecConfig().GetDynamicGpCheckBlocks())
app.gpo = gasprice.NewOracle(gpoConfig)
}
return app
}

Expand Down Expand Up @@ -705,7 +705,7 @@ func (app *OKExChainApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBloc

// EndBlocker updates every end block
func (app *OKExChainApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
if appconfig.GetOecConfig().GetDynamicGpMode() != types.CloseMode {
if appconfig.GetOecConfig().GetDynamicGpMode() != types.MinimalGpMode {
currentBlockGPsCopy := app.gpo.CurrentBlockGPs.Copy()
_ = app.gpo.BlockGPQueue.Push(currentBlockGPsCopy)
GlobalGp = app.gpo.RecommendGP()
Expand Down
23 changes: 0 additions & 23 deletions app/app_abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import (
"time"

appconfig "github.com/okex/exchain/app/config"
"github.com/okex/exchain/app/types"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/system/trace"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/x/evm"
"github.com/okex/exchain/x/wasm/watcher"
)

Expand All @@ -26,14 +23,6 @@ func (app *OKExChainApp) DeliverTx(req abci.RequestDeliverTx) (res abci.Response

resp := app.BaseApp.DeliverTx(req)

if appconfig.GetOecConfig().GetDynamicGpMode() != types.CloseMode {
tx, err := evm.TxDecoder(app.marshal)(req.Tx)
if err == nil {
//optimize get tx gas price can not get value from verifySign method
app.gpo.CurrentBlockGPs.Update(tx.GetGasPrice(), uint64(resp.GasUsed))
}
}

return resp
}

Expand All @@ -46,18 +35,6 @@ func (app *OKExChainApp) DeliverRealTx(req abci.TxEssentials) (res abci.Response
resp := app.BaseApp.DeliverRealTx(req)
app.EvmKeeper.Watcher.RecordTxAndFailedReceipt(req, &resp, app.GetTxDecoder())

var err error
if appconfig.GetOecConfig().GetDynamicGpMode() != types.CloseMode {
tx, _ := req.(sdk.Tx)
if tx == nil {
tx, err = evm.TxDecoder(app.Codec())(req.GetRaw())
}
if err == nil {
//optimize get tx gas price can not get value from verifySign method
app.gpo.CurrentBlockGPs.Update(tx.GetGasPrice(), uint64(resp.GasUsed))
}
}

return resp
}

Expand Down
12 changes: 12 additions & 0 deletions app/app_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sort"
"strings"

appconfig "github.com/okex/exchain/app/config"
"github.com/okex/exchain/app/gasprice"
ethermint "github.com/okex/exchain/app/types"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -145,3 +147,13 @@ func groupByAddrAndSortFeeSplits(txFeesplit []*sdk.FeeSplitInfo) (feesplits map[

return
}

func updateGPOHandler(gpo *gasprice.Oracle) sdk.UpdateGPOHandler {
return func(dynamicGpInfos []sdk.DynamicGasInfo) {
if appconfig.GetOecConfig().GetDynamicGpMode() != ethermint.MinimalGpMode {
for _, dgi := range dynamicGpInfos {
gpo.CurrentBlockGPs.Update(dgi.GetGP(), dgi.GetGU())
}
}
}
}
10 changes: 6 additions & 4 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package app

import (
"math/big"
"os"
"testing"

ethcommon "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"

"github.com/okex/exchain/app/crypto/ethsecp256k1"
cosmossdk "github.com/okex/exchain/libs/cosmos-sdk/types"
authclient "github.com/okex/exchain/libs/cosmos-sdk/x/auth/client/utils"
"github.com/okex/exchain/libs/tendermint/global"
tendertypes "github.com/okex/exchain/libs/tendermint/types"
"github.com/okex/exchain/x/distribution/keeper"
evmtypes "github.com/okex/exchain/x/evm/types"
"github.com/stretchr/testify/suite"
"math/big"
"os"
"testing"

"github.com/okex/exchain/libs/cosmos-sdk/x/upgrade"
"github.com/okex/exchain/x/dex"
Expand Down
Loading

0 comments on commit 082ebe8

Please sign in to comment.