Skip to content

Commit 60b922f

Browse files
authored
core/txpool: add notice to Clear that is not meant for production code (#31567)
The `Sync(..)` function explicitly says not to rely on in production code, but it is used in `Clear(..)` so should add a similar mention.
1 parent a7f24c2 commit 60b922f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,9 @@ func (p *BlobPool) GetBlobs(vhashes []common.Hash) ([]*kzg4844.Blob, []*kzg4844.
13491349

13501350
// Add inserts a set of blob transactions into the pool if they pass validation (both
13511351
// consensus validity and pool restrictions).
1352+
//
1353+
// Note, if sync is set the method will block until all internal maintenance
1354+
// related to the add is finished. Only use this during tests for determinism.
13521355
func (p *BlobPool) Add(txs []*types.Transaction, sync bool) []error {
13531356
var (
13541357
adds = make([]*types.Transaction, 0, len(txs))
@@ -1792,6 +1795,9 @@ func (p *BlobPool) Status(hash common.Hash) txpool.TxStatus {
17921795

17931796
// Clear implements txpool.SubPool, removing all tracked transactions
17941797
// from the blob pool and persistent store.
1798+
//
1799+
// Note, do not use this in production / live code. In live code, the pool is
1800+
// meant to reset on a separate thread to avoid DoS vectors.
17951801
func (p *BlobPool) Clear() {
17961802
p.lock.Lock()
17971803
defer p.lock.Unlock()

core/txpool/legacypool/legacypool.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,8 @@ func (pool *LegacyPool) addRemoteSync(tx *types.Transaction) error {
927927

928928
// Add enqueues a batch of transactions into the pool if they are valid.
929929
//
930-
// If sync is set, the method will block until all internal maintenance related
931-
// to the add is finished. Only use this during tests for determinism!
930+
// Note, if sync is set the method will block until all internal maintenance
931+
// related to the add is finished. Only use this during tests for determinism.
932932
func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error {
933933
// Filter out known ones without obtaining the pool lock or recovering signatures
934934
var (
@@ -1886,6 +1886,9 @@ func numSlots(tx *types.Transaction) int {
18861886

18871887
// Clear implements txpool.SubPool, removing all tracked txs from the pool
18881888
// and rotating the journal.
1889+
//
1890+
// Note, do not use this in production / live code. In live code, the pool is
1891+
// meant to reset on a separate thread to avoid DoS vectors.
18891892
func (pool *LegacyPool) Clear() {
18901893
pool.mu.Lock()
18911894
defer pool.mu.Unlock()

core/txpool/txpool.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ func (p *TxPool) ValidateTxBasics(tx *types.Transaction) error {
350350
// Add enqueues a batch of transactions into the pool if they are valid. Due
351351
// to the large transaction churn, add may postpone fully integrating the tx
352352
// to a later point to batch multiple ones together.
353+
//
354+
// Note, if sync is set the method will block until all internal maintenance
355+
// related to the add is finished. Only use this during tests for determinism.
353356
func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
354357
// Split the input transactions between the subpools. It shouldn't really
355358
// happen that we receive merged batches, but better graceful than strange
@@ -503,8 +506,8 @@ func (p *TxPool) Status(hash common.Hash) TxStatus {
503506
// internal background reset operations. This method will run an explicit reset
504507
// operation to ensure the pool stabilises, thus avoiding flakey behavior.
505508
//
506-
// Note, do not use this in production / live code. In live code, the pool is
507-
// meant to reset on a separate thread to avoid DoS vectors.
509+
// Note, this method is only used for testing and is susceptible to DoS vectors.
510+
// In production code, the pool is meant to reset on a separate thread.
508511
func (p *TxPool) Sync() error {
509512
sync := make(chan error)
510513
select {
@@ -516,6 +519,10 @@ func (p *TxPool) Sync() error {
516519
}
517520

518521
// Clear removes all tracked txs from the subpools.
522+
//
523+
// Note, this method invokes Sync() and is only used for testing, because it is
524+
// susceptible to DoS vectors. In production code, the pool is meant to reset on
525+
// a separate thread.
519526
func (p *TxPool) Clear() {
520527
// Invoke Sync to ensure that txs pending addition don't get added to the pool after
521528
// the subpools are subsequently cleared

0 commit comments

Comments
 (0)