validateTxPoolInternals checks various consistency invariants within the pool.
(pool *TxPool)
| 91 | |
| 92 | // validateTxPoolInternals checks various consistency invariants within the pool. |
| 93 | func validateTxPoolInternals(pool *TxPool) error { |
| 94 | pool.mu.RLock() |
| 95 | defer pool.mu.RUnlock() |
| 96 | |
| 97 | // Ensure the total transaction set is consistent with pending + queued |
| 98 | pending, queued := pool.stats() |
| 99 | if total := pool.all.Count(); total != pending+queued { |
| 100 | return fmt.Errorf("total transaction count %d != %d pending + %d queued", total, pending, queued) |
| 101 | } |
| 102 | if priced := pool.priced.items.Len() - pool.priced.stales; priced != pending+queued { |
| 103 | return fmt.Errorf("total priced transaction count %d != %d pending + %d queued", priced, pending, queued) |
| 104 | } |
| 105 | // Ensure the next nonce to assign is the correct one |
| 106 | for addr, txs := range pool.pending { |
| 107 | // Find the last transaction |
| 108 | var last uint64 |
| 109 | for nonce := range txs.txs.items { |
| 110 | if last < nonce { |
| 111 | last = nonce |
| 112 | } |
| 113 | } |
| 114 | if nonce := pool.pendingState.GetNonce(addr); nonce != last+1 { |
| 115 | return fmt.Errorf("pending nonce mismatch: have %v, want %v", nonce, last+1) |
| 116 | } |
| 117 | } |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | // validateEvents checks that the correct number of transaction addition events |
| 122 | // were fired on the pool's event feed. |
no test coverage detected