@@ -363,7 +363,7 @@ func (p *Peer) RequestReceipts(hashes []common.Hash, sink chan *Response) (*Requ
363363 return req , nil
364364}
365365
366- // handlePartialReceipts re-request partial receipts
366+ // HandlePartialReceipts re-request partial receipts
367367func (p * Peer ) HandlePartialReceipts (previousId uint64 ) error {
368368 split := p .receiptBuffer [previousId ].idx
369369 id := rand .Uint64 ()
@@ -385,17 +385,17 @@ func (p *Peer) HandlePartialReceipts(previousId uint64) error {
385385 return p .dispatchRequest (req )
386386}
387387
388- // validateReceipt validate and check completion of partial request
389- // This function also modifies packet (trim partial response or append previously collected receipts)
388+ // ValidateReceipt validates a receipt packet and checks whether a partial request is complete.
389+ // It also mutates the packet in place, trimming the partial response or appending previously collected receipts.
390390func (p * Peer ) ValidateReceipt (packet * ReceiptsPacket70 ) (int , error ) {
391391 from := 0
392392 requestId := packet .RequestId
393393 if len (packet .List ) == 0 {
394394 return 0 , fmt .Errorf ("receipt list size 0" )
395395 }
396396
397- // process first block
398- // : partially collected before and completed by this response
397+ // Process the first block
398+ // If the request was partially collected earlier, append the buffered data so this response completes it.
399399 firstReceipt := packet .List [0 ]
400400 if firstReceipt == nil {
401401 return 0 , fmt .Errorf ("nil first receipt" )
@@ -407,7 +407,7 @@ func (p *Peer) ValidateReceipt(packet *ReceiptsPacket70) (int, error) {
407407 delete (p .receiptBuffer , requestId )
408408 }
409409
410- // process last block
410+ // Trim and buffer the last block when the response is incomplete.
411411 if packet .LastBlockIncomplete {
412412 lastReceipts := packet .List [len (packet .List )- 1 ]
413413 if lastReceipts == nil {
@@ -421,25 +421,25 @@ func (p *Peer) ValidateReceipt(packet *ReceiptsPacket70) (int, error) {
421421 previousLog = buffer .size
422422 }
423423
424- // 1. Verify the total number of tx delivered
424+ // 1. Verify that the total number of transactions delivered is under the limit.
425425 if uint64 (previousTxs + len (lastReceipts .items )) > lastReceipts .items [0 ].GasUsed / 21_000 {
426426 // should be dropped, don't clear the buffer
427427 return 0 , fmt .Errorf ("total number of tx exceeded limit" )
428428 }
429429
430- // 2. Verify the size of each receipt against the gas limit of the corresponding transaction
430+ // 2. Verify the size of each receipt against the maximum transaction size.
431431 for _ , rc := range lastReceipts .items {
432432 if uint64 (len (rc .Logs )) > params .MaxTxGas / params .LogDataGas {
433433 return 0 , fmt .Errorf ("total size of receipt exceeded limit" )
434434 }
435435 previousLog += uint64 (len (rc .Logs ))
436436 }
437- // 3. Verify the total download receipt size is no longer than allowed by the block gas limit
437+ // 3. Verify that the overall downloaded receipt size does not exceed the block gas limit.
438438 if previousLog > params .MaxGasLimit / params .LogDataGas {
439439 return 0 , fmt .Errorf ("total download receipt size exceeded the limit" )
440440 }
441441
442- // Update buffer & trim packet
442+ // Update the buffered data and trim the packet to exclude the incomplete block.
443443 if buffer , ok := p .receiptBuffer [requestId ]; ok {
444444 buffer .idx = buffer .idx + len (packet .List ) - 1
445445 buffer .list .items = append (buffer .list .items , lastReceipts .items ... )
0 commit comments