Skip to content

Commit

Permalink
Merge PR: op for params and blockedcontract Cache (#1661)
Browse files Browse the repository at this point in the history
* op ante account verify

* add err log

* solve gasmeter bug

* solve a log bug

* solve a log bug

* solve a log bug

* add txhash to log

* add txhash to log

* add txhash to log

* solve a bug for ante

* restructure ante

* add seq

* restructure seq

* restructure ante for gas consume

* restructure ante log

* change gas meter

* restructure ante gasmeter

* add pin AccountAggregateValidationDecorator

* op params

* op params solve bug

* temp cache blockcontract

* op other chain deecorator

* solve params bug

* solve a bug

* solve a bug

* op params and blockedmethod cache

* solve  blocked contract cache bug for update in delive or AyncDeliver

* solve a params cache bug

* change get contract blocked list gasmeter

* add deliver into context

* complete cache for params

* op ante

* make unit test passing

* add height control for params cache

* add milestone ante height

* remove useless code

* dynamic analyzer config

* solve bug for analyzer dynamic config

* add some log

* resolve conflict

* revert AccountAggregateValidateDecorator logic

* use AccountAggregateValidateDecorator logic

* remove ante dufee logic

* remove useless code

* remove height quarantine

* unUse async

* change code name

* change WithDeliver to SetDeliver.
remove gasmeter for GetContractMethodBlockedList.

* change EvmParamsCache to evmParamsCache

Co-authored-by: xiangjianmeng <[email protected]>
  • Loading branch information
BananaLF and xiangjianmeng authored Mar 10, 2022
1 parent 34a3dd8 commit 0261e6f
Show file tree
Hide file tree
Showing 24 changed files with 239 additions and 47 deletions.
1 change: 0 additions & 1 deletion app/ante/GasLimitDecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ func (g GasLimitDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,

return next(ctx, tx, simulate)
}

1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func NewOKExChainApp(
app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName,
)
app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc)
app.ParamsKeeper.RegisterSignal(evmtypes.SetEvmParamsNeedUpdate)
app.EvmKeeper = evm.NewKeeper(
app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], &app.AccountKeeper, app.SupplyKeeper, app.BankKeeper, logger)
(&bankKeeper).SetInnerTxKeeper(app.EvmKeeper)
Expand Down
25 changes: 23 additions & 2 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
iavlconfig "github.com/okex/exchain/libs/iavl/config"
tmconfig "github.com/okex/exchain/libs/tendermint/config"
"github.com/okex/exchain/libs/tendermint/libs/log"
"github.com/okex/exchain/x/common/analyzer"

"github.com/spf13/viper"
)
Expand Down Expand Up @@ -59,6 +60,9 @@ type OecConfig struct {

// enable-wtx
enableWtx bool

// enable-analyzer
enableAnalyzer bool
}

const (
Expand All @@ -74,7 +78,7 @@ const (
FlagGasLimitBuffer = "gas-limit-buffer"
FlagEnableDynamicGp = "enable-dynamic-gp"
FlagDynamicGpWeight = "dynamic-gp-weight"
FlagEnableWrappedTx = "enable-wtx"
FlagEnableWrappedTx = "enable-wtx"

FlagCsTimeoutPropose = "consensus.timeout_propose"
FlagCsTimeoutProposeDelta = "consensus.timeout_propose_delta"
Expand Down Expand Up @@ -165,6 +169,7 @@ func RegisterDynamicConfig(logger log.Logger) {
oecConfig := GetOecConfig()
tmconfig.SetDynamicConfig(oecConfig)
iavlconfig.SetDynamicConfig(oecConfig)
analyzer.SetDynamicConfig(oecConfig)
}

func (c *OecConfig) loadFromConfig() {
Expand All @@ -186,6 +191,7 @@ func (c *OecConfig) loadFromConfig() {
c.SetIavlCacheSize(viper.GetInt(iavl.FlagIavlCacheSize))
c.SetNodeKeyWhitelist(viper.GetString(FlagNodeKeyWhitelist))
c.SetEnableWtx(viper.GetBool(FlagEnableWrappedTx))
c.SetEnableAnalyzer(viper.GetBool(analyzer.FlagEnableAnalyzer))
}

func resolveNodeKeyWhitelist(plain string) []string {
Expand Down Expand Up @@ -220,7 +226,8 @@ func (c *OecConfig) format() string {
consensus.timeout_precommit: %s
consensus.timeout_precommit_delta: %s
iavl-cache-size: %d`,
iavl-cache-size: %d
enable-analyzer: %v`,
c.GetMempoolRecheck(),
c.GetMempoolForceRecheckGap(),
c.GetMempoolSize(),
Expand All @@ -237,6 +244,7 @@ func (c *OecConfig) format() string {
c.GetCsTimeoutPrecommit(),
c.GetCsTimeoutPrecommitDelta(),
c.GetIavlCacheSize(),
c.GetEnableAnalyzer(),
)
}

Expand Down Expand Up @@ -345,9 +353,22 @@ func (c *OecConfig) update(key, value interface{}) {
return
}
c.SetIavlCacheSize(r)
case analyzer.FlagEnableAnalyzer:
r, err := strconv.ParseBool(v)
if err != nil {
return
}
c.SetEnableAnalyzer(r)
}
}

func (c *OecConfig) GetEnableAnalyzer() bool {
return c.enableAnalyzer
}
func (c *OecConfig) SetEnableAnalyzer(value bool) {
c.enableAnalyzer = value
}

func (c *OecConfig) GetMempoolRecheck() bool {
return c.mempoolRecheck
}
Expand Down
1 change: 1 addition & 0 deletions app/innertx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (suite *InnerTxTestSuite) SetupTest() {

suite.app = Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: chain_id, Time: time.Now().UTC()})
suite.ctx.SetDeliver()
suite.stateDB = evm_types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)
suite.codec = codec.New()

Expand Down
5 changes: 5 additions & 0 deletions app/rpc/namespaces/eth/simulation/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (p SubspaceProxy) GetParamSet(ctx sdk.Context, ps params.ParamSet) {
}

}

func (p SubspaceProxy) RegisterSignal(handler func()) {

}

func (p SubspaceProxy) SetParamSet(ctx sdk.Context, ps params.ParamSet) {

}
Expand Down
2 changes: 1 addition & 1 deletion cmd/client/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func RegisterAppFlag(cmd *cobra.Command) {

cmd.Flags().Bool(app.FlagEnableRepairState, false, "Enable auto repair state on start")

cmd.Flags().Bool(analyzer.FlagEnableAnalyzer, true, "Enable auto open log analyzer")
cmd.Flags().Bool(analyzer.FlagEnableAnalyzer, false, "Enable auto open log analyzer")
cmd.Flags().Bool(sanity.FlagDisableSanity, false, "Disable sanity check")
cmd.Flags().Int(tmtypes.FlagSigCacheSize, 200000, "Maximum number of signatures in the cache")
}
2 changes: 1 addition & 1 deletion cmd/exchaind/repair_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ func repairStateCmd(ctx *server.Context) *cobra.Command {
cmd.Flags().Int64(app.FlagStartHeight, 0, "Set the start block height for repair")
cmd.Flags().Bool(flatkv.FlagEnable, false, "Enable flat kv storage for read performance")
cmd.Flags().String(app.Elapsed, app.DefaultElapsedSchemas, "schemaName=1|0,,,")
cmd.Flags().Bool(analyzer.FlagEnableAnalyzer, true, "Enable auto open log analyzer")
cmd.Flags().Bool(analyzer.FlagEnableAnalyzer, false, "Enable auto open log analyzer")
return cmd
}
4 changes: 4 additions & 0 deletions libs/cosmos-sdk/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context
ctx = ctx.WithTxBytes(getRealTxByte(txBytes))
}

if mode == runTxModeDeliver {
ctx.SetDeliver()
}

return ctx
}

