Skip to content

proxy: fix BuildList to use non-const iteration for interface types - #304

Open
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/buildlist
Open

proxy: fix BuildList to use non-const iteration for interface types#304
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/buildlist

Conversation

@ryanofsky

@ryanofsky ryanofsky commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Needed for bitcoin/bitcoin#10102 since #277 was merged.

Since #277, it is no longer possible to return vector<unique_ptr<ExternalSigner>> from Node::listExternalSigners() in bitcoin/bitcoin#10102, because the proxy server objects libmultiprocess creates to wrap the ExternalSigner objects need to take ownership of the objects to keep them alive, so they need to be moved out of the returned vector, which can only be done if BuildField is passed a non-const vector element.

This PR restores previous behavior before #277 making it possible to mutate container elements while serializing them, in cases like this where it is necessary.

@DrahtBot

DrahtBot commented Jul 8, 2026

Copy link
Copy Markdown

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

Reviews

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #298 (Fix error handling when creating clients (mp::ConnectStream) by xyzconstant)

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.

@ryanofsky

Copy link
Copy Markdown
Collaborator Author

Updated a0b01d7 -> 46deb5e (pr/buildlist.2 -> pr/buildlist.3, compare) to fix IWYU CI failures: add #include <mp/proxy-io.h> to generated proxy-client files and reserve() call in listCallbacks https://github.com/bitcoin-core/libmultiprocess/actions/runs/28966350534/job/85950397301

Comment thread test/mp/test/test.cpp Outdated

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for review. Looks like there are some things that should be improved here so I will make this a draft

Comment thread include/mp/proxy-types.h Outdated
Comment thread test/mp/test/test.cpp Outdated
@ryanofsky
ryanofsky marked this pull request as draft July 9, 2026 13:55
BuildList turns a C++ container into a capnp list. It looped over the
container with `for (const auto& elem : value)`, so every element was
const. That breaks when the elements are interface pointers: to send one
to the capnp server the proxy code has to take ownership away from the
unique_ptr by calling unique_ptr::release(), and that cannot be called on
a const object. So the code failed to compile, and returning a list of
interface pointers stopped working after bitcoin-core#277.

Fix this by looping with a plain iterator and passing each element to
BuildField as non-const, only moving elements out of the container when
the container itself is a temporary. See the code comment for details.

In Bitcoin Core, interfaces::Node::listExternalSigners() returns a
vector<unique_ptr<ExternalSigner>> over IPC and hits this code path.

Add a `listBars` method to the test FooInterface that returns a
vector<unique_ptr<Bar>>, plus a test that calls it over IPC, so this is
covered and does not break again.

Co-Authored-by: Sjors Provoost <sjors@sprovoost.nl>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated 46deb5e -> b14b0bf (pr/buildlist.3 -> pr/buildlist.4, compare) updating test as suggested

Rebased b14b0bf -> 5b13fe5 (pr/buildlist.4 -> pr/buildlist.5, compare) due to silent conflict with #305 and adding more rvalueness preserving code for more safety (to avoid moving from lvalues)

Updated 5b13fe5 -> f9e1c8d (pr/buildlist.5 -> pr/buildlist.6, compare) to fix IWYU error https://github.com/bitcoin-core/libmultiprocess/actions/runs/30508160651/job/90762305561?pr=304

Comment thread test/mp/test/test.cpp Outdated
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.

3 participants