Skip to content

refactor: remove GetBlockHash helper, use CChain::operator[] directly#7334

Open
knst wants to merge 1 commit into
dashpay:developfrom
knst:refactor-remove-getblockhash
Open

refactor: remove GetBlockHash helper, use CChain::operator[] directly#7334
knst wants to merge 1 commit into
dashpay:developfrom
knst:refactor-remove-getblockhash

Conversation

@knst
Copy link
Copy Markdown
Collaborator

@knst knst commented May 21, 2026

Issue being fixed or feature implemented

Single-use helper that calls CChain::operator[] with extra checks but it has unexpected behaviour for value -1 [it returns tip] but caller never has it.
Better to remove it to prevent misusages in the future, also to clean up global namespace.

What was done?

Removed GetBlockHash from global namespace and its only usage replaced to operator[] call.

How Has This Been Tested?

N/A

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@knst knst added this to the 24 milestone May 21, 2026
@github-actions
Copy link
Copy Markdown

✅ No Merge Conflicts Detected

This PR currently has no conflicts with other open PRs.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

Walkthrough

This PR removes the GetBlockHash() helper function from the validation module and refactors its single callsite in CQuorumBlockProcessor::GetQuorumBlockHash to directly index the active chain. The function implementation and declaration are deleted, and the blockprocessor code is updated to handle null CBlockIndex* pointers directly with logging. Additionally, the PR introduces new mempool APIs in the validation header: a FopenFn type alias for mockable file operations and declarations for DumpMempool() and LoadMempool() functions that accept an optional custom file-open callback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title directly and accurately describes the main change: removing the GetBlockHash helper function and replacing it with direct CChain::operator[] usage.
Description check ✅ Passed The pull request description clearly explains the issue being fixed (single-use helper with unexpected behavior), what was changed (removal of GetBlockHash and replacement with operator[] call), and addresses testing and breaking changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@thepastaclaw thepastaclaw left a comment

Choose a reason for hiding this comment

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

Code Review

Verified the refactor at commit c98fdc8. Removing the single-use GetBlockHash helper in favor of CChain::operator[] is behavior-preserving at the sole call site: caller asserts cs_main is held (line 489) making the dropped internal lock redundant, computed quorumStartHeight is always non-negative so the -1 sentinel was unreachable, and operator[] returns nullptr on out-of-range/empty-chain matching the prior false-return contract. No agent or CodeRabbit findings to validate.

Reviewed commit: c98fdc8

@knst knst requested review from PastaPastaPasta and UdjinM6 May 21, 2026 11:01
@knst knst changed the title refactor: remove helper GetBlockHash which now is matched with operator[] refactor: remove GetBlockHash helper, use CChain::operator[] directly May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants