@@ -1179,6 +1179,24 @@ func TestTransactionFetcherDoSProtection(t *testing.T) {
1179
1179
size : 111 ,
1180
1180
})
1181
1181
}
1182
+ var (
1183
+ hashesC []common.Hash
1184
+ typesC []byte
1185
+ sizesC []uint32
1186
+ announceC []announce
1187
+ )
1188
+ for i := 0 ; i < maxTxAnnounces + 2 ; i ++ {
1189
+ hash := common.Hash {0x03 , byte (i / 256 ), byte (i % 256 )}
1190
+ hashesC = append (hashesC , hash )
1191
+ typesC = append (typesC , types .LegacyTxType )
1192
+ sizesC = append (sizesC , 111 )
1193
+
1194
+ announceC = append (announceC , announce {
1195
+ hash : hash ,
1196
+ kind : types .LegacyTxType ,
1197
+ size : 111 ,
1198
+ })
1199
+ }
1182
1200
testTransactionFetcherParallel (t , txFetcherTest {
1183
1201
init : func () * TxFetcher {
1184
1202
return NewTxFetcher (
@@ -1192,43 +1210,52 @@ func TestTransactionFetcherDoSProtection(t *testing.T) {
1192
1210
// Announce half of the transaction and wait for them to be scheduled
1193
1211
doTxNotify {peer : "A" , hashes : hashesA [:maxTxAnnounces / 2 ], types : typesA [:maxTxAnnounces / 2 ], sizes : sizesA [:maxTxAnnounces / 2 ]},
1194
1212
doTxNotify {peer : "B" , hashes : hashesB [:maxTxAnnounces / 2 - 1 ], types : typesB [:maxTxAnnounces / 2 - 1 ], sizes : sizesB [:maxTxAnnounces / 2 - 1 ]},
1213
+ doTxNotify {peer : "C" , hashes : hashesC [:maxTxAnnounces / 2 - 1 ], types : typesC [:maxTxAnnounces / 2 - 1 ], sizes : sizesC [:maxTxAnnounces / 2 - 1 ]},
1195
1214
doWait {time : txArriveTimeout , step : true },
1196
1215
1197
1216
// Announce the second half and keep them in the wait list
1198
1217
doTxNotify {peer : "A" , hashes : hashesA [maxTxAnnounces / 2 : maxTxAnnounces ], types : typesA [maxTxAnnounces / 2 : maxTxAnnounces ], sizes : sizesA [maxTxAnnounces / 2 : maxTxAnnounces ]},
1199
1218
doTxNotify {peer : "B" , hashes : hashesB [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ], types : typesB [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ], sizes : sizesB [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ]},
1219
+ doTxNotify {peer : "C" , hashes : hashesC [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ], types : typesC [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ], sizes : sizesC [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ]},
1200
1220
1201
1221
// Ensure the hashes are split half and half
1202
1222
isWaiting (map [string ][]announce {
1203
1223
"A" : announceA [maxTxAnnounces / 2 : maxTxAnnounces ],
1204
1224
"B" : announceB [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ],
1225
+ "C" : announceC [maxTxAnnounces / 2 - 1 : maxTxAnnounces - 1 ],
1205
1226
}),
1206
1227
isScheduled {
1207
1228
tracking : map [string ][]announce {
1208
1229
"A" : announceA [:maxTxAnnounces / 2 ],
1209
1230
"B" : announceB [:maxTxAnnounces / 2 - 1 ],
1231
+ "C" : announceC [:maxTxAnnounces / 2 - 1 ],
1210
1232
},
1211
1233
fetching : map [string ][]common.Hash {
1212
1234
"A" : hashesA [:maxTxRetrievals ],
1213
1235
"B" : hashesB [:maxTxRetrievals ],
1236
+ "C" : hashesC [:maxTxRetrievals ],
1214
1237
},
1215
1238
},
1216
1239
// Ensure that adding even one more hash results in dropping the hash
1217
1240
doTxNotify {peer : "A" , hashes : []common.Hash {hashesA [maxTxAnnounces ]}, types : []byte {typesA [maxTxAnnounces ]}, sizes : []uint32 {sizesA [maxTxAnnounces ]}},
1218
1241
doTxNotify {peer : "B" , hashes : hashesB [maxTxAnnounces - 1 : maxTxAnnounces + 1 ], types : typesB [maxTxAnnounces - 1 : maxTxAnnounces + 1 ], sizes : sizesB [maxTxAnnounces - 1 : maxTxAnnounces + 1 ]},
1242
+ doTxNotify {peer : "C" , hashes : hashesC [maxTxAnnounces - 1 : maxTxAnnounces + 2 ], types : typesC [maxTxAnnounces - 1 : maxTxAnnounces + 2 ], sizes : sizesC [maxTxAnnounces - 1 : maxTxAnnounces + 2 ]},
1219
1243
1220
1244
isWaiting (map [string ][]announce {
1221
1245
"A" : announceA [maxTxAnnounces / 2 : maxTxAnnounces ],
1222
1246
"B" : announceB [maxTxAnnounces / 2 - 1 : maxTxAnnounces ],
1247
+ "C" : announceC [maxTxAnnounces / 2 - 1 : maxTxAnnounces ],
1223
1248
}),
1224
1249
isScheduled {
1225
1250
tracking : map [string ][]announce {
1226
1251
"A" : announceA [:maxTxAnnounces / 2 ],
1227
1252
"B" : announceB [:maxTxAnnounces / 2 - 1 ],
1253
+ "C" : announceC [:maxTxAnnounces / 2 - 1 ],
1228
1254
},
1229
1255
fetching : map [string ][]common.Hash {
1230
1256
"A" : hashesA [:maxTxRetrievals ],
1231
1257
"B" : hashesB [:maxTxRetrievals ],
1258
+ "C" : hashesC [:maxTxRetrievals ],
1232
1259
},
1233
1260
},
1234
1261
},
0 commit comments