Skip to content

Conversation

furszy
Copy link
Member

@furszy furszy commented Dec 31, 2022

Coming from #23549 (review)

The current scanblocks flow walks-through every block in the active chain
until hits the chain tip or processes 10k blocks, then calls lookupFilterRange
function to obtain all filters from that particular range.

This is only done to obtain the heights range to look up the block
filters. Which is unneeded.

As scanblocks only lookup block filters in the active chain, we can
directly calculate the lookup range heights, by using the chain tip,
without requiring to traverse the chain block by block.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 31, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Does this require a release note for the s/filtertype/filter_type/ change?

@@ -2474,8 +2474,9 @@ static RPCHelpMan scanblocks()
} while (start_index != stop_block);

ret.pushKV("from_height", start_block_height);
ret.pushKV("to_height", stop_block->nHeight);
ret.pushKV("to_height", start_index->nHeight); // start_index is always the last scanned block here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference,end_range->nHeight would be a bit easier to read, but is not guaranteed to have a value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the user could have aborted the process at the very beginning.

maybe could change it to:

end_range ? end_range->nHeight : start_index->nHeight;

but I'm not so sure that this makes code easier to read.

@furszy
Copy link
Member Author

furszy commented Apr 30, 2023

Thanks for the review TheCharlatan.

Does this require a release note for the s/filtertype/filter_type/ change?

Not necessarily. We branched-off v25 and haven't released yet. It would just need to be back ported.
But.. will just drop that commit. The change made more sense back in December just after merging #23549.

furszy added 2 commits April 30, 2023 19:14
The current flow walks-through every block in the active chain until
hits the chain tip or processes 10k blocks, then calls
`lookupFilterRange()` to obtain all the filters from that
particular range.

This is only done to obtain the heights range to look up the block
filters. Which is unneeded.

As `scanblocks` only lookup block filters in the active chain, we can
directly calculate the lookup range heights, by using the chain tip,
without requiring to traverse the chain block by block.
To tell the user whether the process was aborted or not.

Plus, as the process can be aborted prior to the end range,
have also changed the "to_height" result value to return the
last scanned block instead of the end range block.
@furszy furszy force-pushed the 2022_simplify_scan_blocks branch from 4fcf035 to b922f6b Compare April 30, 2023 18:26
Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b922f6b

@achow101
Copy link
Member

achow101 commented May 1, 2023

ACK b922f6b

@DrahtBot DrahtBot removed the request for review from achow101 May 1, 2023 13:02
@achow101 achow101 merged commit 0eae93e into bitcoin:master May 1, 2023
@furszy furszy deleted the 2022_simplify_scan_blocks branch May 1, 2023 13:12
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 1, 2023
b922f6b rpc: scanblocks, add "completed" flag to the result obj (furszy)
ce50acc rpc: scanblocks, do not traverse the whole chain block by block (furszy)

Pull request description:

  Coming from bitcoin#23549 (review)

  The current `scanblocks` flow walks-through every block in the active chain
  until hits the chain tip or processes 10k blocks, then calls `lookupFilterRange`
  function to obtain all filters from that particular range.

  This is only done to obtain the heights range to look up the block
  filters. Which is unneeded.

  As `scanblocks` only lookup block filters in the active chain, we can
  directly calculate the lookup range heights, by using the chain tip,
  without requiring to traverse the chain block by block.

ACKs for top commit:
  achow101:
    ACK b922f6b
  TheCharlatan:
    ACK b922f6b

Tree-SHA512: 0587e6d9cf87a59184adb2dbc26a4e2bce3a16233594c6c330f69feb49bf7dc63fdacf44fc20308e93441159ebc604c63eb7de19204d3e745a2ff16004892b45
@bitcoin bitcoin locked and limited conversation to collaborators Apr 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants