kernel: trim Chain interface #33820

pull stickies-v wants to merge 2 commits into bitcoin:master from stickies-v:2025-11/kernel-trim-chain-interface changing 3 files +2 −33
  1. stickies-v commented at 4:50 pm on November 7, 2025: contributor

    Removes btck_chain_get_genesis and btck_chain_get_tip.

    They are trivially replaced with btck_chain_get_by_height (as indicated in the updated bitcoinkernel_wrapper.h), so I think it makes sense to trim the interface.

    For btck_chain_get_tip: on master we don’t provide any guarantees that the returned block index still corresponds to the actual tip, so the extra call doesn’t seem like a regression to me.

  2. kernel: remove btck_chain_get_genesis
    It is equivalent to calling btck_chain_get_by_height(0).
    737b6566f6
  3. kernel: remove btck_chain_get_tip
    It is equivalent to calling btck_chain_get_by_height with the
    height obtained from btck_chain_get_height. In neither case do we
    provide guarantees that the returned block index still corresponds
    to the actual tip.
    f4b3ba18d9
  4. DrahtBot added the label Validation on Nov 7, 2025
  5. DrahtBot commented at 4:51 pm on November 7, 2025: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK yuvicc
    Concept ACK TheCharlatan

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

  6. yuvicc commented at 2:32 pm on November 8, 2025: contributor

    ACK f4b3ba18d9bf3e7c2c55a98f3c3d98129a1fa6e2

    This makes sense to me.

  7. in src/kernel/bitcoinkernel_wrapper.h:970 in f4b3ba18d9
    968@@ -969,7 +969,7 @@ class ChainView : public View<btck_Chain>
    969 
    970     BlockTreeEntry Tip() const
    


    TheCharlatan commented at 10:23 pm on November 8, 2025:
    I wonder if we should even keep these methods now. The previous calls to tip and genesis were at least thread safe (which these are no longer). I agree that it is not worth keeping them just for the sake of it, but also not sure if they still provide utility here.

    stickies-v commented at 9:38 am on November 10, 2025:

    The previous calls to tip and genesis were at least thread safe

    With previous, do you mean master? I’m not sure how the current calls are not thread safe? These are read-only calls without side effects? And both in master and this PR, the caller has no guarantees that the returned tip is indeed the tip because cs_main isn’t exposed (regardless of threads)?

    I wonder if we should even keep these methods now.

    I agree, but I want to generalize that even more. I think Range objects should be the only public interface for their contents. Duplicated getter and count methods on the parent seem confusing and unnecessary, and are best made private imo. I’m taking that approach with py-bitcoinkernel and I think it works well. But I think given the added scope that’s better suited for a separate PR, which I’ll push out soon.


    maflcko commented at 9:45 am on November 10, 2025:

    With previous, do you mean master? I’m not sure how the current calls are not thread safe? These are read-only calls without side effects? And both in master and this PR, the caller has no guarantees that the returned tip is indeed the tip because cs_main isn’t exposed (regardless of threads)?

    I think there could be a rare and theoretical race where the function does not return any tip, but rather throws std::runtime_error("No entry in the chain at the provided height"); when the height is re-orged out to a lower more-work height. But this is mostly an edge case.


    stickies-v commented at 10:29 am on November 10, 2025:

    I hadn’t thought of the reduced-height reorg scenario, thanks for that. Reorg-safety in general is still an unsolved problem for the public interface, and this is another case of that.

    Note: the problem you report already exists for objects based on the Range class whenever size() depends on chain length, such as for Chain::Entries with Chain::Entries::back() being able to throw a std::runtime_error.


    TheCharlatan commented at 10:35 am on November 10, 2025:
    Yes, I was merely mentioning it, because the Tip and Genesis methods in current master at least provided a bit better integrity. I don’t think this is important at all though. External callers should provide synchronization for this. So the two calls should just be removed imo.
  8. TheCharlatan commented at 10:24 pm on November 8, 2025: contributor

    Concept ACK

    These were introduced before we had a dedicated iterator for traversing the chain. At this point, their benefit (thread safety) is kind of marginal.


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: 2025-11-30 00:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me