docs(core/txpool): notice Clear is not for production #31567 (#2184)

This commit is contained in:
Daniel Liu 2026-03-17 16:23:42 +08:00 committed by GitHub
parent 3a505d50b0
commit 1e5d6e5d1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View file

@ -1052,8 +1052,8 @@ func (pool *LegacyPool) addRemoteSync(tx *types.Transaction) error {
// Add enqueues a batch of transactions into the pool if they are valid. // Add enqueues a batch of transactions into the pool if they are valid.
// //
// If sync is set, the method will block until all internal maintenance related // Note, if sync is set the method will block until all internal maintenance
// to the add is finished. Only use this during tests for determinism! // related to the add is finished. Only use this during tests for determinism.
func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error { func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error {
// Filter out known ones without obtaining the pool lock or recovering signatures // Filter out known ones without obtaining the pool lock or recovering signatures
var ( var (
@ -2003,6 +2003,9 @@ func numSlots(tx *types.Transaction) int {
// Clear implements txpool.SubPool, removing all tracked txs from the pool // Clear implements txpool.SubPool, removing all tracked txs from the pool
// and rotating the journal. // and rotating the journal.
//
// Note, do not use this in production / live code. In live code, the pool is
// meant to reset on a separate thread to avoid DoS vectors.
func (pool *LegacyPool) Clear() { func (pool *LegacyPool) Clear() {
pool.mu.Lock() pool.mu.Lock()
defer pool.mu.Unlock() defer pool.mu.Unlock()

View file

@ -275,8 +275,9 @@ func (p *TxPool) Get(hash common.Hash) *types.Transaction {
} }
// Add enqueues a batch of transactions into the pool if they are valid. Due // Add enqueues a batch of transactions into the pool if they are valid. Due
// to the large transaction churn, add may postpone fully integrating the tx //
// to a later point to batch multiple ones together. // Note, if sync is set the method will block until all internal maintenance
// related to the add is finished. Only use this during tests for determinism.
func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error { func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
// Split the input transactions between the subpools. It shouldn't really // Split the input transactions between the subpools. It shouldn't really
// happen that we receive merged batches, but better graceful than strange // happen that we receive merged batches, but better graceful than strange
@ -456,8 +457,8 @@ func (pool *TxPool) IsSigner(addr common.Address) bool {
// internal background reset operations. This method will run an explicit reset // internal background reset operations. This method will run an explicit reset
// operation to ensure the pool stabilises, thus avoiding flakey behavior. // operation to ensure the pool stabilises, thus avoiding flakey behavior.
// //
// Note, do not use this in production / live code. In live code, the pool is // Note, this method is only used for testing and is susceptible to DoS vectors.
// meant to reset on a separate thread to avoid DoS vectors. // In production code, the pool is meant to reset on a separate thread.
func (p *TxPool) Sync() error { func (p *TxPool) Sync() error {
sync := make(chan error) sync := make(chan error)
select { select {