kernel: document validation state outputs as overwritten in-place #35189

pull w0xlt wants to merge 1 commits into bitcoin:master from w0xlt:kernel_block_check_doc changing 1 files +7 −7
  1. w0xlt commented at 1:01 AM on May 1, 2026: contributor

    This PR updates the public kernel API documentation for validation-state output parameters that are still caller-provided:

    • btck_transaction_check
    • btck_block_check

    Both wrappers reset the supplied validation state on entry before running validation, so callers should treat the state as overwritten in-place rather than preserving prior contents.

  2. DrahtBot added the label Validation on May 1, 2026
  3. DrahtBot commented at 1:01 AM on May 1, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35189.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK yuvicc
    Stale ACK sedited, alexanderwiederin

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #33856 (kernel: Refactor process_block_header to return btck_BlockValidationState by yuvicc)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. sedited approved
  5. sedited commented at 7:53 AM on May 1, 2026: contributor

    ACK ed81aca01a058daa3d9b2d15f0db52bf38487879

  6. sedited commented at 7:59 AM on May 1, 2026: contributor

    I wonder what the better pattern is here. Should we always be resetting them?

  7. fanquake added this to a project on May 1, 2026
  8. github-project-automation[bot] changed the project status on May 1, 2026
  9. in src/kernel/bitcoinkernel.h:1309 in ed81aca01a
    1307 | - *                                  btck_block_validation_state_create and updated
    1308 | - *                                  in-place with the validation result.
    1309 | + * @param[out]    validation_state  Non-null, previously created with
    1310 | + *                                  btck_block_validation_state_create. Reset on
    1311 | + *                                  entry (any prior contents are overwritten) and
    1312 | + *                                  updated in-place with the validation result
    


    maflcko commented at 3:04 PM on May 5, 2026:

    Doesn't "updated in-place" imply that any value is overwritten? I think it would be better to only document the out-params that are not always updated in-place and overwritten. (or rather, try to always update them and overwrite them, where possible)


    w0xlt commented at 11:51 PM on May 13, 2026:

    I agree that updated in-place can imply this to someone familiar with the validation-state pattern, but I think it is still worth spelling out here because this is public kernel API documentation.

    From a caller’s point of view, “updated in-place” mainly says that the object passed in is mutated. It does not necessarily make it obvious that any previous result is cleared before the check runs. Since callers may reuse the same btck_BlockValidationState across calls, documenting the reset-on-entry behavior makes the contract explicit and avoids them having to know how the internal ValidationState paths behave.


    maflcko commented at 6:12 AM on May 14, 2026:

    Ok, but I think briefly saying Overwritten in-place with the ... is fine, if updated in-place is too ambiguous and could mean that it is not reset.

    Also, what I wanted to say that this should be consistent, and it seems more important to look at the cases where it is not overwritten. Currently there is:

     * [@param](/github-metadata-backup-bitcoin-bitcoin/contributor/param/)[out] block_validation_state   The result of the btck_BlockHeader validation.
    

    So this looks like a bug that should be fixed there.


    w0xlt commented at 6:26 AM on May 19, 2026:

    good point, thanks. I updated the wording to use “Overwritten in-place...” for btck_block_check. I also fixed the inconsistent btck_chainstate_manager_process_block_header case you pointed out.

  10. yuvicc commented at 11:44 AM on May 13, 2026: contributor

    ACK ed81aca01a058daa3d9b2d15f0db52bf38487879

  11. fanquake commented at 12:22 PM on May 13, 2026: member
  12. w0xlt commented at 11:46 PM on May 13, 2026: contributor

    Should we always be resetting them?

    With the current public kernel API wrappers, yes. ValidationState is only updated on failure in many validation paths; a successful check can just return true without rewriting the state. So if a caller reuses a state object after a failed check, the old INVALID result could otherwise carry over into a later successful call.

  13. w0xlt commented at 11:51 PM on May 13, 2026: contributor

    @fanquake done.

  14. w0xlt force-pushed on May 19, 2026
  15. in src/kernel/bitcoinkernel.h:1394 in 60e0cb9463 outdated
    1392 | - *                                  btck_block_validation_state_create and updated
    1393 | - *                                  in-place with the validation result.
    1394 | + * @param[out]    validation_state  Non-null, previously created with
    1395 | + *                                  btck_block_validation_state_create.
    1396 | + *                                  Overwritten in-place with the validation
    1397 | + *                                  result.
    


    maflcko commented at 6:26 AM on May 19, 2026:

    The btck_transaction_check docstring should use the same wording as well, no?


    w0xlt commented at 6:37 AM on May 19, 2026:

    Done. Thanks.

  16. w0xlt force-pushed on May 19, 2026
  17. DrahtBot added the label CI failed on May 19, 2026
  18. w0xlt renamed this:
    kernel: document `btck_block_check` resets `validation_state`
    kernel: reset header validation state before processing
    on May 19, 2026
  19. w0xlt commented at 6:43 AM on May 19, 2026: contributor

    PR title and description updated.

    After #33856, btck_chainstate_manager_process_block_header returns a fresh btck_BlockValidationState, so no header validation state reset change is needed here.

    No behavior change.

  20. DrahtBot removed the label CI failed on May 19, 2026
  21. DrahtBot added the label Needs rebase on May 19, 2026
  22. kernel: document overwritten validation state outputs
    Document btck_transaction_check and btck_block_check validation state output parameters as overwritten in-place. This matches their reset-on-entry behavior and avoids implying callers should preserve prior state.
    0358c26d42
  23. w0xlt force-pushed on May 19, 2026
  24. w0xlt renamed this:
    kernel: reset header validation state before processing
    kernel: document validation state outputs as overwritten in-place
    on May 19, 2026
  25. DrahtBot removed the label Needs rebase on May 20, 2026
  26. yuvicc commented at 5:16 AM on May 20, 2026: contributor

    re-ACK 0358c26d427a21c147c96b91e6d4f2261cb3ac46

  27. DrahtBot requested review from sedited on May 20, 2026
  28. DrahtBot requested review from alexanderwiederin on May 20, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:52 UTC