Skip to content

Commit 423cb37

Browse files
author
MarcoFalke
committed
Merge #14027: Skip stale tip checking if outbound connections are off or if reindexing.
66b3fc5 Skip stale tip checking if outbound connections are off or if reindexing. (Gregory Maxwell) Pull request description: I got tired of the pointless stale tip notices in reindex and on nodes with connections disabled. Tree-SHA512: eb07d9c5c787ae6dea02cdd1d67a48a36a30adc5ccc74d6f1c0c7364d404dc8848b35d2b8daf5283f7c8f36f1a3c463aacb190d70a22d1fe796a301bb1f03228
2 parents b88dd7c + 66b3fc5 commit 423cb37

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class CConnman
149149
nLocalServices = connOptions.nLocalServices;
150150
nMaxConnections = connOptions.nMaxConnections;
151151
nMaxOutbound = std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections);
152+
m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
152153
nMaxAddnode = connOptions.nMaxAddnode;
153154
nMaxFeeler = connOptions.nMaxFeeler;
154155
nBestHeight = connOptions.nBestHeight;
@@ -174,6 +175,7 @@ class CConnman
174175
void Stop();
175176
void Interrupt();
176177
bool GetNetworkActive() const { return fNetworkActive; };
178+
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
177179
void SetNetworkActive(bool active);
178180
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool fOneShot = false, bool fFeeler = false, bool manual_connection = false);
179181
bool CheckIncomingNonce(uint64_t nonce);
@@ -416,6 +418,7 @@ class CConnman
416418
int nMaxOutbound;
417419
int nMaxAddnode;
418420
int nMaxFeeler;
421+
bool m_use_addrman_outgoing;
419422
std::atomic<int> nBestHeight;
420423
CClientUIInterface* clientInterface;
421424
NetEventsInterface* m_msgproc;

src/net_processing.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,8 +3144,6 @@ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds)
31443144
NodeId worst_peer = -1;
31453145
int64_t oldest_block_announcement = std::numeric_limits<int64_t>::max();
31463146

3147-
LOCK(cs_main);
3148-
31493147
connman->ForEachNode([&](CNode* pnode) {
31503148
AssertLockHeld(cs_main);
31513149

@@ -3193,17 +3191,18 @@ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds)
31933191

31943192
void PeerLogicValidation::CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams)
31953193
{
3194+
LOCK(cs_main);
3195+
31963196
if (connman == nullptr) return;
31973197

31983198
int64_t time_in_seconds = GetTime();
31993199

32003200
EvictExtraOutboundPeers(time_in_seconds);
32013201

32023202
if (time_in_seconds > m_stale_tip_check_time) {
3203-
LOCK(cs_main);
32043203
// Check whether our tip is stale, and if so, allow using an extra
32053204
// outbound peer
3206-
if (TipMayBeStale(consensusParams)) {
3205+
if (!fImporting && !fReindex && connman->GetNetworkActive() && connman->GetUseAddrmanOutgoing() && TipMayBeStale(consensusParams)) {
32073206
LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", time_in_seconds - g_last_tip_update);
32083207
connman->SetTryNewOutboundPeer(true);
32093208
} else if (connman->GetTryNewOutboundPeer()) {

src/net_processing.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <net.h>
1010
#include <validationinterface.h>
1111
#include <consensus/params.h>
12+
#include <sync.h>
13+
14+
extern CCriticalSection cs_main;
1215

1316
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
1417
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
@@ -65,7 +68,7 @@ class PeerLogicValidation final : public CValidationInterface, public NetEventsI
6568
/** Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound */
6669
void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
6770
/** If we have extra outbound peers, try to disconnect the one with the oldest block announcement */
68-
void EvictExtraOutboundPeers(int64_t time_in_seconds);
71+
void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
6972

7073
private:
7174
int64_t m_stale_tip_check_time; //! Next time to check for stale tip

0 commit comments

Comments
 (0)