Skip to content

Commit

Permalink
avoid double insert
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlanders committed Jan 26, 2024
1 parent 1e88549 commit 3b2c3bb
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ func (txmp *TxMempool) CheckTx(
"nonce", res.EVMNonce,
"address", res.EVMSenderAddress,
)

if wtx.gossipEl != txmp.recheckCursor {
panic("corrupted reCheckTx cursor")
}
txmp.removeTx(wtx, !txmp.config.KeepInvalidTxsInCache)
} else {
// otherwise add to pending txs store
Expand Down Expand Up @@ -659,15 +655,19 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, res *abci.ResponseCheck
txmp.metrics.Size.Set(float64(txmp.Size()))
txmp.metrics.PendingSize.Set(float64(txmp.PendingSize()))

txmp.insertTx(wtx)
txmp.logger.Debug(
"inserted good transaction",
"priority", wtx.priority,
"tx", fmt.Sprintf("%X", wtx.tx.Hash()),
"height", txmp.height,
"num_txs", txmp.Size(),
)
txmp.notifyTxsAvailable()
if txmp.insertTx(wtx) {
txmp.logger.Debug(
"inserted good transaction",
"priority", wtx.priority,
"tx", fmt.Sprintf("%X", wtx.tx.Hash()),
"height", txmp.height,
"num_txs", txmp.Size(),
)
txmp.notifyTxsAvailable()
} else {
fmt.Println("DEBUG: ******************************** NOT INSERTING, ALREADY EXISTS")
}

return nil
}

Expand Down Expand Up @@ -843,8 +843,10 @@ func (txmp *TxMempool) mustNotExist(msg string, wtx *WrappedTx) {
}
}

func (txmp *TxMempool) insertTx(wtx *WrappedTx) {
txmp.mustNotExist("insertTx", wtx)
func (txmp *TxMempool) insertTx(wtx *WrappedTx) bool {
if txmp.isInMempool(wtx.tx) {
return false
}

txmp.txStore.SetTx(wtx)
txmp.priorityIndex.PushTx(wtx)
Expand All @@ -858,6 +860,7 @@ func (txmp *TxMempool) insertTx(wtx *WrappedTx) {
wtx.gossipEl = gossipEl

atomic.AddInt64(&txmp.sizeBytes, int64(wtx.Size()))
return true
}

func (txmp *TxMempool) removeTx(wtx *WrappedTx, removeFromCache bool) {
Expand Down

0 comments on commit 3b2c3bb

Please sign in to comment.