Skip to content

Commit e2a1a1e

Browse files
committed
Merge #8606: Fix some locks
144ed76 Fix some locks (Pieter Wuille)
2 parents 8ea4440 + 144ed76 commit e2a1a1e

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
@@ -4789,10 +4789,16 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
47894789
pfrom->PushMessage(NetMsgType::BLOCK, block);
47904790
else if (inv.type == MSG_FILTERED_BLOCK)
47914791
{
4792-
LOCK(pfrom->cs_filter);
4793-
if (pfrom->pfilter)
4792+
bool send = false;
4793+
CMerkleBlock merkleBlock;
47944794
{
4795-
CMerkleBlock merkleBlock(block, *pfrom->pfilter);
4795+
LOCK(pfrom->cs_filter);
4796+
if (pfrom->pfilter) {
4797+
send = true;
4798+
merkleBlock = CMerkleBlock(block, *pfrom->pfilter);
4799+
}
4800+
}
4801+
if (send) {
47964802
pfrom->PushMessage(NetMsgType::MERKLEBLOCK, merkleBlock);
47974803
// CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see
47984804
// This avoids hurting performance by pointlessly requiring a round-trip
@@ -6060,8 +6066,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60606066
CBloomFilter filter;
60616067
vRecv >> filter;
60626068

6063-
LOCK(pfrom->cs_filter);
6064-
60656069
if (!filter.IsWithinSizeConstraints())
60666070
{
60676071
// There is no excuse for sending a too-large filter
@@ -6070,11 +6074,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60706074
}
60716075
else
60726076
{
6077+
LOCK(pfrom->cs_filter);
60736078
delete pfrom->pfilter;
60746079
pfrom->pfilter = new CBloomFilter(filter);
60756080
pfrom->pfilter->UpdateEmptyFull();
6081+
pfrom->fRelayTxes = true;
60766082
}
6077-
pfrom->fRelayTxes = true;
60786083
}
60796084

60806085

@@ -6085,20 +6090,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
60856090

60866091
// Nodes must NEVER send a data item > 520 bytes (the max size for a script data object,
60876092
// and thus, the maximum size any matched object can have) in a filteradd message
6088-
if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE)
6089-
{
6090-
LOCK(cs_main);
6091-
Misbehaving(pfrom->GetId(), 100);
6093+
bool bad = false;
6094+
if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) {
6095+
bad = true;
60926096
} else {
60936097
LOCK(pfrom->cs_filter);
6094-
if (pfrom->pfilter)
6098+
if (pfrom->pfilter) {
60956099
pfrom->pfilter->insert(vData);
6096-
else
6097-
{
6098-
LOCK(cs_main);
6099-
Misbehaving(pfrom->GetId(), 100);
6100+
} else {
6101+
bad = true;
61006102
}
61016103
}
6104+
if (bad) {
6105+
LOCK(cs_main);
6106+
Misbehaving(pfrom->GetId(), 100);
6107+
}
61026108
}
61036109

61046110

0 commit comments

Comments
 (0)