Skip to content

Commit 64360f1

Browse files
committed
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.
1 parent dc511dc commit 64360f1

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

src/chainparams.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class CMainParams : public CChainParams {
9292
pchMessageStart[3] = 0xd9;
9393
vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
9494
nDefaultPort = 8333;
95-
nMaxTipAge = 24 * 60 * 60;
9695
nPruneAfterHeight = 100000;
9796

9897
genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
@@ -169,7 +168,6 @@ class CTestNetParams : public CChainParams {
169168
pchMessageStart[3] = 0x07;
170169
vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a");
171170
nDefaultPort = 18333;
172-
nMaxTipAge = 0x7fffffff;
173171
nPruneAfterHeight = 1000;
174172

175173
genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
@@ -233,7 +231,6 @@ class CRegTestParams : public CChainParams {
233231
pchMessageStart[1] = 0xbf;
234232
pchMessageStart[2] = 0xb5;
235233
pchMessageStart[3] = 0xda;
236-
nMaxTipAge = 24 * 60 * 60;
237234
nDefaultPort = 18444;
238235
nPruneAfterHeight = 1000;
239236

src/chainparams.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class CChainParams
6464
bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
6565
/** Policy: Filter transactions that do not match well-defined patterns */
6666
bool RequireStandard() const { return fRequireStandard; }
67-
int64_t MaxTipAge() const { return nMaxTipAge; }
6867
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
6968
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
7069
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
@@ -84,7 +83,6 @@ class CChainParams
8483
//! Raw pub key bytes for the broadcast alert signing key.
8584
std::vector<unsigned char> vAlertPubKey;
8685
int nDefaultPort;
87-
long nMaxTipAge;
8886
uint64_t nPruneAfterHeight;
8987
std::vector<CDNSSeedData> vSeeds;
9088
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];

src/init.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ std::string HelpMessage(HelpMessageMode mode)
456456
strUsage += HelpMessageOpt("-limitfreerelay=<n>", strprintf("Continuously rate-limit free transactions to <n>*1000 bytes per minute (default: %u)", DEFAULT_LIMITFREERELAY));
457457
strUsage += HelpMessageOpt("-relaypriority", strprintf("Require high priority for relaying free or low-fee transactions (default: %u)", DEFAULT_RELAYPRIORITY));
458458
strUsage += HelpMessageOpt("-maxsigcachesize=<n>", strprintf("Limit size of signature cache to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_SIZE));
459+
strUsage += HelpMessageOpt("-maxtipage=<n>", strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)", DEFAULT_MAX_TIP_AGE));
459460
}
460461
strUsage += HelpMessageOpt("-minrelaytxfee=<amt>", strprintf(_("Fees (in %s/kB) smaller than this are considered zero fee for relaying, mining and transaction creation (default: %s)"),
461462
CURRENCY_UNIT, FormatMoney(DEFAULT_MIN_RELAY_TX_FEE)));
@@ -994,6 +995,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
994995
if (GetBoolArg("-peerbloomfilters", true))
995996
nLocalServices |= NODE_BLOOM;
996997

998+
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
999+
9971000
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
9981001

9991002
// Initialize elliptic curve code

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
7474
size_t nCoinCacheUsage = 5000 * 300;
7575
uint64_t nPruneTarget = 0;
7676
bool fAlerts = DEFAULT_ALERTS;
77+
/* If the tip is older than this (in seconds), the node is considered to be in initial block download.
78+
*/
79+
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
7780

7881
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying, mining and transaction creation) */
7982
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
@@ -1402,7 +1405,7 @@ bool IsInitialBlockDownload()
14021405
if (lockIBDState)
14031406
return false;
14041407
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
1405-
pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge());
1408+
pindexBestHeader->GetBlockTime() < GetTime() - nMaxTipAge);
14061409
if (!state)
14071410
lockIBDState = true;
14081411
return state;

src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
8989
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
9090
static const unsigned int DEFAULT_LIMITFREERELAY = 15;
9191
static const bool DEFAULT_RELAYPRIORITY = true;
92+
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
9293

9394
/** Default for -permitbaremultisig */
9495
static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
@@ -127,6 +128,7 @@ extern bool fCheckpointsEnabled;
127128
extern size_t nCoinCacheUsage;
128129
extern CFeeRate minRelayTxFee;
129130
extern bool fAlerts;
131+
extern int64_t nMaxTipAge;
130132

131133
/** Best header we've seen so far (used for getheaders queries' starting points). */
132134
extern CBlockIndex *pindexBestHeader;

0 commit comments

Comments
 (0)