Skip to content

Commit

Permalink
free known inventory of peer on disconnect (#1427)
Browse files Browse the repository at this point in the history
* free known inventory of peer on disconnect

* free known inventory from heap by setting to nil

* move freeing of cache to closing of the quit channel

* skip dumping transactions for legacy mempool if block height is a pos block height
  • Loading branch information
lazynina authored Oct 30, 2024
1 parent c1b6944 commit 4ca35f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/legacy_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ func MakeDirIfNonExistent(filePath string) error {

func (mp *DeSoMempool) OpenTempDBAndDumpTxns() error {
blockHeight := uint64(mp.bc.blockTip().Height + 1)
if mp.bc.params.IsPoSBlockHeight(blockHeight) {
glog.V(2).Infof("OpenTempDBAndDumpTxns: Not dumping mempool txns for PoS block %v", blockHeight)
return nil
}
allTxns := mp.readOnlyUniversalTransactionList

tempMempoolDBDir := filepath.Join(mp.mempoolDir, "temp_mempool_dump")
Expand Down
8 changes: 6 additions & 2 deletions lib/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type Peer struct {

// Inventory stuff.
// The inventory that we know the peer already has.
knownInventory lru.Set[InvVect]
knownInventory *lru.Set[InvVect]

// Whether the peer is ready to receive INV messages. For a peer that
// still needs a mempool download, this is false.
Expand Down Expand Up @@ -652,7 +652,7 @@ func NewPeer(_id uint64, _conn net.Conn, _isOutbound bool, _netAddr *wire.NetAdd
outputQueueChan: make(chan DeSoMessage),
peerDisconnectedChan: peerDisconnectedChan,
quit: make(chan interface{}),
knownInventory: *lru.NewSet[InvVect](maxKnownInventory),
knownInventory: lru.NewSet[InvVect](maxKnownInventory),
blocksToSend: make(map[BlockHash]bool),
stallTimeoutSeconds: _stallTimeoutSeconds,
minTxFeeRateNanosPerKB: _minFeeRateNanosPerKB,
Expand Down Expand Up @@ -1365,6 +1365,10 @@ func (pp *Peer) Disconnect(reason string) {
// Signaling the quit channel allows all the other goroutines to stop running.
close(pp.quit)

// Free the cache of known inventory.
pp.knownInventory.Clear()
pp.knownInventory = nil

// Add the Peer to donePeers so that the ConnectionManager and Server can do any
// cleanup they need to do.
pp.peerDisconnectedChan <- pp
Expand Down

0 comments on commit 4ca35f0

Please sign in to comment.