proxy: fix BuildList to use non-const iteration for interface types - #304
proxy: fix BuildList to use non-const iteration for interface types#304ryanofsky wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Updated a0b01d7 -> 46deb5e ( |
ryanofsky
left a comment
There was a problem hiding this comment.
Thanks for review. Looks like there are some things that should be improved here so I will make this a draft
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>
There was a problem hiding this comment.
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
Needed for bitcoin/bitcoin#10102 since #277 was merged.
Since #277, it is no longer possible to return
vector<unique_ptr<ExternalSigner>>fromNode::listExternalSigners()in bitcoin/bitcoin#10102, because the proxy server objects libmultiprocess creates to wrap theExternalSignerobjects 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 ifBuildFieldis 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.