server/mempool: Evict orphans on peer disconnect.

This removes any remaining orphan transactions that were sent by a peer
when it disconnects since it is extremely unlikely that the missing
parents will ever materialize from elsewhere.
This commit is contained in:
Dave Collins 2016-10-28 12:49:26 -05:00
parent 2124accf62
commit 6d5714e1b7
No known key found for this signature in database
GPG key ID: B8904D9D9C93D1F2
2 changed files with 18 additions and 1 deletions

9
log.go
View file

@ -220,3 +220,12 @@ func directionString(inbound bool) string {
}
return "outbound"
}
// pickNoun returns the singular or plural form of a noun depending
// on the count n.
func pickNoun(n uint64, singular, plural string) string {
if n == 1 {
return singular
}
return plural
}

View file

@ -1596,7 +1596,7 @@ func (s *server) outboundPeerConnected(c *connmgr.ConnReq, conn net.Conn) {
}
// peerDoneHandler handles peer disconnects by notifiying the server that it's
// done.
// done along with other performing other desirable cleanup.
func (s *server) peerDoneHandler(sp *serverPeer) {
sp.WaitForDisconnect()
s.donePeers <- sp
@ -1604,6 +1604,14 @@ func (s *server) peerDoneHandler(sp *serverPeer) {
// Only tell block manager we are gone if we ever told it we existed.
if sp.VersionKnown() {
s.blockManager.DonePeer(sp)
// Evict any remaining orphans that were sent by the peer.
numEvicted := s.txMemPool.RemoveOrphansByTag(mempool.Tag(sp.ID()))
if numEvicted > 0 {
txmpLog.Debugf("Evicted %d %s from peer %v (id %d)",
numEvicted, pickNoun(numEvicted, "orphan",
"orphans"), sp, sp.ID())
}
}
close(sp.quit)
}