Skip to content

Commit cf48bd5

Browse files
committed
chore: polish comments
1 parent 4c2548e commit cf48bd5

File tree

6 files changed

+24
-25
lines changed

6 files changed

+24
-25
lines changed

cmd/devp2p/internal/ethtest/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (s *Suite) EthTests() []utesting.Test {
8181
{Name: "ZeroRequestID", Fn: s.TestZeroRequestID},
8282
// get history
8383
{Name: "GetBlockBodies", Fn: s.TestGetBlockBodies},
84-
{Name: "GetReceipts70", Fn: s.TestGetReceipts},
84+
{Name: "GetReceipts", Fn: s.TestGetReceipts},
8585
// test transactions
8686
{Name: "LargeTxRequest", Fn: s.TestLargeTxRequest, Slow: true},
8787
{Name: "Transaction", Fn: s.TestTransaction},

eth/downloader/queue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
679679
// If no data items were retrieved, mark them as unavailable for the origin peer
680680
if results == 0 {
681681
for _, header := range request.Headers {
682-
request.Peer.MarkLacking(header.Hash()) //todo?
682+
request.Peer.MarkLacking(header.Hash())
683683
}
684684
}
685685
// Assemble each of the results with their headers and retrieved data parts
@@ -720,7 +720,6 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
720720
resDropMeter.Mark(int64(results - accepted))
721721

722722
// Return all failed or missing fetches to the queue
723-
//todo
724723
if incomplete {
725724
for _, header := range request.Headers[from+accepted : from+results] {
726725
taskQueue.Push(header, -int64(header.Number.Uint64()))

eth/downloader/queue_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ func TestEmptyBlocks(t *testing.T) {
274274
}
275275
}
276276

277-
// TestPartialReceiptDelivery checks two points below
278-
// 1. Receipts failed validation should be re requested to the other peers
279-
// 2. Partial delivery should not be expired
277+
// TestPartialReceiptDelivery checks two points:
278+
// 1. Receipts that fail validation should be re-requested from other peers.
279+
// 2. Partial delivery should not expire.
280280
func TestPartialReceiptDelivery(t *testing.T) {
281281
blocks, receipts := makeChain(64, 0, testGenesis, blockConfig{txPeriod: 1, txCount: 5})
282282
chain := chainData{blocks: blocks, receipts: receipts, offset: 0}
@@ -305,7 +305,7 @@ func TestPartialReceiptDelivery(t *testing.T) {
305305

306306
t.Logf("request: length %d", len(req.Headers))
307307

308-
// 1. Deliver partial receipt: should not clear the remaining receipts from pending list
308+
// 1. Deliver a partial receipt: this must not clear the remaining receipts from the pending list
309309
firstCutoff := len(req.Headers) / 3
310310
receiptRLP, rcHashes := getPartialReceiptsDelivery(0, firstCutoff, receipts)
311311
accepted, err := q.DeliverReceipts(peer.id, receiptRLP, rcHashes, true, 0)
@@ -333,7 +333,7 @@ func TestPartialReceiptDelivery(t *testing.T) {
333333
t.Fatalf("there should be in flight receipts")
334334
}
335335

336-
// 2. Deliver partial receipt with invalid receipt: should clear invalid receipt from pending list
336+
// 2. Deliver a partial receipt containing an invalid entry: the invalid receipt should be removed from the pending list
337337
secondCutoff := firstCutoff + len(req.Headers)/3
338338
receiptRLP, rcHashes = getPartialReceiptsDelivery(firstCutoff, secondCutoff, receipts)
339339
// one invalid receipt
@@ -346,7 +346,7 @@ func TestPartialReceiptDelivery(t *testing.T) {
346346
t.Fatalf("delivery should fail")
347347
}
348348

349-
// invalid receipt should returned back to the pending pool
349+
// The invalid receipt should be returned to the pending pool
350350
if pending := q.PendingReceipts(); pending != numBlock-len(req.Headers)+1 {
351351
t.Fatalf("wrong pending receipt length, got %d, exp %d", pending, numBlock-len(req.Headers))
352352
}
@@ -364,7 +364,7 @@ func TestPartialReceiptDelivery(t *testing.T) {
364364
}
365365
}
366366

367-
// 3. Deliver partial receipt to complete request
367+
// 3. Deliver the remaining receipts to complete the request
368368
thirdCutoff := len(req.Headers)
369369
receiptRLP, rcHashes = getPartialReceiptsDelivery(secondCutoff, thirdCutoff, receipts)
370370
accepted, err = q.DeliverReceipts(peer.id, receiptRLP, rcHashes, false, secondCutoff)

eth/protocols/eth/handler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func testGetBlockReceipts(t *testing.T, protocol uint) {
553553
func TestGetBlockPartialReceipts(t *testing.T) { testGetBlockPartialReceipts(t, ETH70) }
554554

555555
func testGetBlockPartialReceipts(t *testing.T, protocol int) {
556-
// First generate chain and overwrite receipts
556+
// First, generate the chain and overwrite the receipts.
557557
generator := func(_ int, block *core.BlockGen) {
558558
for j := 0; j < 5; j++ {
559559
tx, err := types.SignTx(
@@ -573,7 +573,7 @@ func testGetBlockPartialReceipts(t *testing.T, protocol int) {
573573
blockCutoff := 2
574574
receiptCutoff := 4
575575

576-
// Replace receipts in DB with larger receipts
576+
// Replace the receipts in the database with larger receipts.
577577
targetBlock := backend.chain.GetBlockByNumber(uint64(blockCutoff))
578578
receipts := backend.chain.GetReceiptsByHash(targetBlock.Hash())
579579
receiptSize := params.MaxTxGas / params.LogDataGas // ~2MiB per receipt
@@ -626,7 +626,7 @@ func testGetBlockPartialReceipts(t *testing.T, protocol int) {
626626
t.Errorf("receipts mismatch: %v", err)
627627
}
628628

629-
// Simulate re-request
629+
// Simulate the continued request
630630
partialReceipt = []*ReceiptList69{NewReceiptList69(receipts[receiptCutoff:])}
631631

632632
p2p.Send(peer.app, GetReceiptsMsg, &GetReceiptsPacket70{

eth/protocols/eth/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ func serviceGetReceiptsQuery69(chain *core.BlockChain, query GetReceiptsRequest)
353353
}
354354

355355
// serviceGetReceiptsQuery70 assembles the response to a receipt query.
356-
// If the size of receipts is larger than 10MB, it would cut it and flag lastBlockIncomplete
357-
// It omits up to firstBlockReceiptIndex receipt from the first receipt list
356+
// If the receipts exceed 10 MiB, it trims them and sets the lastBlockIncomplete flag.
357+
// Indices smaller than firstBlockReceiptIndex are omitted from the first block receipt list.
358358
func serviceGetReceiptsQuery70(chain *core.BlockChain, query GetReceiptsRequest, firstBlockReceiptIndex uint64) ([]rlp.RawValue, bool) {
359359
var (
360360
bytes int

eth/protocols/eth/peer.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
367367
func (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.
390390
func (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

Comments
 (0)