Skip to content

Commit 89dc822

Browse files
committed
Merge bitcoin/bitcoin#29641: scripted-diff: Use LogInfo over LogPrintf
fa4395d refactor: Remove unused LogPrintf (MarcoFalke) fa05181 scripted-diff: LogPrintf -> LogInfo (MarcoFalke) Pull request description: `LogPrintf` has many issues: * It does not mention the log severity (info). * It is a deprecated alias for `LogInfo`, according to the dev notes. * It wastes review cycles, because reviewers sometimes point out that it is deprecated. * It makes the code inconsistent, when both versions of the alias are used. Fix all issues by removing the deprecated alias. ACKs for top commit: ajtowns: ACK fa4395d stickies-v: ACK fa4395d rkrux: lgtm ACK fa4395d Tree-SHA512: de95d56df27b9ee33548cc7ee7595e2d253474094473089ee67787ddb171384383c683142672c3e2c1984e19eee629b2c469dc85713640a73391610581edbdbe
2 parents eb19a2d + fa4395d commit 89dc822

File tree

17 files changed

+61
-67
lines changed

17 files changed

+61
-67
lines changed

doc/developer-notes.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,7 @@ logging messages. They should be used as follows:
752752
messages or for infrequent and important events such as a new block tip
753753
being found or a new outbound connection being made. These log messages
754754
are unconditional, so care must be taken that they can't be used by an
755-
attacker to fill up storage. Note that `LogPrintf(fmt, params...)` is
756-
a deprecated alias for `LogInfo`.
755+
attacker to fill up storage.
757756

758757
- `LogError(fmt, params...)` should be used in place of `LogInfo` for
759758
severe problems that require the node (or a subsystem) to shut down

src/common/args.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ void ArgsManager::logArgsPrefix(
860860
std::optional<unsigned int> flags = GetArgFlags('-' + arg.first);
861861
if (flags) {
862862
std::string value_str = (*flags & SENSITIVE) ? "****" : value.write();
863-
LogPrintf("%s %s%s=%s\n", prefix, section_str, arg.first, value_str);
863+
LogInfo("%s %s%s=%s\n", prefix, section_str, arg.first, value_str);
864864
}
865865
}
866866
}
@@ -873,7 +873,7 @@ void ArgsManager::LogArgs() const
873873
logArgsPrefix("Config file arg:", section.first, section.second);
874874
}
875875
for (const auto& setting : m_settings.rw_settings) {
876-
LogPrintf("Setting file arg: %s = %s\n", setting.first, setting.second.write());
876+
LogInfo("Setting file arg: %s = %s\n", setting.first, setting.second.write());
877877
}
878878
logArgsPrefix("Command-line arg:", "", m_settings.command_line_options);
879879
}

