Commit 61849f0
committed
Merge bitcoin/bitcoin#27918: fuzz: addrman, avoid
025fda0 fuzz: addrman, avoid `ConsumeDeserializable` when possible (brunoerg)
Pull request description:
Using specific functions like `ConsumeService`, `ConsumeAddress` and `ConsumeNetAddr` may be more effective than using `ConsumeDeserializable`. They always return some value while `ConsumeDeserializable` may return `std::nullopt`.
E.g.: In this part of the code, if `op_net_addr` is `std::nullopt`, we basically generated the addresses (if so) unnecessarily, because we won't be able to use them:
```cpp
std::vector<CAddress> addresses;
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
if (!opt_address) {
break;
}
addresses.push_back(*opt_address);
}
const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
if (opt_net_addr) {
addr_man.Add(addresses, *opt_net_addr, std::chrono::seconds{ConsumeTime(fuzzed_data_provider, 0, 100000000)});
}
```
Also, if we are not calling `Add` effectively, it would also be affect other functions that may "depend" on it.
ACKs for top commit:
dergoegge:
Code review ACK 025fda0
Tree-SHA512: 02450bec0b084c15ba0cd1cbdfbac067c8fea4ccf27be0c86d54e020f029a6c749a16d8e0558f9d6d35a7ca9db8916f180c872f09474702b5591129e9be0d192ConsumeDeserializable when possible1 file changed
+7
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
| 266 | + | |
275 | 267 | | |
| 268 | + | |
276 | 269 | | |
277 | 270 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
| 271 | + | |
282 | 272 | | |
283 | 273 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 274 | + | |
288 | 275 | | |
289 | 276 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 277 | + | |
294 | 278 | | |
295 | 279 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
| 280 | + | |
300 | 281 | | |
301 | 282 | | |
302 | 283 | | |
| |||
334 | 315 | | |
335 | 316 | | |
336 | 317 | | |
337 | | - | |
| 318 | + | |
0 commit comments