Skip to content

Commit 44d9ac7

Browse files
Merge dashpay#5904: backport: Merge bitcoin#21712,21192, 21695,21244,21595
262fe0a (followup) bitcoin#21244: Move GetBackupsDir to ArgsManager (Vijay) 1f4e26b Merge bitcoin#21595: cli: create -addrinfo (W. J. van der Laan) 6a45e72 Merge bitcoin#21244: Move GetDataDir to ArgsManager (fanquake) 4d28f3a Merge bitcoin#21695: Remove no longer used contrib/bitcoin-qt.pro from the repo (fanquake) 9de77e8 Merge bitcoin#21192: cli: Treat high detail levels as maximum in -netinfo (Wladimir J. van der Laan) e22ebca Merge bitcoin#21712: qa: Test default include_mempool value of gettxout (MarcoFalke) Pull request description: backport: Merge bitcoin#21712,21192, 21695,21244,21595 Top commit has no ACKs. Tree-SHA512: 61e72fa6db7aa0234cdccca91b3639dbfed6eabea4d9d65d25e89ac17de0b1d1b5eddf41985b1335bbd34ca71465a9760bf62ed33418a8d79a3d742156c52f35
2 parents 544d333 + 262fe0a commit 44d9ac7

21 files changed

+318
-244
lines changed

contrib/dash-qt.pro

Lines changed: 0 additions & 26 deletions
This file was deleted.

