Skip to content

Commit 3f8fa7f

Browse files
committed
Make sure to clean up mapBlockSource if we've already seen the block
Credit TheBlueMatt
1 parent e222618 commit 3f8fa7f

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
@@ -2134,9 +2134,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
21342134
}
21352135
bool fNewBlock = false;
21362136
ProcessNewBlock(chainparams, pblock, true, &fNewBlock);
2137-
if (fNewBlock)
2137+
if (fNewBlock) {
21382138
pfrom->nLastBlockTime = GetTime();
2139-
2139+
} else {
2140+
LOCK(cs_main);
2141+
mapBlockSource.erase(pblock->GetHash());
2142+
}
21402143
LOCK(cs_main); // hold cs_main for CBlockIndex::IsValid()
21412144
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS)) {
21422145
// Clear download state for this block, which is in
@@ -2211,8 +2214,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
22112214
// Since we requested this block (it was in mapBlocksInFlight), force it to be processed,
22122215
// even if it would not be a candidate for new tip (missing previous block, chain not long enough, etc)
22132216
ProcessNewBlock(chainparams, pblock, true, &fNewBlock);
2214-
if (fNewBlock)
2217+
if (fNewBlock) {
22152218
pfrom->nLastBlockTime = GetTime();
2219+
} else {
2220+
LOCK(cs_main);
2221+
mapBlockSource.erase(pblock->GetHash());
2222+
}
22162223
}
22172224
}
22182225

@@ -2390,8 +2397,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
23902397
}
23912398
bool fNewBlock = false;
23922399
ProcessNewBlock(chainparams, pblock, forceProcessing, &fNewBlock);
2393-
if (fNewBlock)
2400+
if (fNewBlock) {
23942401
pfrom->nLastBlockTime = GetTime();
2402+
} else {
2403+
LOCK(cs_main);
2404+
mapBlockSource.erase(pblock->GetHash());
2405+
}
23952406
}
23962407

23972408

0 commit comments

Comments
 (0)