Skip to content

Commit

Permalink
Merge PR: Close checktx lock (#95)
Browse files Browse the repository at this point in the history
* close checktx mutex by flag

* add log for ReapMaxBytesMaxGas

Co-authored-by: evan.han <iloversevan@gmail.com>
  • Loading branch information
xiangjianmeng and ilovers committed Oct 26, 2021
1 parent 8f764a7 commit 11a1f72
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
13 changes: 9 additions & 4 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ func (app *localClient) DeliverTxAsync(params types.RequestDeliverTx) *ReqRes {
}

func (app *localClient) CheckTxAsync(req types.RequestCheckTx) *ReqRes {
app.mtx.Lock()
defer app.mtx.Unlock()
isCloseCheckTxMutex := types.GetCloseCheckTxMutex()
if !isCloseCheckTxMutex {
app.mtx.Lock()
defer app.mtx.Unlock()
}

res := app.Application.CheckTx(req)
return app.callback(
Expand Down Expand Up @@ -212,8 +215,10 @@ func (app *localClient) DeliverTxSync(req types.RequestDeliverTx) (*types.Respon
}

func (app *localClient) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
app.mtx.Lock()
defer app.mtx.Unlock()
if !types.GetCloseCheckTxMutex() {
app.mtx.Lock()
defer app.mtx.Unlock()
}

res := app.Application.CheckTx(req)
return &res, nil
Expand Down
32 changes: 29 additions & 3 deletions abci/types/exchain_flags.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
package types

import "github.com/spf13/viper"
var closeQueryMutex bool
var closeCheckTxMutex bool
var removeCheckTx bool

const FlagCloseMutex = "close-mutex"
const (
FlagCloseMutex = "close-mutex"
FlagCloseCheckTxMutex = "close-checktx-mutex"
FlagRemoveCheckTx = "remove-checktx"
)

func GetCloseMutex() bool {
return viper.GetBool(FlagCloseMutex)
return closeQueryMutex
}

func SetCloseMutex(isClose bool) {
closeQueryMutex = isClose
}

func GetCloseCheckTxMutex() bool {
return closeCheckTxMutex
}

func SetCloseCheckTxMutex(isClose bool) {
closeCheckTxMutex = isClose
}

func GetRemoveCheckTx() bool {
return removeCheckTx
}

func SetRemoveCheckTx(isRemove bool) {
removeCheckTx = isRemove
}
2 changes: 0 additions & 2 deletions cmd/tendermint/commands/run_node_exchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
)

// AddNodeFlags exposes some common configuration options on the command-line
Expand All @@ -20,5 +19,4 @@ func addMoreFlags(cmd *cobra.Command) {
"Node listen address. (0.0.0.0:0 means any interface, any port)")

cmd.Flags().Duration("consensus.timeout_commit", config.Consensus.TimeoutCommit, "Set node block interval time")
cmd.Flags().Bool(abci.FlagCloseMutex, false, "Close local client query mutex for better concurrency")
}
4 changes: 4 additions & 0 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs {
// size per tx, and set the initial capacity based off of that.
// txs := make([]types.Tx, 0, tmmath.MinInt(mem.txs.Len(), max/mem.avgTxSize))
txs := make([]types.Tx, 0, mem.txs.Len())
defer func() {
mem.logger.Info("ReapMaxBytesMaxGas", "ProposingHeight", mem.height+1,
"MempoolTxs", mem.txs.Len(), "ReapTxs", len(txs))
}()
for e := mem.txs.Front(); e != nil; e = e.Next() {
memTx := e.Value.(*mempoolTx)
// Check total size requirement
Expand Down

0 comments on commit 11a1f72

Please sign in to comment.