From f57e2c3577ba4acb23b389361809b91f34a6d83c Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 9 Dec 2022 14:54:27 +0800 Subject: [PATCH] Bug Fix on memory leak when doing send tx, block etc to peers (#212) * resolve conflict * update version number --- .gitignore | 2 +- eth/peer.go | 19 +++++++++++++++++++ internal/debug/flags.go | 2 +- params/version.go | 6 +++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 6c6f16ee66..015aa05495 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,4 @@ profile.cov **/yarn-error.log coverage.txt -go.sum \ No newline at end of file +go.sum diff --git a/eth/peer.go b/eth/peer.go index 283a1bfc56..66fe2d137c 100644 --- a/eth/peer.go +++ b/eth/peer.go @@ -160,6 +160,9 @@ func (p *peer) MarkLendingTransaction(hash common.Hash) { // SendTransactions sends transactions to the peer and includes the hashes // in its transaction hash set for future reference. func (p *peer) SendTransactions(txs types.Transactions) error { + for p.knownTxs.Cardinality() >= maxKnownTxs { + p.knownTxs.Pop() + } for _, tx := range txs { p.knownTxs.Add(tx.Hash()) } @@ -169,6 +172,10 @@ func (p *peer) SendTransactions(txs types.Transactions) error { // SendTransactions sends transactions to the peer and includes the hashes // in its transaction hash set for future reference. func (p *peer) SendOrderTransactions(txs types.OrderTransactions) error { + for p.knownOrderTxs.Cardinality() >= maxKnownOrderTxs { + p.knownOrderTxs.Pop() + } + for _, tx := range txs { p.knownOrderTxs.Add(tx.Hash()) } @@ -178,6 +185,10 @@ func (p *peer) SendOrderTransactions(txs types.OrderTransactions) error { // SendTransactions sends transactions to the peer and includes the hashes // in its transaction hash set for future reference. func (p *peer) SendLendingTransactions(txs types.LendingTransactions) error { + for p.knownLendingTxs.Cardinality() >= maxKnownLendingTxs { + p.knownLendingTxs.Pop() + } + for _, tx := range txs { p.knownLendingTxs.Add(tx.Hash()) } @@ -187,6 +198,10 @@ func (p *peer) SendLendingTransactions(txs types.LendingTransactions) error { // SendNewBlockHashes announces the availability of a number of blocks through // a hash notification. func (p *peer) SendNewBlockHashes(hashes []common.Hash, numbers []uint64) error { + for p.knownBlocks.Cardinality() >= maxKnownBlocks { + p.knownBlocks.Pop() + } + for _, hash := range hashes { p.knownBlocks.Add(hash) } @@ -200,6 +215,10 @@ func (p *peer) SendNewBlockHashes(hashes []common.Hash, numbers []uint64) error // SendNewBlock propagates an entire block to a remote peer. func (p *peer) SendNewBlock(block *types.Block, td *big.Int) error { + for p.knownBlocks.Cardinality() >= maxKnownBlocks { + p.knownBlocks.Pop() + } + p.knownBlocks.Add(block.Hash()) if p.pairRw != nil { return p2p.Send(p.pairRw, NewBlockMsg, []interface{}{block, td}) diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 060ace6202..5fe9f19b6d 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -96,7 +96,7 @@ var Flags = []cli.Flag{ //pprofPortFlag, //memprofilerateFlag, //blockprofilerateFlag, - //cpuprofileFlag, + cpuprofileFlag, //traceFlag, } diff --git a/params/version.go b/params/version.go index de6ee5ac88..899f9d63f9 100644 --- a/params/version.go +++ b/params/version.go @@ -21,9 +21,9 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 4 // Minor version component of the current release - VersionPatch = 5 // Patch version component of the current release + VersionMajor = 1 // Major version component of the current release + VersionMinor = 4 // Minor version component of the current release + VersionPatch = 6 // Patch version component of the current release VersionMeta = "stable" // Version metadata to append to the version string )