diff --git a/blockmanager.go b/blockmanager.go index 05df36b0..4b15d638 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -1138,14 +1138,16 @@ func (b *blockManager) handleNotifyMsg(notification *btcchain.Notification) { } // Remove all of the transactions (except the coinbase) in the - // connected block from the transaction pool. Also, remove any + // connected block from the transaction pool. Secondly, remove any // transactions which are now double spends as a result of these - // new transactions. Note that removing a transaction from + // new transactions. Finally, remove any transaction that is + // no longer an orphan. Note that removing a transaction from // pool also removes any transactions which depend on it, // recursively. for _, tx := range block.Transactions()[1:] { b.server.txMemPool.RemoveTransaction(tx) b.server.txMemPool.RemoveDoubleSpends(tx) + b.server.txMemPool.RemoveOrphan(tx.Sha()) } if r := b.server.rpcServer; r != nil { diff --git a/mempool.go b/mempool.go index cbdafcbd..3fc5fe36 100644 --- a/mempool.go +++ b/mempool.go @@ -396,9 +396,8 @@ func calcMinRequiredTxRelayFee(serializedSize int64) int64 { return minFee } -// removeOrphan removes the passed orphan transaction from the orphan pool and -// previous orphan index. -// +// removeOrphan is the internal function which implements the public +// RemoveOrphan. See the comment for RemoveOrphan for more details. // This function MUST be called with the mempool lock held (for writes). func (mp *txMemPool) removeOrphan(txHash *btcwire.ShaHash) { // Nothing to do if passed tx is not an orphan. @@ -430,6 +429,15 @@ func (mp *txMemPool) removeOrphan(txHash *btcwire.ShaHash) { delete(mp.orphans, *txHash) } +// RemoveOrphan removes the passed orphan transaction from the orphan pool and +// previous orphan index. +// This function is safe for concurrent access. +func (mp *txMemPool) RemoveOrphan(txHash *btcwire.ShaHash) { + mp.Lock() + mp.removeOrphan(txHash) + mp.Unlock() +} + // limitNumOrphans limits the number of orphan transactions by evicting a random // orphan if adding a new one would cause it to overflow the max allowed. //