@@ -227,6 +227,7 @@ type LegacyPool struct {
227
227
queueTxEventCh chan * types.Transaction
228
228
reorgDoneCh chan chan struct {}
229
229
reorgShutdownCh chan struct {} // requests shutdown of scheduleReorgLoop
230
+ reorgPauseCh chan bool // requests to pause scheduleReorgLoop
230
231
wg sync.WaitGroup // tracks loop, scheduleReorgLoop
231
232
initDoneCh chan struct {} // is closed once the pool is initialized (for tests)
232
233
@@ -258,6 +259,7 @@ func New(config Config, chain BlockChain) *LegacyPool {
258
259
queueTxEventCh : make (chan * types.Transaction ),
259
260
reorgDoneCh : make (chan chan struct {}),
260
261
reorgShutdownCh : make (chan struct {}),
262
+ reorgPauseCh : make (chan bool ),
261
263
initDoneCh : make (chan struct {}),
262
264
}
263
265
pool .locals = newAccountSet (pool .signer )
@@ -1198,13 +1200,14 @@ func (pool *LegacyPool) scheduleReorgLoop() {
1198
1200
curDone chan struct {} // non-nil while runReorg is active
1199
1201
nextDone = make (chan struct {})
1200
1202
launchNextRun bool
1203
+ reorgsPaused bool
1201
1204
reset * txpoolResetRequest
1202
1205
dirtyAccounts * accountSet
1203
1206
queuedEvents = make (map [common.Address ]* sortedMap )
1204
1207
)
1205
1208
for {
1206
1209
// Launch next background reorg if needed
1207
- if curDone == nil && launchNextRun {
1210
+ if curDone == nil && launchNextRun && ! reorgsPaused {
1208
1211
// Run the background reorg and announcements
1209
1212
go pool .runReorg (nextDone , reset , dirtyAccounts , queuedEvents )
1210
1213
@@ -1256,6 +1259,7 @@ func (pool *LegacyPool) scheduleReorgLoop() {
1256
1259
}
1257
1260
close (nextDone )
1258
1261
return
1262
+ case reorgsPaused = <- pool .reorgPauseCh :
1259
1263
}
1260
1264
}
1261
1265
}
@@ -1705,6 +1709,24 @@ func (pool *LegacyPool) demoteUnexecutables() {
1705
1709
}
1706
1710
}
1707
1711
1712
+ // PauseReorgs stops any new reorg jobs to be started but doesn't interrupt any existing ones that are in flight
1713
+ // Keep in mind this function might block, although it is not expected to block for any significant amount of time
1714
+ func (pool * TxPool ) PauseReorgs () {
1715
+ select {
1716
+ case pool .reorgPauseCh <- true :
1717
+ case <- pool .reorgShutdownCh :
1718
+ }
1719
+ }
1720
+
1721
+ // ResumeReorgs allows new reorg jobs to be started.
1722
+ // Keep in mind this function might block, although it is not expected to block for any significant amount of time
1723
+ func (pool * TxPool ) ResumeReorgs () {
1724
+ select {
1725
+ case pool .reorgPauseCh <- false :
1726
+ case <- pool .reorgShutdownCh :
1727
+ }
1728
+ }
1729
+
1708
1730
// addressByHeartbeat is an account address tagged with its last activity timestamp.
1709
1731
type addressByHeartbeat struct {
1710
1732
address common.Address
0 commit comments