Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show All 17 Lines | |||||
#include "net.h" | #include "net.h" | ||||
#include "netbase.h" | #include "netbase.h" | ||||
#include "netmessagemaker.h" | #include "netmessagemaker.h" | ||||
#include "policy/fees.h" | #include "policy/fees.h" | ||||
#include "policy/policy.h" | #include "policy/policy.h" | ||||
#include "primitives/block.h" | #include "primitives/block.h" | ||||
#include "primitives/transaction.h" | #include "primitives/transaction.h" | ||||
#include "random.h" | #include "random.h" | ||||
#include "reverse_iterator.h" | |||||
#include "scheduler.h" | #include "scheduler.h" | ||||
#include "tinyformat.h" | #include "tinyformat.h" | ||||
#include "txmempool.h" | #include "txmempool.h" | ||||
#include "ui_interface.h" | #include "ui_interface.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilmoneystr.h" | #include "utilmoneystr.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "validationinterface.h" | #include "validationinterface.h" | ||||
#include <boost/range/adaptor/reversed.hpp> | |||||
#if defined(NDEBUG) | #if defined(NDEBUG) | ||||
#error "Bitcoin cannot be compiled without assertions." | #error "Bitcoin cannot be compiled without assertions." | ||||
#endif | #endif | ||||
// Used only to inform the wallet of when we last received a block. | // Used only to inform the wallet of when we last received a block. | ||||
std::atomic<int64_t> nTimeBestReceived(0); | std::atomic<int64_t> nTimeBestReceived(0); | ||||
struct IteratorComparator { | struct IteratorComparator { | ||||
▲ Show 20 Lines • Show All 1,016 Lines • ▼ Show 20 Lines | if (!fInitialDownload) { | ||||
} | } | ||||
} | } | ||||
// Relay inventory, but don't relay old inventory during initial block | // Relay inventory, but don't relay old inventory during initial block | ||||
// download. | // download. | ||||
connman->ForEachNode([nNewHeight, &vHashes](CNode *pnode) { | connman->ForEachNode([nNewHeight, &vHashes](CNode *pnode) { | ||||
if (nNewHeight > (pnode->nStartingHeight != -1 | if (nNewHeight > (pnode->nStartingHeight != -1 | ||||
? pnode->nStartingHeight - 2000 | ? pnode->nStartingHeight - 2000 | ||||
: 0)) { | : 0)) { | ||||
for (const uint256 &hash : boost::adaptors::reverse(vHashes)) { | for (const uint256 &hash : reverse_iterate(vHashes)) { | ||||
pnode->PushBlockHash(hash); | pnode->PushBlockHash(hash); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
connman->WakeMessageHandler(); | connman->WakeMessageHandler(); | ||||
} | } | ||||
nTimeBestReceived = GetTime(); | nTimeBestReceived = GetTime(); | ||||
▲ Show 20 Lines • Show All 567 Lines • ▼ Show 20 Lines | if (!ProcessNewBlockHeaders(config, headers, state, &pindexLast, | ||||
// direct fetch and rely on parallel download instead. | // direct fetch and rely on parallel download instead. | ||||
if (!chainActive.Contains(pindexWalk)) { | if (!chainActive.Contains(pindexWalk)) { | ||||
LogPrint( | LogPrint( | ||||
BCLog::NET, "Large reorg, won't direct fetch to %s (%d)\n", | BCLog::NET, "Large reorg, won't direct fetch to %s (%d)\n", | ||||
pindexLast->GetBlockHash().ToString(), pindexLast->nHeight); | pindexLast->GetBlockHash().ToString(), pindexLast->nHeight); | ||||
} else { | } else { | ||||
std::vector<CInv> vGetData; | std::vector<CInv> vGetData; | ||||
// Download as much as possible, from earliest to latest. | // Download as much as possible, from earliest to latest. | ||||
for (const CBlockIndex *pindex : | for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) { | ||||
boost::adaptors::reverse(vToFetch)) { | |||||
if (nodestate->nBlocksInFlight >= | if (nodestate->nBlocksInFlight >= | ||||
MAX_BLOCKS_IN_TRANSIT_PER_PEER) { | MAX_BLOCKS_IN_TRANSIT_PER_PEER) { | ||||
// Can't download any more from this peer | // Can't download any more from this peer | ||||
break; | break; | ||||
} | } | ||||
vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash())); | vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash())); | ||||
MarkBlockAsInFlight(config, pfrom->GetId(), | MarkBlockAsInFlight(config, pfrom->GetId(), | ||||
pindex->GetBlockHash(), | pindex->GetBlockHash(), | ||||
▲ Show 20 Lines • Show All 2,601 Lines • Show Last 20 Lines |