[net] remove fUpdateConnectionTime from FinalizeNode

PeerManager can just call directly into CAddrMan::Connected() now.
This commit is contained in:
John Newbery 2020-10-23 10:28:33 +01:00
parent 7c4cc67c0c
commit 3fc06d3d7b
4 changed files with 19 additions and 25 deletions

View file

@ -2621,11 +2621,7 @@ void CConnman::StopNodes()
void CConnman::DeleteNode(CNode* pnode) void CConnman::DeleteNode(CNode* pnode)
{ {
assert(pnode); assert(pnode);
bool fUpdateConnectionTime = false; m_msgproc->FinalizeNode(*pnode);
m_msgproc->FinalizeNode(*pnode, fUpdateConnectionTime);
if (fUpdateConnectionTime) {
addrman.Connected(pnode->addr);
}
delete pnode; delete pnode;
} }

View file

@ -770,7 +770,7 @@ public:
virtual void InitializeNode(CNode* pnode) = 0; virtual void InitializeNode(CNode* pnode) = 0;
/** Handle removal of a peer (clear state) */ /** Handle removal of a peer (clear state) */
virtual void FinalizeNode(const CNode& node, bool& update_connection_time) = 0; virtual void FinalizeNode(const CNode& node) = 0;
/** /**
* Process protocol messages received from a given node * Process protocol messages received from a given node

View file

@ -238,7 +238,7 @@ public:
/** Implement NetEventsInterface */ /** Implement NetEventsInterface */
void InitializeNode(CNode* pnode) override; void InitializeNode(CNode* pnode) override;
void FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) override; void FinalizeNode(const CNode& node) override;
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override; bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override;
bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing); bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing);
@ -969,12 +969,12 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta); scheduler.scheduleFromNow([&] { ReattemptInitialBroadcast(scheduler); }, delta);
} }
void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) void PeerManagerImpl::FinalizeNode(const CNode& node)
{ {
NodeId nodeid = node.GetId(); NodeId nodeid = node.GetId();
fUpdateConnectionTime = false;
LOCK(cs_main);
int misbehavior{0}; int misbehavior{0};
{
LOCK(cs_main);
{ {
// We remove the PeerRef from g_peer_map here, but we don't always // We remove the PeerRef from g_peer_map here, but we don't always
// destruct the Peer. Sometimes another thread is still holding a // destruct the Peer. Sometimes another thread is still holding a
@ -991,12 +991,6 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
if (state->fSyncStarted) if (state->fSyncStarted)
nSyncStarted--; nSyncStarted--;
if (node.fSuccessfullyConnected && misbehavior == 0 &&
!node.IsBlockOnlyConn() && !node.IsInboundConn()) {
// Only change visible addrman state for outbound, full-relay peers
fUpdateConnectionTime = true;
}
for (const QueuedBlock& entry : state->vBlocksInFlight) { for (const QueuedBlock& entry : state->vBlocksInFlight) {
mapBlocksInFlight.erase(entry.hash); mapBlocksInFlight.erase(entry.hash);
} }
@ -1021,6 +1015,14 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
assert(m_wtxid_relay_peers == 0); assert(m_wtxid_relay_peers == 0);
assert(m_txrequest.Size() == 0); assert(m_txrequest.Size() == 0);
} }
} // cs_main
if (node.fSuccessfullyConnected && misbehavior == 0 &&
!node.IsBlockOnlyConn() && !node.IsInboundConn()) {
// Only change visible addrman state for full outbound peers. We don't
// call Connected() for feeler connections since they don't have
// fSuccessfullyConnected set.
m_addrman.Connected(node.addr);
}
LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid);
} }

View file

@ -117,8 +117,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
BOOST_CHECK(dummyNode1.fDisconnect == true); BOOST_CHECK(dummyNode1.fDisconnect == true);
SetMockTime(0); SetMockTime(0);
bool dummy; peerLogic->FinalizeNode(dummyNode1);
peerLogic->FinalizeNode(dummyNode1, dummy);
} }
static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &peerLogic, CConnmanTest* connman) static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &peerLogic, CConnmanTest* connman)
@ -199,9 +198,8 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true); BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true);
BOOST_CHECK(vNodes.back()->fDisconnect == false); BOOST_CHECK(vNodes.back()->fDisconnect == false);
bool dummy;
for (const CNode *node : vNodes) { for (const CNode *node : vNodes) {
peerLogic->FinalizeNode(*node, dummy); peerLogic->FinalizeNode(*node);
} }
connman->ClearNodes(); connman->ClearNodes();
@ -249,9 +247,8 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
BOOST_CHECK(banman->IsDiscouraged(addr1)); // Expect both 1 and 2 BOOST_CHECK(banman->IsDiscouraged(addr1)); // Expect both 1 and 2
BOOST_CHECK(banman->IsDiscouraged(addr2)); // to be discouraged now BOOST_CHECK(banman->IsDiscouraged(addr2)); // to be discouraged now
bool dummy; peerLogic->FinalizeNode(dummyNode1);
peerLogic->FinalizeNode(dummyNode1, dummy); peerLogic->FinalizeNode(dummyNode2);
peerLogic->FinalizeNode(dummyNode2, dummy);
} }
BOOST_AUTO_TEST_CASE(DoS_bantime) BOOST_AUTO_TEST_CASE(DoS_bantime)
@ -279,8 +276,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
} }
BOOST_CHECK(banman->IsDiscouraged(addr)); BOOST_CHECK(banman->IsDiscouraged(addr));
bool dummy; peerLogic->FinalizeNode(dummyNode);
peerLogic->FinalizeNode(dummyNode, dummy);
} }
class TxOrphanageTest : public TxOrphanage class TxOrphanageTest : public TxOrphanage