|
|
@ -537,7 +537,7 @@ CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb) { |
|
|
|
|
|
|
|
|
|
|
|
/** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
|
|
|
|
/** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
|
|
|
|
* at most count entries. */ |
|
|
|
* at most count entries. */ |
|
|
|
void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBlockIndex*>& vBlocks, NodeId& nodeStaller) { |
|
|
|
void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) { |
|
|
|
if (count == 0) |
|
|
|
if (count == 0) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
@ -594,6 +594,10 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<CBl |
|
|
|
// We consider the chain that this peer is on invalid.
|
|
|
|
// We consider the chain that this peer is on invalid.
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!State(nodeid)->fHaveWitness && IsWitnessEnabled(pindex->pprev, consensusParams)) { |
|
|
|
|
|
|
|
// We wouldn't download this block or its descendants from this peer.
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
if (pindex->nStatus & BLOCK_HAVE_DATA || chainActive.Contains(pindex)) { |
|
|
|
if (pindex->nStatus & BLOCK_HAVE_DATA || chainActive.Contains(pindex)) { |
|
|
|
if (pindex->nChainTx) |
|
|
|
if (pindex->nChainTx) |
|
|
|
state->pindexLastCommonBlock = pindex; |
|
|
|
state->pindexLastCommonBlock = pindex; |
|
|
@ -6726,16 +6730,14 @@ bool SendMessages(CNode* pto) |
|
|
|
if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { |
|
|
|
if (!pto->fDisconnect && !pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { |
|
|
|
vector<CBlockIndex*> vToDownload; |
|
|
|
vector<CBlockIndex*> vToDownload; |
|
|
|
NodeId staller = -1; |
|
|
|
NodeId staller = -1; |
|
|
|
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller); |
|
|
|
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams); |
|
|
|
BOOST_FOREACH(CBlockIndex *pindex, vToDownload) { |
|
|
|
BOOST_FOREACH(CBlockIndex *pindex, vToDownload) { |
|
|
|
if (State(pto->GetId())->fHaveWitness || !IsWitnessEnabled(pindex->pprev, consensusParams)) { |
|
|
|
|
|
|
|
uint32_t nFetchFlags = GetFetchFlags(pto, pindex->pprev, consensusParams); |
|
|
|
uint32_t nFetchFlags = GetFetchFlags(pto, pindex->pprev, consensusParams); |
|
|
|
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash())); |
|
|
|
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash())); |
|
|
|
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), consensusParams, pindex); |
|
|
|
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), consensusParams, pindex); |
|
|
|
LogPrint("net", "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(), |
|
|
|
LogPrint("net", "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(), |
|
|
|
pindex->nHeight, pto->id); |
|
|
|
pindex->nHeight, pto->id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (state.nBlocksInFlight == 0 && staller != -1) { |
|
|
|
if (state.nBlocksInFlight == 0 && staller != -1) { |
|
|
|
if (State(staller)->nStallingSince == 0) { |
|
|
|
if (State(staller)->nStallingSince == 0) { |
|
|
|
State(staller)->nStallingSince = nNow; |
|
|
|
State(staller)->nStallingSince = nNow; |
|
|
|