mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
3411577473
84934bf70e11fe4cda1cfda60113a54895d4fdd5 multiprocess: Add echoipc RPC method and test (Russell Yanofsky) 7d76cf667eff512043a28d4407cc89f58796c42b multiprocess: Add comments and documentation (Russell Yanofsky) ddf7ecc8dfc64cf121099fb047e1ac871de94f4c multiprocess: Add bitcoin-node process spawning support (Russell Yanofsky) 10afdf0280fa93bfffb0a7665c60dc155cd84514 multiprocess: Add Ipc interface implementation (Russell Yanofsky) 745c9cebd50fea1664efef571dc1ee1bddc96102 multiprocess: Add Ipc and Init interface definitions (Russell Yanofsky) 5d62d7f6cd48bbc4e9f37ecc369f38d5e1e0036c Update libmultiprocess library (Russell Yanofsky) Pull request description: This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10). --- This PR adds basic process spawning and IPC method call support to `bitcoin-node` executables built with `--enable-multiprocess`[*]. These changes are used in https://github.com/bitcoin/bitcoin/pull/10102 to let node, gui, and wallet functionality run in different processes, and extended in https://github.com/bitcoin/bitcoin/pull/19460 and https://github.com/bitcoin/bitcoin/pull/19461 after that to allow gui and wallet processes to be started and stopped independently and connect to the node over a socket. These changes can also be used to implement new functionality outside the `bitcoin-node` process like external indexes or pluggable transports (https://github.com/bitcoin/bitcoin/pull/18988). The `Ipc::spawnProcess` and `Ipc::serveProcess` methods added here are entry points for spawning a child process and serving a parent process, and being able to make bidirectional, multithreaded method calls between the processes. A simple example of this is implemented in commit "Add echoipc RPC method and test." Changes in this PR aside from the echo test were originally part of #10102, but have been split and moved here for easier review, and so they can be used for other applications like external plugins. Additional notes about this PR can be found at https://bitcoincore.reviews/19160 [*] Note: the `--enable-multiprocess` feature is still experimental, and not enabled by default, and not yet supported on windows. More information can be found in [doc/multiprocess.md](https://github.com/bitcoin/bitcoin/blob/master/doc/multiprocess.md) ACKs for top commit: fjahr: re-ACK 84934bf70e11fe4cda1cfda60113a54895d4fdd5 ariard: ACK 84934bf. Changes since last ACK fixes the silent merge conflict about `EnsureAnyNodeContext()`. Rebuilt and checked again debug command `echoipc`. Tree-SHA512: 52a948b5e18a26d7d7a09b83003eaae9b1ed2981978c36c959fe9a55abf70ae6a627c4ff913a3428be17400a3dace30c58b5057fa75c319662c3be98f19810c6
110 lines
4.3 KiB
Python
Executable File
110 lines
4.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2019-2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test RPC misc output."""
|
|
import xml.etree.ElementTree as ET
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import (
|
|
assert_raises_rpc_error,
|
|
assert_equal,
|
|
assert_greater_than,
|
|
assert_greater_than_or_equal,
|
|
)
|
|
|
|
from test_framework.authproxy import JSONRPCException
|
|
|
|
|
|
class RpcMiscTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 1
|
|
self.supports_cli = False
|
|
|
|
def run_test(self):
|
|
node = self.nodes[0]
|
|
|
|
self.log.info("test CHECK_NONFATAL")
|
|
assert_raises_rpc_error(
|
|
-1,
|
|
'Internal bug detected: \'request.params[9].get_str() != "trigger_internal_bug"\'',
|
|
lambda: node.echo(arg9='trigger_internal_bug'),
|
|
)
|
|
|
|
self.log.info("test getmemoryinfo")
|
|
memory = node.getmemoryinfo()['locked']
|
|
assert_greater_than(memory['used'], 0)
|
|
assert_greater_than(memory['free'], 0)
|
|
assert_greater_than(memory['total'], 0)
|
|
# assert_greater_than_or_equal() for locked in case locking pages failed at some point
|
|
assert_greater_than_or_equal(memory['locked'], 0)
|
|
assert_greater_than(memory['chunks_used'], 0)
|
|
assert_greater_than(memory['chunks_free'], 0)
|
|
assert_equal(memory['used'] + memory['free'], memory['total'])
|
|
|
|
self.log.info("test mallocinfo")
|
|
try:
|
|
mallocinfo = node.getmemoryinfo(mode="mallocinfo")
|
|
self.log.info('getmemoryinfo(mode="mallocinfo") call succeeded')
|
|
tree = ET.fromstring(mallocinfo)
|
|
assert_equal(tree.tag, 'malloc')
|
|
except JSONRPCException:
|
|
self.log.info('getmemoryinfo(mode="mallocinfo") not available')
|
|
assert_raises_rpc_error(-8, 'mallocinfo mode not available', node.getmemoryinfo, mode="mallocinfo")
|
|
|
|
assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar")
|
|
|
|
self.log.info("test logging rpc and help")
|
|
|
|
# Test logging RPC returns the expected number of logging categories.
|
|
assert_equal(len(node.logging()), 38)
|
|
|
|
# Test toggling a logging category on/off/on with the logging RPC.
|
|
assert_equal(node.logging()['qt'], True)
|
|
node.logging(exclude=['qt'])
|
|
assert_equal(node.logging()['qt'], False)
|
|
node.logging(include=['qt'])
|
|
assert_equal(node.logging()['qt'], True)
|
|
|
|
# Test logging RPC returns the logging categories in alphabetical order.
|
|
sorted_logging_categories = sorted(node.logging())
|
|
assert_equal(list(node.logging()), sorted_logging_categories)
|
|
|
|
# Test logging help returns the logging categories string in alphabetical order.
|
|
categories = ', '.join(sorted_logging_categories)
|
|
logging_help = self.nodes[0].help('logging')
|
|
assert f"valid logging categories are: {categories}" in logging_help
|
|
|
|
self.log.info("test echoipc (testing spawned process in multiprocess build)")
|
|
assert_equal(node.echoipc("hello"), "hello")
|
|
|
|
self.log.info("test getindexinfo")
|
|
self.restart_node(0, ["-txindex=0"])
|
|
# Without any indices running the RPC returns an empty object
|
|
assert_equal(node.getindexinfo(), {})
|
|
|
|
# Restart the node with indices and wait for them to sync
|
|
self.restart_node(0, ["-txindex", "-blockfilterindex", "-coinstatsindex"])
|
|
self.wait_until(lambda: all(i["synced"] for i in node.getindexinfo().values()))
|
|
|
|
# Returns a list of all running indices by default
|
|
values = {"synced": True, "best_block_height": 200}
|
|
assert_equal(
|
|
node.getindexinfo(),
|
|
{
|
|
"txindex": values,
|
|
"basic block filter index": values,
|
|
"coinstatsindex": values,
|
|
}
|
|
)
|
|
# Specifying an index by name returns only the status of that index
|
|
for i in {"txindex", "basic block filter index", "coinstatsindex"}:
|
|
assert_equal(node.getindexinfo(i), {i: values})
|
|
|
|
# Specifying an unknown index name returns an empty result
|
|
assert_equal(node.getindexinfo("foo"), {})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
RpcMiscTest().main()
|