Skip to content

Commit e18accc

Browse files
committed
Merge bitcoin#30186: fuzz: increase txorphan harness stability
8defc18 scripted-diff: Replace nNextSweep with m_next_sweep (marcofleon) 0048680 increase txorphan harness stability (marcofleon) Pull request description: This moves `nNextSweep` from being a static variable in `LimitOrphans` to being a member of the `TxOrphanage` class. This improves the stability of the `txorphan` fuzz harness, as each orphanage (created every iteration) now has its own value for `nNextSweep`. ACKs for top commit: maflcko: utACK 8defc18 dergoegge: Code review ACK 8defc18 glozow: utACK 8defc18, I can rebase on this pretty easily Tree-SHA512: 54d4a5074def764f6c895308b94e417662d2f21f157925421131745f22743907df59971f4ce545063658cd74ec133792cdd8df96ae3e69af8314e9b0ff899d48
2 parents 457e184 + 8defc18 commit e18accc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/txorphanage.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
119119
LOCK(m_mutex);
120120

121121
unsigned int nEvicted = 0;
122-
static NodeSeconds nNextSweep;
123122
auto nNow{Now<NodeSeconds>()};
124-
if (nNextSweep <= nNow) {
123+
if (m_next_sweep <= nNow) {
125124
// Sweep out expired orphan pool entries:
126125
int nErased = 0;
127126
auto nMinExpTime{nNow + ORPHAN_TX_EXPIRE_TIME - ORPHAN_TX_EXPIRE_INTERVAL};
@@ -136,7 +135,7 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans, FastRandomContext& rng)
136135
}
137136
}
138137
// Sweep again 5 minutes after the next entry that expires in order to batch the linear scan.
139-
nNextSweep = nMinExpTime + ORPHAN_TX_EXPIRE_INTERVAL;
138+
m_next_sweep = nMinExpTime + ORPHAN_TX_EXPIRE_INTERVAL;
140139
if (nErased > 0) LogPrint(BCLog::TXPACKAGES, "Erased %d orphan tx due to expiration\n", nErased);
141140
}
142141
while (m_orphans.size() > max_orphans)

src/txorphanage.h

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class TxOrphanage {
105105

106106
/** Erase an orphan by wtxid */
107107
int EraseTxNoLock(const Wtxid& wtxid) EXCLUSIVE_LOCKS_REQUIRED(m_mutex);
108+
109+
/** Timestamp for the next scheduled sweep of expired orphans */
110+
NodeSeconds m_next_sweep GUARDED_BY(m_mutex){0s};
108111
};
109112

110113
#endif // BITCOIN_TXORPHANAGE_H

0 commit comments

Comments
 (0)