Skip to content

Commit bf16cd5

Browse files
committed
feat: add handleGetReceipts70
1 parent 429066f commit bf16cd5

File tree

16 files changed

+593
-105
lines changed

16 files changed

+593
-105
lines changed

cmd/devp2p/internal/ethtest/conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func (s *Suite) dialAs(key *ecdsa.PrivateKey) (*Conn, error) {
6666
return nil, err
6767
}
6868
conn.caps = []p2p.Cap{
69-
{Name: "eth", Version: 69},
69+
{Name: "eth", Version: 70},
7070
}
71-
conn.ourHighestProtoVersion = 69
71+
conn.ourHighestProtoVersion = 70
7272
return &conn, nil
7373
}
7474

cmd/devp2p/internal/ethtest/suite.go

Lines changed: 6 additions & 5 deletions
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: "GetReceipts", Fn: s.TestGetReceipts},
84+
{Name: "GetReceipts70", Fn: s.TestGetReceipts},
8585
// test transactions
8686
{Name: "LargeTxRequest", Fn: s.TestLargeTxRequest, Slow: true},
8787
{Name: "Transaction", Fn: s.TestTransaction},
@@ -434,15 +434,16 @@ func (s *Suite) TestGetReceipts(t *utesting.T) {
434434
}
435435

436436
// Create block bodies request.
437-
req := &eth.GetReceiptsPacket{
438-
RequestId: 66,
439-
GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes),
437+
req := &eth.GetReceiptsPacket70{
438+
RequestId: 66,
439+
GetReceiptsRequest: (eth.GetReceiptsRequest)(hashes),
440+
FirstBlockReceiptIndex: 0,
440441
}
441442
if err := conn.Write(ethProto, eth.GetReceiptsMsg, req); err != nil {
442443
t.Fatalf("could not write to connection: %v", err)
443444
}
444445
// Wait for response.
445-
resp := new(eth.ReceiptsPacket[*eth.ReceiptList69])
446+
resp := new(eth.ReceiptsPacket70)
446447
if err := conn.ReadMsg(ethProto, eth.ReceiptsMsg, &resp); err != nil {
447448
t.Fatalf("error reading block bodies msg: %v", err)
448449
}

