Page MenuHomePhabricator

refactor, blockstorage: Generalize GetFirstStoredBlock
AcceptedPublic

Authored by PiRK on Fri, Apr 11, 12:53.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Summary

GetFirstStoredBlock is generalized to check for any data status with a
status mask that needs to be passed as a parameter. To reflect this the
function is also renamed to GetFirstBlock.

Co-authored-by: stickies-v <stickies-v@protonmail.com>

In our codebase the status mask is a private member of BlockStatus, but we can achieve the same thing by passing a test function that takes a BlockStatus and returns a bool.

Core  ->  Bitcoin ABC
GetFirstBlock(upper_block, BLOCK_HAVE_DATA, &lower_block)
    -> GetFirstBlock(upper_block, [](BlockStatus status) {return status.hasData();}, &lower_block)
GetFirstBlock(upper_block, BLOCK_HAVE_MASK, &lower_block)
    -> GetFirstBlock(upper_block, [](BlockStatus status) {return status.hasData() && status.hasUndo();}, &lower_block)

This is a partial backport of core#29668
https://github.com/bitcoin/bitcoin/pull/29668/commits/96b4facc912927305b06a233cb8b36e7e5964c08

Test Plan

ninja check-functional-extended

Event Timeline

PiRK requested review of this revision.Fri, Apr 11, 12:53
PiRK edited the summary of this revision. (Show Details)
Fabien requested changes to this revision.Fri, Apr 11, 14:10
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/node/blockstorage.h
374 ↗(On Diff #53457)
This revision now requires changes to proceed.Fri, Apr 11, 14:10

pass status by const ref

This revision is now accepted and ready to land.Sat, Apr 12, 09:54