Commit 5871b5b
committed
Merge bitcoin#25571: refactor: Make mapBlocksUnknownParent local, and rename it
dd065da refactor: Make mapBlocksUnknownParent local, and rename it (Hennadii Stepanov)
Pull request description:
This PR is a second attempt at bitcoin#19594. This PR has two motivations:
- Improve code hygiene by eliminating a global variable, `mapBlocksUnknownParent`
- Fix fuzz test OOM when running too long ([see bitcoin#19594 comment](bitcoin#19594 (comment)))
A minor added advantage is to release `mapBlocksUnknownParent` memory when the reindexing phase is done. The current situation is somewhat similar to a memory leak because this map exists unused for the remaining lifetime of the process. It's true that this map should be empty of data elements after use, but its internal metadata (indexing structures, etc.) can have non-trivial size because there can be many thousands of simultaneous elements in this map.
This PR helps our efforts to reduce the use of global variables. This variable isn't just global, it's hidden inside a function (it looks like a local variable but has the `static` attribute).
This global variable exists because the `-reindex` processing code calls `LoadExternalBlockFile()` multiple times (once for each block file), but that function must preserve some state between calls (the `mapBlocksUnknownParent` map). This PR fixes this by allocating this map as a local variable in the caller's scope and passing it in on each call. When reindexing completes, the map goes out of scope and is deallocated.
I tested this manually by reindexing on mainnet and signet. Also, the existing `feature_reindex.py` functional test passes.
ACKs for top commit:
mzumsande:
re-ACK dd065da
theStack:
re-ACK dd065da
shaavan:
reACK dd065da
Tree-SHA512: 9cd20e44d2fa1096dd405bc107bc065ea8f904f5b3f63080341b08d8cf57b790df565f58815c2f331377d044d5306708b4bf6bdfc5ef8d0ed85d8e97d744732cFile tree
4 files changed
+60
-12
lines changed- src
- node
- test/fuzz
4 files changed
+60
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
834 | 835 | | |
835 | 836 | | |
836 | 837 | | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
837 | 841 | | |
838 | 842 | | |
839 | 843 | | |
| |||
844 | 848 | | |
845 | 849 | | |
846 | 850 | | |
847 | | - | |
| 851 | + | |
848 | 852 | | |
849 | 853 | | |
850 | 854 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
4256 | 4257 | | |
4257 | 4258 | | |
4258 | 4259 | | |
4259 | | - | |
| 4260 | + | |
| 4261 | + | |
| 4262 | + | |
| 4263 | + | |
4260 | 4264 | | |
4261 | 4265 | | |
4262 | | - | |
4263 | | - | |
| 4266 | + | |
| 4267 | + | |
| 4268 | + | |
| 4269 | + | |
4264 | 4270 | | |
4265 | 4271 | | |
4266 | 4272 | | |
| |||
4310 | 4316 | | |
4311 | 4317 | | |
4312 | 4318 | | |
4313 | | - | |
4314 | | - | |
| 4319 | + | |
| 4320 | + | |
| 4321 | + | |
4315 | 4322 | | |
4316 | 4323 | | |
4317 | 4324 | | |
| |||
4340 | 4347 | | |
4341 | 4348 | | |
4342 | 4349 | | |
| 4350 | + | |
| 4351 | + | |
4343 | 4352 | | |
4344 | 4353 | | |
4345 | 4354 | | |
4346 | 4355 | | |
4347 | 4356 | | |
4348 | 4357 | | |
4349 | | - | |
| 4358 | + | |
4350 | 4359 | | |
4351 | 4360 | | |
4352 | 4361 | | |
| |||
4361 | 4370 | | |
4362 | 4371 | | |
4363 | 4372 | | |
4364 | | - | |
| 4373 | + | |
4365 | 4374 | | |
4366 | 4375 | | |
4367 | 4376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
578 | | - | |
579 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
580 | 608 | | |
581 | 609 | | |
582 | 610 | | |
| |||
0 commit comments