Call EraseObjectRequest as soon as an object is read from the stream (#3783)

EraseObjectRequest should nat be postponed for later (no reason to do so) or skipped due to early returns (this is a bug).
This commit is contained in:
UdjinM6 2020-10-28 22:02:05 +03:00 committed by GitHub
parent 7cca0b0617
commit fb4f76c4a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 33 deletions

View File

@ -106,7 +106,7 @@ void CChainLocksHandler::ProcessMessage(CNode* pfrom, const std::string& strComm
void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLockSig& clsig, const uint256& hash) void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLockSig& clsig, const uint256& hash)
{ {
{ if (from != -1) {
LOCK(cs_main); LOCK(cs_main);
EraseObjectRequest(from, CInv(MSG_CLSIG, hash)); EraseObjectRequest(from, CInv(MSG_CLSIG, hash));
} }

View File

@ -28,30 +28,29 @@ void CDKGPendingMessages::PushPendingMessage(NodeId from, CDataStream& vRecv)
// this will also consume the data, even if we bail out early // this will also consume the data, even if we bail out early
auto pm = std::make_shared<CDataStream>(std::move(vRecv)); auto pm = std::make_shared<CDataStream>(std::move(vRecv));
{
LOCK(cs);
if (messagesPerNode[from] >= maxMessagesPerNode) {
// TODO ban?
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
return;
}
messagesPerNode[from]++;
}
CHashWriter hw(SER_GETHASH, 0); CHashWriter hw(SER_GETHASH, 0);
hw.write(pm->data(), pm->size()); hw.write(pm->data(), pm->size());
uint256 hash = hw.GetHash(); uint256 hash = hw.GetHash();
LOCK2(cs_main, cs); if (from != -1) {
LOCK(cs_main);
EraseObjectRequest(from, CInv(invType, hash));
}
LOCK(cs);
if (messagesPerNode[from] >= maxMessagesPerNode) {
// TODO ban?
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
return;
}
messagesPerNode[from]++;
if (!seenMessages.emplace(hash).second) { if (!seenMessages.emplace(hash).second) {
LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from); LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from);
return; return;
} }
EraseObjectRequest(from, CInv(invType, hash));
pendingMessages.emplace_back(std::make_pair(from, std::move(pm))); pendingMessages.emplace_back(std::make_pair(from, std::move(pm)));
} }
@ -451,10 +450,6 @@ bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendi
const auto& msg = *p.second; const auto& msg = *p.second;
auto hash = ::SerializeHash(msg); auto hash = ::SerializeHash(msg);
{
LOCK(cs_main);
EraseObjectRequest(p.first, CInv(MessageType, hash));
}
bool ban = false; bool ban = false;
if (!session.PreVerifyMessage(hash, msg, ban)) { if (!session.PreVerifyMessage(hash, msg, ban)) {

View File

@ -676,6 +676,13 @@ void CInstantSendManager::ProcessMessage(CNode* pfrom, const std::string& strCom
void CInstantSendManager::ProcessMessageInstantSendLock(CNode* pfrom, const llmq::CInstantSendLock& islock, CConnman& connman) void CInstantSendManager::ProcessMessageInstantSendLock(CNode* pfrom, const llmq::CInstantSendLock& islock, CConnman& connman)
{ {
auto hash = ::SerializeHash(islock);
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_ISLOCK, hash));
}
bool ban = false; bool ban = false;
if (!PreVerifyInstantSendLock(pfrom->GetId(), islock, ban)) { if (!PreVerifyInstantSendLock(pfrom->GetId(), islock, ban)) {
if (ban) { if (ban) {
@ -685,8 +692,6 @@ void CInstantSendManager::ProcessMessageInstantSendLock(CNode* pfrom, const llmq
return; return;
} }
auto hash = ::SerializeHash(islock);
LOCK(cs); LOCK(cs);
if (db.GetInstantSendLockByHash(hash) != nullptr) { if (db.GetInstantSendLockByHash(hash) != nullptr) {
return; return;
@ -879,11 +884,6 @@ std::unordered_set<uint256> CInstantSendManager::ProcessPendingInstantSendLocks(
void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& hash, const CInstantSendLock& islock) void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& hash, const CInstantSendLock& islock)
{ {
{
LOCK(cs_main);
EraseObjectRequest(from, CInv(MSG_ISLOCK, hash));
}
CTransactionRef tx; CTransactionRef tx;
uint256 hashBlock; uint256 hashBlock;
const CBlockIndex* pindexMined = nullptr; const CBlockIndex* pindexMined = nullptr;

View File

@ -481,6 +481,11 @@ void CSigningManager::ProcessMessage(CNode* pfrom, const std::string& strCommand
void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const CRecoveredSig& recoveredSig, CConnman& connman) void CSigningManager::ProcessMessageRecoveredSig(CNode* pfrom, const CRecoveredSig& recoveredSig, CConnman& connman)
{ {
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash()));
}
bool ban = false; bool ban = false;
if (!PreVerifyRecoveredSig(pfrom->GetId(), recoveredSig, ban)) { if (!PreVerifyRecoveredSig(pfrom->GetId(), recoveredSig, ban)) {
if (ban) { if (ban) {
@ -681,11 +686,6 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re
{ {
auto llmqType = (Consensus::LLMQType)recoveredSig.llmqType; auto llmqType = (Consensus::LLMQType)recoveredSig.llmqType;
{
LOCK(cs_main);
EraseObjectRequest(nodeId, CInv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash()));
}
if (db.HasRecoveredSigForHash(recoveredSig.GetHash())) { if (db.HasRecoveredSigForHash(recoveredSig.GetHash())) {
return; return;
} }

View File

@ -2778,6 +2778,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
CInv inv(nInvType, tx.GetHash()); CInv inv(nInvType, tx.GetHash());
pfrom->AddInventoryKnown(inv); pfrom->AddInventoryKnown(inv);
{
LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), inv);
}
// Process custom logic, no matter if tx will be accepted to mempool later or not // Process custom logic, no matter if tx will be accepted to mempool later or not
if (nInvType == MSG_DSTX) { if (nInvType == MSG_DSTX) {
uint256 hashTx = tx.GetHash(); uint256 hashTx = tx.GetHash();
@ -2830,8 +2835,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
bool fMissingInputs = false; bool fMissingInputs = false;
CValidationState state; CValidationState state;
EraseObjectRequest(pfrom->GetId(), inv);
if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs /* pfMissingInputs */, if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, ptx, &fMissingInputs /* pfMissingInputs */,
false /* bypass_limits */, 0 /* nAbsurdFee */)) { false /* bypass_limits */, 0 /* nAbsurdFee */)) {
// Process custom txes, this changes AlreadyHave to "true" // Process custom txes, this changes AlreadyHave to "true"