Skip to content
Open
16 changes: 10 additions & 6 deletions src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

#include "budget/budgetmanager.h"

#include "addrman.h"
#include "chainparams.h"
#include "consensus/validation.h"
#include "evo/deterministicmns.h"
#include "masternodeman.h"
#include "netmessagemaker.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "tiertwo/netfulfilledman.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "util/validation.h"
#include "validation.h" // GetTransaction, cs_main
#include "validation.h" // GetTransaction, cs_main

#ifdef ENABLE_WALLET
#include "wallet/wallet.h" // future: use interface instead.
Expand All @@ -28,6 +30,8 @@ CBudgetManager g_budgetman;
// Used to check both proposals and finalized-budgets collateral txes
bool CheckCollateral(const uint256& nTxCollateralHash, const uint256& nExpectedHash, std::string& strError, int64_t& nTime, int nCurrentHeight, bool fBudgetFinalization);

void EraseObjectRequest(NodeId nodeId, const CInv& inv);

void CBudgetManager::ReloadMapSeen()
{
const auto reloadSeenMap = [](auto& mutex1, auto& mutex2, const auto& mapBudgets, auto& mapSeen, auto& mapOrphans) {
Expand Down Expand Up @@ -1306,7 +1310,7 @@ int CBudgetManager::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(proposal.GetHash(), MSG_BUDGET_PROPOSAL);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_BUDGET_PROPOSAL, proposal.GetHash()));
}
return ProcessProposal(proposal);
}
Expand All @@ -1319,7 +1323,7 @@ int CBudgetManager::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(vote.GetHash(), MSG_BUDGET_VOTE);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_BUDGET_VOTE, vote.GetHash()));
}

CValidationState state;
Expand All @@ -1342,7 +1346,7 @@ int CBudgetManager::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(finalbudget.GetHash(), MSG_BUDGET_FINALIZED);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_BUDGET_FINALIZED, finalbudget.GetHash()));
}
return ProcessFinalizedBudget(finalbudget, pfrom);
}
Expand All @@ -1355,7 +1359,7 @@ int CBudgetManager::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(vote.GetHash(), MSG_BUDGET_FINALIZED_VOTE);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_BUDGET_FINALIZED_VOTE, vote.GetHash()));
}

CValidationState state;
Expand Down
4 changes: 3 additions & 1 deletion src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "spork.h"
#include "validation.h"

void EraseObjectRequest(NodeId nodeId, const CInv& inv);

namespace llmq
{
std::unique_ptr<CQuorumBlockProcessor> quorumBlockProcessor{nullptr};
Expand Down Expand Up @@ -52,7 +54,7 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, CDataStream& vRecv, int
uint256 qfc_hash{::SerializeHash(qc)};
{
LOCK(cs_main);
g_connman->RemoveAskFor(qfc_hash, MSG_QUORUM_FINAL_COMMITMENT);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_QUORUM_FINAL_COMMITMENT, qfc_hash));
}

if (qc.IsNull()) {
Expand Down
5 changes: 3 additions & 2 deletions src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock
{
{
LOCK(cs_main);
g_connman->RemoveAskFor(hash, MSG_CLSIG);
EraseObjectRequest(from, CInv(MSG_CLSIG, hash));
}

{
Expand Down Expand Up @@ -484,4 +484,5 @@ void CChainLocksHandler::Cleanup()
lastCleanupTime = GetTimeMillis();
}

}
} // namespace llmq

2 changes: 1 addition & 1 deletion src/llmq/quorums_dkgsessionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, CDataStream& vRecv, in

LOCK2(cs_main, cs);

g_connman->RemoveAskFor(hash, invType);
EraseObjectRequest(from, CInv(invType, hash));

