mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
multiprocess: Add IPC wrapper for Mining interface
This commit is contained in:
parent
06882f8401
commit
33c2eee285
7 changed files with 106 additions and 1 deletions
|
@ -9,10 +9,14 @@ add_library(bitcoin_ipc STATIC EXCLUDE_FROM_ALL
|
||||||
)
|
)
|
||||||
|
|
||||||
target_capnp_sources(bitcoin_ipc ${PROJECT_SOURCE_DIR}
|
target_capnp_sources(bitcoin_ipc ${PROJECT_SOURCE_DIR}
|
||||||
capnp/echo.capnp capnp/init.capnp
|
capnp/common.capnp
|
||||||
|
capnp/echo.capnp
|
||||||
|
capnp/init.capnp
|
||||||
|
capnp/mining.capnp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(bitcoin_ipc
|
target_link_libraries(bitcoin_ipc
|
||||||
PRIVATE
|
PRIVATE
|
||||||
core_interface
|
core_interface
|
||||||
|
univalue
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define BITCOIN_IPC_CAPNP_COMMON_TYPES_H
|
#define BITCOIN_IPC_CAPNP_COMMON_TYPES_H
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
|
#include <interfaces/types.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
@ -93,6 +94,26 @@ requires ipc::capnp::Deserializable<LocalType>
|
||||||
return read_dest.construct(::deserialize, wrapper);
|
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
|
//! Overload CustomBuildField and CustomReadField to serialize UniValue
|
||||||
//! parameters and return values as JSON strings.
|
//! parameters and return values as JSON strings.
|
||||||
template <typename Value, typename Output>
|
template <typename Value, typename Output>
|
||||||
|
|
16
src/ipc/capnp/common.capnp
Normal file
16
src/ipc/capnp/common.capnp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
@0xcd2c6232cb484a28;
|
||||||
|
|
||||||
|
using Cxx = import "/capnp/c++.capnp";
|
||||||
|
$Cxx.namespace("ipc::capnp::messages");
|
||||||
|
|
||||||
|
using Proxy = import "/mp/proxy.capnp";
|
||||||
|
$Proxy.includeTypes("ipc/capnp/common-types.h");
|
||||||
|
|
||||||
|
struct BlockRef $Proxy.wrap("interfaces::BlockRef") {
|
||||||
|
hash @0 :Data;
|
||||||
|
height @1 :Int32;
|
||||||
|
}
|
|
@ -6,5 +6,6 @@
|
||||||
#define BITCOIN_IPC_CAPNP_INIT_TYPES_H
|
#define BITCOIN_IPC_CAPNP_INIT_TYPES_H
|
||||||
|
|
||||||
#include <ipc/capnp/echo.capnp.proxy-types.h>
|
#include <ipc/capnp/echo.capnp.proxy-types.h>
|
||||||
|
#include <ipc/capnp/mining.capnp.proxy-types.h>
|
||||||
|
|
||||||
#endif // BITCOIN_IPC_CAPNP_INIT_TYPES_H
|
#endif // BITCOIN_IPC_CAPNP_INIT_TYPES_H
|
||||||
|
|
|
@ -10,11 +10,14 @@ $Cxx.namespace("ipc::capnp::messages");
|
||||||
using Proxy = import "/mp/proxy.capnp";
|
using Proxy = import "/mp/proxy.capnp";
|
||||||
$Proxy.include("interfaces/echo.h");
|
$Proxy.include("interfaces/echo.h");
|
||||||
$Proxy.include("interfaces/init.h");
|
$Proxy.include("interfaces/init.h");
|
||||||
|
$Proxy.include("interfaces/mining.h");
|
||||||
$Proxy.includeTypes("ipc/capnp/init-types.h");
|
$Proxy.includeTypes("ipc/capnp/init-types.h");
|
||||||
|
|
||||||
using Echo = import "echo.capnp";
|
using Echo = import "echo.capnp";
|
||||||
|
using Mining = import "mining.capnp";
|
||||||
|
|
||||||
interface Init $Proxy.wrap("interfaces::Init") {
|
interface Init $Proxy.wrap("interfaces::Init") {
|
||||||
construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);
|
construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);
|
||||||
makeEcho @1 (context :Proxy.Context) -> (result :Echo.Echo);
|
makeEcho @1 (context :Proxy.Context) -> (result :Echo.Echo);
|
||||||
|
makeMining @2 (context :Proxy.Context) -> (result :Mining.Mining);
|
||||||
}
|
}
|
||||||
|
|
16
src/ipc/capnp/mining-types.h
Normal file
16
src/ipc/capnp/mining-types.h
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_IPC_CAPNP_MINING_TYPES_H
|
||||||
|
#define BITCOIN_IPC_CAPNP_MINING_TYPES_H
|
||||||
|
|
||||||
|
#include <interfaces/mining.h>
|
||||||
|
#include <ipc/capnp/common.capnp.proxy-types.h>
|
||||||
|
#include <ipc/capnp/common-types.h>
|
||||||
|
#include <ipc/capnp/mining.capnp.proxy.h>
|
||||||
|
#include <node/miner.h>
|
||||||
|
#include <node/types.h>
|
||||||
|
#include <validation.h>
|
||||||
|
|
||||||
|
#endif // BITCOIN_IPC_CAPNP_MINING_TYPES_H
|
44
src/ipc/capnp/mining.capnp
Normal file
44
src/ipc/capnp/mining.capnp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
@0xc77d03df6a41b505;
|
||||||
|
|
||||||
|
using Cxx = import "/capnp/c++.capnp";
|
||||||
|
$Cxx.namespace("ipc::capnp::messages");
|
||||||
|
|
||||||
|
using Common = import "common.capnp";
|
||||||
|
using Proxy = import "/mp/proxy.capnp";
|
||||||
|
$Proxy.include("interfaces/mining.h");
|
||||||
|
$Proxy.includeTypes("ipc/capnp/mining-types.h");
|
||||||
|
|
||||||
|
interface Mining $Proxy.wrap("interfaces::Mining") {
|
||||||
|
isTestChain @0 (context :Proxy.Context) -> (result: Bool);
|
||||||
|
isInitialBlockDownload @1 (context :Proxy.Context) -> (result: Bool);
|
||||||
|
getTip @2 (context :Proxy.Context) -> (result: Common.BlockRef, hasResult: Bool);
|
||||||
|
waitTipChanged @3 (context :Proxy.Context, currentTip: Data, timeout: Float64) -> (result: Common.BlockRef);
|
||||||
|
createNewBlock @4 (scriptPubKey: Data, options: BlockCreateOptions) -> (result: BlockTemplate);
|
||||||
|
processNewBlock @5 (context :Proxy.Context, block: Data) -> (newBlock: Bool, result: Bool);
|
||||||
|
getTransactionsUpdated @6 (context :Proxy.Context) -> (result: UInt32);
|
||||||
|
testBlockValidity @7 (context :Proxy.Context, block: Data, checkMerkleRoot: Bool) -> (state: BlockValidationState, result: Bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
|
||||||
|
getBlockHeader @0 (context: Proxy.Context) -> (result: Data);
|
||||||
|
getBlock @1 (context: Proxy.Context) -> (result: Data);
|
||||||
|
getTxFees @2 (context: Proxy.Context) -> (result: List(Int64));
|
||||||
|
getTxSigops @3 (context: Proxy.Context) -> (result: List(Int64));
|
||||||
|
getCoinbaseTx @4 (context: Proxy.Context) -> (result: Data);
|
||||||
|
getCoinbaseCommitment @5 (context: Proxy.Context) -> (result: Data);
|
||||||
|
getWitnessCommitmentIndex @6 (context: Proxy.Context) -> (result: Int32);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
|
||||||
|
useMempool @0 :Bool $Proxy.name("use_mempool");
|
||||||
|
coinbaseMaxAdditionalWeight @1 :UInt64 $Proxy.name("coinbase_max_additional_weight");
|
||||||
|
coinbaseOutputMaxAdditionalSigops @2 :UInt64 $Proxy.name("coinbase_output_max_additional_sigops");
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO add fields to this struct
|
||||||
|
struct BlockValidationState $Proxy.wrap("BlockValidationState") {
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue