Skip to content

Commit d51978e

Browse files
authoredDec 12, 2024··
fix: remove go routines for RecheckTx (#1553)
Closes: #1552
1 parent 890a59b commit d51978e

File tree

2 files changed

+34
-58
lines changed

2 files changed

+34
-58
lines changed
 

‎mempool/cat/pool.go

+19-27
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ package cat
33
import (
44
"errors"
55
"fmt"
6-
"runtime"
76
"sort"
87
"sync"
98
"time"
109

11-
"github.com/creachadair/taskgroup"
12-
1310
abci "github.com/tendermint/tendermint/abci/types"
1411
"github.com/tendermint/tendermint/config"
1512
"github.com/tendermint/tendermint/libs/log"
@@ -672,36 +669,31 @@ func (txmp *TxPool) recheckTransactions() {
672669
)
673670

674671
// Collect transactions currently in the mempool requiring recheck.
672+
// TODO: we are iterating over a map, which may scramble the order of transactions
673+
// such that they are not in order, dictated by nonce and then priority. This may
674+
// cause transactions to needlessly be kicked out in RecheckTx
675675
wtxs := txmp.store.getAllTxs()
676676

677677
// Issue CheckTx calls for each remaining transaction, and when all the
678678
// rechecks are complete signal watchers that transactions may be available.
679-
go func() {
680-
g, start := taskgroup.New(nil).Limit(2 * runtime.NumCPU())
681-
682-
for _, wtx := range wtxs {
683-
wtx := wtx
684-
start(func() error {
685-
// The response for this CheckTx is handled by the default recheckTxCallback.
686-
rsp, err := txmp.proxyAppConn.CheckTxSync(abci.RequestCheckTx{
687-
Tx: wtx.tx,
688-
Type: abci.CheckTxType_Recheck,
689-
})
690-
if err != nil {
691-
txmp.logger.Error("failed to execute CheckTx during recheck",
692-
"err", err, "key", fmt.Sprintf("%x", wtx.key))
693-
} else {
694-
txmp.handleRecheckResult(wtx, rsp)
695-
}
696-
return nil
697-
})
679+
for _, wtx := range wtxs {
680+
wtx := wtx
681+
// The response for this CheckTx is handled by the default recheckTxCallback.
682+
rsp, err := txmp.proxyAppConn.CheckTxSync(abci.RequestCheckTx{
683+
Tx: wtx.tx,
684+
Type: abci.CheckTxType_Recheck,
685+
})
686+
if err != nil {
687+
txmp.logger.Error("failed to execute CheckTx during recheck",
688+
"err", err, "key", fmt.Sprintf("%x", wtx.key))
689+
} else {
690+
txmp.handleRecheckResult(wtx, rsp)
698691
}
699-
_ = txmp.proxyAppConn.FlushAsync()
692+
}
693+
_ = txmp.proxyAppConn.FlushAsync()
700694

701-
// When recheck is complete, trigger a notification for more transactions.
702-
_ = g.Wait()
703-
txmp.notifyTxsAvailable()
704-
}()
695+
// When recheck is complete, trigger a notification for more transactions.
696+
txmp.notifyTxsAvailable()
705697
}
706698

707699
// availableBytes returns the number of bytes available in the mempool.

‎mempool/v1/mempool.go

+15-31
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package v1
22

33
import (
44
"fmt"
5-
"runtime"
65
"sort"
76
"sync"
87
"sync/atomic"
98
"time"
109

11-
"github.com/creachadair/taskgroup"
12-
1310
abci "github.com/tendermint/tendermint/abci/types"
1411
"github.com/tendermint/tendermint/config"
1512
"github.com/tendermint/tendermint/libs/clist"
@@ -650,8 +647,6 @@ func (txmp *TxMempool) insertTx(wtx *WrappedTx) {
650647
// that case is handled by addNewTransaction instead.
651648
func (txmp *TxMempool) handleRecheckResult(tx types.Tx, checkTxRes *abci.ResponseCheckTx) {
652649
txmp.metrics.RecheckTimes.Add(1)
653-
txmp.mtx.Lock()
654-
defer txmp.mtx.Unlock()
655650

656651
// Find the transaction reported by the ABCI callback. It is possible the
657652
// transaction was evicted during the recheck, in which case the transaction
@@ -713,34 +708,23 @@ func (txmp *TxMempool) recheckTransactions() {
713708

714709
// Issue CheckTx calls for each remaining transaction, and when all the
715710
// rechecks are complete signal watchers that transactions may be available.
716-
go func() {
717-
g, start := taskgroup.New(nil).Limit(2 * runtime.NumCPU())
718-
719-
for _, wtx := range wtxs {
720-
wtx := wtx
721-
start(func() error {
722-
// The response for this CheckTx is handled by the default recheckTxCallback.
723-
rsp, err := txmp.proxyAppConn.CheckTxSync(abci.RequestCheckTx{
724-
Tx: wtx.tx,
725-
Type: abci.CheckTxType_Recheck,
726-
})
727-
if err != nil {
728-
txmp.logger.Error("failed to execute CheckTx during recheck",
729-
"err", err, "hash", fmt.Sprintf("%x", wtx.tx.Hash()))
730-
} else {
731-
txmp.handleRecheckResult(wtx.tx, rsp)
732-
}
733-
return nil
734-
})
711+
for _, wtx := range wtxs {
712+
wtx := wtx
713+
// The response for this CheckTx is handled by the default recheckTxCallback.
714+
rsp, err := txmp.proxyAppConn.CheckTxSync(abci.RequestCheckTx{
715+
Tx: wtx.tx,
716+
Type: abci.CheckTxType_Recheck,
717+
})
718+
if err != nil {
719+
txmp.logger.Error("failed to execute CheckTx during recheck",
720+
"err", err, "hash", fmt.Sprintf("%x", wtx.tx.Hash()))
721+
} else {
722+
txmp.handleRecheckResult(wtx.tx, rsp)
735723
}
736-
_ = txmp.proxyAppConn.FlushAsync()
724+
}
725+
_ = txmp.proxyAppConn.FlushAsync()
737726

738-
// When recheck is complete, trigger a notification for more transactions.
739-
_ = g.Wait()
740-
txmp.mtx.Lock()
741-
defer txmp.mtx.Unlock()
742-
txmp.notifyTxsAvailable()
743-
}()
727+
txmp.notifyTxsAvailable()
744728
}
745729

746730
// canAddTx returns an error if we cannot insert the provided *WrappedTx into

0 commit comments

Comments
 (0)
Please sign in to comment.