diff --git a/src/init.cpp b/src/init.cpp index 51690cfff..22af3c181 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1439,6 +1439,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) else if (nRandomXVerifyThreads > MAX_SCRIPTCHECK_THREADS) nRandomXVerifyThreads = MAX_SCRIPTCHECK_THREADS; + // Per-peer block-download window (see MAX_BLOCKS_IN_TRANSIT_PER_PEER). Raising this lifts + // the bandwidth-delay-product ceiling on high-latency peers during IBD. Clamp to a sane range. + MAX_BLOCKS_IN_TRANSIT_PER_PEER = GetArg("-maxblocksintransit", DEFAULT_MAX_BLOCKS_IN_TRANSIT_PER_PEER); + if (MAX_BLOCKS_IN_TRANSIT_PER_PEER < 1) + MAX_BLOCKS_IN_TRANSIT_PER_PEER = 1; + else if (MAX_BLOCKS_IN_TRANSIT_PER_PEER > 4096) + MAX_BLOCKS_IN_TRANSIT_PER_PEER = 4096; + LogPrintf("Per-peer max blocks in transit: %d\n", MAX_BLOCKS_IN_TRANSIT_PER_PEER); + fServer = GetBoolArg("-server", false); //fprintf(stderr,"%s tik6\n", __FUNCTION__); diff --git a/src/main.cpp b/src/main.cpp index 4c7f0ec6d..d397f4f3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,6 +90,7 @@ static int64_t nTimeBestReceived = 0; CWaitableCriticalSection csBestBlock; CConditionVariable cvBlockChange; int nScriptCheckThreads = 0; +int MAX_BLOCKS_IN_TRANSIT_PER_PEER = DEFAULT_MAX_BLOCKS_IN_TRANSIT_PER_PEER; int nRandomXVerifyThreads = 0; // parallel RandomX pre-verification worker count (0 = inline only) bool fExperimentalMode = true; bool fImporting = false; diff --git a/src/main.h b/src/main.h index a9d627e50..7b33a93d0 100644 --- a/src/main.h +++ b/src/main.h @@ -95,8 +95,13 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; -/** Number of blocks that can be requested at any given time from a single peer. */ -static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16; +/** Number of blocks that can be requested at any given time from a single peer. + * Runtime-tunable via -maxblocksintransit. The default of 16 caps single-peer IBD + * throughput at (window / RTT): on a high-latency peer with tiny (sub-checkpoint) + * blocks the transfer is bandwidth-delay-product bound, so a larger window lifts the + * ceiling at negligible bandwidth cost. */ +static const int DEFAULT_MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16; +extern int MAX_BLOCKS_IN_TRANSIT_PER_PEER; /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */ static const unsigned int BLOCK_STALLING_TIMEOUT = 2; /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends