Skip to content

Commit

Permalink
add txpool trace log (#1352)
Browse files Browse the repository at this point in the history
* optimize code

fmt import

add trace-tx-pool log

* clean

Co-authored-by: laizy <[email protected]>
  • Loading branch information
lucas7788 and laizy committed Jul 6, 2021
1 parent 3a989d9 commit 2d1d7d1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func setCommonConfig(ctx *cli.Context, cfg *config.CommonConfig) {
cfg.DataDir = ctx.String(utils.GetFlagName(utils.DataDirFlag))
//add new flag for ethgaslimit
cfg.ETHTxGasLimit = ctx.Uint64(utils.GetFlagName(utils.ETHTxGasLimitFlag))
cfg.TraceTxPool = ctx.Bool(utils.GetFlagName(utils.TraceTxPoolFlag))
}

func setConsensusConfig(ctx *cli.Context, cfg *config.ConsensusConfig) {
Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ var (
Usage: "Disable broadcast tx from network in tx pool",
}

TraceTxPoolFlag = cli.BoolFlag{
Name: "trace-tx-pool",
Usage: "trace info log in tx pool",
}

NonOptionFlag = cli.StringFlag{
Name: "option",
Usage: "this command does not need option, please run directly",
Expand Down
1 change: 1 addition & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ type CommonConfig struct {
ETHTxGasLimit uint64
//NGasLimit uint64
WasmVerifyMethod VerifyMethod
TraceTxPool bool
}

type ConsensusConfig struct {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func setupAPP() *cli.App {
utils.TxpoolPreExecDisableFlag,
utils.DisableSyncVerifyTxFlag,
utils.DisableBroadcastNetTxFlag,
utils.TraceTxPoolFlag,
//p2p setting
utils.ReservedPeersOnlyFlag,
utils.ReservedPeersFileFlag,
Expand Down
10 changes: 5 additions & 5 deletions txnpool/common/transaction_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (tp *TXPool) AddTxList(txEntry *VerifiedTx) errors.ErrCode {
}

if _, ok := tp.validTxMap[txHash]; ok {
log.Infof("AddTxList: transaction %x is already in the pool", txHash)
ShowTraceLog("AddTxList: transaction %x is already in the pool", txHash)
return errors.ErrDuplicatedTx
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func (tp *TXPool) CleanCompletedTransactionList(txs []*types.Transaction, height
if _, ok := tp.validTxMap[tx.Hash()]; ok {
delete(tp.validTxMap, tx.Hash())
cleaned++
log.Infof("transaction cleaned: %s", tx.Hash().ToHexString())
ShowTraceLog("transaction cleaned: %s", tx.Hash().ToHexString())
}
}

Expand Down Expand Up @@ -336,7 +336,7 @@ func (tp *TXPool) GetTxPool(byCount bool, height uint32) ([]*VerifiedTx, []*type
}
}

log.Infof("remove expired tx: %s from pool", tx.Hash().ToHexString())
ShowTraceLog("remove expired tx: %s from pool", tx.Hash().ToHexString())
}
tp.Unlock()

Expand Down Expand Up @@ -433,7 +433,7 @@ func (tp *TXPool) RemoveTxsBelowGasPrice(gasPrice uint64) {
if tx.IsEipTx() {
tp.eipTxPool[tx.Payer].Remove(uint64(tx.Nonce))
}
log.Infof("tx %s cleaned because of lower gas: %d, want: %d", tx.Hash().ToHexString(), txEntry.Tx.GasPrice, gasPrice)
ShowTraceLog("tx %s cleaned because of lower gas: %d, want: %d", tx.Hash().ToHexString(), txEntry.Tx.GasPrice, gasPrice)
}
}
}
Expand All @@ -448,7 +448,7 @@ func (tp *TXPool) Remain() []*types.Transaction {
for _, txEntry := range tp.validTxMap {
txList = append(txList, txEntry.Tx)
delete(tp.validTxMap, txEntry.Tx.Hash())
log.Infof("pool remain: remove tx: %s from pool", txEntry.Tx.Hash().ToHexString())
ShowTraceLog("pool remain: remove tx: %s from pool", txEntry.Tx.Hash().ToHexString())
}

return txList
Expand Down
10 changes: 10 additions & 0 deletions txnpool/common/txnpool_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sync/atomic"

"github.com/ontio/ontology/common"
"github.com/ontio/ontology/common/config"
"github.com/ontio/ontology/common/log"
"github.com/ontio/ontology/core/ledger"
"github.com/ontio/ontology/core/types"
"github.com/ontio/ontology/errors"
Expand Down Expand Up @@ -179,3 +181,11 @@ func GetOngBalance(account common.Address) (*big.Int, error) {

return big.NewInt(0).SetUint64(amount), nil
}

func ShowTraceLog(format string, a ...interface{}) {
if config.DefConfig.Common.TraceTxPool {
log.Infof(format, a)
} else {
log.Debugf(format, a)
}
}
11 changes: 5 additions & 6 deletions txnpool/proc/txnpool_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *TXPoolServer) movePendingTxToPool(txEntry *tc.VerifiedTx) { //solve the

errCode := s.txPool.AddTxList(txEntry)
s.removePendingTxLocked(txEntry.Tx.Hash(), errCode)
log.Infof("tx moved from pending pool to tx pool: %s, err: %s", txEntry.Tx.Hash().ToHexString(), errCode.Error())
tc.ShowTraceLog("tx moved from pending pool to tx pool: %s, err: %s", txEntry.Tx.Hash().ToHexString(), errCode.Error())
}

// removes a transaction from the pending list
Expand All @@ -158,7 +158,7 @@ func (s *TXPoolServer) removePendingTx(hash common.Uint256, err errors.ErrCode)
s.mu.Lock()
s.removePendingTxLocked(hash, err)
s.mu.Unlock()
log.Infof("transaction removed from pending pool: %s, err: %s", hash.ToHexString(), err.Error())
tc.ShowTraceLog("transaction removed from pending pool: %s, err: %s", hash.ToHexString(), err.Error())
}

func (s *TXPoolServer) broadcastTx(pt *serverPendingTx) {
Expand Down Expand Up @@ -228,7 +228,7 @@ func (s *TXPoolServer) startTxVerify(tx *txtypes.Transaction, sender tc.SenderTy
return false
}

log.Infof("transaction added to pending pool: %s", tx.Hash().ToHexString())
tc.ShowTraceLog("transaction added to pending pool: %s", tx.Hash().ToHexString())

if tx := s.getTransaction(tx.Hash()); tx != nil {
log.Debugf("verifyTx: transaction %x already in the txn pool", tx.Hash())
Expand Down Expand Up @@ -274,11 +274,10 @@ func (s *TXPoolServer) getTxPool(byCount bool, height uint32) []*tc.VerifiedTx {

for _, t := range oldTxList {
s.reVerifyStateful(t, tc.NilSender)
log.Infof("reverify transaction : %s", t.Hash().ToHexString())
tc.ShowTraceLog("reverify transaction : %s", t.Hash().ToHexString())
}

log.Infof("get tx pool valid: %d, expired: %d", len(avlTxList), len(oldTxList))

return avlTxList
}

Expand Down Expand Up @@ -369,7 +368,7 @@ func (s *TXPoolServer) reVerifyStateful(tx *txtypes.Transaction, sender tc.Sende
return
}

log.Infof("tx added to pending pool for reverify: %s", tx.Hash().ToHexString())
tc.ShowTraceLog("tx added to pending pool for reverify: %s", tx.Hash().ToHexString())

pt.checkingStatus.SetStateless()
s.stateful.SubmitVerifyTask(tx, s.rspCh)
Expand Down
7 changes: 6 additions & 1 deletion validator/increment/increment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

ethcomm "github.com/ethereum/go-ethereum/common"
"github.com/ontio/ontology/common"
"github.com/ontio/ontology/common/config"
"github.com/ontio/ontology/common/log"
"github.com/ontio/ontology/core/ledger"
"github.com/ontio/ontology/core/types"
Expand Down Expand Up @@ -134,7 +135,11 @@ func (self *IncrementValidator) Verify(tx *types.Transaction, startHeight uint32
}

if uint64(tx.Nonce) != nonceCtx[tx.Payer] {
log.Infof("wrong nonce for %s, tx: %s, exptected: %d, got: %d", tx.Payer.ToBase58(),
trace := log.Debugf
if config.DefConfig.Common.TraceTxPool {
trace = log.Infof
}
trace("wrong nonce for %s, tx: %s, exptected: %d, got: %d", tx.Payer.ToBase58(),
tx.Hash().ToHexString(), nonceCtx[tx.Payer], tx.Nonce)
return fmt.Errorf("wrong nonce for %s, exptected: %d, got: %d", tx.Payer.ToBase58(),
nonceCtx[tx.Payer], tx.Nonce)
Expand Down

0 comments on commit 2d1d7d1

Please sign in to comment.