Skip to content

Commit f83cdb6

Browse files
Merge #7245: backport: Merge bitcoin#27005, 28644, 26940, 27511, 28403, 28361, 28409
3ded43e Merge bitcoin#28409: test: Combine sync_send_with_ping and sync_with_ping (fanquake) 17ef2a4 Merge bitcoin#28361: fuzz: add ConstructPubKeyBytes util function (fanquake) 7513a30 Merge bitcoin#28403: test: Bump walletpassphrase timeouts to avoid intermittent issues (Andrew Chow) 928d0da Merge bitcoin#27511: rpc: Add test-only RPC getaddrmaninfo for new/tried table address count (Andrew Chow) 2b95fb2 Merge bitcoin#26940: test: create random and coins utils, add amount helper, dedupe add_coin (Andrew Chow) e822355 Merge bitcoin#28644: test: Fuzz merge with -use_value_profile=0 for now (fanquake) 5025990 Merge bitcoin#27005: util: Use steady clock for logging timer (fanquake) Pull request description: bitcoin backports ACKs for top commit: PastaPastaPasta: utACK 3ded43e Tree-SHA512: 04a8cf43a89972048fc911ca48948e3d82b7420035714c5fdf35ab45e5b6631d495926bdafad0ce0c517b7a2ac51e454c95b59ae81da90570d4b0f7bcdd7c548
2 parents a9beff7 + 3ded43e commit f83cdb6

61 files changed

Lines changed: 277 additions & 105 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Makefile.test_util.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ EXTRA_LIBRARIES += \
1010
TEST_UTIL_H = \
1111
test/util/blockfilter.h \
1212
test/util/chainstate.h \
13+
test/util/coins.h \
1314
test/util/json.h \
1415
test/util/index.h \
1516
test/util/llmq_tests.h \
1617
test/util/logging.h \
1718
test/util/mining.h \
1819
test/util/net.h \
1920
test/util/poolresourcetester.h \
21+
test/util/random.h \
2022
test/util/script.h \
2123
test/util/setup_common.h \
2224
test/util/str.h \
@@ -31,6 +33,7 @@ libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
3133
libtest_util_a_SOURCES = \
3234
test/util/blockfilter.cpp \
3335
test/util/index.cpp \
36+
test/util/coins.cpp \
3437
test/util/json.cpp \
3538
test/util/logging.cpp \
3639
test/util/mining.cpp \

src/logging/timer.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <util/types.h>
1313

1414
#include <chrono>
15+
#include <optional>
1516
#include <string>
1617

1718

@@ -28,14 +29,14 @@ class Timer
2829
std::string prefix,
2930
std::string end_msg,
3031
BCLog::LogFlags log_category = BCLog::LogFlags::ALL,
31-
bool msg_on_completion = true) :
32-
m_prefix(std::move(prefix)),
33-
m_title(std::move(end_msg)),
34-
m_log_category(log_category),
35-
m_message_on_completion(msg_on_completion)
32+
bool msg_on_completion = true)
33+
: m_prefix(std::move(prefix)),
34+
m_title(std::move(end_msg)),
35+
m_log_category(log_category),
36+
m_message_on_completion(msg_on_completion)
3637
{
3738
this->Log(strprintf("%s started", m_title));
38-
m_start_t = GetTime<std::chrono::microseconds>();
39+
m_start_t = std::chrono::steady_clock::now();
3940
}
4041

4142
~Timer()
@@ -60,24 +61,25 @@ class Timer
6061

6162
std::string LogMsg(const std::string& msg)
6263
{
63-
const auto end_time = GetTime<std::chrono::microseconds>() - m_start_t;
64-
if (m_start_t.count() <= 0) {
64+
const auto end_time{std::chrono::steady_clock::now()};
65+
if (!m_start_t) {
6566
return strprintf("%s: %s", m_prefix, msg);
6667
}
68+
const auto duration{end_time - *m_start_t};
6769

6870
if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
69-
return strprintf("%s: %s (%iμs)", m_prefix, msg, end_time.count());
71+
return strprintf("%s: %s (%iμs)", m_prefix, msg, Ticks<std::chrono::microseconds>(duration));
7072
} else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
71-
return strprintf("%s: %s (%.2fms)", m_prefix, msg, end_time.count() * 0.001);
73+
return strprintf("%s: %s (%.2fms)", m_prefix, msg, Ticks<MillisecondsDouble>(duration));
7274
} else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
73-
return strprintf("%s: %s (%.2fs)", m_prefix, msg, end_time.count() * 0.000001);
75+
return strprintf("%s: %s (%.2fs)", m_prefix, msg, Ticks<SecondsDouble>(duration));
7476
} else {
7577
static_assert(ALWAYS_FALSE<TimeType>, "Error: unexpected time type");
7678
}
7779
}
7880

7981
private:
80-
std::chrono::microseconds m_start_t{};
82+
std::optional<std::chrono::steady_clock::time_point> m_start_t{};
8183

8284
//! Log prefix; usually the name of the function this was created in.
8385
const std::string m_prefix;

src/rpc/net.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,55 @@ static RPCHelpMan setmnthreadactive()
11251125
};
11261126
}
11271127

