Remove hashes from setAskFor (#1264)

We should remove hash from setAskFor when the message corresponding to previous inv arrives, otherwise it's stays there forever and setAskFor overflows (i.e. AskFor returns immediately without processing).
This commit is contained in:
UdjinM6 2017-01-18 00:02:59 +04:00 committed by GitHub
parent f1ee9d9c71
commit f81ea67a08
5 changed files with 32 additions and 14 deletions

View File

@ -152,6 +152,8 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
uint256 nHash = govobj.GetHash(); uint256 nHash = govobj.GetHash();
std::string strHash = nHash.ToString(); std::string strHash = nHash.ToString();
pfrom->setAskFor.erase(nHash);
LogPrint("gobject", "MNGOVERNANCEOBJECT -- Received object: %s\n", strHash); LogPrint("gobject", "MNGOVERNANCEOBJECT -- Received object: %s\n", strHash);
if(!AcceptObjectMessage(nHash)) { if(!AcceptObjectMessage(nHash)) {
@ -236,6 +238,8 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
uint256 nHash = vote.GetHash(); uint256 nHash = vote.GetHash();
std::string strHash = nHash.ToString(); std::string strHash = nHash.ToString();
pfrom->setAskFor.erase(nHash);
if(!AcceptVoteMessage(nHash)) { if(!AcceptVoteMessage(nHash)) {
LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Received unrequested vote object: %s, hash: %s, peer = %d\n", LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Received unrequested vote object: %s, hash: %s, peer = %d\n",
vote.ToString(), strHash, pfrom->GetId()); vote.ToString(), strHash, pfrom->GetId());

View File

@ -5692,11 +5692,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if(strCommand == NetMsgType::TX) { if(strCommand == NetMsgType::TX) {
vRecv >> tx; vRecv >> tx;
} else if(strCommand == NetMsgType::TXLOCKREQUEST) {
vRecv >> tx;
nInvType = MSG_TXLOCK_REQUEST;
} else if (strCommand == NetMsgType::DSTX) { } else if (strCommand == NetMsgType::DSTX) {
vRecv >> dstx; vRecv >> dstx;
tx = dstx.tx; tx = dstx.tx;
uint256 hashTx = tx.GetHash();
nInvType = MSG_DSTX; nInvType = MSG_DSTX;
}
CInv inv(nInvType, tx.GetHash());
pfrom->AddInventoryKnown(inv);
pfrom->setAskFor.erase(inv.hash);
if (strCommand == NetMsgType::DSTX) {
uint256 hashTx = tx.GetHash();
if(mapDarksendBroadcastTxes.count(hashTx)) { if(mapDarksendBroadcastTxes.count(hashTx)) {
LogPrint("privatesend", "DSTX -- Already have %s, skipping...\n", hashTx.ToString()); LogPrint("privatesend", "DSTX -- Already have %s, skipping...\n", hashTx.ToString());
@ -5724,20 +5734,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LogPrintf("DSTX -- Got Masternode transaction %s\n", hashTx.ToString()); LogPrintf("DSTX -- Got Masternode transaction %s\n", hashTx.ToString());
mempool.PrioritiseTransaction(hashTx, hashTx.ToString(), 1000, 0.1*COIN); mempool.PrioritiseTransaction(hashTx, hashTx.ToString(), 1000, 0.1*COIN);
pmn->fAllowMixingTx = false; pmn->fAllowMixingTx = false;
} else if (strCommand == NetMsgType::TXLOCKREQUEST) {
vRecv >> tx;
nInvType = MSG_TXLOCK_REQUEST;
} }
CInv inv(nInvType, tx.GetHash());
pfrom->AddInventoryKnown(inv);
LOCK(cs_main); LOCK(cs_main);
bool fMissingInputs = false; bool fMissingInputs = false;
CValidationState state; CValidationState state;
pfrom->setAskFor.erase(inv.hash);
mapAlreadyAskedFor.erase(inv.hash); mapAlreadyAskedFor.erase(inv.hash);
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs))

View File

@ -340,18 +340,22 @@ void CMasternodePayments::ProcessMessage(CNode* pfrom, std::string& strCommand,
if(!pCurrentBlockIndex) return; if(!pCurrentBlockIndex) return;
uint256 nHash = vote.GetHash();
pfrom->setAskFor.erase(nHash);
{ {
LOCK(cs_mapMasternodePaymentVotes); LOCK(cs_mapMasternodePaymentVotes);
if(mapMasternodePaymentVotes.count(vote.GetHash())) { if(mapMasternodePaymentVotes.count(nHash)) {
LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n", vote.GetHash().ToString(), pCurrentBlockIndex->nHeight); LogPrint("mnpayments", "MASTERNODEPAYMENTVOTE -- hash=%s, nHeight=%d seen\n", nHash.ToString(), pCurrentBlockIndex->nHeight);
return; return;
} }
// Avoid processing same vote multiple times // Avoid processing same vote multiple times
mapMasternodePaymentVotes[vote.GetHash()] = vote; mapMasternodePaymentVotes[nHash] = vote;
// but first mark vote as non-verified, // but first mark vote as non-verified,
// AddPaymentVote() below should take care of it if vote is actually ok // AddPaymentVote() below should take care of it if vote is actually ok
mapMasternodePaymentVotes[vote.GetHash()].MarkAsNotVerified(); mapMasternodePaymentVotes[nHash].MarkAsNotVerified();
} }
int nFirstBlock = pCurrentBlockIndex->nHeight - GetStorageLimit(); int nFirstBlock = pCurrentBlockIndex->nHeight - GetStorageLimit();

View File

@ -780,6 +780,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CMasternodeBroadcast mnb; CMasternodeBroadcast mnb;
vRecv >> mnb; vRecv >> mnb;
pfrom->setAskFor.erase(mnb.GetHash());
LogPrint("masternode", "MNANNOUNCE -- Masternode announce, masternode=%s\n", mnb.vin.prevout.ToStringShort()); LogPrint("masternode", "MNANNOUNCE -- Masternode announce, masternode=%s\n", mnb.vin.prevout.ToStringShort());
// backward compatibility patch // backward compatibility patch
@ -805,13 +807,17 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CMasternodePing mnp; CMasternodePing mnp;
vRecv >> mnp; vRecv >> mnp;
uint256 nHash = mnp.GetHash();
pfrom->setAskFor.erase(nHash);
LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s\n", mnp.vin.prevout.ToStringShort()); LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s\n", mnp.vin.prevout.ToStringShort());
// Need LOCK2 here to ensure consistent locking order because the CheckAndUpdate call below locks cs_main // Need LOCK2 here to ensure consistent locking order because the CheckAndUpdate call below locks cs_main
LOCK2(cs_main, cs); LOCK2(cs_main, cs);
if(mapSeenMasternodePing.count(mnp.GetHash())) return; //seen if(mapSeenMasternodePing.count(nHash)) return; //seen
mapSeenMasternodePing.insert(std::make_pair(mnp.GetHash(), mnp)); mapSeenMasternodePing.insert(std::make_pair(nHash, mnp));
LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort()); LogPrint("masternode", "MNPING -- Masternode ping, masternode=%s new\n", mnp.vin.prevout.ToStringShort());

View File

@ -30,6 +30,7 @@ void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStr
std::string strLogMsg; std::string strLogMsg;
{ {
LOCK(cs_main); LOCK(cs_main);
pfrom->setAskFor.erase(hash);
if(!chainActive.Tip()) return; if(!chainActive.Tip()) return;
strLogMsg = strprintf("SPORK -- hash: %s id: %d value: %10d bestHeight: %d peer=%d", hash.ToString(), spork.nSporkID, spork.nValue, chainActive.Height(), pfrom->id); strLogMsg = strprintf("SPORK -- hash: %s id: %d value: %10d bestHeight: %d peer=%d", hash.ToString(), spork.nSporkID, spork.nValue, chainActive.Height(), pfrom->id);
} }