You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2054946 [Chain] Prune entire orphaned chains. (Zannick)
Pull request description:
### Problem
Pruned blocks sometimes cause other blocks in the index (mostly descendants of orphans) to have invalid parents, which may trip an assert `pindexWalk->pprev` (#692) on startup. Additionally, because block indexes *don't own their own hash values*, removing the index from `mapBlockIndex` where the hash is allocated may lead to a use-after-free corrupting the hash of a block written to disk (may be the cause of #930 (comment)).
### Solution
Select pruning candidates in two rounds: first, based on height. Then, add all descendants of the blocks chosen in the first round.
For the memory issue, add a `shared_ptr` field to CBlockIndex that provides the hash value when the block is removed from mapBlockIndex. This will manage the memory of the hash for the lifetime of the object (which is forever anyway) and allows for efficient sharing and copying as usual (unique_ptr does not).
### Testing
Via regtest. See #692 (comment)
Tree-SHA512: ef000928dff3ad45e214f07e23795d92b1a75c6221180982e02a82f28a69349975a46813a34d966c1bb73bd927d007ce892e0d85afe1cac055c1da3931e3ea5b
0 commit comments