Merge bitcoin/bitcoin#31740: depends: Update libmultiprocess library before converting to subtree

4e0aa1835b3e980ceda29ec90e7115d7fef53f51 test: Add test for IPC serialization bug (Ryan Ofsky)
2221c8814d765c1e6109a6f0ecec00d5b4af2ec6 depends: Update libmultiprocess library before converting to subtree (Ryan Ofsky)

Pull request description:

  This should be the final update to the libmultiprocess package via the depends system. It brings in the libmultiprocess cmake changes from https://github.com/chaincodelabs/libmultiprocess/pull/136 needed to support building as subtree. After this, followup PR #31741 will add libmultiprocess as a git subtree and depends will just use the git subtree instead of hardcoding its own version hash.

  Since there have been libmultiprocess API changes since the last update, this commit also updates bitcoin code to be compatible with them.

  This update has the following new changes since previous update #31105:

  https://github.com/chaincodelabs/libmultiprocess/pull/121 ProxyClientBase: avoid static_cast to partially constructed object
  https://github.com/chaincodelabs/libmultiprocess/pull/120 proxy-types.h: add static_assert to detect int/enum size mismatch
  https://github.com/chaincodelabs/libmultiprocess/pull/127 ProxyClientBase: avoid static_cast to partially destructed object
  https://github.com/chaincodelabs/libmultiprocess/pull/129 Fix "disconnected: write(m_post_fd, &buffer, 1): Broken pipe" EventLoop shutdown races.
  https://github.com/chaincodelabs/libmultiprocess/pull/130 refactor: Add CleanupRun function to dedup clean list code
  https://github.com/chaincodelabs/libmultiprocess/pull/131 doc: fix startAsyncThread comment
  https://github.com/chaincodelabs/libmultiprocess/pull/133 Fix debian "libatomic not found" error in downstream builds
  https://github.com/chaincodelabs/libmultiprocess/pull/94 c++ 20 cleanups
  https://github.com/chaincodelabs/libmultiprocess/pull/135 refactor: proxy-types.h API cleanup
  https://github.com/chaincodelabs/libmultiprocess/pull/136 cmake: Support being included with add_subdirectory
  https://github.com/chaincodelabs/libmultiprocess/pull/137 doc: Fix broken markdown links

ACKs for top commit:
  Sjors:
    ACK 4e0aa1835b3e980ceda29ec90e7115d7fef53f51
  vasild:
    ACK 4e0aa1835b3e980ceda29ec90e7115d7fef53f51
  TheCharlatan:
    ACK 4e0aa1835b3e980ceda29ec90e7115d7fef53f51

Tree-SHA512: 6d81cdf7f44762c7f476212295f6224054fd0a61315bb54786bc7758a2b33e5a2fce925c71e36f7bda320049aa14e7218a458ceb03dacbb869632c466c4789b0
This commit is contained in:
merge-script 2025-01-29 12:10:23 +00:00
commit ad2f9324c6
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
8 changed files with 36 additions and 50 deletions

View File

@ -1,8 +1,8 @@
package=native_libmultiprocess
$(package)_version=abe254b9734f2e2b220d1456de195532d6e6ac1e
$(package)_version=07c917f7ca910d66abc6d3873162fc9061704074
$(package)_download_path=https://github.com/chaincodelabs/libmultiprocess/archive
$(package)_file_name=$($(package)_version).tar.gz
$(package)_sha256_hash=85777073259fdc75d24ac5777a19991ec1156c5f12db50b252b861c95dcb4f46
$(package)_sha256_hash=ac9db311e3b22aac3c7b7b7b3f6b7fee5cf3043ebb3c3bf412049e8b17166de8
$(package)_dependencies=native_capnp
define $(package)_config_cmds

View File