Expand Down
3 changes: 0 additions & 3 deletions libs/cosmos-sdk/baseapp/baseapp_runtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (app *BaseApp) runAnte(info *runTxInfo, mode runTxMode) error {
newCtx, err := app.anteHandler(anteCtx, info.tx, mode == runTxModeSimulate) // NewAnteHandler
app.pin(AnteChain, false, mode)


// 3. AnteOther
app.pin(AnteOther, true, mode)
ms := info.ctx.MultiStore()
Expand Down Expand Up @@ -164,7 +163,6 @@ func (app *BaseApp) runAnte(info *runTxInfo, mode runTxMode) error {
}
app.pin(AnteOther, false, mode)


// 4. CacheStoreWrite
if mode != runTxModeDeliverInAsync {
app.pin(CacheStoreWrite, true, mode)
Expand All @@ -176,7 +174,6 @@ func (app *BaseApp) runAnte(info *runTxInfo, mode runTxMode) error {
return nil
}


func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {

tx, err := app.txDecoder(req.Tx)
Expand Down
30 changes: 19 additions & 11 deletions libs/cosmos-sdk/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Context struct {
voteInfo []abci.VoteInfo
gasMeter GasMeter
blockGasMeter GasMeter
isDeliver bool
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
wrappedCheckTx bool // if wrappedCheckTx == true, then checkTx must also be true
Expand All @@ -53,17 +54,20 @@ type Context struct {
type Request = Context

// Read-only accessors
func (c Context) Context() context.Context { return c.ctx }
func (c Context) MultiStore() MultiStore { return c.ms }
func (c Context) BlockHeight() int64 { return c.header.Height }
func (c Context) BlockTime() time.Time { return c.header.Time }
func (c Context) ChainID() string { return c.chainID }
func (c Context) From() string { return c.from }
func (c Context) TxBytes() []byte { return c.txBytes }
func (c Context) Logger() log.Logger { return c.logger }
func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo }
func (c Context) GasMeter() GasMeter { return c.gasMeter }
func (c Context) BlockGasMeter() GasMeter { return c.blockGasMeter }
func (c Context) Context() context.Context { return c.ctx }
func (c Context) MultiStore() MultiStore { return c.ms }
func (c Context) BlockHeight() int64 { return c.header.Height }
func (c Context) BlockTime() time.Time { return c.header.Time }
func (c Context) ChainID() string { return c.chainID }
func (c Context) From() string { return c.from }
func (c Context) TxBytes() []byte { return c.txBytes }
func (c Context) Logger() log.Logger { return c.logger }
func (c Context) VoteInfos() []abci.VoteInfo { return c.voteInfo }
func (c Context) GasMeter() GasMeter { return c.gasMeter }
func (c Context) BlockGasMeter() GasMeter { return c.blockGasMeter }
func (c Context) IsDeliver() bool {
return c.isDeliver
}
func (c Context) IsCheckTx() bool { return c.checkTx }
func (c Context) IsReCheckTx() bool { return c.recheckTx }
func (c Context) IsTraceTx() bool { return c.traceTx }
Expand Down Expand Up @@ -175,6 +179,10 @@ func (c Context) WithAsync() Context {
return c
}

func (c *Context) SetDeliver() {
c.isDeliver = true
}

func (c Context) WithBlockHeader(header abci.Header) Context {
// https://github.com/gogo/protobuf/issues/519
header.Time = header.Time.UTC()
Expand Down
2 changes: 1 addition & 1 deletion libs/cosmos-sdk/x/auth/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewValidateBasicDecorator() ValidateBasicDecorator {
return ValidateBasicDecorator{}
}

func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
func (vbd ValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// simulate means 'eth_call' or 'eth_estimateGas', when it means 'eth_estimateGas' we can not 'VerifySig'.so skip here
if simulate {
return next(ctx, tx, simulate)
Expand Down
2 changes: 1 addition & 1 deletion libs/tendermint/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func execBlockOnProxyApp(context *executionTask) (*ABCIResponses, error) {
if txRes.Code == abci.CodeTypeOK {
validTxs++
} else {
logger.Debug("Invalid tx", "code", txRes.Code, "log", txRes.Log)
logger.Debug("Invalid tx", "code", txRes.Code, "log", txRes.Log, "index", txIndex)
invalidTxs++
}
abciResponses.DeliverTxs[txIndex] = txRes
Expand Down
41 changes: 24 additions & 17 deletions x/common/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,27 @@ import (
const FlagEnableAnalyzer string = "enable-analyzer"

var (
singleAnalys *analyer
openAnalyzer bool
once sync.Once
singleAnalys *analyer
openAnalyzer bool
once sync.Once
dynamicConfig IDynamicConfig = MockDynamicConfig{}
)

func SetDynamicConfig(c IDynamicConfig) {
dynamicConfig = c
}

type IDynamicConfig interface {
GetEnableAnalyzer() bool
}

type MockDynamicConfig struct {
}

func (c MockDynamicConfig) GetEnableAnalyzer() bool {
return viper.GetBool(FlagEnableAnalyzer)
}

type analyer struct {
status bool
currentTxIndex int64
Expand All @@ -41,13 +57,6 @@ func init() {
}
}

func getOpen() bool {
once.Do(func() {
openAnalyzer = viper.GetBool(FlagEnableAnalyzer)
})
return openAnalyzer
}

func newAnalys(height int64) {
if singleAnalys == nil {
singleAnalys = &analyer{
Expand All @@ -58,7 +67,7 @@ func newAnalys(height int64) {
}

func OnAppBeginBlockEnter(height int64) {
if !getOpen() {
if !dynamicConfig.GetEnableAnalyzer() {
return
}
newAnalys(height)
Expand Down Expand Up @@ -137,7 +146,7 @@ func (s *analyer) format() {
trace.GetElapsedInfo().AddInfo(trace.Evm, fmt.Sprintf(EVM_FORMAT, s.dbRead, s.dbWrite, evmcore-s.dbRead-s.dbWrite))
}

func addInfo(name string, keys []string, record map[string]int64) {
func addInfo(name string, keys []string, record map[string]int64) {
var comma, format string
for _, v := range keys {
format += fmt.Sprintf("%s%s<%dms>", comma, v, record[v])
Expand All @@ -146,7 +155,6 @@ func addInfo(name string, keys []string, record map[string]int64) {
trace.GetElapsedInfo().AddInfo(name, format)
}


func (s *analyer) genRecord() (int64, map[string]int64) {
var evmcore int64
var record = make(map[string]int64)
Expand All @@ -173,7 +181,7 @@ func (s *analyer) genRecord() (int64, map[string]int64) {
return evmcore, record
}

func formatDeliverTx(record map[string]int64) {
func formatDeliverTx(record map[string]int64) {

// deliver txs
var deliverTxsKeys = []string{
Expand All @@ -192,8 +200,7 @@ func formatDeliverTx(record map[string]int64) {
addInfo(trace.DeliverTxs, deliverTxsKeys, record)
}


func formatEvmHandlerDetail(record map[string]int64) {
func formatEvmHandlerDetail(record map[string]int64) {

// run msg
var evmHandlerKeys = []string{
Expand All @@ -214,7 +221,7 @@ func formatEvmHandlerDetail(record map[string]int64) {
addInfo(trace.EvmHandlerDetail, evmHandlerKeys, record)
}

func formatRunAnteDetail(record map[string]int64) {
func formatRunAnteDetail(record map[string]int64) {

// ante
var anteKeys = []string{
Expand Down
7 changes: 4 additions & 3 deletions x/evm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const (

// nolint
var (
NewKeeper = keeper.NewKeeper
TxDecoder = types.TxDecoder
NewSimulateKeeper = keeper.NewSimulateKeeper
NewKeeper = keeper.NewKeeper
TxDecoder = types.TxDecoder
NewSimulateKeeper = keeper.NewSimulateKeeper
SetEvmParamsNeedUpdate = types.SetEvmParamsNeedUpdate
)

//nolint
Expand Down
2 changes: 2 additions & 0 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (suite *EvmTestSuite) SetupTest() {

suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: chain_id, Time: time.Now().UTC()})
suite.ctx.SetDeliver()
suite.stateDB = types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)
suite.handler = evm.NewHandler(suite.app.EvmKeeper)
suite.querier = keeper.NewQuerier(*suite.app.EvmKeeper)
Expand Down Expand Up @@ -801,6 +802,7 @@ func (suite *EvmContractBlockedListTestSuite) SetupTest() {

suite.app = app.Setup(checkTx)
suite.ctx = suite.app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, ChainID: "ethermint-3", Time: time.Now().UTC()})
suite.ctx.SetDeliver()
suite.stateDB = types.CreateEmptyCommitStateDB(suite.app.EvmKeeper.GenerateCSDBParams(), suite.ctx)
suite.handler = evm.NewHandler(suite.app.EvmKeeper)

Expand Down
6 changes: 5 additions & 1 deletion x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func NewKeeper(
db := types.BloomDb()
types.InitIndexer(db)
}

// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
k := &Keeper{
cdc: cdc,
Expand Down Expand Up @@ -310,3 +309,8 @@ func (k *Keeper) IsAddressBlocked(ctx sdk.Context, addr sdk.AccAddress) bool {
csdb := types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx)
return csdb.GetParams().EnableContractBlockedList && csdb.IsContractInBlockedList(addr.Bytes())
}

func (k *Keeper) IsContractInBlockedList(ctx sdk.Context, addr sdk.AccAddress) bool {
csdb := types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx)
return csdb.IsContractInBlockedList(addr.Bytes())
}
Loading

0 comments on commit 0261e6f

Please sign in to comment.