From f5c228576a282fbd30c67913fa890159726f8245 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 9 Dec 2025 13:58:38 +0800 Subject: [PATCH] eth/protocols/eth: prevent allocation if the response is complete --- eth/protocols/eth/peer.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/eth/protocols/eth/peer.go b/eth/protocols/eth/peer.go index e5a6edcccd..3508ecf8f1 100644 --- a/eth/protocols/eth/peer.go +++ b/eth/protocols/eth/peer.go @@ -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 }