Skip to content

Commit 29c2c90

Browse files
committed
Merge bitcoin/bitcoin#28721: multiprocess compatibility updates
3b70f7b doc: fix broken doc/design/multiprocess.md links after #24352 (Ryan Ofsky) 6d43aad span: Make Span template deduction guides work in SFINAE context (Ryan Ofsky) 8062c3b util: Add ArgsManager SetConfigFilePath method (Ryan Ofsky) 441d00c interfaces: Rename CalculateBumpFees methods to be compatible with capn'proto (Ryan Ofsky) 156f49d interfaces: Change getUnspentOutput return type to avoid multiprocess segfault (Ryan Ofsky) 4978754 interfaces: Add schedulerMockForward method so mockscheduler RPC can work across processes (Ryan Ofsky) 924327e interfaces: Fix const virtual method that breaks multiprocess support (Ryan Ofsky) 82a379e streams: Add SpanReader ignore method (Russell Yanofsky) Pull request description: This is a collection of small changes to interfaces and code which were needed as part of multiprocess PR #10102, but have been moved here to make that PR smaller. All of these changes are refactoring changes which do not affect behavior of current code --- This PR is part of the [process separation project](bitcoin/bitcoin#28722). ACKs for top commit: achow101: ACK 3b70f7b naumenkogs: ACK 3b70f7b maflcko: re-ACK 3b70f7b 🎆 Tree-SHA512: 2368772b887056ad8a9f84c299cfde76ba45943770e3b5353130580900afa9611302195b899ced7b6e303b11f053ff204cae7c28ff4e12c55562fcc81119ba4c
2 parents e862bce + 3b70f7b commit 29c2c90

File tree

19 files changed

+147
-29
lines changed

19 files changed

+147
-29
lines changed

doc/design/multiprocess.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The `-debug=ipc` command line option can be used to see requests and responses b
1919

2020
## Installation
2121

22-
The multiprocess feature requires [Cap'n Proto](https://capnproto.org/) and [libmultiprocess](https://github.com/chaincodelabs/libmultiprocess) as dependencies. A simple way to get starting using it without installing these dependencies manually is to use the [depends system](../depends) with the `MULTIPROCESS=1` [dependency option](../depends#dependency-options) passed to make:
22+
The multiprocess feature requires [Cap'n Proto](https://capnproto.org/) and [libmultiprocess](https://github.com/chaincodelabs/libmultiprocess) as dependencies. A simple way to get starting using it without installing these dependencies manually is to use the [depends system](../../depends) with the `MULTIPROCESS=1` [dependency option](../../depends#dependency-options) passed to make:
2323

2424
```
2525
cd <BITCOIN_SOURCE_DIRECTORY>
@@ -32,12 +32,12 @@ BITCOIND=bitcoin-node test/functional/test_runner.py
3232

3333
The configure script will pick up settings and library locations from the depends directory, so there is no need to pass `--enable-multiprocess` as a separate flag when using the depends system (it's controlled by the `MULTIPROCESS=1` option).
3434

35-
Alternately, you can install [Cap'n Proto](https://capnproto.org/) and [libmultiprocess](https://github.com/chaincodelabs/libmultiprocess) packages on your system, and just run `./configure --enable-multiprocess` without using the depends system. The configure script will be able to locate the installed packages via [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/). See [Installation](https://github.com/chaincodelabs/libmultiprocess#installation) section of the libmultiprocess readme for install steps. See [build-unix.md](build-unix.md) and [build-osx.md](build-osx.md) for information about installing dependencies in general.
35+
Alternately, you can install [Cap'n Proto](https://capnproto.org/) and [libmultiprocess](https://github.com/chaincodelabs/libmultiprocess) packages on your system, and just run `./configure --enable-multiprocess` without using the depends system. The configure script will be able to locate the installed packages via [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/). See [Installation](https://github.com/chaincodelabs/libmultiprocess/blob/master/doc/install.md) section of the libmultiprocess readme for install steps. See [build-unix.md](../build-unix.md) and [build-osx.md](../build-osx.md) for information about installing dependencies in general.
3636

3737
## IPC implementation details
3838

3939
Cross process Node, Wallet, and Chain interfaces are defined in
40-
[`src/interfaces/`](../src/interfaces/). These are C++ classes which follow
40+
[`src/interfaces/`](../../src/interfaces/). These are C++ classes which follow
4141
[conventions](../developer-notes.md#internal-interface-guidelines), like passing
4242
serializable arguments so they can be called from different processes, and
4343
making methods pure virtual so they can have proxy implementations that forward
@@ -58,7 +58,7 @@ actual serialization and socket communication.
5858
As much as possible, calls between processes are meant to work the same as
5959
calls within a single process without adding limitations or requiring extra
6060
implementation effort. Processes communicate with each other by calling regular
61-
[C++ interface methods](../src/interfaces/README.md). Method arguments and
61+
[C++ interface methods](../../src/interfaces/README.md). Method arguments and
6262
return values are automatically serialized and sent between processes. Object
6363
references and `std::function` arguments are automatically tracked and mapped
6464
to allow invoked code to call back into invoking code at any time, and there is

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ BITCOIN_TESTS =\
146146
test/sigopcount_tests.cpp \
147147
test/skiplist_tests.cpp \
148148
test/sock_tests.cpp \
149+
test/span_tests.cpp \
149150
test/streams_tests.cpp \
150151
test/sync_tests.cpp \
151152
test/system_tests.cpp \

src/common/args.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,13 @@ fs::path ArgsManager::GetConfigFilePath() const
720720
return *Assert(m_config_path);
721721
}
722722

723+
void ArgsManager::SetConfigFilePath(fs::path path)
724+
{
725+
LOCK(cs_args);
726+
assert(!m_config_path);
727+
m_config_path = path;
728+
}
729+
723730
ChainType ArgsManager::GetChainType() const
724731
{
725732
std::variant<ChainType, std::string> arg = GetChainArg();

src/common/args.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class ArgsManager
180180
* Return config file path (read-only)
181181
*/
182182
fs::path GetConfigFilePath() const;
183+
void SetConfigFilePath(fs::path);
183184
[[nodiscard]] bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);
184185

185186
/**

src/interfaces/chain.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ class Chain
244244
// outputs in the same transaction) or have shared ancestry, the bump fees are calculated
245245
// independently, i.e. as if only one of them is spent. This may result in double-fee-bumping. This
246246
// caveat can be rectified per use of the sister-function CalculateCombinedBumpFee(…).
247-
virtual std::map<COutPoint, CAmount> CalculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) = 0;
247+
virtual std::map<COutPoint, CAmount> calculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) = 0;
248248

249249
//! Calculate the combined bump fee for an input set per the same strategy
250250
// as in CalculateIndividualBumpFees(…).
251251
// Unlike CalculateIndividualBumpFees(…), this does not return individual
252252
// bump fees per outpoint, but a single bump fee for the shared ancestry.
253253
// The combined bump fee may be used to correct overestimation due to
254254
// shared ancestry by multiple UTXOs after coin selection.
255-
virtual std::optional<CAmount> CalculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) = 0;
255+
virtual std::optional<CAmount> calculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) = 0;
256256

257257
//! Get the node's package limits.
258258
//! Currently only returns the ancestor and descendant count limits, but could be enhanced to
@@ -395,6 +395,9 @@ class ChainClient
395395

396396
//! Set mock time.
397397
virtual void setMockTime(int64_t time) = 0;
398+
399+
//! Mock the scheduler to fast forward in time.
400+
virtual void schedulerMockForward(std::chrono::seconds delta_seconds) = 0;
398401
};
399402

400403
//! Return implementation of Chain interface.

src/interfaces/node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class Node
204204
//! Unset RPC timer interface.
205205
virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0;
206206

207-
//! Get unspent outputs associated with a transaction.
208-
virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;
207+
//! Get unspent output associated with a transaction.
208+
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
209209

210210
//! Broadcast transaction.
211211
virtual TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Wallet
118118
wallet::AddressPurpose* purpose) = 0;
119119

120120
//! Get wallet address list.
121-
virtual std::vector<WalletAddress> getAddresses() const = 0;
121+
virtual std::vector<WalletAddress> getAddresses() = 0;
122122

123123
//! Get receive requests.
124124
virtual std::vector<std::string> getAddressReceiveRequests() = 0;

src/node/interfaces.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,12 @@ class NodeImpl : public Node
328328
std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); }
329329
void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); }
330330
void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); }
331-
bool getUnspentOutput(const COutPoint& output, Coin& coin) override
331+
std::optional<Coin> getUnspentOutput(const COutPoint& output) override
332332
{
333333
LOCK(::cs_main);
334-
return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin);
334+
Coin coin;
335+
if (chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin)) return coin;
336+
return {};
335337
}
336338
TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) override
337339
{
@@ -670,7 +672,7 @@ class ChainImpl : public Chain
670672
m_node.mempool->GetTransactionAncestry(txid, ancestors, descendants, ancestorsize, ancestorfees);
671673
}
672674

673-
std::map<COutPoint, CAmount> CalculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
675+
std::map<COutPoint, CAmount> calculateIndividualBumpFees(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
674676
{
675677
if (!m_node.mempool) {
676678
std::map<COutPoint, CAmount> bump_fees;
@@ -682,7 +684,7 @@ class ChainImpl : public Chain
682684
return MiniMiner(*m_node.mempool, outpoints).CalculateBumpFees(target_feerate);
683685
}
684686

685-
std::optional<CAmount> CalculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
687+
std::optional<CAmount> calculateCombinedBumpFee(const std::vector<COutPoint>& outpoints, const CFeeRate& target_feerate) override
686688
{
687689
if (!m_node.mempool) {
688690
return 0;

src/qt/transactiondesc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,10 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
360360
{
361361
COutPoint prevout = txin.prevout;
362362

363-
Coin prev;
364-
if(node.getUnspentOutput(prevout, prev))
365-
{
363+
if (auto prev{node.getUnspentOutput(prevout)}) {
366364
{
367365
strHTML += "<li>";
368-
const CTxOut &vout = prev.out;
366+
const CTxOut& vout = prev->out;
369367
CTxDestination address;
370368
if (ExtractDestination(vout.scriptPubKey, address))
371369
{

src/rpc/node.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ static RPCHelpMan mockscheduler()
9191
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
9292
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
9393
SyncWithValidationInterfaceQueue();
94+
for (const auto& chain_client : node_context.chain_clients) {
95+
chain_client->schedulerMockForward(std::chrono::seconds(delta_seconds));
96+
}
9497

9598
return UniValue::VNULL;
9699
},

0 commit comments

Comments
 (0)