mining: pass missing context to createNewBlock() and checkBlock() #33936

pull Sjors wants to merge 1 commits into bitcoin:master from Sjors:2025/11/ipc-context changing 2 files +7 −7
  1. Sjors commented at 12:36 pm on November 24, 2025: member

    Adding a context parameter ensures that these methods are run in their own thread and don’t block other calls.

    For createNewBlock() this is not expected to have much impact, because block template creation is fast.

    For checkBlock() this ensures that if we receive a slow to validate block from an untrusted origin (the IPC connection itself is assumed to trusted), it will not block the IPC server. But since validation itself blocks cs_main this is also not a huge performance win.

    This is a breaking change both ways:

    • clients must use the updated capnp file
    • updated clients can’t call these methods on an unupgraded node

    Because it’s a breaking change, but not really important, this PR is marked pending some other more important breaking change. See #33777.

  2. DrahtBot added the label Mining on Nov 24, 2025
  3. DrahtBot commented at 12:36 pm on November 24, 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/33936.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  4. Sjors referenced this in commit bb7d5a45aa on Nov 24, 2025
  5. Sjors marked this as a draft on Nov 24, 2025
  6. Sjors commented at 2:15 pm on November 24, 2025: member

    Although the change is fine, the original motivation is incorrect. I thought this would fix a serious memory management issue where the destroy was never called, but that’s not the case, see #33940 (comment).

    I marked the PR draft and updated the description to explain what it achieves and why it’s not urgent.

  7. mining: pass missing context to BlockTemplate methods
    Adding a context parameter ensures that these methods are run in
    their own thread and don't block other calls. They were missing
    for:
    
    - createNewBlock()
    - checkBlock()
    
    This  ensures that when checkBlock() receives a slow to validate
    block from an untrusted origin (the IPC connection itself is
    assumed to trusted), it will not block the IPC server (though
    validation itself still blocks cs_main).
    
    This is a breaking change both ways:
    - clients must use the updated capnp file
    - updated clients can't call these methods
      on an unupgraded node
    c6238c35dd
  8. Sjors force-pushed on Nov 24, 2025
  9. ryanofsky commented at 3:25 pm on November 24, 2025: contributor

    This is a breaking change

    Could be nice to return an explicit error to clients that are too old with a change like the following from #33777 (comment):

     0--- a/src/ipc/capnp/init.capnp
     1+++ b/src/ipc/capnp/init.capnp
     2@@ -19,5 +19,8 @@ using Mining = import "mining.capnp";
     3 interface Init $Proxy.wrap("interfaces::Init") {
     4     construct [@0](/bitcoin-bitcoin/contributor/0/) (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);
     5     makeEcho [@1](/bitcoin-bitcoin/contributor/1/) (context :Proxy.Context) -> (result :Echo.Echo);
     6-    makeMining [@2](/bitcoin-bitcoin/contributor/2/) (context :Proxy.Context) -> (result :Mining.Mining);
     7+    makeMining [@3](/bitcoin-bitcoin/contributor/3/) (context :Proxy.Context) -> (result :Mining.Mining);
     8+
     9+    # DEPRECATED: no longer supported; server returns an error.
    10+    makeMiningV2 [@2](/bitcoin-bitcoin/contributor/2/) () -> ();
    11 }
    12--- a/src/interfaces/init.h
    13+++ b/src/interfaces/init.h
    14@@ -39,6 +39,7 @@ public:
    15     virtual Ipc* ipc() { return nullptr; }
    16     virtual bool canListenIpc() { return false; }
    17     virtual const char* exeName() { return nullptr; }
    18+    virtual void makeMiningV2() { throw std::runtime_error("Old mining interface (@2) not supported. Please update your client!"); }
    19 };
    20 
    21 //! Return implementation of Init interface for the node process. If the argv
    
  10. Sjors commented at 3:53 pm on November 24, 2025: member
    Bumping the version number would also allow clients that wish to support older Bitcoin Core version to keep two capnp files around.

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-26 06:13 UTC

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