From 4ad8622af968c9a6ce24f16573ecc953a808a3b8 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 18 Sep 2014 10:23:36 -0400 Subject: [PATCH] Remove transactions from orphan pool. This change removes transactions from a newly connected block from the orphan pool if they exist. Additionally, any orphan transactions that are no longer orphan transactions are moved to the mempool and inv'd to the currently connected peers. --- blockmanager.go | 6 ++++-- mempool.go | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) 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. //