|
|
@ -5364,28 +5364,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
if (inv.type == MSG_BLOCK) { |
|
|
|
if (inv.type == MSG_BLOCK) { |
|
|
|
UpdateBlockAvailability(pfrom->GetId(), inv.hash); |
|
|
|
UpdateBlockAvailability(pfrom->GetId(), inv.hash); |
|
|
|
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { |
|
|
|
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { |
|
|
|
// First request the headers preceding the announced block. In the normal fully-synced
|
|
|
|
// We used to request the full block here, but since headers-announcements are now the
|
|
|
|
// case where a new block is announced that succeeds the current tip (no reorganization),
|
|
|
|
// primary method of announcement on the network, and since, in the case that a node
|
|
|
|
// there are no such headers.
|
|
|
|
// fell back to inv we probably have a reorg which we should get the headers for first,
|
|
|
|
// Secondly, and only when we are close to being synced, we request the announced block directly,
|
|
|
|
// we now only provide a getheaders response here. When we receive the headers, we will
|
|
|
|
// to avoid an extra round-trip. Note that we must *first* ask for the headers, so by the
|
|
|
|
// then ask for the blocks we need.
|
|
|
|
// time the block arrives, the header chain leading up to it is already validated. Not
|
|
|
|
|
|
|
|
// doing this will result in the received block being rejected as an orphan in case it is
|
|
|
|
|
|
|
|
// not a direct successor.
|
|
|
|
|
|
|
|
connman.PushMessage(pfrom, NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), inv.hash); |
|
|
|
connman.PushMessage(pfrom, NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), inv.hash); |
|
|
|
CNodeState *nodestate = State(pfrom->GetId()); |
|
|
|
|
|
|
|
if (CanDirectFetch(chainparams.GetConsensus()) && |
|
|
|
|
|
|
|
nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER && |
|
|
|
|
|
|
|
(!IsWitnessEnabled(chainActive.Tip(), chainparams.GetConsensus()) || State(pfrom->GetId())->fHaveWitness)) { |
|
|
|
|
|
|
|
inv.type |= nFetchFlags; |
|
|
|
|
|
|
|
if (nodestate->fSupportsDesiredCmpctVersion) |
|
|
|
|
|
|
|
vToFetch.push_back(CInv(MSG_CMPCT_BLOCK, inv.hash)); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
vToFetch.push_back(inv); |
|
|
|
|
|
|
|
// Mark block as in flight already, even though the actual "getdata" message only goes out
|
|
|
|
|
|
|
|
// later (within the same cs_main lock, though).
|
|
|
|
|
|
|
|
MarkBlockAsInFlight(pfrom->GetId(), inv.hash, chainparams.GetConsensus()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); |
|
|
|
LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|