2019-03-01 19:54:15 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-12-31 18:50:11 +01:00
|
|
|
# Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-03-01 19:54:15 +01:00
|
|
|
# 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
|
2019-12-09 19:52:38 +01:00
|
|
|
self.supports_cli = False
|
2019-03-01 19:54:15 +01:00
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
node = self.nodes[0]
|
|
|
|
|
2022-02-27 09:05:32 +01:00
|
|
|
self.log.info("test CHECK_NONFATAL")
|
|
|
|
assert_raises_rpc_error(
|
|
|
|
-1,
|
2020-08-14 09:24:42 +02:00
|
|
|
'Internal bug detected: \'request.params[9].get_str() != "trigger_internal_bug"\'',
|
|
|
|
lambda: node.echo(arg9='trigger_internal_bug'),
|
2022-02-27 09:05:32 +01:00
|
|
|
)
|
|
|
|
|
2019-03-01 19:54:15 +01:00
|
|
|
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')
|
2021-12-02 08:31:47 +01:00
|
|
|
assert_raises_rpc_error(-8, 'mallocinfo mode not available', node.getmemoryinfo, mode="mallocinfo")
|
2019-03-01 19:54:15 +01:00
|
|
|
|
|
|
|
assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar")
|
|
|
|
|
Merge bitcoin/bitcoin#22530: log: sort logging categories alphabetically
d596dba9877e7ead3fb5426cbe7e608fbcbfe3eb test: assert logging categories are sorted in rpc and help (Jon Atack)
17bbff3b88132c0c95b29b59100456b85e26df75 log, refactor: use guard clause in LogCategoriesList() (Jon Atack)
7c57297319bc386afaf06528778384fe58576ef9 log: sort LogCategoriesList and LogCategoriesString alphabetically (Jon Atack)
f720cfa824f1be863349e7016080f8fb1c3c76c2 test: verify number of categories returned by logging RPC (Jon Atack)
Pull request description:
Sorting the logging categories seems more user-friendly with the number of categories we now have, allowing CLI users to more quickly find a particular category.
before
```
$ bitcoin-cli help logging
...
The valid logging categories are: net, tor, mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman, selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej, libevent, coindb, qt, leveldb, validation, i2p, ipc
$ bitcoind -h | grep -A8 "debug=<category>"
-debug=<category>
...
output all debugging information. <category> can be: net, tor,
mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman,
selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej,
libevent, coindb, qt, leveldb, validation, i2p, ipc.
$ bitcoin-cli logging [] '["addrman"]'
{
"net": false,
"tor": true,
"mempool": false,
"http": false,
"bench": false,
"zmq": false,
"walletdb": false,
"rpc": false,
"estimatefee": false,
"addrman": false,
"selectcoins": false,
"reindex": false,
"cmpctblock": false,
"rand": false,
"prune": false,
"proxy": true,
"mempoolrej": false,
"libevent": false,
"coindb": false,
"qt": false,
"leveldb": false,
"validation": false,
"i2p": true,
"ipc": false
}
```
after
```
$ bitcoin-cli help logging
...
The valid logging categories are: addrman, bench, cmpctblock, coindb, estimatefee, http, i2p, ipc, leveldb, libevent, mempool, mempoolrej, net, proxy, prune, qt, rand, reindex, rpc, selectcoins, tor, validation, walletdb, zmq
$ bitcoind -h | grep -A8 "debug=<category>"
-debug=<category>
...
output all debugging information. <category> can be: addrman,
bench, cmpctblock, coindb, estimatefee, http, i2p, ipc, leveldb,
libevent, mempool, mempoolrej, net, proxy, prune, qt, rand,
reindex, rpc, selectcoins, tor, validation, walletdb, zmq.
$ bitcoin-cli logging [] '["addrman"]'
{
"addrman": false,
"bench": false,
"cmpctblock": false,
"coindb": false,
"estimatefee": false,
"http": false,
"i2p": false,
"ipc": false,
"leveldb": false,
"libevent": false,
"mempool": false,
"mempoolrej": false,
"net": false,
"proxy": false,
"prune": false,
"qt": false,
"rand": false,
"reindex": false,
"rpc": false,
"selectcoins": false,
"tor": false,
"validation": false,
"walletdb": false,
"zmq": false
}
```
ACKs for top commit:
theStack:
re-ACK d596dba9877e7ead3fb5426cbe7e608fbcbfe3eb
Tree-SHA512: d546257f562b0a288d1b19a028f1a510aaf21bd21da058e7c84653d305ea8662ecb4647ebefd2b97411f845fe5b0b841d40d3fe6814eefcb8ce82df341dfce22
2021-07-28 14:29:53 +02:00
|
|
|
self.log.info("test logging rpc and help")
|
|
|
|
|
|
|
|
# Test logging RPC returns the expected number of logging categories.
|
Merge bitcoin/bitcoin#22736: log, sync: change lock contention from preprocessor directive to log category
7e698732836121912f179b7c743a72dd6fdffa72 sync: remove DEBUG_LOCKCONTENTION preprocessor directives (Jon Atack)
9b08006bc502e67956d6ab518388fad6397cac8d log, sync: improve lock contention logging and add time duration (Jon Atack)
3f4c6b87f1098436693c4990f2082515ec0ece26 log, timer: add timing macro in usec LOG_TIME_MICROS_WITH_CATEGORY (Jon Atack)
b7a17444e0746c562ae97b26eba431577947b06a log, sync: add LOCK logging category, apply it to lock contention (Jon Atack)
Pull request description:
To enable lock contention logging, `DEBUG_LOCKCONTENTION` has to be defined at compilation. Once built, the logging is not limited to a category and is high frequency, verbose and in all-caps. With these factors combined, it seems likely to be rarely used.
This patch:
- adds a `lock` logging category
- adds a timing macro in microseconds, `LOG_TIME_MICROS_WITH_CATEGORY`
- updates `BCLog::LogMsg()` to omit irrelevant decimals for microseconds and skip unneeded code and math
- improves the lock contention logging, drops the all-caps, and displays the duration in microseconds
- removes the conditional compilation directives
- allows lock contentions to be logged on startup with `-debug=lock` or at run time with `bitcoin-cli logging '["lock"]'`
```
$ bitcoind -signet -debug=lock
2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1920 started
2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1920 completed (4μs)
2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1302 started
2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1302 completed (4μs)
2021-09-01T12:40:02Z LockContention: cs_vNodes, net.cpp:2242 started
2021-09-01T12:40:02Z LockContention: cs_vNodes, net.cpp:2242 completed (20μs)
2021-09-01T12:43:04Z LockContention: ::cs_main, validation.cpp:4980 started
2021-09-01T12:43:04Z LockContention: ::cs_main, validation.cpp:4980 completed (3μs)
$ bitcoin-cli -signet logging
"lock": true,
$ bitcoin-cli -signet logging [] '["lock"]'
"lock": false,
$ bitcoin-cli -signet logging '["lock"]'
"lock": true,
```
I've tested this with Clang 13 and GCC 10.2.1, on Debian, with and without `--enable-debug`.
ACKs for top commit:
hebasto:
re-ACK 7e698732836121912f179b7c743a72dd6fdffa72, added a contention duration to the log message since my [previous](https://github.com/bitcoin/bitcoin/pull/22736#pullrequestreview-743764606) review.
theStack:
re-ACK 7e698732836121912f179b7c743a72dd6fdffa72 🔏 ⏲️
Tree-SHA512: c4b5eb88d3a2c051acaa842b3055ce30efde1f114f61da6e55fcaa27476c1c33a60bc419f7f5ccda532e1bdbe70815222ec2b2b6d9226f29c8e94e598aacfee7
2021-09-06 10:31:05 +02:00
|
|
|
assert_equal(len(node.logging()), 37)
|
Merge bitcoin/bitcoin#22530: log: sort logging categories alphabetically
d596dba9877e7ead3fb5426cbe7e608fbcbfe3eb test: assert logging categories are sorted in rpc and help (Jon Atack)
17bbff3b88132c0c95b29b59100456b85e26df75 log, refactor: use guard clause in LogCategoriesList() (Jon Atack)
7c57297319bc386afaf06528778384fe58576ef9 log: sort LogCategoriesList and LogCategoriesString alphabetically (Jon Atack)
f720cfa824f1be863349e7016080f8fb1c3c76c2 test: verify number of categories returned by logging RPC (Jon Atack)
Pull request description:
Sorting the logging categories seems more user-friendly with the number of categories we now have, allowing CLI users to more quickly find a particular category.
before
```
$ bitcoin-cli help logging
...
The valid logging categories are: net, tor, mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman, selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej, libevent, coindb, qt, leveldb, validation, i2p, ipc
$ bitcoind -h | grep -A8 "debug=<category>"
-debug=<category>
...
output all debugging information. <category> can be: net, tor,
mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman,
selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej,
libevent, coindb, qt, leveldb, validation, i2p, ipc.
$ bitcoin-cli logging [] '["addrman"]'
{
"net": false,
"tor": true,
"mempool": false,
"http": false,
"bench": false,
"zmq": false,
"walletdb": false,
"rpc": false,
"estimatefee": false,
"addrman": false,
"selectcoins": false,
"reindex": false,
"cmpctblock": false,
"rand": false,
"prune": false,
"proxy": true,
"mempoolrej": false,
"libevent": false,
"coindb": false,
"qt": false,
"leveldb": false,
"validation": false,
"i2p": true,
"ipc": false
}
```
after
```
$ bitcoin-cli help logging
...
The valid logging categories are: addrman, bench, cmpctblock, coindb, estimatefee, http, i2p, ipc, leveldb, libevent, mempool, mempoolrej, net, proxy, prune, qt, rand, reindex, rpc, selectcoins, tor, validation, walletdb, zmq
$ bitcoind -h | grep -A8 "debug=<category>"
-debug=<category>
...
output all debugging information. <category> can be: addrman,
bench, cmpctblock, coindb, estimatefee, http, i2p, ipc, leveldb,
libevent, mempool, mempoolrej, net, proxy, prune, qt, rand,
reindex, rpc, selectcoins, tor, validation, walletdb, zmq.
$ bitcoin-cli logging [] '["addrman"]'
{
"addrman": false,
"bench": false,
"cmpctblock": false,
"coindb": false,
"estimatefee": false,
"http": false,
"i2p": false,
"ipc": false,
"leveldb": false,
"libevent": false,
"mempool": false,
"mempoolrej": false,
"net": false,
"proxy": false,
"prune": false,
"qt": false,
"rand": false,
"reindex": false,
"rpc": false,
"selectcoins": false,
"tor": false,
"validation": false,
"walletdb": false,
"zmq": false
}
```
ACKs for top commit:
theStack:
re-ACK d596dba9877e7ead3fb5426cbe7e608fbcbfe3eb
Tree-SHA512: d546257f562b0a288d1b19a028f1a510aaf21bd21da058e7c84653d305ea8662ecb4647ebefd2b97411f845fe5b0b841d40d3fe6814eefcb8ce82df341dfce22
2021-07-28 14:29:53 +02:00
|
|
|
|
|
|
|
# Test toggling a logging category on/off/on with the logging RPC.
|
2019-05-15 21:49:48 +02:00
|
|
|
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)
|
|
|
|
|
Merge bitcoin/bitcoin#22530: log: sort logging categories alphabetically
d596dba9877e7ead3fb5426cbe7e608fbcbfe3eb test: assert logging categories are sorted in rpc and help (Jon Atack)
17bbff3b88132c0c95b29b59100456b85e26df75 log, refactor: use guard clause in LogCategoriesList() (Jon Atack)
7c57297319bc386afaf06528778384fe58576ef9 log: sort LogCategoriesList and LogCategoriesString alphabetically (Jon Atack)
f720cfa824f1be863349e7016080f8fb1c3c76c2 test: verify number of categories returned by logging RPC (Jon Atack)
Pull request description:
Sorting the logging categories seems more user-friendly with the number of categories we now have, allowing CLI users to more quickly find a particular category.
before
```
$ bitcoin-cli help logging
...
The valid logging categories are: net, tor, mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman, selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej, libevent, coindb, qt, leveldb, validation, i2p, ipc
$ bitcoind -h | grep -A8 "debug=<category>"
-debug=<category>
...
output all debugging information. <category> can be: net, tor,
mempool, http, bench, zmq, walletdb, rpc, estimatefee, addrman,
selectcoins, reindex, cmpctblock, rand, prune, proxy, mempoolrej,
libevent, coindb, qt, leveldb, validation, i2p, ipc.
$ bitcoin-cli logging [] '["addrman"]'
{
"net": false,
"tor": true,
"mempool": false,
"http": false,
"bench": false,
"zmq": false,
"walletdb": false,
"rpc": false,
"estimatefee": false,
"addrman": false,
"selectcoins": false,
"reindex": false,
"cmpctblock": false,
"rand": false,
"prune": false,
"proxy": true,
"mempoolrej": false,
"libevent": false,
"coindb": false,
"qt": false,
"leveldb": false,
"validation": false,
"i2p": true,
"ipc": false
}
```
after
```
$ bitcoin-cli help logging
...
The valid logging categories are: addrman, bench, cmpctblock, coindb, estimatefee, http, i2p, ipc, leveldb, libevent, mempool, mempoolrej, net, proxy, prune, qt, rand, reindex, rpc, selectcoins, tor, validation, walletdb, zmq
$ bitcoind -h | grep -A8 "debug=<category>"
-debug=<category>
...
output all debugging information. <category> can be: addrman,
bench, cmpctblock, coindb, estimatefee, http, i2p, ipc, leveldb,
libevent, mempool, mempoolrej, net, proxy, prune, qt, rand,
reindex, rpc, selectcoins, tor, validation, walletdb, zmq.
$ bitcoin-cli logging [] '["addrman"]'
{
"addrman": false,
"bench": false,
"cmpctblock": false,
"coindb": false,
"estimatefee": false,
"http": false,
"i2p": false,
"ipc": false,
"leveldb": false,
"libevent": false,
"mempool": false,
"mempoolrej": false,
"net": false,
"proxy": false,
"prune": false,
"qt": false,
"rand": false,
"reindex": false,
"rpc": false,
"selectcoins": false,
"tor": false,
"validation": false,
"walletdb": false,
"zmq": false
}
```
ACKs for top commit:
theStack:
re-ACK d596dba9877e7ead3fb5426cbe7e608fbcbfe3eb
Tree-SHA512: d546257f562b0a288d1b19a028f1a510aaf21bd21da058e7c84653d305ea8662ecb4647ebefd2b97411f845fe5b0b841d40d3fe6814eefcb8ce82df341dfce22
2021-07-28 14:29:53 +02:00
|
|
|
# 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
|
|
|
|
|
2023-07-25 10:57:35 +02:00
|
|
|
self.log.info("test getindexinfo")
|
2023-07-17 15:57:30 +02:00
|
|
|
self.restart_node(0, ["-txindex=0"])
|
2023-07-25 10:57:35 +02:00
|
|
|
# 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
|
2023-07-30 13:49:32 +02:00
|
|
|
self.restart_node(0, ["-txindex", "-blockfilterindex", "-coinstatsindex"])
|
2020-08-27 08:21:53 +02:00
|
|
|
self.wait_until(lambda: all(i["synced"] for i in node.getindexinfo().values()))
|
2023-07-25 10:57:35 +02:00
|
|
|
|
|
|
|
# Returns a list of all running indices by default
|
2023-07-30 13:49:32 +02:00
|
|
|
values = {"synced": True, "best_block_height": 200}
|
2023-07-25 10:57:35 +02:00
|
|
|
assert_equal(
|
|
|
|
node.getindexinfo(),
|
|
|
|
{
|
2023-07-30 13:49:32 +02:00
|
|
|
"txindex": values,
|
|
|
|
"basic block filter index": values,
|
|
|
|
"coinstatsindex": values,
|
2023-07-25 10:57:35 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
# Specifying an index by name returns only the status of that index
|
2023-07-30 13:49:32 +02:00
|
|
|
for i in {"txindex", "basic block filter index", "coinstatsindex"}:
|
|
|
|
assert_equal(node.getindexinfo(i), {i: values})
|
2023-07-25 10:57:35 +02:00
|
|
|
|
|
|
|
# Specifying an unknown index name returns an empty result
|
|
|
|
assert_equal(node.getindexinfo("foo"), {})
|
|
|
|
|
2019-05-15 21:49:48 +02:00
|
|
|
|
2019-03-01 19:54:15 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
RpcMiscTest().main()
|