@@ -34,13 +34,14 @@ import (
3434// stateReq represents a batch of state fetch requests grouped together into
3535// a single data retrieval network packet.
3636type stateReq struct {
37- nItems uint16 // Number of items requested for download (max is 384, so uint16 is sufficient)
38- tasks map [common.Hash ]* stateTask // Download tasks to track previous attempts
39- timeout time.Duration // Maximum round trip time for this to complete
40- timer * time.Timer // Timer to fire when the RTT timeout expires
41- peer * peerConnection // Peer that we're requesting from
42- response [][]byte // Response data of the peer (nil for timeouts)
43- dropped bool // Flag whether the peer dropped off early
37+ nItems uint16 // Number of items requested for download (max is 384, so uint16 is sufficient)
38+ tasks map [common.Hash ]* stateTask // Download tasks to track previous attempts
39+ timeout time.Duration // Maximum round trip time for this to complete
40+ timer * time.Timer // Timer to fire when the RTT timeout expires
41+ peer * peerConnection // Peer that we're requesting from
42+ delivered time.Time // Time when the packet was delivered (independent when we process it)
43+ response [][]byte // Response data of the peer (nil for timeouts)
44+ dropped bool // Flag whether the peer dropped off early
4445}
4546
4647// timedOut returns if this request timed out.
@@ -148,6 +149,7 @@ func (d *Downloader) runStateSync(s *stateSync) *stateSync {
148149 // Finalize the request and queue up for processing
149150 req .timer .Stop ()
150151 req .response = pack .(* statePack ).states
152+ req .delivered = time .Now ()
151153
152154 finished = append (finished , req )
153155 delete (active , pack .PeerId ())
@@ -349,7 +351,6 @@ func (s *stateSync) loop() (err error) {
349351 return errCanceled
350352
351353 case req := <- s .deliver :
352- deliveryTime := time .Now ()
353354 // Response, disconnect or timeout triggered, drop the peer if stalling
354355 log .Trace ("Received node data response" , "peer" , req .peer .id , "count" , len (req .response ), "dropped" , req .dropped , "timeout" , ! req .dropped && req .timedOut ())
355356 if req .nItems <= 2 && ! req .dropped && req .timedOut () {
@@ -376,7 +377,7 @@ func (s *stateSync) loop() (err error) {
376377 }
377378 // Process all the received blobs and check for stale delivery
378379 delivered , err := s .process (req )
379- req .peer .SetNodeDataIdle (delivered , deliveryTime )
380+ req .peer .SetNodeDataIdle (delivered , req . delivered )
380381 if err != nil {
381382 log .Warn ("Node data write error" , "err" , err )
382383 return err
0 commit comments