Fix governance.cpp

This commit is contained in:
Alexander Block 2020-04-06 13:58:01 +02:00
parent 29d3b75f28
commit 56da433bd9
3 changed files with 13 additions and 2 deletions

View File

@ -1033,8 +1033,8 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
// 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;
}

View File

@ -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)

View File

@ -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