Navigation Menu

Skip to content

Commit

Permalink
Skip stale tip checking if outbound connections are off or if reindex…
Browse files Browse the repository at this point in the history
…ing.

Summary: This is a backport of Core [[bitcoin/bitcoin#14027 | PR14027]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6452
  • Loading branch information
gmaxwell authored and ftrader committed Jul 3, 2020
1 parent 6342f98 commit ea75a9a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/net.h
Expand Up @@ -154,6 +154,7 @@ class CConnman {
nMaxConnections = connOptions.nMaxConnections;
nMaxOutbound =
std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections);
m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
nMaxAddnode = connOptions.nMaxAddnode;
nMaxFeeler = connOptions.nMaxFeeler;
nBestHeight = connOptions.nBestHeight;
Expand Down Expand Up @@ -196,6 +197,7 @@ class CConnman {

void Interrupt();
bool GetNetworkActive() const { return fNetworkActive; };
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
void SetNetworkActive(bool active);
void OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure,
CSemaphoreGrant *grantOutbound = nullptr,
Expand Down Expand Up @@ -431,6 +433,7 @@ class CConnman {
int nMaxOutbound;
int nMaxAddnode;
int nMaxFeeler;
bool m_use_addrman_outgoing;
std::atomic<int> nBestHeight;
CClientUIInterface *clientInterface;
NetEventsInterface *m_msgproc;
Expand Down
8 changes: 4 additions & 4 deletions src/net_processing.cpp
Expand Up @@ -3953,8 +3953,6 @@ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds) {
NodeId worst_peer = -1;
int64_t oldest_block_announcement = std::numeric_limits<int64_t>::max();

LOCK(cs_main);

connman->ForEachNode([&](CNode *pnode) {
AssertLockHeld(cs_main);

Expand Down Expand Up @@ -4021,6 +4019,8 @@ void PeerLogicValidation::EvictExtraOutboundPeers(int64_t time_in_seconds) {

void PeerLogicValidation::CheckForStaleTipAndEvictPeers(
const Consensus::Params &consensusParams) {
LOCK(cs_main);

if (connman == nullptr) {
return;
}
Expand All @@ -4033,10 +4033,10 @@ void PeerLogicValidation::CheckForStaleTipAndEvictPeers(
return;
}

LOCK(cs_main);
// Check whether our tip is stale, and if so, allow using an extra outbound
// peer.
if (TipMayBeStale(consensusParams)) {
if (!fImporting && !fReindex && connman->GetNetworkActive() &&
connman->GetUseAddrmanOutgoing() && TipMayBeStale(consensusParams)) {
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);
Expand Down
6 changes: 5 additions & 1 deletion src/net_processing.h
Expand Up @@ -8,8 +8,11 @@

#include <consensus/params.h>
#include <net.h>
#include <sync.h>
#include <validationinterface.h>

extern RecursiveMutex cs_main;

class Config;

/**
Expand Down Expand Up @@ -106,7 +109,8 @@ class PeerLogicValidation final : public CValidationInterface,
* If we have extra outbound peers, try to disconnect the one with the
* oldest block announcement.
*/
void EvictExtraOutboundPeers(int64_t time_in_seconds);
void EvictExtraOutboundPeers(int64_t time_in_seconds)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

private:
//! Next time to check for stale tip
Expand Down

0 comments on commit ea75a9a

Please sign in to comment.