Skip to content

Commit 9dd6a2b

Browse files
committed
Merge #10824: Avoid unnecessary work in SetNetworkActive
a2420ae Avoid unnecessary work in SetNetworkActive (João Barbosa) Pull request description: This PR adds an early return to avoid unnecessary notifications when the status doesn't change. Tree-SHA512: 85d05ca6fa36cb581f94bc154d08bd72cd53f6a857173c6fb2f184058f9c0208c4cf5e5d196825a78339902d8f256688eb6793f99abc7be9c7cfac85136180d9
2 parents 5c003cb + a2420ae commit 9dd6a2b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/net.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,16 +2183,18 @@ void CConnman::SetNetworkActive(bool active)
21832183
{
21842184
LogPrint(BCLog::NET, "SetNetworkActive: %s\n", active);
21852185

2186-
if (!active) {
2187-
fNetworkActive = false;
2186+
if (fNetworkActive == active) {
2187+
return;
2188+
}
2189+
2190+
fNetworkActive = active;
21882191

2192+
if (!fNetworkActive) {
21892193
LOCK(cs_vNodes);
21902194
// Close sockets to all nodes
21912195
for (CNode* pnode : vNodes) {
21922196
pnode->CloseSocketDisconnect();
21932197
}
2194-
} else {
2195-
fNetworkActive = true;
21962198
}
21972199

21982200
uiInterface.NotifyNetworkActiveChanged(fNetworkActive);

0 commit comments

Comments
 (0)