mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-13 10:21:37 +00:00
eth/protocols/eth: prevent allocation if the response is complete
This commit is contained in:
parent
fb1ce79543
commit
f5c228576a
1 changed files with 12 additions and 8 deletions
|
|
@ -459,15 +459,19 @@ func (p *Peer) bufferReceiptsPacket(packet *ReceiptsPacket70, backend Backend) e
|
|||
}
|
||||
return nil
|
||||
}
|
||||
// If the request is completed, append previously collected receipts
|
||||
// to the packet and remove the buffered receipts.
|
||||
if len(buffer.list) > 0 {
|
||||
buffer.list[len(buffer.list)-1].Append(packet.List[0])
|
||||
packet.List = packet.List[1:]
|
||||
}
|
||||
packet.List = append(buffer.list, packet.List...)
|
||||
|
||||
// If the request is complete, append the previously collected receipts to the
|
||||
// packet and discard the buffered receipts. Also clear the cached buffer used
|
||||
// for storing partial responses.
|
||||
delete(p.receiptBuffer, requestId)
|
||||
|
||||
// Short circuit if there is nothing cached previously
|
||||
if len(buffer.list) == 0 {
|
||||
return nil
|
||||
}
|
||||
// Aggregate the cached result into the packet
|
||||
buffer.list[len(buffer.list)-1].Append(packet.List[0])
|
||||
packet.List = packet.List[1:]
|
||||
packet.List = append(buffer.list, packet.List...)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue