@@ -811,6 +811,8 @@ func (s *Syncer) assignAccountTasks(cancel chan struct{}) {
811811 if idle == "" {
812812 return
813813 }
814+ peer := s .peers [idle ]
815+
814816 // Matched a pending task to an idle peer, allocate a unique request id
815817 var reqid uint64
816818 for {
@@ -834,22 +836,22 @@ func (s *Syncer) assignAccountTasks(cancel chan struct{}) {
834836 task : task ,
835837 }
836838 req .timeout = time .AfterFunc (requestTimeout , func () {
837- log . Debug ("Account range request timed out" )
839+ peer . Log (). Debug ("Account range request timed out" , "reqid" , reqid )
838840 s .scheduleRevertAccountRequest (req )
839841 })
840842 s .accountReqs [reqid ] = req
841843 delete (s .accountIdlers , idle )
842844
843845 s .pend .Add (1 )
844- go func (peer SyncPeer , root common.Hash ) {
846+ go func (root common.Hash ) {
845847 defer s .pend .Done ()
846848
847849 // Attempt to send the remote request and revert if it fails
848850 if err := peer .RequestAccountRange (reqid , root , req .origin , req .limit , maxRequestSize ); err != nil {
849851 peer .Log ().Debug ("Failed to request account range" , "err" , err )
850852 s .scheduleRevertAccountRequest (req )
851853 }
852- }(s .peers [ idle ], s . root ) // We're in the lock, peers[id] surely exists
854+ }(s .root )
853855
854856 // Inject the request into the task to block further assignments
855857 task .req = req
@@ -891,6 +893,8 @@ func (s *Syncer) assignBytecodeTasks(cancel chan struct{}) {
891893 if idle == "" {
892894 return
893895 }
896+ peer := s .peers [idle ]
897+
894898 // Matched a pending task to an idle peer, allocate a unique request id
895899 var reqid uint64
896900 for {
@@ -921,22 +925,22 @@ func (s *Syncer) assignBytecodeTasks(cancel chan struct{}) {
921925 task : task ,
922926 }
923927 req .timeout = time .AfterFunc (requestTimeout , func () {
924- log . Debug ("Bytecode request timed out" )
928+ peer . Log (). Debug ("Bytecode request timed out" , "reqid" , reqid )
925929 s .scheduleRevertBytecodeRequest (req )
926930 })
927931 s .bytecodeReqs [reqid ] = req
928932 delete (s .bytecodeIdlers , idle )
929933
930934 s .pend .Add (1 )
931- go func (peer SyncPeer ) {
935+ go func () {
932936 defer s .pend .Done ()
933937
934938 // Attempt to send the remote request and revert if it fails
935939 if err := peer .RequestByteCodes (reqid , hashes , maxRequestSize ); err != nil {
936940 log .Debug ("Failed to request bytecodes" , "err" , err )
937941 s .scheduleRevertBytecodeRequest (req )
938942 }
939- }(s . peers [ idle ]) // We're in the lock, peers[id] surely exists
943+ }()
940944 }
941945}
942946
@@ -976,6 +980,8 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
976980 if idle == "" {
977981 return
978982 }
983+ peer := s .peers [idle ]
984+
979985 // Matched a pending task to an idle peer, allocate a unique request id
980986 var reqid uint64
981987 for {
@@ -1045,14 +1051,14 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
10451051 req .limit = subtask .Last
10461052 }
10471053 req .timeout = time .AfterFunc (requestTimeout , func () {
1048- log . Debug ("Storage request timed out" )
1054+ peer . Log (). Debug ("Storage request timed out" , "reqid" , reqid )
10491055 s .scheduleRevertStorageRequest (req )
10501056 })
10511057 s .storageReqs [reqid ] = req
10521058 delete (s .storageIdlers , idle )
10531059
10541060 s .pend .Add (1 )
1055- go func (peer SyncPeer , root common.Hash ) {
1061+ go func (root common.Hash ) {
10561062 defer s .pend .Done ()
10571063
10581064 // Attempt to send the remote request and revert if it fails
@@ -1064,7 +1070,7 @@ func (s *Syncer) assignStorageTasks(cancel chan struct{}) {
10641070 log .Debug ("Failed to request storage" , "err" , err )
10651071 s .scheduleRevertStorageRequest (req )
10661072 }
1067- }(s .peers [ idle ], s . root ) // We're in the lock, peers[id] surely exists
1073+ }(s .root )
10681074
10691075 // Inject the request into the subtask to block further assignments
10701076 if subtask != nil {
@@ -1121,6 +1127,8 @@ func (s *Syncer) assignTrienodeHealTasks(cancel chan struct{}) {
11211127 if idle == "" {
11221128 return
11231129 }
1130+ peer := s .peers [idle ]
1131+
11241132 // Matched a pending task to an idle peer, allocate a unique request id
11251133 var reqid uint64
11261134 for {
@@ -1160,22 +1168,22 @@ func (s *Syncer) assignTrienodeHealTasks(cancel chan struct{}) {
11601168 task : s .healer ,
11611169 }
11621170 req .timeout = time .AfterFunc (requestTimeout , func () {
1163- log . Debug ("Trienode heal request timed out" )
1171+ peer . Log (). Debug ("Trienode heal request timed out" , "reqid" , reqid )
11641172 s .scheduleRevertTrienodeHealRequest (req )
11651173 })
11661174 s .trienodeHealReqs [reqid ] = req
11671175 delete (s .trienodeHealIdlers , idle )
11681176
11691177 s .pend .Add (1 )
1170- go func (peer SyncPeer , root common.Hash ) {
1178+ go func (root common.Hash ) {
11711179 defer s .pend .Done ()
11721180
11731181 // Attempt to send the remote request and revert if it fails
11741182 if err := peer .RequestTrieNodes (reqid , root , pathsets , maxRequestSize ); err != nil {
11751183 log .Debug ("Failed to request trienode healers" , "err" , err )
11761184 s .scheduleRevertTrienodeHealRequest (req )
11771185 }
1178- }(s .peers [ idle ], s . root ) // We're in the lock, peers[id] surely exists
1186+ }(s .root )
11791187 }
11801188}
11811189
@@ -1227,6 +1235,8 @@ func (s *Syncer) assignBytecodeHealTasks(cancel chan struct{}) {
12271235 if idle == "" {
12281236 return
12291237 }
1238+ peer := s .peers [idle ]
1239+
12301240 // Matched a pending task to an idle peer, allocate a unique request id
12311241 var reqid uint64
12321242 for {
@@ -1258,22 +1268,22 @@ func (s *Syncer) assignBytecodeHealTasks(cancel chan struct{}) {
12581268 task : s .healer ,
12591269 }
12601270 req .timeout = time .AfterFunc (requestTimeout , func () {
1261- log . Debug ("Bytecode heal request timed out" )
1271+ peer . Log (). Debug ("Bytecode heal request timed out" , "reqid" , reqid )
12621272 s .scheduleRevertBytecodeHealRequest (req )
12631273 })
12641274 s .bytecodeHealReqs [reqid ] = req
12651275 delete (s .bytecodeHealIdlers , idle )
12661276
12671277 s .pend .Add (1 )
1268- go func (peer SyncPeer ) {
1278+ go func () {
12691279 defer s .pend .Done ()
12701280
12711281 // Attempt to send the remote request and revert if it fails
12721282 if err := peer .RequestByteCodes (reqid , hashes , maxRequestSize ); err != nil {
12731283 log .Debug ("Failed to request bytecode healers" , "err" , err )
12741284 s .scheduleRevertBytecodeHealRequest (req )
12751285 }
1276- }(s . peers [ idle ]) // We're in the lock, peers[id] surely exists
1286+ }()
12771287 }
12781288}
12791289
0 commit comments