Skip to content

Commit 2d1d7d1

Browse files
lucas7788laizy
andcommitted
add txpool trace log (#1352)
* optimize code fmt import add trace-tx-pool log * clean Co-authored-by: laizy <aochyi@126.com>
1 parent 3a989d9 commit 2d1d7d1

File tree

8 files changed

+34
-12
lines changed

8 files changed

+34
-12
lines changed

cmd/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func setCommonConfig(ctx *cli.Context, cfg *config.CommonConfig) {
142142
cfg.DataDir = ctx.String(utils.GetFlagName(utils.DataDirFlag))
143143
//add new flag for ethgaslimit
144144
cfg.ETHTxGasLimit = ctx.Uint64(utils.GetFlagName(utils.ETHTxGasLimitFlag))
145+
cfg.TraceTxPool = ctx.Bool(utils.GetFlagName(utils.TraceTxPoolFlag))
145146
}
146147

147148
func setConsensusConfig(ctx *cli.Context, cfg *config.ConsensusConfig) {

cmd/utils/flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ var (
520520
Usage: "Disable broadcast tx from network in tx pool",
521521
}
522522

523+
TraceTxPoolFlag = cli.BoolFlag{
524+
Name: "trace-tx-pool",
525+
Usage: "trace info log in tx pool",
526+
}
527+
523528
NonOptionFlag = cli.StringFlag{
524529
Name: "option",
525530
Usage: "this command does not need option, please run directly",

common/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ type CommonConfig struct {
637637
ETHTxGasLimit uint64
638638
//NGasLimit uint64
639639
WasmVerifyMethod VerifyMethod
640+
TraceTxPool bool
640641
}
641642

642643
type ConsensusConfig struct {

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func setupAPP() *cli.App {
103103
utils.TxpoolPreExecDisableFlag,
104104
utils.DisableSyncVerifyTxFlag,
105105
utils.DisableBroadcastNetTxFlag,
106+
utils.TraceTxPoolFlag,
106107
//p2p setting
107108
utils.ReservedPeersOnlyFlag,
108109
utils.ReservedPeersFileFlag,

txnpool/common/transaction_pool.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (tp *TXPool) AddTxList(txEntry *VerifiedTx) errors.ErrCode {
190190
}
191191

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

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

@@ -336,7 +336,7 @@ func (tp *TXPool) GetTxPool(byCount bool, height uint32) ([]*VerifiedTx, []*type
336336
}
337337
}
338338

339-
log.Infof("remove expired tx: %s from pool", tx.Hash().ToHexString())
339+
ShowTraceLog("remove expired tx: %s from pool", tx.Hash().ToHexString())
340340
}
341341
tp.Unlock()
342342

@@ -433,7 +433,7 @@ func (tp *TXPool) RemoveTxsBelowGasPrice(gasPrice uint64) {
433433
if tx.IsEipTx() {
434434
tp.eipTxPool[tx.Payer].Remove(uint64(tx.Nonce))
435435
}
436-
log.Infof("tx %s cleaned because of lower gas: %d, want: %d", tx.Hash().ToHexString(), txEntry.Tx.GasPrice, gasPrice)
436+
ShowTraceLog("tx %s cleaned because of lower gas: %d, want: %d", tx.Hash().ToHexString(), txEntry.Tx.GasPrice, gasPrice)
437437
}
438438
}
439439
}
@@ -448,7 +448,7 @@ func (tp *TXPool) Remain() []*types.Transaction {
448448
for _, txEntry := range tp.validTxMap {
449449
txList = append(txList, txEntry.Tx)
450450
delete(tp.validTxMap, txEntry.Tx.Hash())
451-
log.Infof("pool remain: remove tx: %s from pool", txEntry.Tx.Hash().ToHexString())
451+
ShowTraceLog("pool remain: remove tx: %s from pool", txEntry.Tx.Hash().ToHexString())
452452
}
453453

454454
return txList

txnpool/common/txnpool_common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"sync/atomic"
2424

2525
"github.com/ontio/ontology/common"
26+
"github.com/ontio/ontology/common/config"
27+
"github.com/ontio/ontology/common/log"
2628
"github.com/ontio/ontology/core/ledger"
2729
"github.com/ontio/ontology/core/types"
2830
"github.com/ontio/ontology/errors"
@@ -179,3 +181,11 @@ func GetOngBalance(account common.Address) (*big.Int, error) {
179181

180182
return big.NewInt(0).SetUint64(amount), nil
181183
}
184+
185+
func ShowTraceLog(format string, a ...interface{}) {
186+
if config.DefConfig.Common.TraceTxPool {
187+
log.Infof(format, a)
188+
} else {
189+
log.Debugf(format, a)
190+
}
191+
}

txnpool/proc/txnpool_server.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (s *TXPoolServer) movePendingTxToPool(txEntry *tc.VerifiedTx) { //solve the
147147

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

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

164164
func (s *TXPoolServer) broadcastTx(pt *serverPendingTx) {
@@ -228,7 +228,7 @@ func (s *TXPoolServer) startTxVerify(tx *txtypes.Transaction, sender tc.SenderTy
228228
return false
229229
}
230230

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

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

275275
for _, t := range oldTxList {
276276
s.reVerifyStateful(t, tc.NilSender)
277-
log.Infof("reverify transaction : %s", t.Hash().ToHexString())
277+
tc.ShowTraceLog("reverify transaction : %s", t.Hash().ToHexString())
278278
}
279279

280280
log.Infof("get tx pool valid: %d, expired: %d", len(avlTxList), len(oldTxList))
281-
282281
return avlTxList
283282
}
284283

@@ -369,7 +368,7 @@ func (s *TXPoolServer) reVerifyStateful(tx *txtypes.Transaction, sender tc.Sende
369368
return
370369
}
371370

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

374373
pt.checkingStatus.SetStateless()
375374
s.stateful.SubmitVerifyTask(tx, s.rspCh)

validator/increment/increment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
ethcomm "github.com/ethereum/go-ethereum/common"
2626
"github.com/ontio/ontology/common"
27+
"github.com/ontio/ontology/common/config"
2728
"github.com/ontio/ontology/common/log"
2829
"github.com/ontio/ontology/core/ledger"
2930
"github.com/ontio/ontology/core/types"
@@ -134,7 +135,11 @@ func (self *IncrementValidator) Verify(tx *types.Transaction, startHeight uint32
134135
}
135136

136137
if uint64(tx.Nonce) != nonceCtx[tx.Payer] {
137-
log.Infof("wrong nonce for %s, tx: %s, exptected: %d, got: %d", tx.Payer.ToBase58(),
138+
trace := log.Debugf
139+
if config.DefConfig.Common.TraceTxPool {
140+
trace = log.Infof
141+
}
142+
trace("wrong nonce for %s, tx: %s, exptected: %d, got: %d", tx.Payer.ToBase58(),
138143
tx.Hash().ToHexString(), nonceCtx[tx.Payer], tx.Nonce)
139144
return fmt.Errorf("wrong nonce for %s, exptected: %d, got: %d", tx.Payer.ToBase58(),
140145
nonceCtx[tx.Payer], tx.Nonce)

0 commit comments

Comments
 (0)