src/common/config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
192192
if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) {
193193
return false;
194194
}
195-
LogPrintf("Included configuration file %s\n", conf_file_name);
195+
LogInfo("Included configuration file %s\n", conf_file_name);
196196
} else {
197197
error = "Failed to include configuration file " + conf_file_name;
198198
return false;

src/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BCLog::Logger& LogInstance()
3030
* cleaned up by the OS/libc. Defining a logger as a global object doesn't work
3131
* since the order of destruction of static/global objects is undefined.
3232
* Consider if the logger gets destroyed, and then some later destructor calls
33-
* LogPrintf, maybe indirectly, and you get a core dump at shutdown trying to
33+
* LogInfo, maybe indirectly, and you get a core dump at shutdown trying to
3434
* access the logger. When the shutdown sequence is fully audited and tested,
3535
* explicit destruction of these objects can be implemented by changing this
3636
* from a raw pointer to a std::unique_ptr.

src/logging.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,6 @@ inline void LogPrintFormatInternal(std::source_location&& source_loc, BCLog::Log
369369
#define LogWarning(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Warning, /*should_ratelimit=*/true, __VA_ARGS__)
370370
#define LogError(...) LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Error, /*should_ratelimit=*/true, __VA_ARGS__)
371371

372-
// Deprecated unconditional logging.
373-
#define LogPrintf(...) LogInfo(__VA_ARGS__)
374-
375372
// Use a macro instead of a function for conditional logging to prevent
376373
// evaluating arguments when logging for the category is not enabled.
377374

src/logging/timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Timer
5353
const std::string full_msg = this->LogMsg(msg);
5454

5555
if (m_log_category == BCLog::LogFlags::ALL) {
56-
LogPrintf("%s\n", full_msg);
56+
LogInfo("%s\n", full_msg);
5757
} else {
5858
LogDebug(m_log_category, "%s\n", full_msg);
5959
}

src/net.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ bool AddLocal(const CService& addr_, int nScore)
287287
if (!g_reachable_nets.Contains(addr))
288288
return false;
289289

290-
LogPrintf("AddLocal(%s,%i)\n", addr.ToStringAddrPort(), nScore);
290+
LogInfo("AddLocal(%s,%i)\n", addr.ToStringAddrPort(), nScore);
291291

292292
{
293293
LOCK(g_maplocalhost_mutex);
@@ -310,7 +310,7 @@ bool AddLocal(const CNetAddr &addr, int nScore)
310310
void RemoveLocal(const CService& addr)
311311
{
312312
LOCK(g_maplocalhost_mutex);
313-
LogPrintf("RemoveLocal(%s)\n", addr.ToStringAddrPort());
313+
LogInfo("RemoveLocal(%s)\n", addr.ToStringAddrPort());
314314
mapLocalHost.erase(addr);
315315
}
316316

@@ -421,7 +421,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect,
421421
// It is possible that we already have a connection to the IP/port pszDest resolved to.
422422
// In that case, drop the connection that was just created.
423423
if (AlreadyConnectedToAddressPort(addrConnect)) {
424-
LogPrintf("Not opening a connection to %s, already connected to %s\n", pszDest, addrConnect.ToStringAddrPort());
424+
LogInfo("Not opening a connection to %s, already connected to %s\n", pszDest, addrConnect.ToStringAddrPort());
425425
return nullptr;
426426
}
427427
// Add the address to the resolved addresses vector so we can try to connect to it later on
@@ -1739,7 +1739,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
17391739
if (!sock) {
17401740
const int nErr = WSAGetLastError();
17411741
if (nErr != WSAEWOULDBLOCK) {
1742-
LogPrintf("socket error accept failed: %s\n", NetworkErrorString(nErr));
1742+
LogInfo("socket error accept failed: %s\n", NetworkErrorString(nErr));
17431743
}
17441744
return;
17451745
}
@@ -1785,7 +1785,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
17851785
}
17861786

17871787
if (!sock->IsSelectable()) {
1788-
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToStringAddrPort());
1788+
LogInfo("connection from %s dropped: non-selectable socket\n", addr.ToStringAddrPort());
17891789
return;
17901790
}
17911791

@@ -2258,7 +2258,7 @@ void CConnman::ThreadDNSAddressSeed()
22582258
if (!gArgs.GetArgs("-seednode").empty()) {
22592259
auto start = NodeClock::now();
22602260
constexpr std::chrono::seconds SEEDNODE_TIMEOUT = 30s;
2261-
LogPrintf("-seednode enabled. Trying the provided seeds for %d seconds before defaulting to the dnsseeds.\n", SEEDNODE_TIMEOUT.count());
2261+
LogInfo("-seednode enabled. Trying the provided seeds for %d seconds before defaulting to the dnsseeds.\n", SEEDNODE_TIMEOUT.count());
22622262
while (!m_interrupt_net->interrupted()) {
22632263
if (!m_interrupt_net->sleep_for(500ms)) {
22642264
return;
@@ -2267,13 +2267,13 @@ void CConnman::ThreadDNSAddressSeed()
22672267
// Abort if we have spent enough time without reaching our target.
22682268
// Giving seed nodes 30 seconds so this does not become a race against fixedseeds (which triggers after 1 min)
22692269
if (NodeClock::now() > start + SEEDNODE_TIMEOUT) {
2270-
LogPrintf("Couldn't connect to enough peers via seed nodes. Handing fetch logic to the DNS seeds.\n");
2270+
LogInfo("Couldn't connect to enough peers via seed nodes. Handing fetch logic to the DNS seeds.\n");
22712271
break;
22722272
}
22732273

22742274
outbound_connection_count = GetFullOutboundConnCount();
22752275
if (outbound_connection_count >= SEED_OUTBOUND_CONNECTION_THRESHOLD) {
2276-
LogPrintf("P2P peers available. Finished fetching data from seed nodes.\n");
2276+
LogInfo("P2P peers available. Finished fetching data from seed nodes.\n");
22772277
break;
22782278
}
22792279
}
@@ -2316,7 +2316,7 @@ void CConnman::ThreadDNSAddressSeed()
23162316
seeds_right_now += DNSSEEDS_TO_QUERY_AT_ONCE;
23172317

23182318
if (addrman.Size() > 0) {
2319-
LogPrintf("Waiting %d seconds before querying DNS seeds.\n", seeds_wait_time.count());
2319+
LogInfo("Waiting %d seconds before querying DNS seeds.\n", seeds_wait_time.count());
23202320
std::chrono::seconds to_wait = seeds_wait_time;
23212321
while (to_wait.count() > 0) {
23222322
// if sleeping for the MANY_PEERS interval, wake up
@@ -2328,10 +2328,10 @@ void CConnman::ThreadDNSAddressSeed()
23282328

23292329
if (GetFullOutboundConnCount() >= SEED_OUTBOUND_CONNECTION_THRESHOLD) {
23302330
if (found > 0) {
2331-
LogPrintf("%d addresses found from DNS seeds\n", found);
2332-
LogPrintf("P2P peers available. Finished DNS seeding.\n");
2331+
LogInfo("%d addresses found from DNS seeds\n", found);
2332+
LogInfo("P2P peers available. Finished DNS seeding.\n");
23332333
} else {
2334-
LogPrintf("P2P peers available. Skipped DNS seeding.\n");
2334+
LogInfo("P2P peers available. Skipped DNS seeding.\n");
23352335
}
23362336
return;
23372337
}
@@ -2343,13 +2343,13 @@ void CConnman::ThreadDNSAddressSeed()
23432343

23442344
// hold off on querying seeds if P2P network deactivated
23452345
if (!fNetworkActive) {
2346-
LogPrintf("Waiting for network to be reactivated before querying DNS seeds.\n");
2346+
LogInfo("Waiting for network to be reactivated before querying DNS seeds.\n");
23472347
do {
23482348
if (!m_interrupt_net->sleep_for(1s)) return;
23492349
} while (!fNetworkActive);
23502350
}
23512351

2352-
LogPrintf("Loading addresses from DNS seed %s\n", seed);
2352+
LogInfo("Loading addresses from DNS seed %s\n", seed);
23532353
// If -proxy is in use, we make an ADDR_FETCH connection to the DNS resolved peer address
23542354
// for the base dns seed domain in chainparams
23552355
if (HaveNameProxy()) {
@@ -2385,9 +2385,9 @@ void CConnman::ThreadDNSAddressSeed()
23852385
}
23862386
--seeds_right_now;
23872387
}
2388-
LogPrintf("%d addresses found from DNS seeds\n", found);
2388+
LogInfo("%d addresses found from DNS seeds\n", found);
23892389
} else {
2390-
LogPrintf("Skipping DNS seeds. Enough peers have been found\n");
2390+
LogInfo("Skipping DNS seeds. Enough peers have been found\n");
23912391
}
23922392
}
23932393

@@ -2568,7 +2568,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
25682568
constexpr std::chrono::seconds ADD_NEXT_SEEDNODE = 10s;
25692569

25702570
if (!add_fixed_seeds) {
2571-
LogPrintf("Fixed seeds are disabled\n");
2571+
LogInfo("Fixed seeds are disabled\n");
25722572
}
25732573

25742574
while (!m_interrupt_net->interrupted()) {
@@ -2607,15 +2607,15 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
26072607
// It is cheapest to check if enough time has passed first.
26082608
if (GetTime<std::chrono::seconds>() > start + std::chrono::minutes{1}) {
26092609
add_fixed_seeds_now = true;
2610-
LogPrintf("Adding fixed seeds as 60 seconds have passed and addrman is empty for at least one reachable network\n");
2610+
LogInfo("Adding fixed seeds as 60 seconds have passed and addrman is empty for at least one reachable network\n");
26112611
}
26122612

26132613
// Perform cheap checks before locking a mutex.
26142614
else if (!dnsseed && !use_seednodes) {
26152615
LOCK(m_added_nodes_mutex);
26162616
if (m_added_node_params.empty()) {
26172617
add_fixed_seeds_now = true;
2618-
LogPrintf("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n");
2618+
LogInfo("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n");
26192619
}
26202620
}
26212621

@@ -2634,7 +2634,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
26342634
local.SetInternal("fixedseeds");
26352635
addrman.Add(seed_addrs, local);
26362636
add_fixed_seeds = false;
2637-
LogPrintf("Added %d fixed seeds from reachable networks.\n", seed_addrs.size());
2637+
LogInfo("Added %d fixed seeds from reachable networks.\n", seed_addrs.size());
26382638
}
26392639
}
26402640

@@ -3158,7 +3158,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
31583158
// the program was closed and restarted.
31593159
if (sock->SetSockOpt(SOL_SOCKET, SO_REUSEADDR, &nOne, sizeof(int)) == SOCKET_ERROR) {
31603160
strError = Untranslated(strprintf("Error setting SO_REUSEADDR on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
3161-
LogPrintf("%s\n", strError.original);
3161+
LogInfo("%s\n", strError.original);
31623162
}
31633163

31643164
// some systems don't have IPV6_V6ONLY but are always v6only; others do have the option
@@ -3167,14 +3167,14 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
31673167
#ifdef IPV6_V6ONLY
31683168
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_V6ONLY, &nOne, sizeof(int)) == SOCKET_ERROR) {
31693169
strError = Untranslated(strprintf("Error setting IPV6_V6ONLY on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
3170-
LogPrintf("%s\n", strError.original);
3170+
LogInfo("%s\n", strError.original);
31713171
}
31723172
#endif
31733173
#ifdef WIN32
31743174
int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
31753175
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, &nProtLevel, sizeof(int)) == SOCKET_ERROR) {
31763176
strError = Untranslated(strprintf("Error setting IPV6_PROTECTION_LEVEL on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
3177-
LogPrintf("%s\n", strError.original);
3177+
LogInfo("%s\n", strError.original);
31783178
}
31793179
#endif
31803180
}
@@ -3188,7 +3188,7 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
31883188
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original);
31893189
return false;
31903190
}
3191-
LogPrintf("Bound to %s\n", addrBind.ToStringAddrPort());
3191+
LogInfo("Bound to %s\n", addrBind.ToStringAddrPort());
31923192

