Skip to content

Commit 5f2b25e

Browse files
committed
dbft: close the pool once the check is finished
It has some goroutines spawned during Init and they keep the reference to pool which can affect memory consumption given that we create these pools just for temporary checks. Signed-off-by: Roman Khimov <[email protected]>
1 parent 7fefef1 commit 5f2b25e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

consensus/dbft/dbft.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ func (c *DBFT) verifyPreBlockCb(b dbft.PreBlock[common.Hash]) bool {
858858
ethBlock := dbftBlock.ToEthBlock()
859859

860860
localPool := c.newLocalPool(parent)
861+
defer localPool.CloseSilently()
861862
errs := localPool.Add(dbftBlock.transactions, false, false)
862863
for i, err := range errs {
863864
if err != nil {
@@ -1093,6 +1094,7 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
10931094
return true
10941095
}
10951096
)
1097+
defer localPool.CloseSilently()
10961098
for i := range pre.transactions {
10971099
var isEnvelope = j < len(pre.envelopesData) && pre.envelopesData[j].index == i
10981100
if !isEnvelope || // pre.transactions[i] is not an envelope, use it as-is.

core/txpool/legacypool/legacypool.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,21 @@ func (pool *LegacyPool) loop() {
475475
}
476476
}
477477

478-
// Close terminates the transaction pool.
479-
func (pool *LegacyPool) Close() error {
478+
// CloseSilently is the same as Close(), but doesn't log. Intended to be used
479+
// for short-lived verification pools (not the main node tx pool).
480+
func (pool *LegacyPool) CloseSilently() {
480481
// Terminate the pool reorger and return
481482
close(pool.reorgShutdownCh)
482483
pool.wg.Wait()
483484

484485
if pool.journal != nil {
485486
pool.journal.close()
486487
}
488+
}
489+
490+
// Close terminates the transaction pool.
491+
func (pool *LegacyPool) Close() error {
492+
pool.CloseSilently()
487493
log.Info("Transaction pool stopped")
488494
return nil
489495
}

0 commit comments

Comments
 (0)