Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert lock order from #708. #961

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6612,7 +6612,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (vInv.size() > MAX_INV_SZ)
{
pfrom->Misbehaving(50);
printf("\r\n **Hacker tried to send inventory > MAX_INV_SZ **\r\n");
return error("message inv size() = %" PRIszu "", vInv.size());
}

Expand All @@ -6624,6 +6623,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
break;
}
}

LOCK(cs_main);
CTxDB txdb("r");
for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
{
Expand Down Expand Up @@ -6671,6 +6672,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (fDebug10) printf("received getdata (%" PRIszu " invsz)\n", vInv.size());
}

LOCK(cs_main);
for (auto const& inv : vInv)
{
if (fShutdown)
Expand Down Expand Up @@ -6739,6 +6741,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
uint256 hashStop;
vRecv >> locator >> hashStop;

LOCK(cs_main);

// Find the last block the caller has in the main chain
CBlockIndex* pindex = locator.GetBlockIndex();

Expand Down Expand Up @@ -6776,6 +6780,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
uint256 hashStop;
vRecv >> locator >> hashStop;

LOCK(cs_main);

CBlockIndex* pindex = NULL;
if (locator.IsNull())
{
Expand Down Expand Up @@ -6814,6 +6820,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CInv inv(MSG_TX, tx.GetHash());
pfrom->AddInventoryKnown(inv);

LOCK(cs_main);

bool fMissingInputs = false;
if (AcceptToMemoryPool(mempool, tx, &fMissingInputs))
{
Expand Down Expand Up @@ -6892,6 +6900,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CInv inv(MSG_BLOCK, hashBlock);
pfrom->AddInventoryKnown(inv);

LOCK(cs_main);

if (ProcessBlock(pfrom, &block, false))
{
mapAlreadyAskedFor.erase(inv);
Expand Down Expand Up @@ -6920,6 +6930,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

else if (strCommand == "mempool")
{
LOCK(cs_main);

std::vector<uint256> vtxid;
mempool.queryHashes(vtxid);
vector<CInv> vInv;
Expand Down Expand Up @@ -7212,13 +7224,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

// requires LOCK(cs_vRecvMsg)
bool ProcessMessages(CNode* pfrom)
{
LOCK(cs_main);

TRY_LOCK(pfrom->cs_vRecvMsg, lockRecv);
if (!lockRecv)
return true;

{
//
// Message format
// (4) message start
Expand Down Expand Up @@ -7286,7 +7292,7 @@ bool ProcessMessages(CNode* pfrom)
bool fRet = false;
try
{
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime);
fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime);
if (fShutdown)
break;
}
Expand Down Expand Up @@ -7971,10 +7977,6 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
if(!lockMain)
return true;

TRY_LOCK(pto->cs_vSend, lockSend);
if (!lockSend)
return true;

// Don't send anything until we get their version message
if (pto->nVersion == 0)
return true;
Expand Down
15 changes: 12 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,14 +2053,23 @@ void ThreadMessageHandler2(void* parg)

//11-25-2015
// Receive messages
if (!ProcessMessages(pnode))
pnode->CloseSocketDisconnect();
{
TRY_LOCK(pnode->cs_vRecvMsg, lockRecv);
if (lockRecv)
if (!ProcessMessages(pnode))
pnode->CloseSocketDisconnect();
}

if (fShutdown)
return;

// Send messages
SendMessages(pnode, pnode == pnodeTrickle);
{
TRY_LOCK(pnode->cs_vSend, lockSend);
if (lockSend)
SendMessages(pnode, pnode == pnodeTrickle);
}

if (fShutdown)
return;
}
Expand Down