Skip to content

Commit 955012c

Browse files
authored
Merge pull request bitcoin#550 from ptschip/dev_timeout
Prevent the mapThinBlocksInflight timer from tripping
2 parents f524c09 + 34acfbf commit 955012c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6686,7 +6686,7 @@ bool SendMessages(CNode* pto)
66866686
std::map<uint256, int64_t>::iterator iter = pto->mapThinBlocksInFlight.begin();
66876687
while (iter != pto->mapThinBlocksInFlight.end())
66886688
{
6689-
if ((GetTime() - (*iter).second) > THINBLOCK_DOWNLOAD_TIMEOUT)
6689+
if ((*iter).second != -1 && (GetTime() - (*iter).second) > THINBLOCK_DOWNLOAD_TIMEOUT)
66906690
{
66916691
if (!pto->fWhitelisted && Params().NetworkIDString() != "regtest")
66926692
{

src/parallel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,18 @@ void HandleBlockMessageThread(CNode *pfrom, const string &strCommand, const CBlo
496496
CValidationState state;
497497
uint64_t nSizeBlock = ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION);
498498

499+
// At this point we have either a block or a fully reconstructed thinblock but we still need to
500+
// maintain a mapThinBlocksInFlight entry so that we don't re-request a full block from
501+
// the same node while the block is processing. Furthermore by setting the time = -1 we prevent
502+
// the timeout from triggering and inadvertently disconnecting the node in the event that the block
503+
// takes a longer time to process than the THINBLOCK_DOWNLOAD_TIMEOUT interval.
504+
{
505+
LOCK(pfrom->cs_mapthinblocksinflight);
506+
if (pfrom->mapThinBlocksInFlight.count(inv.hash))
507+
pfrom->mapThinBlocksInFlight[inv.hash] = -1;
508+
}
509+
510+
499511
boost::thread::id this_id(boost::this_thread::get_id());
500512
PV.InitThread(this_id, pfrom, block, inv); // initialize the mapBlockValidationThread entries
501513

0 commit comments

Comments
 (0)