if (!seenMessages.emplace(hash).second) {
LogPrint(BCLog::NET, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from);
Expand Down
7 changes: 5 additions & 2 deletions src/llmq/quorums_signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "quorums_signing.h"
#include "chainparams.h"
#include "clientversion.h"
#include "netaddress.h"
#include "quorums_signing_shares.h"
Expand All @@ -12,13 +13,15 @@
#include "activemasternode.h"
#include "bls/bls_batchverifier.h"
#include "cxxtimer.h"
#include "net_processing.h"
#include "validation.h"

#include <algorithm>
#include <limits>
#include <unordered_set>

void EraseObjectRequest(NodeId nodeId, const CInv& inv);
void Misbehaving(NodeId nodeid, int howmuch, const std::string& message = "");

namespace llmq
{

Expand Down Expand Up @@ -640,7 +643,7 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re

{
LOCK(cs_main);
connman.RemoveAskFor(recoveredSig.GetHash(), MSG_QUORUM_RECOVERED_SIG);
EraseObjectRequest(nodeId, CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash()));
}

if (db.HasRecoveredSigForHash(recoveredSig.GetHash())) {
Expand Down
7 changes: 4 additions & 3 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@

#include "masternode-payments.h"

#include "budget/budgetmanager.h"
#include "chainparams.h"
#include "evo/deterministicmns.h"
#include "fs.h"
#include "budget/budgetmanager.h"
#include "masternodeman.h"
#include "netmessagemaker.h"
#include "tiertwo/netfulfilledman.h"
#include "spork.h"
#include "sync.h"
#include "tiertwo/netfulfilledman.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "util/system.h"
#include "utilmoneystr.h"
#include "validation.h"

void EraseObjectRequest(NodeId nodeId, const CInv& inv);

/** Object for who's going to get paid on which blocks */
CMasternodePayments masternodePayments;
Expand Down Expand Up @@ -430,7 +431,7 @@ bool CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(winner.GetHash(), MSG_MASTERNODE_WINNER);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_MASTERNODE_WINNER, winner.GetHash()));
}

ProcessMNWinner(winner, pfrom, state);
Expand Down
10 changes: 6 additions & 4 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include "masternodeman.h"

#include "addrman.h"
#include "chainparams.h"
#include "evo/deterministicmns.h"
#include "fs.h"
#include "masternode-payments.h"
#include "masternode-sync.h"
#include "masternode.h"
#include "messagesigner.h"
#include "netbase.h"
#include "netmessagemaker.h"
#include "shutdown.h"
Expand All @@ -23,6 +23,8 @@

#define MN_WINNER_MINIMUM_AGE 8000 // Age in seconds. This should be > MASTERNODE_REMOVAL_SECONDS to avoid misconfigured new nodes in the list.

void EraseObjectRequest(NodeId nodeId, const CInv& inv);

/** Masternode manager */
CMasternodeMan mnodeman;
/** Keep track of the active Masternode */
Expand Down Expand Up @@ -968,7 +970,7 @@ int CMasternodeMan::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(mnb.GetHash(), MSG_MASTERNODE_ANNOUNCE);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_MASTERNODE_ANNOUNCE, mnb.GetHash()));
}
return ProcessMNBroadcast(pfrom, mnb);

Expand All @@ -979,7 +981,7 @@ int CMasternodeMan::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(mnb.GetHash(), MSG_MASTERNODE_ANNOUNCE);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_MASTERNODE_ANNOUNCE, mnb.GetHash()));
}

// For now, let's not process mnb2 with pre-BIP155 node addr format.
Expand All @@ -998,7 +1000,7 @@ int CMasternodeMan::ProcessMessageInner(CNode* pfrom, std::string& strCommand, C
{
// Clear inv request
LOCK(cs_main);
g_connman->RemoveAskFor(mnp.GetHash(), MSG_MASTERNODE_PING);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_MASTERNODE_PING, mnp.GetHash()));
}
return ProcessMNPing(pfrom, mnp);

Expand Down
58 changes: 0 additions & 58 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfLimited[NET_MAX] = {};
std::string strSubVersion;

limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);

void CConnman::AddOneShot(const std::string& strDest)
{
LOCK(cs_vOneShots);
Expand Down Expand Up @@ -2571,16 +2569,6 @@ void CConnman::RelayInv(CInv& inv, int minProtoVersion)
}
}

void CConnman::RemoveAskFor(const uint256& invHash, int invType)
{
mapAlreadyAskedFor.erase(CInv(invType, invHash));

LOCK(cs_vNodes);
for (const auto& pnode : vNodes) {
pnode->AskForInvReceived(invHash);
}
}

