| 621 | } |
| 622 | |
| 623 | void PeerLogicValidation::FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) { |
| 624 | fUpdateConnectionTime = false; |
| 625 | LOCK(cs_main); |
| 626 | CNodeState *state = State(nodeid); |
| 627 | assert(state != nullptr); |
| 628 | |
| 629 | if (state->fSyncStarted) |
| 630 | nSyncStarted--; |
| 631 | |
| 632 | if (state->nMisbehavior == 0 && state->fCurrentlyConnected) { |
| 633 | fUpdateConnectionTime = true; |
| 634 | } |
| 635 | |
| 636 | for (const QueuedBlock& entry : state->vBlocksInFlight) { |
| 637 | mapBlocksInFlight.erase(entry.hash); |
| 638 | } |
| 639 | EraseOrphansFor(nodeid); |
| 640 | nPreferredDownload -= state->fPreferredDownload; |
| 641 | nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0); |
| 642 | assert(nPeersWithValidatedDownloads >= 0); |
| 643 | g_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect; |
| 644 | assert(g_outbound_peers_with_protect_from_disconnect >= 0); |
| 645 | |
| 646 | mapNodeState.erase(nodeid); |
| 647 | |
| 648 | if (mapNodeState.empty()) { |
| 649 | // Do a consistency check after the last peer is removed. |
| 650 | assert(mapBlocksInFlight.empty()); |
| 651 | assert(nPreferredDownload == 0); |
| 652 | assert(nPeersWithValidatedDownloads == 0); |
| 653 | assert(g_outbound_peers_with_protect_from_disconnect == 0); |
| 654 | } |
| 655 | LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); |
| 656 | } |
| 657 | |
| 658 | bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { |
| 659 | LOCK(cs_main); |