1128+
static RPCHelpMan getaddrmaninfo()
1129+
{
1130+
return RPCHelpMan{"getaddrmaninfo",
1131+
"\nProvides information about the node's address manager by returning the number of "
1132+
"addresses in the `new` and `tried` tables and their sum for all networks.\n"
1133+
"This RPC is for testing only.\n",
1134+
{},
1135+
RPCResult{
1136+
RPCResult::Type::OBJ_DYN, "", "json object with network type as keys",
1137+
{
1138+
{RPCResult::Type::OBJ, "network", "the network (" + Join(GetNetworkNames(), ", ") + ")",
1139+
{
1140+
{RPCResult::Type::NUM, "new", "number of addresses in the new table, which represent potential peers the node has discovered but hasn't yet successfully connected to."},
1141+
{RPCResult::Type::NUM, "tried", "number of addresses in the tried table, which represent peers the node has successfully connected to in the past."},
1142+
{RPCResult::Type::NUM, "total", "total number of addresses in both new/tried tables"},
1143+
}},
1144+
}
1145+
},
1146+
RPCExamples{
1147+
HelpExampleCli("getaddrmaninfo", "")
1148+
+ HelpExampleRpc("getaddrmaninfo", "")
1149+
},
1150+
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1151+
{
1152+
NodeContext& node = EnsureAnyNodeContext(request.context);
1153+
if (!node.addrman) {
1154+
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
1155+
}
1156+
1157+
UniValue ret(UniValue::VOBJ);
1158+
for (int n = 0; n < NET_MAX; ++n) {
1159+
enum Network network = static_cast<enum Network>(n);
1160+
if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
1161+
UniValue obj(UniValue::VOBJ);
1162+
obj.pushKV("new", node.addrman->Size(network, true));
1163+
obj.pushKV("tried", node.addrman->Size(network, false));
1164+
obj.pushKV("total", node.addrman->Size(network));
1165+
ret.pushKV(GetNetworkName(network), obj);
1166+
}
1167+
UniValue obj(UniValue::VOBJ);
1168+
obj.pushKV("new", node.addrman->Size(std::nullopt, true));
1169+
obj.pushKV("tried", node.addrman->Size(std::nullopt, false));
1170+
obj.pushKV("total", node.addrman->Size());
1171+
ret.pushKV("all_networks", obj);
1172+
return ret;
1173+
},
1174+
};
1175+
}
1176+
11281177
void RegisterNetRPCCommands(CRPCTable &t)
11291178
{
11301179
static const CRPCCommand commands[]{
@@ -1146,6 +1195,7 @@ void RegisterNetRPCCommands(CRPCTable &t)
11461195
{"hidden", &addpeeraddress},
11471196
{"hidden", &sendmsgtopeer},
11481197
{"hidden", &setmnthreadactive},
1198+
{"hidden", &getaddrmaninfo},
11491199
};
11501200
for (const auto& c : commands) {
11511201
t.appendCommand(c.name, &c);

src/test/base58_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <base58.h>
88
#include <test/util/json.h>
99
#include <test/util/setup_common.h> // for InsecureRand*
10+
#include <test/util/random.h>
1011
#include <util/strencodings.h>
1112
#include <util/vector.h>
1213

src/test/bip324_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <key.h>
88
#include <pubkey.h>
99
#include <span.h>
10+
#include <test/util/random.h>
1011
#include <test/util/setup_common.h>
1112
#include <util/strencodings.h>
1213

src/test/blockencodings_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <consensus/merkle.h>
88
#include <pow.h>
99
#include <streams.h>
10+
#include <test/util/random.h>
1011
#include <test/util/txmempool.h>
1112

1213
#include <test/util/setup_common.h>

src/test/bloom_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <primitives/block.h>
1212
#include <serialize.h>
1313
#include <streams.h>
14+
#include <test/util/random.h>
1415
#include <test/util/setup_common.h>
1516
#include <uint256.h>
1617
#include <util/strencodings.h>

src/test/checkqueue_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <checkqueue.h>
88
#include <sync.h>
9+
#include <test/util/random.h>
910
#include <util/time.h>
1011

1112
#include <boost/test/unit_test.hpp>

src/test/coins_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <script/standard.h>
88
#include <streams.h>
99
#include <test/util/poolresourcetester.h>
10+
#include <test/util/random.h>
1011
#include <test/util/setup_common.h>
1112
#include <txdb.h>
1213
#include <uint256.h>
@@ -173,7 +174,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
173174

174175
if (InsecureRandRange(5) == 0 || coin.IsSpent()) {
175176
Coin newcoin;
176-
newcoin.out.nValue = InsecureRand32();
177+
newcoin.out.nValue = InsecureRandMoneyAmount();
177178
newcoin.nHeight = 1;
178179

179180
// Infrequently test adding unspendable coins.

src/test/crypto_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <crypto/sha512.h>
1919
#include <random.h>
2020
#include <streams.h>
21+
#include <test/util/random.h>
2122
#include <test/util/setup_common.h>
2223
#include <util/strencodings.h>
2324

0 commit comments

Comments
 (0)