doc/release-notes-21595.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Tools and Utilities
2+
-------------------
3+
4+
- A new CLI `-addrinfo` command returns the number of addresses known to the
5+
node per network type (including Tor v2 versus v3) and total. This can be
6+
useful to see if the node knows enough addresses in a network to use options
7+
like `-onlynet=<network>` or to upgrade to current and future Tor releases
8+
that support Tor v3 addresses only. (#5904)
9+

doc/translation_process.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ cd src/
2222
make translate
2323
```
2424

25-
`contrib/dash-qt.pro` takes care of generating `.qm` (binary compiled) files from `.ts` (source files) files. It’s mostly automated, and you shouldn’t need to worry about it.
26-
2725
**Example Qt translation**
2826
```cpp
2927
QToolBar *toolbar = addToolBar(tr("Tabs toolbar"));

src/bitcoin-cli.cpp

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
4646
static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
4747
static const bool DEFAULT_NAMED=false;
4848
static const int CONTINUE_EXECUTION=-1;
49+
static constexpr int8_t UNKNOWN_NETWORK{-1};
4950

5051
/** Default number of blocks to generate for RPC generatetoaddress. */
5152
static const std::string DEFAULT_NBLOCKS = "1";
@@ -62,6 +63,7 @@ static void SetupCliArgs(ArgsManager& argsman)
6263
argsman.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6364
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6465
argsman.AddArg("-generate", strprintf("Generate blocks immediately, equivalent to RPC getnewaddress followed by RPC generatetoaddress. Optional positional integer arguments are number of blocks to generate (default: %s) and maximum iterations to try (default: %s), equivalent to RPC generatetoaddress nblocks and maxtries arguments. Example: dash-cli -generate 4 1000", DEFAULT_NBLOCKS, DEFAULT_MAX_TRIES), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
66+
argsman.AddArg("-addrinfo", "Get the number of addresses known to the node, per network and total.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6567
argsman.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6668
argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 4 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6769
argsman.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -243,6 +245,60 @@ class BaseRequestHandler
243245
virtual UniValue ProcessReply(const UniValue &batch_in) = 0;
244246
};
245247

248+
/** Process addrinfo requests */
249+
class AddrinfoRequestHandler : public BaseRequestHandler
250+
{
251+
private:
252+
static constexpr std::array m_networks{"ipv4", "ipv6", "torv2", "torv3", "i2p"};
253+
int8_t NetworkStringToId(const std::string& str) const
254+
{
255+
for (size_t i = 0; i < m_networks.size(); ++i) {
256+
if (str == m_networks.at(i)) return i;
257+
}
258+
return UNKNOWN_NETWORK;
259+
}
260+
261+
public:
262+
UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
263+
{
264+
if (!args.empty()) {
265+
throw std::runtime_error("-addrinfo takes no arguments");
266+
}
267+
UniValue params{RPCConvertValues("getnodeaddresses", std::vector<std::string>{{"0"}})};
268+
return JSONRPCRequestObj("getnodeaddresses", params, 1);
269+
}
270+
271+
UniValue ProcessReply(const UniValue& reply) override
272+
{
273+
if (!reply["error"].isNull()) return reply;
274+
const std::vector<UniValue>& nodes{reply["result"].getValues()};
275+
if (!nodes.empty() && nodes.at(0)["network"].isNull()) {
276+
throw std::runtime_error("-addrinfo requires dashd server to be running v21.0 and up");
277+
}
278+
// Count the number of peers we know by network, including torv2 versus torv3.
279+
std::array<uint64_t, m_networks.size()> counts{{}};
280+
for (const UniValue& node : nodes) {
281+
std::string network_name{node["network"].get_str()};
282+
if (network_name == "onion") {
283+
network_name = node["address"].get_str().size() > 22 ? "torv3" : "torv2";
284+
}
285+
const int8_t network_id{NetworkStringToId(network_name)};
286+
if (network_id == UNKNOWN_NETWORK) continue;
287+
++counts.at(network_id);
288+
}
289+
// Prepare result to return to user.
290+
UniValue result{UniValue::VOBJ}, addresses{UniValue::VOBJ};
291+
uint64_t total{0}; // Total address count
292+
for (size_t i = 0; i < m_networks.size(); ++i) {
293+
addresses.pushKV(m_networks.at(i), counts.at(i));
294+
total += counts.at(i);
295+
}
296+
addresses.pushKV("total", total);
297+
result.pushKV("addresses_known", addresses);
298+
return JSONRPCReplyObj(result, NullUniValue, 1);
299+
}
300+
};
301+
246302
/** Process getinfo requests */
247303
class GetinfoRequestHandler: public BaseRequestHandler
248304
{
@@ -318,13 +374,12 @@ class GetinfoRequestHandler: public BaseRequestHandler
318374
class NetinfoRequestHandler : public BaseRequestHandler
319375
{
320376
private:
321-
static constexpr int8_t UNKNOWN_NETWORK{-1};
322-
static constexpr uint8_t m_networks_size{3};
323-
const std::array<std::string, m_networks_size> m_networks{{"ipv4", "ipv6", "onion"}};
324-
std::array<std::array<uint16_t, m_networks_size + 2>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total/block-relay)
377+
static constexpr uint8_t MAX_DETAIL_LEVEL{4};
378+
static constexpr std::array m_networks{"ipv4", "ipv6", "onion"};
379+
std::array<std::array<uint16_t, m_networks.size() + 2>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total/block-relay)
325380
int8_t NetworkStringToId(const std::string& str) const
326381
{
327-
for (uint8_t i = 0; i < m_networks_size; ++i) {
382+
for (size_t i = 0; i < m_networks.size(); ++i) {
328383
if (str == m_networks.at(i)) return i;
329384
}
330385
return UNKNOWN_NETWORK;
@@ -437,7 +492,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
437492
if (!args.empty()) {
438493
uint8_t n{0};
439494
if (ParseUInt8(args.at(0), &n)) {
440-
m_details_level = n;
495+
m_details_level = std::min(n, MAX_DETAIL_LEVEL);
441496
} else if (args.at(0) == "help") {
442497
m_is_help_requested = true;
443498
} else {
@@ -471,13 +526,13 @@ class NetinfoRequestHandler : public BaseRequestHandler
471526
if (network_id == UNKNOWN_NETWORK) continue;
472527
const bool is_outbound{!peer["inbound"].get_bool()};
473528
const bool is_block_relay{!peer["relaytxes"].get_bool()};
474-
++m_counts.at(is_outbound).at(network_id); // in/out by network
475-
++m_counts.at(is_outbound).at(m_networks_size); // in/out overall
476-
++m_counts.at(2).at(network_id); // total by network
477-
++m_counts.at(2).at(m_networks_size); // total overall
529+
++m_counts.at(is_outbound).at(network_id); // in/out by network
530+
++m_counts.at(is_outbound).at(m_networks.size()); // in/out overall
531+
++m_counts.at(2).at(network_id); // total by network
532+
++m_counts.at(2).at(m_networks.size()); // total overall
478533
if (is_block_relay) {
479-
++m_counts.at(is_outbound).at(m_networks_size + 1); // in/out block-relay
480-
++m_counts.at(2).at(m_networks_size + 1); // total block-relay
534+
++m_counts.at(is_outbound).at(m_networks.size() + 1); // in/out block-relay
535+
++m_counts.at(2).at(m_networks.size() + 1); // total block-relay
481536
}
482537
if (DetailsRequested()) {
483538
// Push data for this peer to the peers vector.
@@ -539,9 +594,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
539594

540595
// Report peer connection totals by type.
541596
result += " ipv4 ipv6 onion total block-relay\n";
542-
const std::array<std::string, 3> rows{{"in", "out", "total"}};
543-
for (uint8_t i = 0; i < m_networks_size; ++i) {
544-
result += strprintf("%-5s %5i %5i %5i %5i %5i\n", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2), m_counts.at(i).at(m_networks_size), m_counts.at(i).at(m_networks_size + 1));
597+
const std::array rows{"in", "out", "total"};
598+
for (uint8_t i = 0; i < m_networks.size(); ++i) {
599+
result += strprintf("%-5s %5i %5i %5i %5i %5i\n", rows.at(i), m_counts.at(i).at(0), m_counts.at(i).at(1), m_counts.at(i).at(2), m_counts.at(i).at(m_networks.size()), m_counts.at(i).at(m_networks.size() + 1));
545600
}
546601

547602
// Report local addresses, ports, and scores.
@@ -908,6 +963,8 @@ static int CommandLineRPC(int argc, char *argv[])
908963
} else {
909964
ParseError(error, strPrint, nRet);
910965
}
966+
} else if (gArgs.GetBoolArg("-addrinfo", false)) {
967+
rh.reset(new AddrinfoRequestHandler());
911968
} else {
912969
rh.reset(new DefaultRequestHandler());
913970
if (args.size() < 1) {

src/init.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static void CleanupBlockRevFiles()
840840
// Remove the rev files immediately and insert the blk file paths into an
841841
// ordered map keyed by block file index.
842842
LogPrintf("Removing unusable blk?????.dat and rev?????.dat files for -reindex with -prune\n");
843-
fs::path blocksdir = GetBlocksDir();
843+
fs::path blocksdir = gArgs.GetBlocksDirPath();
844844
for (fs::directory_iterator it(blocksdir); it != fs::directory_iterator(); it++) {
845845
if (fs::is_regular_file(*it) &&
846846
it->path().filename().string().length() == 12 &&
@@ -1197,7 +1197,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
11971197
InitWarning(warnings);
11981198
}
11991199

1200-
if (!fs::is_directory(GetBlocksDir())) {
1200+
if (!fs::is_directory(gArgs.GetBlocksDirPath())) {
12011201
return InitError(strprintf(_("Specified blocks directory \"%s\" does not exist."), args.GetArg("-blocksdir", "")));
12021202
}
12031203

@@ -2338,8 +2338,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
23382338
InitError(strprintf(_("Error: Disk space is low for %s"), GetDataDir()));
23392339
return false;
23402340
}
2341-
if (!CheckDiskSpace(GetBlocksDir())) {
2342-
InitError(strprintf(_("Error: Disk space is low for %s"), GetBlocksDir()));
2341+
if (!CheckDiskSpace(gArgs.GetBlocksDirPath())) {
2342+
InitError(strprintf(_("Error: Disk space is low for %s"), gArgs.GetBlocksDirPath()));
23432343
return false;
23442344
}
23452345

src/qt/clientmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ QString ClientModel::dataDir() const
251251

252252
QString ClientModel::blocksDir() const
253253
{
254-
return GUIUtil::boostPathToQString(GetBlocksDir());
254+
return GUIUtil::boostPathToQString(gArgs.GetBlocksDirPath());
255255
}
256256

257257
void ClientModel::updateBanlist()

src/qt/guiutil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ void openConfigfile()
643643

644644
void showBackups()
645645
{
646-
fs::path backupsDir = GetBackupsDir();
646+
fs::path backupsDir = gArgs.GetBackupsDirPath();
647647

648648
/* Open folder with default browser */
649649
if (fs::exists(backupsDir))

src/test/dbwrapper_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper)
2626
{
2727
// Perform tests both obfuscated and non-obfuscated.
2828
for (const bool obfuscate : {false, true}) {
29-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false");
29+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_obfuscate_true" : "dbwrapper_obfuscate_false");
3030
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
3131
uint8_t key{'k'};
3232
uint256 in = InsecureRand256();
@@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_basic_data)
4545
{
4646
// Perform tests both obfuscated and non-obfuscated.
4747
for (bool obfuscate : {false, true}) {
48-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_1_obfuscate_true" : "dbwrapper_1_obfuscate_false");
48+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_1_obfuscate_true" : "dbwrapper_1_obfuscate_false");
4949
CDBWrapper dbw(ph, (1 << 20), false, true, obfuscate);
5050

5151
uint256 res;
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_batch)
126126
{
127127
// Perform tests both obfuscated and non-obfuscated.
128128
for (const bool obfuscate : {false, true}) {
129-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_batch_obfuscate_true" : "dbwrapper_batch_obfuscate_false");
129+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_batch_obfuscate_true" : "dbwrapper_batch_obfuscate_false");
130130
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
131131

132132
uint8_t key{'i'};
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
162162
{
163163
// Perform tests both obfuscated and non-obfuscated.
164164
for (const bool obfuscate : {false, true}) {
165-
fs::path ph = GetDataDir() / (obfuscate ? "dbwrapper_iterator_obfuscate_true" : "dbwrapper_iterator_obfuscate_false");
165+
fs::path ph = m_args.GetDataDirPath() / (obfuscate ? "dbwrapper_iterator_obfuscate_true" : "dbwrapper_iterator_obfuscate_false");
166166
CDBWrapper dbw(ph, (1 << 20), true, false, obfuscate);
167167

168168
// The two keys are intentionally chosen for ordering
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
202202
BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
203203
{
204204
// We're going to share this fs::path between two wrappers
205-
fs::path ph = GetDataDir() / "existing_data_no_obfuscate";
205+
fs::path ph = m_args.GetDataDirPath() / "existing_data_no_obfuscate";
206206
create_directories(ph);
207207

208208
// Set up a non-obfuscated wrapper to write some initial data.
@@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(existing_data_no_obfuscate)
243243
BOOST_AUTO_TEST_CASE(existing_data_reindex)
244244
{
245245
// We're going to share this fs::path between two wrappers
246-
fs::path ph = GetDataDir() / "existing_data_reindex";
246+
fs::path ph = m_args.GetDataDirPath() / "existing_data_reindex";
247247
create_directories(ph);
248248

249249
// Set up a non-obfuscated wrapper to write some initial data.
@@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(existing_data_reindex)
278278

279279
BOOST_AUTO_TEST_CASE(iterator_ordering)
280280
{
281-
fs::path ph = GetDataDir() / "iterator_ordering";
281+
fs::path ph = m_args.GetDataDirPath() / "iterator_ordering";
282282
CDBWrapper dbw(ph, (1 << 20), true, false, false);
283283
for (int x=0x00; x<256; ++x) {
284284
uint8_t key = x;
@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
358358
{
359359
char buf[10];
360360

361-
fs::path ph = GetDataDir() / "iterator_string_ordering";
361+
fs::path ph = m_args.GetDataDirPath() / "iterator_string_ordering";
362362
CDBWrapper dbw(ph, (1 << 20), true, false, false);
363363
for (int x=0x00; x<10; ++x) {
364364
for (int y = 0; y < 10; y++) {
@@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(unicodepath)
404404
// On Windows this test will fail if the directory is created using
405405
// the ANSI CreateDirectoryA call and the code page isn't UTF8.
406406
// It will succeed if created with CreateDirectoryW.
407-
fs::path ph = GetDataDir() / "test_runner_₿_🏃_20191128_104644";
407+
fs::path ph = m_args.GetDataDirPath() / "test_runner_₿_🏃_20191128_104644";
408408
CDBWrapper dbw(ph, (1 << 20));
409409

410410
fs::path lockPath = ph / "LOCK";

src/test/denialofservice_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
210210
BOOST_AUTO_TEST_CASE(peer_discouragement)
211211
{
212212
const CChainParams& chainparams = Params();
213-
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
213+
auto banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
214214
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
215215
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), *m_node.scheduler,
216216
*m_node.chainman, *m_node.mempool, *m_node.mn_metaman, *m_node.mn_sync,
@@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
258258
BOOST_AUTO_TEST_CASE(DoS_bantime)
259259
{
260260
const CChainParams& chainparams = Params();
261-
auto banman = std::make_unique<BanMan>(GetDataDir() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
261+
auto banman = std::make_unique<BanMan>(m_args.GetDataDirPath() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
262262
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
263263
auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(), *m_node.scheduler,
264264
*m_node.chainman, *m_node.mempool, *m_node.mn_metaman, *m_node.mn_sync,

src/test/flatfile_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ BOOST_FIXTURE_TEST_SUITE(flatfile_tests, BasicTestingSetup)
1414

1515
BOOST_AUTO_TEST_CASE(flatfile_filename)
1616
{
17-
const auto data_dir = GetDataDir();
17+
const auto data_dir = m_args.GetDataDirPath();
1818

1919
FlatFilePos pos(456, 789);
2020

@@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(flatfile_filename)
2727

2828
BOOST_AUTO_TEST_CASE(flatfile_open)
2929
{
30-
const auto data_dir = GetDataDir();
30+
const auto data_dir = m_args.GetDataDirPath();
3131
FlatFileSeq seq(data_dir, "a", 16 * 1024);
3232

3333
std::string line1("A purely peer-to-peer version of electronic cash would allow online "
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(flatfile_open)
8888

8989
BOOST_AUTO_TEST_CASE(flatfile_allocate)
9090
{
91-
const auto data_dir = GetDataDir();
91+
const auto data_dir = m_args.GetDataDirPath();
9292
FlatFileSeq seq(data_dir, "a", 100);
9393

9494
bool out_of_space;
@@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(flatfile_allocate)
108108

109109
BOOST_AUTO_TEST_CASE(flatfile_flush)
110110
{
111-
const auto data_dir = GetDataDir();
111+
const auto data_dir = m_args.GetDataDirPath();
112112
FlatFileSeq seq(data_dir, "a", 100);
113113

114114
bool out_of_space;

0 commit comments

Comments
 (0)