Auto merge of #3263 - str4d:ibd-upstream-changes, r=bitcartel
InitialBlockDownload upstream changes Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7208 - bitcoin/bitcoin#8007 - bitcoin/bitcoin#9053 - Excluding second commit (requires bitcoin/bitcoin#8865) - bitcoin/bitcoin#10388
This commit is contained in:
@@ -24,6 +24,8 @@ Check that there are no surprising performance regressions:
|
|||||||
|
|
||||||
Ensure that new performance metrics appear on that site.
|
Ensure that new performance metrics appear on that site.
|
||||||
|
|
||||||
|
Update `src/chainparams.cpp` nMinimumChainWork with information from the getblockchaininfo rpc.
|
||||||
|
|
||||||
### Protocol Safety Checks:
|
### Protocol Safety Checks:
|
||||||
|
|
||||||
If this release changes the behavior of the protocol or fixes a serious
|
If this release changes the behavior of the protocol or fixes a serious
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ public:
|
|||||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight =
|
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight =
|
||||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||||
|
|
||||||
|
// The best chain should have at least this much work.
|
||||||
|
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000000281b32ff3198a1");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message start string should be awesome! ⓩ❤
|
* The message start string should be awesome! ⓩ❤
|
||||||
*/
|
*/
|
||||||
@@ -115,7 +118,6 @@ public:
|
|||||||
pchMessageStart[3] = 0x64;
|
pchMessageStart[3] = 0x64;
|
||||||
vAlertPubKey = ParseHex("04b7ecf0baa90495ceb4e4090f6b2fd37eec1e9c85fac68a487f3ce11589692e4a317479316ee814e066638e1db54e37a10689b70286e6315b1087b6615d179264");
|
vAlertPubKey = ParseHex("04b7ecf0baa90495ceb4e4090f6b2fd37eec1e9c85fac68a487f3ce11589692e4a317479316ee814e066638e1db54e37a10689b70286e6315b1087b6615d179264");
|
||||||
nDefaultPort = 8233;
|
nDefaultPort = 8233;
|
||||||
nMaxTipAge = 24 * 60 * 60;
|
|
||||||
nPruneAfterHeight = 100000;
|
nPruneAfterHeight = 100000;
|
||||||
const size_t N = 200, K = 9;
|
const size_t N = 200, K = 9;
|
||||||
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
||||||
@@ -273,13 +275,15 @@ public:
|
|||||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion = 170006;
|
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion = 170006;
|
||||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = 252500;
|
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = 252500;
|
||||||
|
|
||||||
|
// The best chain should have at least this much work.
|
||||||
|
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000000000001d0c4d9cd");
|
||||||
|
|
||||||
pchMessageStart[0] = 0xfa;
|
pchMessageStart[0] = 0xfa;
|
||||||
pchMessageStart[1] = 0x1a;
|
pchMessageStart[1] = 0x1a;
|
||||||
pchMessageStart[2] = 0xf9;
|
pchMessageStart[2] = 0xf9;
|
||||||
pchMessageStart[3] = 0xbf;
|
pchMessageStart[3] = 0xbf;
|
||||||
vAlertPubKey = ParseHex("044e7a1553392325c871c5ace5d6ad73501c66f4c185d6b0453cf45dec5a1322e705c672ac1a27ef7cdaf588c10effdf50ed5f95f85f2f54a5f6159fca394ed0c6");
|
vAlertPubKey = ParseHex("044e7a1553392325c871c5ace5d6ad73501c66f4c185d6b0453cf45dec5a1322e705c672ac1a27ef7cdaf588c10effdf50ed5f95f85f2f54a5f6159fca394ed0c6");
|
||||||
nDefaultPort = 18233;
|
nDefaultPort = 18233;
|
||||||
nMaxTipAge = 24 * 60 * 60;
|
|
||||||
nPruneAfterHeight = 1000;
|
nPruneAfterHeight = 1000;
|
||||||
const size_t N = 200, K = 9;
|
const size_t N = 200, K = 9;
|
||||||
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
||||||
@@ -328,6 +332,7 @@ public:
|
|||||||
fMineBlocksOnDemand = false;
|
fMineBlocksOnDemand = false;
|
||||||
fTestnetToBeDeprecatedFieldRPC = true;
|
fTestnetToBeDeprecatedFieldRPC = true;
|
||||||
|
|
||||||
|
|
||||||
checkpointData = (CCheckpointData) {
|
checkpointData = (CCheckpointData) {
|
||||||
boost::assign::map_list_of
|
boost::assign::map_list_of
|
||||||
(0, consensus.hashGenesisBlock)
|
(0, consensus.hashGenesisBlock)
|
||||||
@@ -391,12 +396,14 @@ public:
|
|||||||
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight =
|
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight =
|
||||||
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
||||||
|
|
||||||
|
// The best chain should have at least this much work.
|
||||||
|
consensus.nMinimumChainWork = uint256S("0x00");
|
||||||
|
|
||||||
pchMessageStart[0] = 0xaa;
|
pchMessageStart[0] = 0xaa;
|
||||||
pchMessageStart[1] = 0xe8;
|
pchMessageStart[1] = 0xe8;
|
||||||
pchMessageStart[2] = 0x3f;
|
pchMessageStart[2] = 0x3f;
|
||||||
pchMessageStart[3] = 0x5f;
|
pchMessageStart[3] = 0x5f;
|
||||||
nDefaultPort = 18344;
|
nDefaultPort = 18344;
|
||||||
nMaxTipAge = 24 * 60 * 60;
|
|
||||||
nPruneAfterHeight = 1000;
|
nPruneAfterHeight = 1000;
|
||||||
const size_t N = 48, K = 5;
|
const size_t N = 48, K = 5;
|
||||||
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K));
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ public:
|
|||||||
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
|
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
|
||||||
/** Policy: Filter transactions that do not match well-defined patterns */
|
/** Policy: Filter transactions that do not match well-defined patterns */
|
||||||
bool RequireStandard() const { return fRequireStandard; }
|
bool RequireStandard() const { return fRequireStandard; }
|
||||||
int64_t MaxTipAge() const { return nMaxTipAge; }
|
|
||||||
int64_t PruneAfterHeight() const { return nPruneAfterHeight; }
|
int64_t PruneAfterHeight() const { return nPruneAfterHeight; }
|
||||||
unsigned int EquihashN() const { return nEquihashN; }
|
unsigned int EquihashN() const { return nEquihashN; }
|
||||||
unsigned int EquihashK() const { return nEquihashK; }
|
unsigned int EquihashK() const { return nEquihashK; }
|
||||||
@@ -107,7 +106,6 @@ protected:
|
|||||||
//! Raw pub key bytes for the broadcast alert signing key.
|
//! Raw pub key bytes for the broadcast alert signing key.
|
||||||
std::vector<unsigned char> vAlertPubKey;
|
std::vector<unsigned char> vAlertPubKey;
|
||||||
int nDefaultPort = 0;
|
int nDefaultPort = 0;
|
||||||
long nMaxTipAge = 0;
|
|
||||||
uint64_t nPruneAfterHeight = 0;
|
uint64_t nPruneAfterHeight = 0;
|
||||||
unsigned int nEquihashN = 0;
|
unsigned int nEquihashN = 0;
|
||||||
unsigned int nEquihashK = 0;
|
unsigned int nEquihashK = 0;
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ struct Params {
|
|||||||
int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; }
|
int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; }
|
||||||
int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; }
|
int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; }
|
||||||
int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; }
|
int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; }
|
||||||
|
uint256 nMinimumChainWork;
|
||||||
};
|
};
|
||||||
} // namespace Consensus
|
} // namespace Consensus
|
||||||
|
|
||||||
|
|||||||
@@ -470,6 +470,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||||||
strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default: %u)", 15));
|
strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default: %u)", 15));
|
||||||
strUsage += HelpMessageOpt("-relaypriority", strprintf("Require high priority for relaying free or low-fee transactions (default: %u)", 0));
|
strUsage += HelpMessageOpt("-relaypriority", strprintf("Require high priority for relaying free or low-fee transactions (default: %u)", 0));
|
||||||
strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf("Limit size of signature cache to <n> entries (default: %u)", 50000));
|
strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf("Limit size of signature cache to <n> entries (default: %u)", 50000));
|
||||||
|
strUsage += HelpMessageOpt("-maxtipage=<n>", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE));
|
||||||
}
|
}
|
||||||
strUsage += HelpMessageOpt("-minrelaytxfee=<amt>", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for relaying (default: %s)"),
|
strUsage += HelpMessageOpt("-minrelaytxfee=<amt>", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for relaying (default: %s)"),
|
||||||
CURRENCY_UNIT, FormatMoney(::minRelayTxFee.GetFeePerK())));
|
CURRENCY_UNIT, FormatMoney(::minRelayTxFee.GetFeePerK())));
|
||||||
@@ -1075,6 +1076,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
if (GetBoolArg("-peerbloomfilters", true))
|
if (GetBoolArg("-peerbloomfilters", true))
|
||||||
nLocalServices |= NODE_BLOOM;
|
nLocalServices |= NODE_BLOOM;
|
||||||
|
|
||||||
|
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
|
||||||
|
|
||||||
#ifdef ENABLE_MINING
|
#ifdef ENABLE_MINING
|
||||||
if (mapArgs.count("-mineraddress")) {
|
if (mapArgs.count("-mineraddress")) {
|
||||||
CTxDestination addr = DecodeDestination(mapArgs["-mineraddress"]);
|
CTxDestination addr = DecodeDestination(mapArgs["-mineraddress"]);
|
||||||
|
|||||||
32
src/main.cpp
32
src/main.cpp
@@ -32,6 +32,7 @@
|
|||||||
#include "wallet/asyncrpcoperation_shieldcoinbase.h"
|
#include "wallet/asyncrpcoperation_shieldcoinbase.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
@@ -75,6 +76,9 @@ bool fCoinbaseEnforcedProtectionEnabled = true;
|
|||||||
size_t nCoinCacheUsage = 5000 * 300;
|
size_t nCoinCacheUsage = 5000 * 300;
|
||||||
uint64_t nPruneTarget = 0;
|
uint64_t nPruneTarget = 0;
|
||||||
bool fAlerts = DEFAULT_ALERTS;
|
bool fAlerts = DEFAULT_ALERTS;
|
||||||
|
/* If the tip is older than this (in seconds), the node is considered to be in initial block download.
|
||||||
|
*/
|
||||||
|
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
|
||||||
|
|
||||||
unsigned int expiryDelta = DEFAULT_TX_EXPIRY_DELTA;
|
unsigned int expiryDelta = DEFAULT_TX_EXPIRY_DELTA;
|
||||||
|
|
||||||
@@ -1724,19 +1728,27 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
|
|||||||
bool IsInitialBlockDownload()
|
bool IsInitialBlockDownload()
|
||||||
{
|
{
|
||||||
const CChainParams& chainParams = Params();
|
const CChainParams& chainParams = Params();
|
||||||
|
|
||||||
|
// Once this function has returned false, it must remain false.
|
||||||
|
static std::atomic<bool> latchToFalse{false};
|
||||||
|
// Optimization: pre-test latch before taking the lock.
|
||||||
|
if (latchToFalse.load(std::memory_order_relaxed))
|
||||||
|
return false;
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
if (latchToFalse.load(std::memory_order_relaxed))
|
||||||
|
return false;
|
||||||
if (fImporting || fReindex)
|
if (fImporting || fReindex)
|
||||||
return true;
|
return true;
|
||||||
if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints()))
|
if (chainActive.Tip() == NULL)
|
||||||
return true;
|
return true;
|
||||||
static bool lockIBDState = false;
|
if (chainActive.Tip()->nChainWork < UintToArith256(chainParams.GetConsensus().nMinimumChainWork))
|
||||||
if (lockIBDState)
|
return true;
|
||||||
return false;
|
if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
|
||||||
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
|
return true;
|
||||||
pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge());
|
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
|
||||||
if (!state)
|
latchToFalse.store(true, std::memory_order_relaxed);
|
||||||
lockIBDState = true;
|
return false;
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool fLargeWorkForkFound = false;
|
static bool fLargeWorkForkFound = false;
|
||||||
@@ -1748,7 +1760,7 @@ void CheckForkWarningConditions()
|
|||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
// Before we get past initial download, we cannot reliably alert about forks
|
// Before we get past initial download, we cannot reliably alert about forks
|
||||||
// (we assume we don't get stuck on a fork before the last checkpoint)
|
// (we assume we don't get stuck on a fork before finishing our initial sync)
|
||||||
if (IsInitialBlockDownload())
|
if (IsInitialBlockDownload())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
|
|||||||
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
|
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
|
||||||
/** Maximum length of reject messages. */
|
/** Maximum length of reject messages. */
|
||||||
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
|
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
|
||||||
|
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
|
||||||
|
|
||||||
// Sanity check the magic numbers when we change them
|
// Sanity check the magic numbers when we change them
|
||||||
BOOST_STATIC_ASSERT(DEFAULT_BLOCK_MAX_SIZE <= MAX_BLOCK_SIZE);
|
BOOST_STATIC_ASSERT(DEFAULT_BLOCK_MAX_SIZE <= MAX_BLOCK_SIZE);
|
||||||
@@ -137,6 +138,7 @@ extern bool fCoinbaseEnforcedProtectionEnabled;
|
|||||||
extern size_t nCoinCacheUsage;
|
extern size_t nCoinCacheUsage;
|
||||||
extern CFeeRate minRelayTxFee;
|
extern CFeeRate minRelayTxFee;
|
||||||
extern bool fAlerts;
|
extern bool fAlerts;
|
||||||
|
extern int64_t nMaxTipAge;
|
||||||
|
|
||||||
/** Best header we've seen so far (used for getheaders queries' starting points). */
|
/** Best header we've seen so far (used for getheaders queries' starting points). */
|
||||||
extern CBlockIndex *pindexBestHeader;
|
extern CBlockIndex *pindexBestHeader;
|
||||||
|
|||||||
Reference in New Issue
Block a user