Skip to content

Commit 0e5cff6

Browse files
committed
Merge #11012: Make sure to clean up mapBlockSource if we've already seen the block
3f8fa7f Make sure to clean up mapBlockSource if we've already seen the block (Cory Fields) Pull request description: Otherwise we may leave them dangling. Credit TheBlueMatt. Tree-SHA512: 8be77e08ebfc4f5b206d5ee7cfbe87f92c1eb5bc2b412471993658fe210306789aaf0f3d1454c635508a7d8effede2cf5ac144d622b0157b872733d9661d65c3
2 parents 6bdf4b3 + 3f8fa7f commit 0e5cff6

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/net_processing.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,9 +2145,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
21452145
}
21462146
bool fNewBlock = false;
21472147
ProcessNewBlock(chainparams, pblock, true, &fNewBlock);
2148-
if (fNewBlock)
2148+
if (fNewBlock) {
21492149
pfrom->nLastBlockTime = GetTime();
2150-
2150+
} else {
2151+
LOCK(cs_main);
2152+
mapBlockSource.erase(pblock->GetHash());
2153+
}
21512154
LOCK(cs_main); // hold cs_main for CBlockIndex::IsValid()
21522155
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS)) {
21532156
// Clear download state for this block, which is in
@@ -2222,8 +2225,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
22222225
// Since we requested this block (it was in mapBlocksInFlight), force it to be processed,
22232226
// even if it would not be a candidate for new tip (missing previous block, chain not long enough, etc)
22242227
ProcessNewBlock(chainparams, pblock, true, &fNewBlock);
2225-
if (fNewBlock)
2228+
if (fNewBlock) {
22262229
pfrom->nLastBlockTime = GetTime();
2230+
} else {
2231+
LOCK(cs_main);
2232+
mapBlockSource.erase(pblock->GetHash());
2233+
}
22272234
}
22282235
}
22292236

@@ -2401,8 +2408,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
24012408
}
24022409
bool fNewBlock = false;
24032410
ProcessNewBlock(chainparams, pblock, forceProcessing, &fNewBlock);
2404-
if (fNewBlock)
2411+
if (fNewBlock) {
24052412
pfrom->nLastBlockTime = GetTime();
2413+
} else {
2414+
LOCK(cs_main);
2415+
mapBlockSource.erase(pblock->GetHash());
2416+
}
24062417
}
24072418

24082419

0 commit comments

Comments
 (0)