Bug Fix on memory leak when doing send tx, block etc to peers (#212)

* resolve conflict

* update version number
This commit is contained in:
Liam 2022-12-09 14:54:27 +08:00 committed by GitHub
parent 78e30c2637
commit f57e2c3577
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View file

@ -160,6 +160,9 @@ func (p *peer) MarkLendingTransaction(hash common.Hash) {
// SendTransactions sends transactions to the peer and includes the hashes // SendTransactions sends transactions to the peer and includes the hashes
// in its transaction hash set for future reference. // in its transaction hash set for future reference.
func (p *peer) SendTransactions(txs types.Transactions) error { func (p *peer) SendTransactions(txs types.Transactions) error {
for p.knownTxs.Cardinality() >= maxKnownTxs {
p.knownTxs.Pop()
}
for _, tx := range txs { for _, tx := range txs {
p.knownTxs.Add(tx.Hash()) 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 // SendTransactions sends transactions to the peer and includes the hashes
// in its transaction hash set for future reference. // in its transaction hash set for future reference.
func (p *peer) SendOrderTransactions(txs types.OrderTransactions) error { func (p *peer) SendOrderTransactions(txs types.OrderTransactions) error {
for p.knownOrderTxs.Cardinality() >= maxKnownOrderTxs {
p.knownOrderTxs.Pop()
}
for _, tx := range txs { for _, tx := range txs {
p.knownOrderTxs.Add(tx.Hash()) 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 // SendTransactions sends transactions to the peer and includes the hashes
// in its transaction hash set for future reference. // in its transaction hash set for future reference.
func (p *peer) SendLendingTransactions(txs types.LendingTransactions) error { func (p *peer) SendLendingTransactions(txs types.LendingTransactions) error {
for p.knownLendingTxs.Cardinality() >= maxKnownLendingTxs {
p.knownLendingTxs.Pop()
}
for _, tx := range txs { for _, tx := range txs {
p.knownLendingTxs.Add(tx.Hash()) 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 // SendNewBlockHashes announces the availability of a number of blocks through
// a hash notification. // a hash notification.
func (p *peer) SendNewBlockHashes(hashes []common.Hash, numbers []uint64) error { func (p *peer) SendNewBlockHashes(hashes []common.Hash, numbers []uint64) error {
for p.knownBlocks.Cardinality() >= maxKnownBlocks {
p.knownBlocks.Pop()
}
for _, hash := range hashes { for _, hash := range hashes {
p.knownBlocks.Add(hash) 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. // SendNewBlock propagates an entire block to a remote peer.
func (p *peer) SendNewBlock(block *types.Block, td *big.Int) error { func (p *peer) SendNewBlock(block *types.Block, td *big.Int) error {
for p.knownBlocks.Cardinality() >= maxKnownBlocks {
p.knownBlocks.Pop()
}
p.knownBlocks.Add(block.Hash()) p.knownBlocks.Add(block.Hash())
if p.pairRw != nil { if p.pairRw != nil {
return p2p.Send(p.pairRw, NewBlockMsg, []interface{}{block, td}) return p2p.Send(p.pairRw, NewBlockMsg, []interface{}{block, td})

View file

@ -96,7 +96,7 @@ var Flags = []cli.Flag{
//pprofPortFlag, //pprofPortFlag,
//memprofilerateFlag, //memprofilerateFlag,
//blockprofilerateFlag, //blockprofilerateFlag,
//cpuprofileFlag, cpuprofileFlag,
//traceFlag, //traceFlag,
} }

View file

@ -23,7 +23,7 @@ import (
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 4 // Minor version component of the current release VersionMinor = 4 // Minor version component of the current release
VersionPatch = 5 // Patch 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 VersionMeta = "stable" // Version metadata to append to the version string
) )