Skip to content

Commit 144ed76

Browse files
committed
Fix some locks
This makes sure that cs_filter is never held while taking cs_main or CNode::cs_vSend.
1 parent bb56676 commit 144ed76

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/main.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4781,10 +4781,16 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
47814781
pfrom->PushMessage(NetMsgType::BLOCK, block);
47824782
else if (inv.type == MSG_FILTERED_BLOCK)
47834783
{
4784-
LOCK(pfrom->cs_filter);
4785-
if (pfrom->pfilter)
4784+
bool send = false;
4785+
CMerkleBlock merkleBlock;
47864786
{
4787-
CMerkleBlock merkleBlock(block, *pfrom->pfilter);
4787+
LOCK(pfrom->cs_filter);
4788+
if (pfrom->pfilter) {
4789+
send = true;
4790+
merkleBlock = CMerkleBlock(block, *pfrom->pfilter);
4791+
}
4792+
}
4793+
if (send) {
47884794
pfrom->PushMessage(NetMsgType::MERKLEBLOCK, merkleBlock);
47894795
// CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see
47904796
// This avoids hurting performance by pointlessly requiring a round-trip
@@ -6052,8 +6058,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60526058
CBloomFilter filter;
60536059
vRecv >> filter;
60546060

6055-
LOCK(pfrom->cs_filter);
6056-
60576061
if (!filter.IsWithinSizeConstraints())
60586062
{
60596063
// There is no excuse for sending a too-large filter
@@ -6062,11 +6066,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60626066
}
60636067
else
60646068
{
6069+
LOCK(pfrom->cs_filter);
60656070
delete pfrom->pfilter;
60666071
pfrom->pfilter = new CBloomFilter(filter);
60676072
pfrom->pfilter->UpdateEmptyFull();
6073+
pfrom->fRelayTxes = true;
60686074
}
6069-
pfrom->fRelayTxes = true;
60706075
}
60716076

60726077

@@ -6077,20 +6082,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60776082

60786083
// Nodes must NEVER send a data item > 520 bytes (the max size for a script data object,
60796084
// and thus, the maximum size any matched object can have) in a filteradd message
6080-
if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE)
6081-
{
6082-
LOCK(cs_main);
6083-
Misbehaving(pfrom->GetId(), 100);
6085+
bool bad = false;
6086+
if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) {
6087+
bad = true;
60846088
} else {
60856089
LOCK(pfrom->cs_filter);
6086-
if (pfrom->pfilter)
6090+
if (pfrom->pfilter) {
60876091
pfrom->pfilter->insert(vData);
6088-
else
6089-
{
6090-
LOCK(cs_main);
6091-
Misbehaving(pfrom->GetId(), 100);
6092+
} else {
6093+
bad = true;
60926094
}
60936095
}
6096+
if (bad) {
6097+
LOCK(cs_main);
6098+
Misbehaving(pfrom->GetId(), 100);
6099+
}
60946100
}
60956101

60966102

0 commit comments

Comments
 (0)