@@ -268,6 +268,7 @@ type TxPool struct {
268
268
queueTxEventCh chan * types.Transaction
269
269
reorgDoneCh chan chan struct {}
270
270
reorgShutdownCh chan struct {} // requests shutdown of scheduleReorgLoop
271
+ reorgPauseCh chan bool // requests to pause scheduleReorgLoop
271
272
wg sync.WaitGroup // tracks loop, scheduleReorgLoop
272
273
initDoneCh chan struct {} // is closed once the pool is initialized (for tests)
273
274
@@ -300,6 +301,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain block
300
301
queueTxEventCh : make (chan * types.Transaction ),
301
302
reorgDoneCh : make (chan chan struct {}),
302
303
reorgShutdownCh : make (chan struct {}),
304
+ reorgPauseCh : make (chan bool ),
303
305
initDoneCh : make (chan struct {}),
304
306
gasPrice : new (big.Int ).SetUint64 (config .PriceLimit ),
305
307
}
@@ -1160,13 +1162,14 @@ func (pool *TxPool) scheduleReorgLoop() {
1160
1162
curDone chan struct {} // non-nil while runReorg is active
1161
1163
nextDone = make (chan struct {})
1162
1164
launchNextRun bool
1165
+ reorgsPaused bool
1163
1166
reset * txpoolResetRequest
1164
1167
dirtyAccounts * accountSet
1165
1168
queuedEvents = make (map [common.Address ]* txSortedMap )
1166
1169
)
1167
1170
for {
1168
1171
// Launch next background reorg if needed
1169
- if curDone == nil && launchNextRun {
1172
+ if curDone == nil && launchNextRun && ! reorgsPaused {
1170
1173
// Run the background reorg and announcements
1171
1174
go pool .runReorg (nextDone , reset , dirtyAccounts , queuedEvents )
1172
1175
@@ -1218,6 +1221,7 @@ func (pool *TxPool) scheduleReorgLoop() {
1218
1221
}
1219
1222
close (nextDone )
1220
1223
return
1224
+ case reorgsPaused = <- pool .reorgPauseCh :
1221
1225
}
1222
1226
}
1223
1227
}
@@ -1677,6 +1681,22 @@ func (pool *TxPool) demoteUnexecutables() {
1677
1681
}
1678
1682
}
1679
1683
1684
+ // PauseReorgs stops any new reorg jobs to be started but doesn't interrupt any existing ones that are in flight
1685
+ func (pool * TxPool ) PauseReorgs () {
1686
+ select {
1687
+ case pool .reorgPauseCh <- true :
1688
+ case <- pool .reorgShutdownCh :
1689
+ }
1690
+ }
1691
+
1692
+ // ResumeReorgs allows new reorg jobs to be started
1693
+ func (pool * TxPool ) ResumeReorgs () {
1694
+ select {
1695
+ case pool .reorgPauseCh <- false :
1696
+ case <- pool .reorgShutdownCh :
1697
+ }
1698
+ }
1699
+
1680
1700
// addressByHeartbeat is an account address tagged with its last activity timestamp.
1681
1701
type addressByHeartbeat struct {
1682
1702
address common.Address
0 commit comments