31933193
// Listen for incoming connections
31943194
if (sock->Listen(SOMAXCONN) == SOCKET_ERROR)
@@ -3209,13 +3209,13 @@ void Discover()
32093209

32103210
for (const CNetAddr &addr: GetLocalAddresses()) {
32113211
if (AddLocal(addr, LOCAL_IF))
3212-
LogPrintf("%s: %s\n", __func__, addr.ToStringAddr());
3212+
LogInfo("%s: %s\n", __func__, addr.ToStringAddr());
32133213
}
32143214
}
32153215

32163216
void CConnman::SetNetworkActive(bool active)
32173217
{
3218-
LogPrintf("%s: %s\n", __func__, active);
3218+
LogInfo("%s: %s\n", __func__, active);
32193219

32203220
if (fNetworkActive == active) {
32213221
return;
@@ -3350,7 +3350,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
33503350
if (m_anchors.size() > MAX_BLOCK_RELAY_ONLY_ANCHORS) {
33513351
m_anchors.resize(MAX_BLOCK_RELAY_ONLY_ANCHORS);
33523352
}
3353-
LogPrintf("%i block-relay-only anchors will be tried for connections.\n", m_anchors.size());
3353+
LogInfo("%i block-relay-only anchors will be tried for connections.\n", m_anchors.size());
33543354
}
33553355

33563356
if (m_client_interface) {
@@ -3384,7 +3384,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
33843384
threadSocketHandler = std::thread(&util::TraceThread, "net", [this] { ThreadSocketHandler(); });
33853385

33863386
if (!gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED))
3387-
LogPrintf("DNS seeding disabled\n");
3387+
LogInfo("DNS seeding disabled\n");
33883388
else
33893389
threadDNSAddressSeed = std::thread(&util::TraceThread, "dnsseed", [this] { ThreadDNSAddressSeed(); });
33903390

src/net_processing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
34943494
// Disconnect if we connected to ourself
34953495
if (pfrom.IsInboundConn() && !m_connman.CheckIncomingNonce(nNonce))
34963496
{
3497-
LogPrintf("connected to self at %s, disconnecting\n", pfrom.addr.ToStringAddrPort());
3497+
LogInfo("connected to self at %s, disconnecting\n", pfrom.addr.ToStringAddrPort());
34983498
pfrom.fDisconnect = true;
34993499
return;
35003500
}
@@ -3663,7 +3663,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
36633663
// can be triggered by an attacker at high rate.
36643664
if (!pfrom.IsInboundConn() || LogAcceptCategory(BCLog::NET, BCLog::Level::Debug)) {
36653665
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3666-
LogPrintf("New %s %s peer connected: version: %d, blocks=%d, peer=%d%s%s\n",
3666+
LogInfo("New %s %s peer connected: version: %d, blocks=%d, peer=%d%s%s\n",
36673667
pfrom.ConnectionTypeAsString(),
36683668
TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type),
36693669
pfrom.nVersion.load(), peer->m_starting_height,
@@ -4285,10 +4285,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42854285
// permission, even if they were already in the mempool, allowing
42864286
// the node to function as a gateway for nodes hidden behind it.
42874287
if (!m_mempool.exists(txid)) {
4288-
LogPrintf("Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n",
4288+
LogInfo("Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n",
42894289
txid.ToString(), wtxid.ToString(), pfrom.GetId());
42904290
} else {
4291-
LogPrintf("Force relaying tx %s (wtxid=%s) from peer=%d\n",
4291+
LogInfo("Force relaying tx %s (wtxid=%s) from peer=%d\n",
42924292
txid.ToString(), wtxid.ToString(), pfrom.GetId());
42934293
RelayTransaction(txid, wtxid);
42944294
}
@@ -5236,7 +5236,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
52365236
// Check whether our tip is stale, and if so, allow using an extra
52375237
// outbound peer
52385238
if (!m_chainman.m_blockman.LoadingBlocks() && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) {
5239-
LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n",
5239+
LogInfo("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n",
52405240
count_seconds(now - m_last_tip_update.load()));
52415241
m_connman.SetTryNewOutboundPeer(true);
52425242
} else if (m_connman.GetTryNewOutboundPeer()) {

src/net_types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ void BanMapFromJson(const UniValue& bans_json, banmap_t& bans)
6060
for (const auto& ban_entry_json : bans_json.getValues()) {
6161
const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].getInt<int>()};
6262
if (version != CBanEntry::CURRENT_VERSION) {
63-
LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version);
63+
LogInfo("Dropping entry with unknown version (%s) from ban list\n", version);
6464
continue;
6565
}
6666
const auto& subnet_str = ban_entry_json[BANMAN_JSON_ADDR_KEY].get_str();
6767
const CSubNet subnet{LookupSubNet(subnet_str)};
6868
if (!subnet.IsValid()) {
69-
LogPrintf("Dropping entry with unparseable address or subnet (%s) from ban list\n", subnet_str);
69+
LogInfo("Dropping entry with unparseable address or subnet (%s) from ban list\n", subnet_str);
7070
continue;
7171
}
7272
bans.insert_or_assign(subnet, CBanEntry{ban_entry_json});

0 commit comments

Comments
 (0)