Skip to content

Commit

Permalink
fix buildprimitive error chaincodelabs/libmultiprocess#51
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed Mar 26, 2021
1 parent ddcfd07 commit e53c7a9
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ EXTRA_DIST += $(libbitcoin_ipc_mpgen_input)
if BUILD_MULTIPROCESS
LIBBITCOIN_IPC=libbitcoin_ipc.a
libbitcoin_ipc_a_SOURCES = \
ipc/capnp/common-types.h \
ipc/capnp/init-types.h \
ipc/capnp/init.cpp \
ipc/capnp/protocol.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/altnet/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <altnet/context.h>
#include <chainparamsbase.h>
#include <interfaces/init.h>
#include <util/strencodings.h>
Expand Down
2 changes: 1 addition & 1 deletion src/init/bitcoin-altnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BitcoinAltnetInit : public interfaces::Init
BitcoinAltnetInit(AltnetContext& altnet, const char* arg0)
: m_altnet(altnet),
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this)) {}
std::unique_ptr<interfaces::Altnet> makeAltnet(interfaces::Validation& validation) override { return MakeUnique<AltnetImpl>(m_altnet, validation); }
std::unique_ptr<interfaces::Altnet> makeAltnet(interfaces::Validation& validation) override { return MakeAltnet(m_altnet, validation); }
interfaces::Ipc* ipc() override { return m_ipc.get(); }
AltnetContext& m_altnet;
std::unique_ptr<interfaces::Ipc> m_ipc;
Expand Down
112 changes: 112 additions & 0 deletions src/ipc/capnp/common-types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) 2021 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_COMMON_TYPES_H
#define BITCOIN_IPC_CAPNP_COMMON_TYPES_H

#include <clientversion.h>
#include <ipc/capnp/validation.capnp.proxy.h>
#include <mp/proxy-types.h>
#include <serialize.h>
#include <streams.h>

namespace ipc {
namespace capnp {
//! Deserialize bitcoin value.
template <typename T>
T Unserialize(T& value, const kj::ArrayPtr<const kj::byte>& data)
{
// Could optimize, it unnecessarily copies the data into a temporary vector.
CDataStream stream(CSerializeData{data.begin(), data.end()}, SER_NETWORK, CLIENT_VERSION);
value.Unserialize(stream);
return value;
}

//! Deserialize bitcoin value.
template <typename T>
T Unserialize(const kj::ArrayPtr<const kj::byte>& data)
{
T value;
Unserialize(value, data);
return value;
}

template <typename T>
using Deserializable = std::is_constructible<T, ::deserialize_type, ::CDataStream&>;

template <typename T>
struct Unserializable
{
private:
template <typename C>
static std::true_type test(decltype(std::declval<C>().Unserialize(std::declval<C&>()))*);
template <typename>
static std::false_type test(...);

public:
static constexpr bool value = decltype(test<T>(nullptr))::value;
};

template <typename T>
struct Serializable
{
private:
template <typename C>
static std::true_type test(decltype(std::declval<C>().Serialize(std::declval<C&>()))*);
template <typename>
static std::false_type test(...);

public:
static constexpr bool value = decltype(test<T>(nullptr))::value;
};
} // namespace capnp
} // namespace ipc

namespace mp {
template <typename LocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(
TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest,
typename std::enable_if<ipc::capnp::Deserializable<LocalType>::value>::type* enable = nullptr)
{
assert(input.has());
auto data = input.get();
// Note: stream copy here is unnecessary, and can be avoided in the future
// when `VectorReader` from #12254 is added.
CDataStream stream({data.begin(), data.end()}, SER_NETWORK, CLIENT_VERSION);
return read_dest.construct(deserialize, stream);
}

template <typename LocalType, typename Input, typename ReadDest>
decltype(auto) CustomReadField(
TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Input&& input, ReadDest&& read_dest,
// FIXME instead of always preferring Deserialize implementation over Unserialize should prefer Deserializing when
// emplacing, unserialize when updating
typename std::enable_if<ipc::capnp::Unserializable<LocalType>::value &&
!ipc::capnp::Deserializable<LocalType>::value>::type* enable = nullptr)
{
return read_dest.update([&](auto& value) {
if (!input.has()) return;
auto data = input.get();
// Note: stream copy here is unnecessary, and can be avoided in the future
// when `VectorReader` from #12254 is added.
CDataStream stream(CSerializeData{data.begin(), data.end()}, SER_NETWORK, CLIENT_VERSION);
value.Unserialize(stream);
});
}

template <typename LocalType, typename Value, typename Output>
void CustomBuildField(
TypeList<LocalType>, Priority<1>, InvokeContext& invoke_context, Value&& value, Output&& output,
typename std::enable_if<ipc::capnp::Serializable<
typename std::remove_cv<typename std::remove_reference<Value>::type>::type>::value>::type* enable = nullptr)
{
CDataStream stream(SER_NETWORK, CLIENT_VERSION);
value.Serialize(stream);
auto result = output.init(stream.size());
memcpy(result.begin(), stream.data(), stream.size());
}

} // namespace mp

#endif // BITCOIN_IPC_CAPNP_COMMON_TYPES_H
2 changes: 1 addition & 1 deletion src/ipc/capnp/validation.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $Cxx.namespace("ipc::capnp::messages");

using Proxy = import "/mp/proxy.capnp";
$Proxy.include("interfaces/validation.h");
$Proxy.include("ipc/capnp/validation.capnp.h");
$Proxy.includeTypes("ipc/capnp/common-types.h");

interface Validation $Proxy.wrap("interfaces::Validation") {
destroy @0 (context :Proxy.Context) -> ();
Expand Down
2 changes: 1 addition & 1 deletion src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class ValidationImpl : public Validation
{
public:
explicit ValidationImpl(NodeContext& node) : m_node(node) {}
bool validateHeaders(const BlockHeader& header) override
bool validateHeaders(const interfaces::BlockHeader& header) override
{
//BlockValidationState state;
//m_node.chainman->ProcessNewBlockHeaders(headers, state, Params());
Expand Down

0 comments on commit e53c7a9

Please sign in to comment.