@@ -792,10 +792,7 @@ func (s *Syncer) assignAccountTasks(cancel chan struct{}) {
792792 }
793793 req .timeout = time .AfterFunc (requestTimeout , func () {
794794 log .Debug ("Account range request timed out" )
795- select {
796- case s .accountReqFails <- req :
797- default :
798- }
795+ s .scheduleRevertAccountRequest (req )
799796 })
800797 s .accountReqs [reqid ] = req
801798 delete (s .accountIdlers , idle )
@@ -807,12 +804,8 @@ func (s *Syncer) assignAccountTasks(cancel chan struct{}) {
807804 // Attempt to send the remote request and revert if it fails
808805 if err := peer .RequestAccountRange (reqid , root , req .origin , req .limit , maxRequestSize ); err != nil {
809806 peer .Log ().Debug ("Failed to request account range" , "err" , err )
810- select {
811- case s .accountReqFails <- req :
812- default :
813- }
807+ s .scheduleRevertAccountRequest (req )
814808 }
815- // Request successfully sent, start a
816809 }(s .peers [idle ], s .root ) // We're in the lock, peers[id] surely exists
817810
818811 // Inject the request into the task to block further assignments
@@ -886,10 +879,7 @@ func (s *Syncer) assignBytecodeTasks(cancel chan struct{}) {
886879 }
887880 req .timeout = time .AfterFunc (requestTimeout , func () {
888881 log .Debug ("Bytecode request timed out" )
889- select {
890- case s .bytecodeReqFails <- req :
891- default :
892- }
882+ s .scheduleRevertBytecodeRequest (req )
893883 })
894884 s .bytecodeReqs [reqid ] = req
895885 delete (s .bytecodeIdlers , idle )
@@ -901,12 +891,8 @@ func (s *Syncer) assignBytecodeTasks(cancel chan struct{}) {
901891 // Attempt to send the remote request and revert if it fails
902892 if err := peer .RequestByteCodes (reqid , hashes , maxRequestSize ); err != nil {
903893 log .Debug ("Failed to request bytecodes" , "err" , err )
904- select {
905- case s .bytecodeReqFails <- req :
906- default :
907- }
894+ s .scheduleRevertBytecodeRequest (req )
908895 }
909- // Request successfully sent, start a
910896 }(s .peers [idle ]) // We're in the lock, peers[id] surely exists
911897 }
912898}
@@ -1018,10 +1004,7 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
10181004 }
10191005 req .timeout = time .AfterFunc (requestTimeout , func () {
10201006 log .Debug ("Storage request timed out" )
1021- select {
1022- case s .storageReqFails <- req :
1023- default :
1024- }
1007+ s .scheduleRevertStorageRequest (req )
10251008 })
10261009 s .storageReqs [reqid ] = req
10271010 delete (s .storageIdlers , idle )
@@ -1037,12 +1020,8 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
10371020 }
10381021 if err := peer .RequestStorageRanges (reqid , root , accounts , origin , limit , maxRequestSize ); err != nil {
10391022 log .Debug ("Failed to request storage" , "err" , err )
1040- select {
1041- case s .storageReqFails <- req :
1042- default :
1043- }
1023+ s .scheduleRevertStorageRequest (req )
10441024 }
1045- // Request successfully sent, start a
10461025 }(s .peers [idle ], s .root ) // We're in the lock, peers[id] surely exists
10471026
10481027 // Inject the request into the subtask to block further assignments
@@ -1140,10 +1119,7 @@ func (s *Syncer) assignTrienodeHealTasks(cancel chan struct{}) {
11401119 }
11411120 req .timeout = time .AfterFunc (requestTimeout , func () {
11421121 log .Debug ("Trienode heal request timed out" )
1143- select {
1144- case s .trienodeHealReqFails <- req :
1145- default :
1146- }
1122+ s .scheduleRevertTrienodeHealRequest (req )
11471123 })
11481124 s .trienodeHealReqs [reqid ] = req
11491125 delete (s .trienodeHealIdlers , idle )
@@ -1155,12 +1131,8 @@ func (s *Syncer) assignTrienodeHealTasks(cancel chan struct{}) {
11551131 // Attempt to send the remote request and revert if it fails
11561132 if err := peer .RequestTrieNodes (reqid , root , pathsets , maxRequestSize ); err != nil {
11571133 log .Debug ("Failed to request trienode healers" , "err" , err )
1158- select {
1159- case s .trienodeHealReqFails <- req :
1160- default :
1161- }
1134+ s .scheduleRevertTrienodeHealRequest (req )
11621135 }
1163- // Request successfully sent, start a
11641136 }(s .peers [idle ], s .root ) // We're in the lock, peers[id] surely exists
11651137 }
11661138}
@@ -1245,10 +1217,7 @@ func (s *Syncer) assignBytecodeHealTasks(cancel chan struct{}) {
12451217 }
12461218 req .timeout = time .AfterFunc (requestTimeout , func () {
12471219 log .Debug ("Bytecode heal request timed out" )
1248- select {
1249- case s .bytecodeHealReqFails <- req :
1250- default :
1251- }
1220+ s .scheduleRevertBytecodeHealRequest (req )
12521221 })
12531222 s .bytecodeHealReqs [reqid ] = req
12541223 delete (s .bytecodeHealIdlers , idle )
@@ -1260,12 +1229,8 @@ func (s *Syncer) assignBytecodeHealTasks(cancel chan struct{}) {
12601229 // Attempt to send the remote request and revert if it fails
12611230 if err := peer .RequestByteCodes (reqid , hashes , maxRequestSize ); err != nil {
12621231 log .Debug ("Failed to request bytecode healers" , "err" , err )
1263- select {
1264- case s .bytecodeHealReqFails <- req :
1265- default :
1266- }
1232+ s .scheduleRevertBytecodeHealRequest (req )
12671233 }
1268- // Request successfully sent, start a
12691234 }(s .peers [idle ]) // We're in the lock, peers[id] surely exists
12701235 }
12711236}
@@ -1325,10 +1290,26 @@ func (s *Syncer) revertRequests(peer string) {
13251290 }
13261291}
13271292
1293+ // scheduleRevertAccountRequest asks the event loop to clean up an account range
1294+ // request and return all failed retrieval tasks to the scheduler for reassignment.
1295+ func (s * Syncer ) scheduleRevertAccountRequest (req * accountRequest ) {
1296+ select {
1297+ case s .accountReqFails <- req :
1298+ // Sync event loop notified
1299+ case <- req .cancel :
1300+ // Sync cycle got cancelled
1301+ case <- req .stale :
1302+ // Request already reverted
1303+ }
1304+ }
1305+
13281306// revertAccountRequest cleans up an account range request and returns all failed
13291307// retrieval tasks to the scheduler for reassignment.
1308+ //
1309+ // Note, this needs to run on the event runloop thread to reschedule to idle peers.
1310+ // On peer threads, use scheduleRevertAccountRequest.
13301311func (s * Syncer ) revertAccountRequest (req * accountRequest ) {
1331- log .Trace ("Reverting account request" , "peer" , req .peer , "reqid" , req .id )
1312+ log .Debug ("Reverting account request" , "peer" , req .peer , "reqid" , req .id )
13321313 select {
13331314 case <- req .stale :
13341315 log .Trace ("Account request already reverted" , "peer" , req .peer , "reqid" , req .id )
@@ -1350,10 +1331,26 @@ func (s *Syncer) revertAccountRequest(req *accountRequest) {
13501331 }
13511332}
13521333
1353- // revertBytecodeRequest cleans up an bytecode request and returns all failed
1334+ // scheduleRevertBytecodeRequest asks the event loop to clean up a bytecode request
1335+ // and return all failed retrieval tasks to the scheduler for reassignment.
1336+ func (s * Syncer ) scheduleRevertBytecodeRequest (req * bytecodeRequest ) {
1337+ select {
1338+ case s .bytecodeReqFails <- req :
1339+ // Sync event loop notified
1340+ case <- req .cancel :
1341+ // Sync cycle got cancelled
1342+ case <- req .stale :
1343+ // Request already reverted
1344+ }
1345+ }
1346+
1347+ // revertBytecodeRequest cleans up a bytecode request and returns all failed
13541348// retrieval tasks to the scheduler for reassignment.
1349+ //
1350+ // Note, this needs to run on the event runloop thread to reschedule to idle peers.
1351+ // On peer threads, use scheduleRevertBytecodeRequest.
13551352func (s * Syncer ) revertBytecodeRequest (req * bytecodeRequest ) {
1356- log .Trace ("Reverting bytecode request" , "peer" , req .peer )
1353+ log .Debug ("Reverting bytecode request" , "peer" , req .peer )
13571354 select {
13581355 case <- req .stale :
13591356 log .Trace ("Bytecode request already reverted" , "peer" , req .peer , "reqid" , req .id )
@@ -1375,10 +1372,26 @@ func (s *Syncer) revertBytecodeRequest(req *bytecodeRequest) {
13751372 }
13761373}
13771374
1375+ // scheduleRevertStorageRequest asks the event loop to clean up a storage range
1376+ // request and return all failed retrieval tasks to the scheduler for reassignment.
1377+ func (s * Syncer ) scheduleRevertStorageRequest (req * storageRequest ) {
1378+ select {
1379+ case s .storageReqFails <- req :
1380+ // Sync event loop notified
1381+ case <- req .cancel :
1382+ // Sync cycle got cancelled
1383+ case <- req .stale :
1384+ // Request already reverted
1385+ }
1386+ }
1387+
13781388// revertStorageRequest cleans up a storage range request and returns all failed
13791389// retrieval tasks to the scheduler for reassignment.
1390+ //
1391+ // Note, this needs to run on the event runloop thread to reschedule to idle peers.
1392+ // On peer threads, use scheduleRevertStorageRequest.
13801393func (s * Syncer ) revertStorageRequest (req * storageRequest ) {
1381- log .Trace ("Reverting storage request" , "peer" , req .peer )
1394+ log .Debug ("Reverting storage request" , "peer" , req .peer )
13821395 select {
13831396 case <- req .stale :
13841397 log .Trace ("Storage request already reverted" , "peer" , req .peer , "reqid" , req .id )
@@ -1404,10 +1417,26 @@ func (s *Syncer) revertStorageRequest(req *storageRequest) {
14041417 }
14051418}
14061419
1407- // revertTrienodeHealRequest cleans up an trienode heal request and returns all
1420+ // scheduleRevertTrienodeHealRequest asks the event loop to clean up a trienode heal
1421+ // request and return all failed retrieval tasks to the scheduler for reassignment.
1422+ func (s * Syncer ) scheduleRevertTrienodeHealRequest (req * trienodeHealRequest ) {
1423+ select {
1424+ case s .trienodeHealReqFails <- req :
1425+ // Sync event loop notified
1426+ case <- req .cancel :
1427+ // Sync cycle got cancelled
1428+ case <- req .stale :
1429+ // Request already reverted
1430+ }
1431+ }
1432+
1433+ // revertTrienodeHealRequest cleans up a trienode heal request and returns all
14081434// failed retrieval tasks to the scheduler for reassignment.
1435+ //
1436+ // Note, this needs to run on the event runloop thread to reschedule to idle peers.
1437+ // On peer threads, use scheduleRevertTrienodeHealRequest.
14091438func (s * Syncer ) revertTrienodeHealRequest (req * trienodeHealRequest ) {
1410- log .Trace ("Reverting trienode heal request" , "peer" , req .peer )
1439+ log .Debug ("Reverting trienode heal request" , "peer" , req .peer )
14111440 select {
14121441 case <- req .stale :
14131442 log .Trace ("Trienode heal request already reverted" , "peer" , req .peer , "reqid" , req .id )
@@ -1429,10 +1458,26 @@ func (s *Syncer) revertTrienodeHealRequest(req *trienodeHealRequest) {
14291458 }
14301459}
14311460
1432- // revertBytecodeHealRequest cleans up an bytecode request and returns all failed
1433- // retrieval tasks to the scheduler for reassignment.
1461+ // scheduleRevertBytecodeHealRequest asks the event loop to clean up a bytecode heal
1462+ // request and return all failed retrieval tasks to the scheduler for reassignment.
1463+ func (s * Syncer ) scheduleRevertBytecodeHealRequest (req * bytecodeHealRequest ) {
1464+ select {
1465+ case s .bytecodeHealReqFails <- req :
1466+ // Sync event loop notified
1467+ case <- req .cancel :
1468+ // Sync cycle got cancelled
1469+ case <- req .stale :
1470+ // Request already reverted
1471+ }
1472+ }
1473+
1474+ // revertBytecodeHealRequest cleans up a bytecode heal request and returns all
1475+ // failed retrieval tasks to the scheduler for reassignment.
1476+ //
1477+ // Note, this needs to run on the event runloop thread to reschedule to idle peers.
1478+ // On peer threads, use scheduleRevertBytecodeHealRequest.
14341479func (s * Syncer ) revertBytecodeHealRequest (req * bytecodeHealRequest ) {
1435- log .Trace ("Reverting bytecode heal request" , "peer" , req .peer )
1480+ log .Debug ("Reverting bytecode heal request" , "peer" , req .peer )
14361481 select {
14371482 case <- req .stale :
14381483 log .Trace ("Bytecode heal request already reverted" , "peer" , req .peer , "reqid" , req .id )
@@ -1768,7 +1813,7 @@ func (s *Syncer) processTrienodeHealResponse(res *trienodeHealResponse) {
17681813 if err := batch .Write (); err != nil {
17691814 log .Crit ("Failed to persist healing data" , "err" , err )
17701815 }
1771- log .Debug ("Persisted set of healing data" , "bytes" , common .StorageSize (batch .ValueSize ()))
1816+ log .Debug ("Persisted set of healing data" , "type" , "trienodes" , " bytes" , common .StorageSize (batch .ValueSize ()))
17721817}
17731818
17741819// processBytecodeHealResponse integrates an already validated bytecode response
@@ -1804,7 +1849,7 @@ func (s *Syncer) processBytecodeHealResponse(res *bytecodeHealResponse) {
18041849 if err := batch .Write (); err != nil {
18051850 log .Crit ("Failed to persist healing data" , "err" , err )
18061851 }
1807- log .Debug ("Persisted set of healing data" , "bytes" , common .StorageSize (batch .ValueSize ()))
1852+ log .Debug ("Persisted set of healing data" , "type" , "bytecode" , " bytes" , common .StorageSize (batch .ValueSize ()))
18081853}
18091854
18101855// forwardAccountTask takes a filled account task and persists anything available
@@ -1940,6 +1985,9 @@ func (s *Syncer) OnAccounts(peer *Peer, id uint64, hashes []common.Hash, account
19401985 logger .Debug ("Peer rejected account range request" , "root" , s .root )
19411986 s .statelessPeers [peer .id ] = struct {}{}
19421987 s .lock .Unlock ()
1988+
1989+ // Signal this request as failed, and ready for rescheduling
1990+ s .scheduleRevertAccountRequest (req )
19431991 return nil
19441992 }
19451993 root := s .root
@@ -2055,6 +2103,9 @@ func (s *Syncer) onByteCodes(peer *Peer, id uint64, bytecodes [][]byte) error {
20552103 logger .Debug ("Peer rejected bytecode request" )
20562104 s .statelessPeers [peer .id ] = struct {}{}
20572105 s .lock .Unlock ()
2106+
2107+ // Signal this request as failed, and ready for rescheduling
2108+ s .scheduleRevertBytecodeRequest (req )
20582109 return nil
20592110 }
20602111 s .lock .Unlock ()
@@ -2166,6 +2217,9 @@ func (s *Syncer) OnStorage(peer *Peer, id uint64, hashes [][]common.Hash, slots
21662217 logger .Debug ("Peer rejected storage request" )
21672218 s .statelessPeers [peer .id ] = struct {}{}
21682219 s .lock .Unlock ()
2220+
2221+ // Signal this request as failed, and ready for rescheduling
2222+ s .scheduleRevertStorageRequest (req )
21692223 return nil
21702224 }
21712225 s .lock .Unlock ()
@@ -2287,6 +2341,9 @@ func (s *Syncer) OnTrieNodes(peer *Peer, id uint64, trienodes [][]byte) error {
22872341 logger .Debug ("Peer rejected trienode heal request" )
22882342 s .statelessPeers [peer .id ] = struct {}{}
22892343 s .lock .Unlock ()
2344+
2345+ // Signal this request as failed, and ready for rescheduling
2346+ s .scheduleRevertTrienodeHealRequest (req )
22902347 return nil
22912348 }
22922349 s .lock .Unlock ()
@@ -2371,6 +2428,9 @@ func (s *Syncer) onHealByteCodes(peer *Peer, id uint64, bytecodes [][]byte) erro
23712428 logger .Debug ("Peer rejected bytecode heal request" )
23722429 s .statelessPeers [peer .id ] = struct {}{}
23732430 s .lock .Unlock ()
2431+
2432+ // Signal this request as failed, and ready for rescheduling
2433+ s .scheduleRevertBytecodeHealRequest (req )
23742434 return nil
23752435 }
23762436 s .lock .Unlock ()
0 commit comments