@ -14,6 +14,19 @@
#include <cstddef>
#include <mp/proxy-types.h>
#include <mp/type-chrono.h>
#include <mp/type-context.h>
#include <mp/type-data.h>
#include <mp/type-decay.h>
#include <mp/type-interface.h>
#include <mp/type-message.h>
#include <mp/type-number.h>
#include <mp/type-optional.h>
#include <mp/type-pointer.h>
#include <mp/type-string.h>
#include <mp/type-struct.h>
#include <mp/type-threadmap.h>
#include <mp/type-vector.h>
#include <type_traits>
#include <utility>
@ -94,26 +107,6 @@ requires ipc::capnp::Deserializable<LocalType>
return read_dest.construct(::deserialize, wrapper);
}
//! Overload CustomBuildField and CustomReadField to serialize std::chrono
//! parameters and return values as numbers.
template <class Rep, class Period, typename Value, typename Output>
void CustomBuildField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1>, InvokeContext& invoke_context, Value&& value,
Output&& output)
{
static_assert(std::numeric_limits<decltype(output.get())>::lowest() <= std::numeric_limits<Rep>::lowest(),
"capnp type does not have enough range to hold lowest std::chrono::duration value");
static_assert(std::numeric_limits<decltype(output.get())>::max() >= std::numeric_limits<Rep>::max(),
"capnp type does not have enough range to hold highest std::chrono::duration value");
output.set(value.count());
}
template <class Rep, class Period, typename Input, typename ReadDest>
decltype(auto) CustomReadField(TypeList<std::chrono::duration<Rep, Period>>, Priority<1>, InvokeContext& invoke_context,
Input&& input, ReadDest&& read_dest)
{
return read_dest.construct(input.get());
}
//! Overload CustomBuildField and CustomReadField to serialize UniValue
//! parameters and return values as JSON strings.
template <typename Value, typename Output>
@ -134,32 +127,6 @@ decltype(auto) CustomReadField(TypeList<UniValue>, Priority<1>, InvokeContext& i
});
}
//! Generic ::capnp::Data field builder for any C++ type that can be converted
//! to a span of bytes, like std::vector<char> or std::array<uint8_t>, or custom
//! blob types like uint256 or PKHash with data() and size() methods pointing to
//! bytes.
//!
//! Note: it might make sense to move this function into libmultiprocess, since
//! it is fairly generic. However this would require decreasing its priority so
//! it can be overridden, which would require more changes inside
//! libmultiprocess to avoid conflicting with the Priority<1> CustomBuildField
//! function it already provides for std::vector. Also, it might make sense to
//! provide a CustomReadField counterpart to this function, which could be
//! called to read C++ types that can be constructed from spans of bytes from
//! ::capnp::Data fields. But so far there hasn't been a need for this.
template <typename LocalType, typename Value, typename Output>
void CustomBuildField(TypeList<LocalType>, Priority<2>, InvokeContext& invoke_context, Value&& value, Output&& output)
requires
(std::is_same_v<decltype(output.get()), ::capnp::Data::Builder>) &&
(std::convertible_to<Value, std::span<const std::byte>> ||
std::convertible_to<Value, std::span<const char>> ||
std::convertible_to<Value, std::span<const unsigned char>> ||
std::convertible_to<Value, std::span<const signed char>>)
{
auto data = std::span{value};
auto result = output.init(data.size());
memcpy(result.begin(), data.data(), data.size());
}
} // namespace mp
#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H

View File

@ -0,0 +1,12 @@
// Copyright (c) 2025 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_IPC_CAPNP_ECHO_TYPES_H
#define BITCOIN_IPC_CAPNP_ECHO_TYPES_H
#include <mp/type-context.h>
#include <mp/type-decay.h>
#include <mp/type-string.h>
#endif // BITCOIN_IPC_CAPNP_ECHO_TYPES_H

View File

@ -9,7 +9,7 @@ $Cxx.namespace("ipc::capnp::messages");
using Proxy = import "/mp/proxy.capnp";
$Proxy.include("interfaces/echo.h");
$Proxy.include("ipc/capnp/echo.capnp.h");
$Proxy.includeTypes("ipc/capnp/echo-types.h");
interface Echo $Proxy.wrap("interfaces::Echo") {
destroy @0 (context :Proxy.Context) -> ();

View File

@ -73,7 +73,7 @@ public:
}
void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) override
{
mp::ProxyTypeRegister::types().at(type)(iface).cleanup.emplace_back(std::move(cleanup));
mp::ProxyTypeRegister::types().at(type)(iface).cleanup_fns.emplace_back(std::move(cleanup));
}
Context& context() override { return m_context; }
void startLoop(const char* exe_name)

View File

@ -20,4 +20,5 @@ interface FooInterface $Proxy.wrap("FooImplementation") {
passTransaction @3 (arg :Data) -> (result :Data);
passVectorChar @4 (arg :Data) -> (result :Data);
passBlockState @5 (arg :Mining.BlockValidationState) -> (result :Mining.BlockValidationState);
passScript @6 (arg :Data) -> (result :Data);
}

View File

@ -121,6 +121,10 @@ void IpcPipeTest()
BOOST_CHECK_EQUAL(bs3.GetRejectReason(), bs4.GetRejectReason());
BOOST_CHECK_EQUAL(bs3.GetDebugMessage(), bs4.GetDebugMessage());
auto script1{CScript() << OP_11};
auto script2{foo->passScript(script1)};
BOOST_CHECK_EQUAL(HexStr(script1), HexStr(script2));
// Test cleanup: disconnect pipe and join thread
disconnect_client();
thread.join();

View File

@ -6,6 +6,7 @@
#define BITCOIN_TEST_IPC_TEST_H
#include <primitives/transaction.h>
#include <script/script.h>
#include <univalue.h>
#include <util/fs.h>
#include <validation.h>
@ -19,6 +20,7 @@ public:
CTransactionRef passTransaction(CTransactionRef t) { return t; }
std::vector<char> passVectorChar(std::vector<char> v) { return v; }
BlockValidationState passBlockState(BlockValidationState s) { return s; }
CScript passScript(CScript s) { return s; }
};
void IpcPipeTest();