void CConnman::UpdateQuorumRelayMemberIfNeeded(CNode* pnode)
{
if (!pnode->m_masternode_iqr_connection && pnode->m_masternode_connection &&
Expand Down Expand Up @@ -2699,52 +2687,6 @@ CNode::~CNode()
CloseSocket(hSocket);
}

void CNode::AskFor(const CInv& inv, int64_t doubleRequestDelay)
{
if (mapAskFor.size() > MAPASKFOR_MAX_SZ || setAskFor.size() > SETASKFOR_MAX_SZ)
return;
// a peer may not have multiple non-responded queue positions for a single inv item
if (!setAskFor.insert(inv.hash).second)
return;

// We're using mapAskFor as a priority queue,
// the key is the earliest time the request can be sent
int64_t nRequestTime;
limitedmap<CInv, int64_t>::const_iterator it = mapAlreadyAskedFor.find(inv);
if (it != mapAlreadyAskedFor.end())
nRequestTime = it->second;
else
nRequestTime = 0;
LogPrint(BCLog::NET, "askfor %s %d (%s) peer=%d\n", inv.ToString(), nRequestTime, FormatISO8601Time(nRequestTime / 1000000), id);

// Make sure not to reuse time indexes to keep things in the same order
int64_t nNow = GetTimeMicros() - 1000000;
static int64_t nLastTime;
++nLastTime;
nNow = std::max(nNow, nLastTime);
nLastTime = nNow;

// Each retry is 2 minutes after the last
nRequestTime = std::max(nRequestTime + doubleRequestDelay, nNow);
if (it != mapAlreadyAskedFor.end())
mapAlreadyAskedFor.update(it, nRequestTime);
else
mapAlreadyAskedFor.insert(std::make_pair(inv, nRequestTime));
mapAskFor.insert(std::make_pair(nRequestTime, inv));
}

void CNode::AskForInvReceived(const uint256& invHash)
{
setAskFor.erase(invHash);
for (auto it = mapAskFor.begin(); it != mapAskFor.end();) {
if (it->second.hash == invHash) {
it = mapAskFor.erase(it);
} else {
++it;
}
}
}

bool CConnman::NodeFullyConnected(const CNode* pnode)
{
return pnode && pnode->fSuccessfullyConnected && !pnode->fDisconnect;
Expand Down
15 changes: 0 additions & 15 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ static const int MAX_ADDNODE_CONNECTIONS = 16;
static const int INBOUND_EVICTION_PROTECTION_TIME = 1;
/** -listen default */
static const bool DEFAULT_LISTEN = true;
/** The maximum number of entries in mapAskFor */
static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
/** The maximum number of entries in setAskFor (larger due to getdata latency)*/
static const size_t SETASKFOR_MAX_SZ = 2 * MAX_INV_SZ;
/** The maximum number of peer connections to maintain. */
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
/** Disconnected peers are added to setOffsetDisconnectedPeers only if node has less than ENOUGH_CONNECTIONS */
Expand Down Expand Up @@ -299,9 +295,6 @@ class CConnman
std::vector<CNode*> CopyNodeVector();
void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);

// Clears AskFor requests for every known peer
void RemoveAskFor(const uint256& invHash, int invType);

void RelayInv(CInv& inv, int minProtoVersion = ActiveProtocol());
bool IsNodeConnected(const CAddress& addr);
// Retrieves a connected peer (if connection success). Used only to check peer address availability for now.
Expand Down Expand Up @@ -568,8 +561,6 @@ bool validateMasternodeIP(const std::string& addrStr); // valid, reacha
extern bool fDiscover;
extern bool fListen;

extern limitedmap<CInv, int64_t> mapAlreadyAskedFor;

/** Subversion as sent to the P2P network in `version` messages */
extern std::string strSubVersion;

Expand Down Expand Up @@ -773,8 +764,6 @@ class CNode
// Set of tier two messages ids we still have to announce.
std::vector<CInv> vInventoryTierTwoToSend;
RecursiveMutex cs_inventory;
std::multimap<int64_t, CInv> mapAskFor;
std::set<uint256> setAskFor;
std::vector<uint256> vBlockRequested;
std::chrono::microseconds nNextInvSend{0};
// Used for BIP35 mempool sending, also protected by cs_inventory
Expand Down Expand Up @@ -925,10 +914,6 @@ class CNode
}
}

void AskFor(const CInv& inv, int64_t doubleRequestDelay = 2 * 60 * 1000000);
// inv response received, clear it from the waiting inv set.
void AskForInvReceived(const uint256& invHash);

void CloseSocketDisconnect();
bool DisconnectOldProtocol(int nVersionIn, int nVersionRequired);

Expand Down
Loading
Loading