Skip to content

Commit

Permalink
tx pool debug level logging optimizations (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
dusan-maksimovic authored Jun 12, 2023
1 parent 5011dd2 commit 5b536ed
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))

Expand All @@ -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...))
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5b536ed

Please sign in to comment.