@@ -35,13 +35,14 @@ import (
3535// stateReq represents a batch of state fetch requests groupped together into
3636// a single data retrieval network packet.
3737type stateReq struct {
38- nItems uint16 // Number of items requested for download (max is 384, so uint16 is sufficient)
39- tasks map [common.Hash ]* stateTask // Download tasks to track previous attempts
40- timeout time.Duration // Maximum round trip time for this to complete
41- timer * time.Timer // Timer to fire when the RTT timeout expires
42- peer * peerConnection // Peer that we're requesting from
43- response [][]byte // Response data of the peer (nil for timeouts)
44- dropped bool // Flag whether the peer dropped off early
38+ nItems uint16 // Number of items requested for download (max is 384, so uint16 is sufficient)
39+ tasks map [common.Hash ]* stateTask // Download tasks to track previous attempts
40+ timeout time.Duration // Maximum round trip time for this to complete
41+ timer * time.Timer // Timer to fire when the RTT timeout expires
42+ peer * peerConnection // Peer that we're requesting from
43+ delivered time.Time // Time when the packet was delivered (independent when we process it)
44+ response [][]byte // Response data of the peer (nil for timeouts)
45+ dropped bool // Flag whether the peer dropped off early
4546}
4647
4748// 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 ())
@@ -350,7 +352,6 @@ func (s *stateSync) loop() (err error) {
350352 return errCanceled
351353
352354 case req := <- s .deliver :
353- deliveryTime := time .Now ()
354355 // Response, disconnect or timeout triggered, drop the peer if stalling
355356 log .Trace ("Received node data response" , "peer" , req .peer .id , "count" , len (req .response ), "dropped" , req .dropped , "timeout" , ! req .dropped && req .timedOut ())
356357 if req .nItems <= 2 && ! req .dropped && req .timedOut () {
@@ -377,7 +378,7 @@ func (s *stateSync) loop() (err error) {
377378 }
378379 // Process all the received blobs and check for stale delivery
379380 delivered , err := s .process (req )
380- req .peer .SetNodeDataIdle (delivered , deliveryTime )
381+ req .peer .SetNodeDataIdle (delivered , req . delivered )
381382 if err != nil {
382383 log .Warn ("Node data write error" , "err" , err )
383384 return err
0 commit comments