From 56da433bd9877f4581fda77e00af7753c211d0bc Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 6 Apr 2020 13:58:01 +0200 Subject: [PATCH] Fix governance.cpp --- src/governance/governance.cpp | 4 ++-- src/net_processing.cpp | 10 ++++++++++ src/net_processing.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index 949da6b19b..d0fc86c8d9 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -1033,8 +1033,8 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector& // stop early to prevent setAskFor overflow { LOCK(cs_main); - size_t nProjectedSize = pnode->setAskFor.size() + nProjectedVotes; - if (nProjectedSize > SETASKFOR_MAX_SZ / 2) continue; + size_t nProjectedSize = GetRequestedObjectCount(pnode->GetId()) + nProjectedVotes; + if (nProjectedSize > MAX_INV_SZ) continue; // to early to ask the same node if (mapAskedRecently[nHashGovobj].count(pnode->addr)) continue; } diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f3eb5ca958..d164dfce7f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -735,6 +735,16 @@ void RequestObject(NodeId nodeId, const CInv& inv, int64_t nNow) EXCLUSIVE_LOCKS RequestObject(state, inv, nNow); } +size_t GetRequestedObjectCount(NodeId nodeId) +{ + AssertLockHeld(cs_main); + auto* state = State(nodeId); + if (!state) { + return 0; + } + return state->m_tx_download.m_tx_process_time.size(); +} + // This function is used for testing the stale tip eviction logic, see // DoS_tests.cpp void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) diff --git a/src/net_processing.h b/src/net_processing.h index 6d98f0c30c..ced80382e6 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -86,5 +86,6 @@ bool IsBanned(NodeId nodeid); void EraseObjectRequest(const uint256& hash); void RequestObject(NodeId nodeId, const CInv& inv, int64_t nNow); +size_t GetRequestedObjectCount(NodeId nodeId); #endif // BITCOIN_NET_PROCESSING_H