Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
support dynamic config (#142)
Browse files Browse the repository at this point in the history
* upd

* test DynamicConfig

* support dynamic config

* use tm config

Co-authored-by: zhongqiuwood <[email protected]>
  • Loading branch information
ylsGit and zhongqiuwood authored Aug 26, 2021
1 parent daa62cd commit 8e5b80e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
15 changes: 7 additions & 8 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"runtime/debug"
"strings"

"github.com/tendermint/tendermint/mempool"

"github.com/gogo/protobuf/proto"
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/mempool"
tmhttp "github.com/tendermint/tendermint/rpc/client/http"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -63,13 +63,12 @@ func IsMempoolEnableSort() bool {
}

func IsMempoolEnableRecheck() bool {
return mempoolEnableRecheck
return cfg.DynamicConfig.GetMempoolRecheck()
}

func SetGlobalMempool(mempool mempool.Mempool, enableSort bool, enableRecheck bool) {
func SetGlobalMempool(mempool mempool.Mempool, enableSort bool) {
globalMempool = mempool
mempoolEnableSort = enableSort
mempoolEnableRecheck = enableRecheck
}

type (
Expand Down Expand Up @@ -648,7 +647,7 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx, height int6
} else if height < startHeight && height != 0 {
return gInfo, result, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
fmt.Sprintf("height(%d) should be greater than start block height(%d)", height, startHeight))
} else {
} else {
ctx = app.getContextForTx(mode, txBytes)
}

Expand Down Expand Up @@ -777,9 +776,9 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx, height int6
if mode == runTxModeCheck {
exTxInfo := tx.GetTxInfo(ctx)

if exTxInfo.Nonce == 0 && exTxInfo.Sender != "" && app.AccHandler != nil{
if exTxInfo.Nonce == 0 && exTxInfo.Sender != "" && app.AccHandler != nil {
addr, _ := sdk.AccAddressFromBech32(exTxInfo.Sender)
exTxInfo.Nonce = app.AccHandler(ctx, addr)
exTxInfo.Nonce = app.AccHandler(ctx, addr)

if app.anteHandler != nil && exTxInfo.Nonce > 0{
exTxInfo.Nonce -= 1 // in ante handler logical, the nonce will incress one
Expand Down
13 changes: 7 additions & 6 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package server

import (
"fmt"
"github.com/cosmos/cosmos-sdk/store/iavl"
"os"
"runtime/pprof"

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

"github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/iavl"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/abci/server"
Expand All @@ -21,8 +21,6 @@ import (
"github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy"

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

// Tendermint full-node start flags
Expand Down Expand Up @@ -56,7 +54,8 @@ const (
func StartCmd(ctx *Context,
cdc *codec.Codec, appCreator AppCreator,
registerRoutesFn func(restServer *lcd.RestServer),
registerAppFlagFn func(cmd *cobra.Command)) *cobra.Command {
registerAppFlagFn func(cmd *cobra.Command),
registerDynamicConfigFn func()) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Run the full node",
Expand All @@ -83,6 +82,8 @@ For profiling and benchmarking purposes, CPU profiling can be enabled via the '-
which accepts a path for the resulting pprof file.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
registerDynamicConfigFn()

_, err := GetPruningOptionsFromFlags()
return err
},
Expand Down Expand Up @@ -272,7 +273,7 @@ func startInProcess(ctx *Context, cdc *codec.Codec, appCreator AppCreator,
go lcd.StartRestServer(cdc, registerRoutesFn, tmNode, viper.GetString(FlagListenAddr))
}

baseapp.SetGlobalMempool(tmNode.Mempool(), cfg.Mempool.SortTxByGp, cfg.Mempool.Recheck)
baseapp.SetGlobalMempool(tmNode.Mempool(), cfg.Mempool.SortTxByGp)

// run forever (the node will not be returned)
select {}
Expand Down
5 changes: 3 additions & 2 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func AddCommands(
rootCmd *cobra.Command,
appCreator AppCreator, appExport AppExporter,
registerRouters func(rs *lcd.RestServer),
registerAppFlagFn func(cmd *cobra.Command)) {
registerAppFlagFn func(cmd *cobra.Command),
registerDynamicConfigFn func()) {

rootCmd.PersistentFlags().String("log_level", ctx.Config.LogLevel, "Log level")
rootCmd.PersistentFlags().String("log_file", ctx.Config.LogFile, "Log file")
Expand All @@ -151,7 +152,7 @@ func AddCommands(
)

rootCmd.AddCommand(
StartCmd(ctx, cdc, appCreator, registerRouters, registerAppFlagFn),
StartCmd(ctx, cdc, appCreator, registerRouters, registerAppFlagFn, registerDynamicConfigFn),
StopCmd(ctx),
UnsafeResetAllCmd(ctx),
flags.LineBreak,
Expand Down

0 comments on commit 8e5b80e

Please sign in to comment.