@@ -264,9 +264,9 @@ void UpdatePreferredDownload(CNode* node, CNodeState* state)
264
264
}
265
265
266
266
// Returns time at which to timeout block request (nTime in microseconds)
267
- int64_t GetBlockTimeout (int64_t nTime, int nValidatedQueuedBefore)
267
+ int64_t GetBlockTimeout (int64_t nTime, int nValidatedQueuedBefore, const Consensus::Params &consensusParams )
268
268
{
269
- return nTime + 500000 * Params (). GetConsensus () .nPowTargetSpacing * (4 + nValidatedQueuedBefore);
269
+ return nTime + 500000 * consensusParams .nPowTargetSpacing * (4 + nValidatedQueuedBefore);
270
270
}
271
271
272
272
void InitializeNode (NodeId nodeid, const CNode *pnode) {
@@ -310,15 +310,15 @@ void MarkBlockAsReceived(const uint256& hash) {
310
310
}
311
311
312
312
// Requires cs_main.
313
- void MarkBlockAsInFlight (NodeId nodeid, const uint256& hash, CBlockIndex *pindex = NULL ) {
313
+ void MarkBlockAsInFlight (NodeId nodeid, const uint256& hash, const Consensus::Params& consensusParams, CBlockIndex *pindex = NULL ) {
314
314
CNodeState *state = State (nodeid);
315
315
assert (state != NULL );
316
316
317
317
// Make sure it's not listed somewhere already.
318
318
MarkBlockAsReceived (hash);
319
319
320
320
int64_t nNow = GetTimeMicros ();
321
- QueuedBlock newentry = {hash, pindex, nNow, pindex != NULL , GetBlockTimeout (nNow, nQueuedValidatedHeaders)};
321
+ QueuedBlock newentry = {hash, pindex, nNow, pindex != NULL , GetBlockTimeout (nNow, nQueuedValidatedHeaders, consensusParams )};
322
322
nQueuedValidatedHeaders += newentry.fValidatedHeaders ;
323
323
list<QueuedBlock>::iterator it = state->vBlocksInFlight .insert (state->vBlocksInFlight .end (), newentry);
324
324
state->nBlocksInFlight ++;
@@ -4181,7 +4181,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4181
4181
vToFetch.push_back (inv);
4182
4182
// Mark block as in flight already, even though the actual "getdata" message only goes out
4183
4183
// later (within the same cs_main lock, though).
4184
- MarkBlockAsInFlight (pfrom->GetId (), inv.hash );
4184
+ MarkBlockAsInFlight (pfrom->GetId (), inv.hash , chainparams. GetConsensus () );
4185
4185
}
4186
4186
LogPrint (" net" , " getheaders (%d) %s to peer=%d\n " , pindexBestHeader->nHeight , inv.hash .ToString (), pfrom->id );
4187
4187
}
@@ -5034,7 +5034,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
5034
5034
// more quickly than once every 5 minutes, then we'll shorten the download window for this block).
5035
5035
if (!pto->fDisconnect && state.vBlocksInFlight .size () > 0 ) {
5036
5036
QueuedBlock &queuedBlock = state.vBlocksInFlight .front ();
5037
- int64_t nTimeoutIfRequestedNow = GetBlockTimeout (nNow, nQueuedValidatedHeaders - state.nBlocksInFlightValidHeaders );
5037
+ int64_t nTimeoutIfRequestedNow = GetBlockTimeout (nNow, nQueuedValidatedHeaders - state.nBlocksInFlightValidHeaders , consensusParams );
5038
5038
if (queuedBlock.nTimeDisconnect > nTimeoutIfRequestedNow) {
5039
5039
LogPrint (" net" , " Reducing block download timeout for peer=%d block=%s, orig=%d new=%d\n " , pto->id , queuedBlock.hash .ToString (), queuedBlock.nTimeDisconnect , nTimeoutIfRequestedNow);
5040
5040
queuedBlock.nTimeDisconnect = nTimeoutIfRequestedNow;
@@ -5055,7 +5055,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
5055
5055
FindNextBlocksToDownload (pto->GetId (), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight , vToDownload, staller);
5056
5056
BOOST_FOREACH (CBlockIndex *pindex, vToDownload) {
5057
5057
vGetData.push_back (CInv (MSG_BLOCK, pindex->GetBlockHash ()));
5058
- MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), pindex);
5058
+ MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), consensusParams, pindex);
5059
5059
LogPrint (" net" , " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
5060
5060
pindex->nHeight , pto->id );
5061
5061
}
0 commit comments