From 5b536ed9f688d4589f43b80f02722654a087f2b4 Mon Sep 17 00:00:00 2001 From: Dusan Maksimovic <94966669+dusan-maksimovic@users.noreply.github.com> Date: Mon, 12 Jun 2023 14:50:56 +0200 Subject: [PATCH] tx pool debug level logging optimizations (#1609) --- txpool/txpool.go | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/txpool/txpool.go b/txpool/txpool.go index 6e562882d7..57f2187edc 100644 --- a/txpool/txpool.go +++ b/txpool/txpool.go @@ -427,11 +427,14 @@ func (p *TxPool) Drop(tx *types.Transaction) { clearAccountQueue(dropped) p.eventManager.signalEvent(proto.EventType_DROPPED, tx.Hash) - p.logger.Debug("dropped account txs", - "num", droppedCount, - "next_nonce", nextNonce, - "address", tx.From.String(), - ) + + if p.logger.IsDebug() { + p.logger.Debug("dropped account txs", + "num", droppedCount, + "next_nonce", nextNonce, + "address", tx.From.String(), + ) + } } // Demote excludes an account from being further processed during block building @@ -440,10 +443,12 @@ func (p *TxPool) Drop(tx *types.Transaction) { func (p *TxPool) Demote(tx *types.Transaction) { account := p.accounts.get(tx.From) if account.Demotions() >= maxAccountDemotions { - p.logger.Debug( - "Demote: threshold reached - dropping account", - "addr", tx.From.String(), - ) + if p.logger.IsDebug() { + p.logger.Debug( + "Demote: threshold reached - dropping account", + "addr", tx.From.String(), + ) + } p.Drop(tx) @@ -718,10 +723,12 @@ func (p *TxPool) pruneAccountsWithNonceHoles() { // successful, an account is created for this address // (only once) and an enqueueRequest is signaled. func (p *TxPool) addTx(origin txOrigin, tx *types.Transaction) error { - p.logger.Debug("add tx", - "origin", origin.String(), - "hash", tx.Hash.String(), - ) + if p.logger.IsDebug() { + p.logger.Debug("add tx", + "origin", origin.String(), + "hash", tx.Hash.String(), + ) + } // validate incoming tx if err := p.validateTx(tx); err != nil { @@ -786,7 +793,9 @@ func (p *TxPool) handleEnqueueRequest(req enqueueRequest) { return } - p.logger.Debug("enqueue request", "hash", tx.Hash.String()) + if p.logger.IsDebug() { + p.logger.Debug("enqueue request", "hash", tx.Hash.String()) + } p.gauge.increase(slotsRequired(tx)) @@ -810,7 +819,9 @@ func (p *TxPool) handlePromoteRequest(req promoteRequest) { // promote enqueued txs promoted, pruned := account.promote() - p.logger.Debug("promote request", "promoted", promoted, "addr", addr.String()) + if p.logger.IsDebug() { + p.logger.Debug("promote request", "promoted", promoted, "addr", addr.String()) + } p.index.remove(pruned...) p.gauge.decrease(slotsRequired(pruned...)) @@ -854,7 +865,9 @@ func (p *TxPool) addGossipTx(obj interface{}, _ peer.ID) { // add tx if err := p.addTx(gossip, tx); err != nil { if errors.Is(err, ErrAlreadyKnown) { - p.logger.Debug("rejecting known tx (gossip)", "hash", tx.Hash.String()) + if p.logger.IsDebug() { + p.logger.Debug("rejecting known tx (gossip)", "hash", tx.Hash.String()) + } return }