Skip to content

Commit

Permalink
Merge pull request #479 from ptschip/dev_thintimer
Browse files Browse the repository at this point in the history
Clear Timer after the request is sent  : issue #477
  • Loading branch information
gandrewstone committed May 2, 2017
2 parents 54bd06b + d1fd7f7 commit 301ed19
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main.cpp
Expand Up @@ -628,6 +628,9 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl
CNodeState *state = State(nodeid);
DbgAssert(state != NULL, return);

// If started then clear the thinblock timer used for preferential downloading
thindata.ClearThinBlockTimer(hash);

// BU why mark as received? because this erases it from the inflight list. Instead we'll check for it
// BU removed: MarkBlockAsReceived(hash);
std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
Expand Down Expand Up @@ -6181,9 +6184,6 @@ bool ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vRecv, in
pfrom->thinBlock.SetNull();
}

// Clear the thinblock timer used for preferential download
thindata.ClearThinBlockTimer(inv.hash);

LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100);
return error("incorrectly constructed xblocktx or inconsistent thinblock data received. Banning peer=%d", pfrom->id);
Expand Down
3 changes: 0 additions & 3 deletions src/parallel.cpp
Expand Up @@ -576,9 +576,6 @@ void HandleBlockMessageThread(CNode *pfrom, const string &strCommand, const CBlo
}
}

// Clear the thinblock timer used for preferential download
thindata.ClearThinBlockTimer(inv.hash);

// Erase any txns from the orphan cache that are no longer needed
PV.ClearOrphanCache(block);

Expand Down
8 changes: 7 additions & 1 deletion src/thinblock.cpp
Expand Up @@ -891,6 +891,12 @@ string CThinBlockData::MempoolLimiterBytesSavedToString()
return ss.str();
}

// Preferential Thinblock Timer:
// The purpose of the timer is to ensure that we more often download an XTHINBLOCK rather than a full block.
// The timer is started when we receive the first announcement indicating there is a new block to download. If the
// block inventory is from a non XTHIN node then we will continue to wait for block announcements until either we
// get one from an XTHIN capable node or the timer is exceeded. If the timer is exceeded before receiving an
// announcement from an XTHIN node then we just download a full block instead of an xthin.
bool CThinBlockData::CheckThinblockTimer(uint256 hash)
{
LOCK(cs_mapThinBlockTimer);
Expand All @@ -913,7 +919,7 @@ bool CThinBlockData::CheckThinblockTimer(uint256 hash)
}
return true;
}

// The timer is cleared as soon as we request a block or thinblock.
void CThinBlockData::ClearThinBlockTimer(uint256 hash)
{
LOCK(cs_mapThinBlockTimer);
Expand Down

0 comments on commit 301ed19

Please sign in to comment.