mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-10 04:33:59 +01:00
multiprocess: Add serialization code for BlockValidationState
Co-authored-by: TheCharlatan <seb.kung@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# file COPYING or https://opensource.org/license/mit/.
|
||||
|
||||
add_library(bitcoin_ipc STATIC EXCLUDE_FROM_ALL
|
||||
capnp/mining.cpp
|
||||
capnp/protocol.cpp
|
||||
interfaces.cpp
|
||||
process.cpp
|
||||
|
||||
@@ -13,4 +13,14 @@
|
||||
#include <node/types.h>
|
||||
#include <validation.h>
|
||||
|
||||
namespace mp {
|
||||
// Custom serialization for BlockValidationState.
|
||||
void CustomBuildMessage(InvokeContext& invoke_context,
|
||||
const BlockValidationState& src,
|
||||
ipc::capnp::messages::BlockValidationState::Builder&& builder);
|
||||
void CustomReadMessage(InvokeContext& invoke_context,
|
||||
const ipc::capnp::messages::BlockValidationState::Reader& reader,
|
||||
BlockValidationState& dest);
|
||||
} // namespace mp
|
||||
|
||||
#endif // BITCOIN_IPC_CAPNP_MINING_TYPES_H
|
||||
|
||||
@@ -39,6 +39,12 @@ struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
|
||||
coinbaseOutputMaxAdditionalSigops @2 :UInt64 $Proxy.name("coinbase_output_max_additional_sigops");
|
||||
}
|
||||
|
||||
# TODO add fields to this struct
|
||||
struct BlockValidationState $Proxy.wrap("BlockValidationState") {
|
||||
# Note: serialization of the BlockValidationState C++ type is somewhat fragile
|
||||
# and using the struct can be awkward. It would be good if testBlockValidity
|
||||
# method were changed to return validity information in a simpler format.
|
||||
struct BlockValidationState {
|
||||
mode @0 :Int32;
|
||||
result @1 :Int32;
|
||||
rejectReason @2 :Text;
|
||||
debugMessage @3 :Text;
|
||||
}
|
||||
|
||||
47
src/ipc/capnp/mining.cpp
Normal file
47
src/ipc/capnp/mining.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2024 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <ipc/capnp/mining-types.h>
|
||||
#include <ipc/capnp/mining.capnp.proxy-types.h>
|
||||
|
||||
#include <mp/proxy-types.h>
|
||||
|
||||
namespace mp {
|
||||
void CustomBuildMessage(InvokeContext& invoke_context,
|
||||
const BlockValidationState& src,
|
||||
ipc::capnp::messages::BlockValidationState::Builder&& builder)
|
||||
{
|
||||
if (src.IsValid()) {
|
||||
builder.setMode(0);
|
||||
} else if (src.IsInvalid()) {
|
||||
builder.setMode(1);
|
||||
} else if (src.IsError()) {
|
||||
builder.setMode(2);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
builder.setResult(static_cast<int>(src.GetResult()));
|
||||
builder.setRejectReason(src.GetRejectReason());
|
||||
builder.setDebugMessage(src.GetDebugMessage());
|
||||
}
|
||||
|
||||
void CustomReadMessage(InvokeContext& invoke_context,
|
||||
const ipc::capnp::messages::BlockValidationState::Reader& reader,
|
||||
BlockValidationState& dest)
|
||||
{
|
||||
if (reader.getMode() == 0) {
|
||||
assert(reader.getResult() == 0);
|
||||
assert(reader.getRejectReason().size() == 0);
|
||||
assert(reader.getDebugMessage().size() == 0);
|
||||
} else if (reader.getMode() == 1) {
|
||||
dest.Invalid(static_cast<BlockValidationResult>(reader.getResult()), reader.getRejectReason(), reader.getDebugMessage());
|
||||
} else if (reader.getMode() == 2) {
|
||||
assert(reader.getResult() == 0);
|
||||
dest.Error(reader.getRejectReason());
|
||||
assert(reader.getDebugMessage().size() == 0);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
} // namespace mp
|
||||
Reference in New Issue
Block a user