+
+func (tp *TxPool) txExpireWorker() {
+ ticker := time.NewTicker(txExpireScanInterval)
+ defer ticker.Stop()
+
+ for now := range ticker.C {
+ tp.expireTx(now)
+ }
+}
+
+// expireTx expires all the Txs that before the input time range
+func (tp *TxPool) expireTx(now time.Time) {
+ tp.mtx.Lock()
+ defer tp.mtx.Unlock()
+
+ cutOff := now.Add(-txTTL)
+ for hash, txD := range tp.pool {
+ if txD.Added.Before(cutOff) {
+ tp.removeTransaction(&hash)
+ }
+ }
+}