@@ -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 ++;
@@ -4183,7 +4183,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4183
4183
vToFetch.push_back (inv);
4184
4184
// Mark block as in flight already, even though the actual "getdata" message only goes out
4185
4185
// later (within the same cs_main lock, though).
4186
- MarkBlockAsInFlight (pfrom->GetId (), inv.hash );
4186
+ MarkBlockAsInFlight (pfrom->GetId (), inv.hash , chainparams. GetConsensus () );
4187
4187
}
4188
4188
LogPrint (" net" , " getheaders (%d) %s to peer=%d\n " , pindexBestHeader->nHeight , inv.hash .ToString (), pfrom->id );
4189
4189
}
@@ -5036,7 +5036,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
5036
5036
// more quickly than once every 5 minutes, then we'll shorten the download window for this block).
5037
5037
if (!pto->fDisconnect && state.vBlocksInFlight .size () > 0 ) {
5038
5038
QueuedBlock &queuedBlock = state.vBlocksInFlight .front ();
5039
- int64_t nTimeoutIfRequestedNow = GetBlockTimeout (nNow, nQueuedValidatedHeaders - state.nBlocksInFlightValidHeaders );
5039
+ int64_t nTimeoutIfRequestedNow = GetBlockTimeout (nNow, nQueuedValidatedHeaders - state.nBlocksInFlightValidHeaders , consensusParams );
5040
5040
if (queuedBlock.nTimeDisconnect > nTimeoutIfRequestedNow) {
5041
5041
LogPrint (" net" , " Reducing block download timeout for peer=%d block=%s, orig=%d new=%d\n " , pto->id , queuedBlock.hash .ToString (), queuedBlock.nTimeDisconnect , nTimeoutIfRequestedNow);
5042
5042
queuedBlock.nTimeDisconnect = nTimeoutIfRequestedNow;
@@ -5057,7 +5057,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
5057
5057
FindNextBlocksToDownload (pto->GetId (), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight , vToDownload, staller);
5058
5058
BOOST_FOREACH (CBlockIndex *pindex, vToDownload) {
5059
5059
vGetData.push_back (CInv (MSG_BLOCK, pindex->GetBlockHash ()));
5060
- MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), pindex);
5060
+ MarkBlockAsInFlight (pto->GetId (), pindex->GetBlockHash (), consensusParams, pindex);
5061
5061
LogPrint (" net" , " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
5062
5062
pindex->nHeight , pto->id );
5063
5063
}
0 commit comments