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:
parent
2124accf62
commit
6d5714e1b7
2 changed files with 18 additions and 1 deletions
9
log.go
9
log.go
|
@ -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
|
||||
}
|
||||
|
|
10
server.go
10
server.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue