From 29aaf13b0a99a48ae77cf8a5f765960faa39fb08 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 14 Dec 2015 13:23:45 +0100 Subject: [PATCH] Make max tip age an option instead of chainparam After discussion in #7164 I think this is better. Max tip age was introduced in #5987 to make it possible to run testnet-in-a-box. But associating this behavior with the testnet chain is wrong conceptually, as it is not needed in normal usage. Should aim to make testnet test the software as-is. Replace it with a (debug) option `-maxtipage`, which can be specified only in the specific case. --- src/chainparams.cpp | 3 --- src/chainparams.h | 2 -- src/init.cpp | 3 +++ src/main.cpp | 5 ++++- src/main.h | 2 ++ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d75231ce3..aa346f954 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -115,7 +115,6 @@ public: pchMessageStart[3] = 0x64; vAlertPubKey = ParseHex("04b7ecf0baa90495ceb4e4090f6b2fd37eec1e9c85fac68a487f3ce11589692e4a317479316ee814e066638e1db54e37a10689b70286e6315b1087b6615d179264"); nDefaultPort = 8233; - nMaxTipAge = 24 * 60 * 60; nPruneAfterHeight = 100000; const size_t N = 200, K = 9; BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); @@ -275,7 +274,6 @@ public: pchMessageStart[3] = 0xbf; vAlertPubKey = ParseHex("044e7a1553392325c871c5ace5d6ad73501c66f4c185d6b0453cf45dec5a1322e705c672ac1a27ef7cdaf588c10effdf50ed5f95f85f2f54a5f6159fca394ed0c6"); nDefaultPort = 18233; - nMaxTipAge = 24 * 60 * 60; nPruneAfterHeight = 1000; const size_t N = 200, K = 9; BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); @@ -387,7 +385,6 @@ public: pchMessageStart[2] = 0x3f; pchMessageStart[3] = 0x5f; nDefaultPort = 18344; - nMaxTipAge = 24 * 60 * 60; nPruneAfterHeight = 1000; const size_t N = 48, K = 5; BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); diff --git a/src/chainparams.h b/src/chainparams.h index f1d9b43c3..df21e57ec 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -68,7 +68,6 @@ public: bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; } /** Policy: Filter transactions that do not match well-defined patterns */ bool RequireStandard() const { return fRequireStandard; } - int64_t MaxTipAge() const { return nMaxTipAge; } int64_t PruneAfterHeight() const { return nPruneAfterHeight; } unsigned int EquihashN() const { return nEquihashN; } unsigned int EquihashK() const { return nEquihashK; } @@ -97,7 +96,6 @@ protected: //! Raw pub key bytes for the broadcast alert signing key. std::vector vAlertPubKey; int nDefaultPort = 0; - long nMaxTipAge = 0; uint64_t nPruneAfterHeight = 0; unsigned int nEquihashN = 0; unsigned int nEquihashK = 0; diff --git a/src/init.cpp b/src/init.cpp index 2962f3b9a..fe5b50c02 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -472,6 +472,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-limitfreerelay=", strprintf("Continuously rate-limit free transactions to *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("-maxsigcachesize=", strprintf("Limit size of signature cache to entries (default: %u)", 50000)); + strUsage += HelpMessageOpt("-maxtipage=", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE)); } strUsage += HelpMessageOpt("-minrelaytxfee=", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for relaying (default: %s)"), CURRENCY_UNIT, FormatMoney(::minRelayTxFee.GetFeePerK()))); @@ -1077,6 +1078,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (GetBoolArg("-peerbloomfilters", true)) nLocalServices |= NODE_BLOOM; + nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); + #ifdef ENABLE_MINING if (mapArgs.count("-mineraddress")) { CTxDestination addr = DecodeDestination(mapArgs["-mineraddress"]); diff --git a/src/main.cpp b/src/main.cpp index 0beb1dd0b..1f1d2037b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,6 +75,9 @@ bool fCoinbaseEnforcedProtectionEnabled = true; size_t nCoinCacheUsage = 5000 * 300; uint64_t nPruneTarget = 0; 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; @@ -1733,7 +1736,7 @@ bool IsInitialBlockDownload() if (lockIBDState) return false; bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 || - pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge()); + pindexBestHeader->GetBlockTime() < GetTime() - nMaxTipAge); if (!state) lockIBDState = true; return state; diff --git a/src/main.h b/src/main.h index 580de352a..201637ab1 100644 --- a/src/main.h +++ b/src/main.h @@ -98,6 +98,7 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60; static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60; /** Maximum length of reject messages. */ 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 BOOST_STATIC_ASSERT(DEFAULT_BLOCK_MAX_SIZE <= MAX_BLOCK_SIZE); @@ -137,6 +138,7 @@ extern bool fCoinbaseEnforcedProtectionEnabled; extern size_t nCoinCacheUsage; extern CFeeRate minRelayTxFee; extern bool fAlerts; +extern int64_t nMaxTipAge; /** Best header we've seen so far (used for getheaders queries' starting points). */ extern CBlockIndex *pindexBestHeader;