@@ -723,7 +723,7 @@ pub struct ChainSync {
723
723
sync_start_time : Option < Instant > ,
724
724
/// Transactions propagation statistics
725
725
transactions_stats : TransactionsStats ,
726
- /// Unfetched transactions
726
+ /// Transactions whose hash has been announced, but that we have not fetched
727
727
unfetched_pooled_transactions : H256FastMap < UnfetchedTransaction > ,
728
728
/// Enable ancient block downloading
729
729
download_old_blocks : bool ,
@@ -1176,33 +1176,45 @@ impl ChainSync {
1176
1176
}
1177
1177
}
1178
1178
1179
- // get some peers to give us transaction pool
1179
+ // get the peer to give us at least some of announced but unfetched transactions
1180
1180
if !self . unfetched_pooled_transactions . is_empty ( ) {
1181
- if let Some ( s) = & mut self . peers . get_mut ( & peer_id) . unwrap ( ) . asking_pooled_transactions {
1181
+ if let Some ( s) = & mut self . peers . get_mut ( & peer_id) . expect ( "this is always an active peer; qed" ) . asking_pooled_transactions {
1182
1182
let now = Instant :: now ( ) ;
1183
1183
1184
1184
let mut new_asking_pooled_transactions = s. iter ( ) . copied ( ) . collect :: < HashSet < _ > > ( ) ;
1185
- let mut new_unfetched_pooled_transactions = self . unfetched_pooled_transactions . clone ( ) ;
1186
- while new_asking_pooled_transactions. len ( ) <= 256 {
1187
- for ( hash, mut item) in self . unfetched_pooled_transactions . drain ( ) {
1188
- if item. next_fetch < now {
1189
- new_asking_pooled_transactions. insert ( hash) ;
1190
- item. tries += 1 ;
1191
- if item. tries < 5 {
1192
- item. next_fetch = now + ( POOLED_TRANSACTIONS_TIMEOUT / 2 ) ;
1193
- new_unfetched_pooled_transactions. insert ( hash, item) ;
1194
- }
1185
+ let mut remaining_unfetched_pooled_transactions = self . unfetched_pooled_transactions . clone ( ) ;
1186
+ for ( hash, mut item) in self . unfetched_pooled_transactions . drain ( ) {
1187
+ if new_asking_pooled_transactions. len ( ) >= 256 {
1188
+ // can't request any more transactions
1189
+ break ;
1190
+ }
1191
+
1192
+ // if enough time has passed since last attempt...
1193
+ if item. next_fetch < now {
1194
+ // ...queue this hash for requesting
1195
+ new_asking_pooled_transactions. insert ( hash) ;
1196
+ item. tries += 1 ;
1197
+
1198
+ // if we just started asking for it, queue it to be asked later on again
1199
+ if item. tries < 5 {
1200
+ item. next_fetch = now + ( POOLED_TRANSACTIONS_TIMEOUT / 2 ) ;
1201
+ remaining_unfetched_pooled_transactions. insert ( hash, item) ;
1202
+ } else {
1203
+ // ...otherwise we assume this transaction does not exist and remove its hash from request queue
1204
+ remaining_unfetched_pooled_transactions. remove ( & hash) ;
1195
1205
}
1196
1206
}
1197
1207
}
1198
1208
1199
1209
let new_asking_pooled_transactions = new_asking_pooled_transactions. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1200
1210
SyncRequester :: request_pooled_transactions ( self , io, peer_id, & new_asking_pooled_transactions) ;
1201
1211
1202
- self . peers . get_mut ( & peer_id) . unwrap ( ) . asking_pooled_transactions = Some ( new_asking_pooled_transactions) ;
1203
- self . unfetched_pooled_transactions = new_unfetched_pooled_transactions ;
1212
+ self . peers . get_mut ( & peer_id) . expect ( "this is always an active peer; qed" ) . asking_pooled_transactions = Some ( new_asking_pooled_transactions) ;
1213
+ self . unfetched_pooled_transactions = remaining_unfetched_pooled_transactions ;
1204
1214
1205
1215
return ;
1216
+ } else {
1217
+ trace ! ( target: "sync" , "Skipping transaction fetch for peer {} as they don't support eth/65" , peer_id) ;
1206
1218
}
1207
1219
}
1208
1220
0 commit comments