Skip to content

Commit 4e67086

Browse files
committed
multiprocess: Add serialization code for CBlockTemplate
1 parent 44acf97 commit 4e67086

File tree

7 files changed

+41
-2
lines changed

7 files changed

+41
-2
lines changed

src/ipc/capnp/mining-types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ void CustomBuildMessage(InvokeContext& invoke_context,
1919
void CustomReadMessage(InvokeContext& invoke_context,
2020
const ipc::capnp::messages::BlockValidationState::Reader& reader,
2121
BlockValidationState& dest);
22+
23+
// Custom serialization for std::unique_ptr<CBlockTemplate>.
24+
void CustomBuildMessage(InvokeContext& invoke_context,
25+
const std::unique_ptr<node::CBlockTemplate>& src,
26+
ipc::capnp::messages::CBlockTemplate::Builder&& builder);
27+
void CustomReadMessage(InvokeContext& invoke_context,
28+
const ipc::capnp::messages::CBlockTemplate::Reader& reader,
29+
std::unique_ptr<node::CBlockTemplate>& dest);
2230
} // namespace mp
2331

2432
#endif // BITCOIN_IPC_CAPNP_MINING_TYPES_H

src/ipc/capnp/mining.capnp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ struct BlockValidationState {
3434
debugMessage @3 :Text;
3535
}
3636

37-
# TODO add fields to this struct
38-
struct CBlockTemplate $Proxy.wrap("std::unique_ptr<node::CBlockTemplate>")
37+
struct CBlockTemplate $Proxy.wrap("node::CBlockTemplate")
3938
{
39+
block @0 :Data;
40+
vTxFees @1 :List(UInt64);
41+
vTxSigOpsCost @2 :List(UInt64);
42+
vchCoinbaseCommitment @3 :Data;
4043
}

src/ipc/capnp/mining.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,21 @@ void CustomReadMessage(InvokeContext& invoke_context,
4444
assert(false);
4545
}
4646
}
47+
48+
void CustomBuildMessage(InvokeContext& invoke_context,
49+
const std::unique_ptr<node::CBlockTemplate>& src,
50+
ipc::capnp::messages::CBlockTemplate::Builder&& builder)
51+
{
52+
if (src) {
53+
BuildField(TypeList<node::CBlockTemplate>(), invoke_context, ValueField(builder), *src);
54+
}
55+
}
56+
57+
void CustomReadMessage(InvokeContext& invoke_context,
58+
const ipc::capnp::messages::CBlockTemplate::Reader& reader,
59+
std::unique_ptr<node::CBlockTemplate>& dest)
60+
{
61+
dest = std::make_unique<node::CBlockTemplate>();
62+
ReadField(TypeList<node::CBlockTemplate>(), invoke_context, ValueField(reader), ReadDestValue(*dest));
63+
}
4764
} // namespace mp

src/test/ipc_test.capnp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface FooInterface $Proxy.wrap("FooImplementation") {
2121
passTransaction @4 (arg :Data) -> (result :Data);
2222
passBlockState @5 (arg :Mining.BlockValidationState) -> (result :Mining.BlockValidationState);
2323
passVectorChar @6 (arg :Data) -> (result :Data);
24+
passBlockTemplate @7 (arg :Mining.CBlockTemplate) -> (result :Mining.CBlockTemplate);
2425
}
2526

2627
struct CustomStruct {

src/test/ipc_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <boost/test/unit_test.hpp>
1818

19+
using node::CBlockTemplate;
20+
1921
namespace mp {
2022
//! Custom conversion functions between C++ and capnp CustomStructs
2123
//! Shift value by 100 to make conversion a little more interesting.
@@ -104,6 +106,11 @@ void IpcTest()
104106
std::vector<char> vec2{foo->passVectorChar(vec1)};
105107
BOOST_CHECK_EQUAL(std::string_view(vec1.begin(), vec1.end()), std::string_view(vec2.begin(), vec2.end()));
106108

109+
CBlockTemplate temp1;
110+
temp1.block.nTime = 5;
111+
CBlockTemplate temp2{foo->passBlockTemplate(temp1)};
112+
BOOST_CHECK_EQUAL(temp1.block.nTime, temp2.block.nTime);
113+
107114
// Test cleanup: disconnect pipe and join thread
108115
disconnect_client();
109116
thread.join();

src/test/ipc_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_TEST_IPC_TEST_H
66
#define BITCOIN_TEST_IPC_TEST_H
77

8+
#include <node/miner.h>
89
#include <primitives/transaction.h>
910
#include <univalue.h>
1011
#include <validation.h>
@@ -24,6 +25,7 @@ class FooImplementation
2425
CTransactionRef passTransaction(CTransactionRef t) { return t; }
2526
BlockValidationState passBlockState(BlockValidationState s) { return s; }
2627
std::vector<char> passVectorChar(std::vector<char> v) { return v; }
28+
node::CBlockTemplate passBlockTemplate(node::CBlockTemplate t) { return t; }
2729
};
2830

2931
void IpcTest();

src/test/ipc_test_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_TEST_IPC_TEST_TYPES_H
77

88
#include <ipc/capnp/common-types.h>
9+
#include <ipc/capnp/mining.capnp.proxy-types.h>
910
#include <ipc/capnp/mining-types.h>
1011
#include <test/ipc_test.capnp.h>
1112

0 commit comments

Comments
 (0)