eth/downloader/fetchers_concurrent.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,15 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error {
307307
// reschedule the timeout timer.
308308
index, live := ordering[res.Req]
309309
if live {
310-
timeouts.Remove(index)
310+
req := timeouts.Remove(index)
311+
delete(ordering, res.Req)
312+
313+
if res.Partial {
314+
ttl := d.peers.rates.TargetTimeout()
315+
ordering[req] = timeouts.Size()
316+
timeouts.Push(req, -time.Now().Add(ttl).UnixNano())
317+
}
318+
311319
if index == 0 {
312320
if !timeout.Stop() {
313321
<-timeout.C
@@ -317,16 +325,17 @@ func (d *Downloader) concurrentFetch(queue typedQueue) error {
317325
timeout.Reset(time.Until(time.Unix(0, -exp)))
318326
}
319327
}
320-
delete(ordering, res.Req)
321328
}
322-
// Delete the pending request (if it still exists) and mark the peer idle
323-
delete(pending, res.Req.Peer)
324-
delete(stales, res.Req.Peer)
329+
if !res.Partial {
330+
// Delete the pending request (if it still exists) and mark the peer idle
331+
delete(pending, res.Req.Peer)
332+
delete(stales, res.Req.Peer)
325333

334+
res.Req.Close()
335+
}
326336
// Signal the dispatcher that the round trip is done. We'll drop the
327337
// peer if the data turns out to be junk.
328338
res.Done <- nil
329-
res.Req.Close()
330339

331340
// If the peer was previously banned and failed to deliver its pack
332341
// in a reasonable time frame, ignore its message.

eth/downloader/fetchers_concurrent_receipts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (q *receiptQueue) deliver(peer *peerConnection, packet *eth.Response) (int,
9191
receipts := *packet.Res.(*eth.ReceiptsRLPResponse)
9292
hashes := packet.Meta.([]common.Hash) // {receipt hashes}
9393

94-
accepted, err := q.queue.DeliverReceipts(peer.id, receipts, hashes)
94+
accepted, err := q.queue.DeliverReceipts(peer.id, receipts, hashes, packet.Partial, packet.From)
9595
switch {
9696
case err == nil && len(receipts) == 0:
9797
peer.log.Trace("Requested receipts delivered")

eth/downloader/queue.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,13 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH
629629
result.SetBodyDone()
630630
}
631631
return q.deliver(id, q.blockTaskPool, q.blockTaskQueue, q.blockPendPool,
632-
bodyReqTimer, bodyInMeter, bodyDropMeter, len(txLists), validate, reconstruct)
632+
bodyReqTimer, bodyInMeter, bodyDropMeter, len(txLists), validate, reconstruct, false, 0)
633633
}
634634

635635
// DeliverReceipts injects a receipt retrieval response into the results queue.
636636
// The method returns the number of transaction receipts accepted from the delivery
637637
// and also wakes any threads waiting for data delivery.
638-
func (q *queue) DeliverReceipts(id string, receiptList []rlp.RawValue, receiptListHashes []common.Hash) (int, error) {
638+
func (q *queue) DeliverReceipts(id string, receiptList []rlp.RawValue, receiptListHashes []common.Hash, incomplete bool, from int) (int, error) {
639639
q.lock.Lock()
640640
defer q.lock.Unlock()
641641

@@ -650,7 +650,7 @@ func (q *queue) DeliverReceipts(id string, receiptList []rlp.RawValue, receiptLi
650650
result.SetReceiptsDone()
651651
}
652652
return q.deliver(id, q.receiptTaskPool, q.receiptTaskQueue, q.receiptPendPool,
653-
receiptReqTimer, receiptInMeter, receiptDropMeter, len(receiptList), validate, reconstruct)
653+
receiptReqTimer, receiptInMeter, receiptDropMeter, len(receiptList), validate, reconstruct, incomplete, from)
654654
}
655655

656656
// deliver injects a data retrieval response into the results queue.
@@ -662,22 +662,24 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
662662
taskQueue *prque.Prque[int64, *types.Header], pendPool map[string]*fetchRequest,
663663
reqTimer *metrics.Timer, resInMeter, resDropMeter *metrics.Meter,
664664
results int, validate func(index int, header *types.Header) error,
665-
reconstruct func(index int, result *fetchResult)) (int, error) {
665+
reconstruct func(index int, result *fetchResult), incomplete bool, from int) (int, error) {
666666
// Short circuit if the data was never requested
667667
request := pendPool[id]
668668
if request == nil {
669669
resDropMeter.Mark(int64(results))
670670
return 0, errNoFetchesPending
671671
}
672-
delete(pendPool, id)
672+
if !incomplete {
673+
delete(pendPool, id)
674+
}
673675

674676
reqTimer.UpdateSince(request.Time)
675677
resInMeter.Mark(int64(results))
676678

677679
// If no data items were retrieved, mark them as unavailable for the origin peer
678680
if results == 0 {
679681
for _, header := range request.Headers {
680-
request.Peer.MarkLacking(header.Hash())
682+
request.Peer.MarkLacking(header.Hash()) //todo?
681683
}
682684
}
683685
// Assemble each of the results with their headers and retrieved data parts
@@ -687,7 +689,7 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
687689
i int
688690
hashes []common.Hash
689691
)
690-
for _, header := range request.Headers {
692+
for _, header := range request.Headers[from:] {
691693
// Short circuit assembly if no more fetch results are found
692694
if i >= results {
693695
break
@@ -701,7 +703,7 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
701703
i++
702704
}
703705

704-
for _, header := range request.Headers[:i] {
706+
for _, header := range request.Headers[from : from+i] {
705707
if res, stale, err := q.resultCache.GetDeliverySlot(header.Number.Uint64()); err == nil && !stale {
706708
reconstruct(accepted, res)
707709
} else {
@@ -718,8 +720,15 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
718720
resDropMeter.Mark(int64(results - accepted))
719721

720722
// Return all failed or missing fetches to the queue
721-
for _, header := range request.Headers[accepted:] {
722-
taskQueue.Push(header, -int64(header.Number.Uint64()))
723+
//todo
724+
if incomplete {
725+
for _, header := range request.Headers[from+accepted : from+results] {
726+
taskQueue.Push(header, -int64(header.Number.Uint64()))
727+
}
728+
} else {
729+
for _, header := range request.Headers[from+accepted:] {
730+
taskQueue.Push(header, -int64(header.Number.Uint64()))
731+
}
723732
}
724733
// Wake up Results
725734
if accepted > 0 {

0 commit comments

Comments
 (0)