Skip to content

Commit 9d0e528

Browse files
committed
implements different disk sizes for different networks on intro
- Creates m_assumed_blockchain_size and m_assumed_chain_state_size on CChainParams. - Implements access to CChainParams' m_assumed_blockchain_size and m_assumed_chain_state_size on node interface. - Implements m_assumed_blockchain_size and m_assumed_chain_state_size on qt/intro via node interface. - Updates release process document with the new CChainParam's values.
1 parent f504a14 commit 9d0e528

File tree

7 files changed

+40
-12
lines changed

7 files changed

+40
-12
lines changed

doc/release-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Before every minor and major release:
2222
Before every major release:
2323

2424
* Update hardcoded [seeds](/contrib/seeds/README.md), see [this pull request](https://github.com/bitcoin/bitcoin/pull/7415) for an example.
25-
* Update [`BLOCK_CHAIN_SIZE`](/src/qt/intro.cpp) to the current size plus some overhead.
25+
* Update [`src/chainparams.cpp`](/src/chainparams.cpp) m_assumed_blockchain_size and m_assumed_chain_state_size with the current size plus some overhead.
2626
* Update `src/chainparams.cpp` chainTxData with statistics about the transaction count and rate. Use the output of the RPC `getchaintxstats`, see
2727
[this pull request](https://github.com/bitcoin/bitcoin/pull/12270) for an example. Reviewers can verify the results by running `getchaintxstats <window_block_count> <window_last_block_hash>` with the `window_block_count` and `window_last_block_hash` from your output.
2828
* Update version of `contrib/gitian-descriptors/*.yml`: usually one'd want to do this on master after branching off the release - but be sure to at least do it before a new major release

src/chainparams.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class CMainParams : public CChainParams {
107107
pchMessageStart[3] = 0xd9;
108108
nDefaultPort = 8333;
109109
nPruneAfterHeight = 100000;
110+
m_assumed_blockchain_size = 200;
111+
m_assumed_chain_state_size = 3;
110112

111113
genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
112114
consensus.hashGenesisBlock = genesis.GetHash();
@@ -216,6 +218,8 @@ class CTestNetParams : public CChainParams {
216218
pchMessageStart[3] = 0x07;
217219
nDefaultPort = 18333;
218220
nPruneAfterHeight = 1000;
221+
m_assumed_blockchain_size = 20;
222+
m_assumed_chain_state_size = 2;
219223

220224
genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
221225
consensus.hashGenesisBlock = genesis.GetHash();
@@ -305,6 +309,8 @@ class CRegTestParams : public CChainParams {
305309
pchMessageStart[3] = 0xda;
306310
nDefaultPort = 18444;
307311
nPruneAfterHeight = 1000;
312+
m_assumed_blockchain_size = 0;
313+
m_assumed_chain_state_size = 0;
308314

309315
UpdateVersionBitsParametersFromArgs(args);
310316

src/chainparams.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class CChainParams
6767
/** Policy: Filter transactions that do not match well-defined patterns */
6868
bool RequireStandard() const { return fRequireStandard; }
6969
uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
70+
/** Minimum free space (in GB) needed for data directory */
71+
uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
72+
/** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
73+
uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
7074
/** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */
7175
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
7276
/** Return the BIP70 network string (main, test or regtest) */
@@ -87,6 +91,8 @@ class CChainParams
8791
CMessageHeader::MessageStartChars pchMessageStart;
8892
int nDefaultPort;
8993
uint64_t nPruneAfterHeight;
94+
uint64_t m_assumed_blockchain_size;
95+
uint64_t m_assumed_chain_state_size;
9096
std::vector<std::string> vSeeds;
9197
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
9298
std::string bech32_hrp;

src/interfaces/node.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class NodeImpl : public Node
5656
bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); }
5757
bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); }
5858
void selectParams(const std::string& network) override { SelectParams(network); }
59+
uint64_t getAssumedBlockchainSize() override { return Params().AssumedBlockchainSize(); }
60+
uint64_t getAssumedChainStateSize() override { return Params().AssumedChainStateSize(); }
5961
std::string getNetwork() override { return Params().NetworkIDString(); }
6062
void initLogging() override { InitLogging(); }
6163
void initParameterInteraction() override { InitParameterInteraction(); }

src/interfaces/node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class Node
5252
//! Choose network parameters.
5353
virtual void selectParams(const std::string& network) = 0;
5454

55+
//! Get the (assumed) blockchain size.
56+
virtual uint64_t getAssumedBlockchainSize() = 0;
57+
58+
//! Get the (assumed) chain state size.
59+
virtual uint64_t getAssumedChainStateSize() = 0;
60+
5561
//! Get network name.
5662
virtual std::string getNetwork() = 0;
5763

src/qt/intro.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#include <cmath>
2323

2424
static const uint64_t GB_BYTES = 1000000000LL;
25-
/* Minimum free space (in GB) needed for data directory */
26-
constexpr uint64_t BLOCK_CHAIN_SIZE = 220;
27-
/* Minimum free space (in GB) needed for data directory when pruned; Does not include prune target */
28-
static const uint64_t CHAIN_STATE_SIZE = 3;
2925
/* Total required space (in GB) depending on user choice (prune, not prune) */
3026
static uint64_t requiredSpace;
3127

@@ -114,26 +110,28 @@ void FreespaceChecker::check()
114110
}
115111

116112

117-
Intro::Intro(QWidget *parent) :
113+
Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_size) :
118114
QDialog(parent),
119115
ui(new Ui::Intro),
120116
thread(0),
121-
signalled(false)
117+
signalled(false),
118+
m_blockchain_size(blockchain_size),
119+
m_chain_state_size(chain_state_size)
122120
{
123121
ui->setupUi(this);
124122
ui->welcomeLabel->setText(ui->welcomeLabel->text().arg(tr(PACKAGE_NAME)));
125123
ui->storageLabel->setText(ui->storageLabel->text().arg(tr(PACKAGE_NAME)));
126124

127125
ui->lblExplanation1->setText(ui->lblExplanation1->text()
128126
.arg(tr(PACKAGE_NAME))
129-
.arg(BLOCK_CHAIN_SIZE)
127+
.arg(m_blockchain_size)
130128
.arg(2009)
131129
.arg(tr("Bitcoin"))
132130
);
133131
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(tr(PACKAGE_NAME)));
134132

135133
uint64_t pruneTarget = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
136-
requiredSpace = BLOCK_CHAIN_SIZE;
134+
requiredSpace = m_blockchain_size;
137135
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
138136
if (pruneTarget) {
139137
uint64_t prunedGBs = std::ceil(pruneTarget * 1024 * 1024.0 / GB_BYTES);
@@ -145,7 +143,7 @@ Intro::Intro(QWidget *parent) :
145143
} else {
146144
ui->lblExplanation3->setVisible(false);
147145
}
148-
requiredSpace += CHAIN_STATE_SIZE;
146+
requiredSpace += m_chain_state_size;
149147
ui->sizeWarningLabel->setText(
150148
tr("%1 will download and store a copy of the Bitcoin block chain.").arg(tr(PACKAGE_NAME)) + " " +
151149
storageRequiresMsg.arg(requiredSpace) + " " +
@@ -201,8 +199,15 @@ bool Intro::pickDataDirectory(interfaces::Node& node)
201199

202200
if(!fs::exists(GUIUtil::qstringToBoostPath(dataDir)) || gArgs.GetBoolArg("-choosedatadir", DEFAULT_CHOOSE_DATADIR) || settings.value("fReset", false).toBool() || gArgs.GetBoolArg("-resetguisettings", false))
203201
{
202+
/* Use selectParams here to guarantee Params() can be used by node interface */
203+
try {
204+
node.selectParams(gArgs.GetChainName());
205+
} catch (const std::exception&) {
206+
return false;
207+
}
208+
204209
/* If current default data directory does not exist, let the user choose one */
205-
Intro intro;
210+
Intro intro(0, node.getAssumedBlockchainSize(), node.getAssumedChainStateSize());
206211
intro.setDataDirectory(dataDir);
207212
intro.setWindowIcon(QIcon(":icons/bitcoin"));
208213

src/qt/intro.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class Intro : public QDialog
3030
Q_OBJECT
3131

3232
public:
33-
explicit Intro(QWidget *parent = 0);
33+
explicit Intro(QWidget *parent = 0,
34+
uint64_t blockchain_size = 0, uint64_t chain_state_size = 0);
3435
~Intro();
3536

3637
QString getDataDirectory();
@@ -71,6 +72,8 @@ private Q_SLOTS:
7172
QMutex mutex;
7273
bool signalled;
7374
QString pathToCheck;
75+
uint64_t m_blockchain_size;
76+
uint64_t m_chain_state_size;
7477

7578
void startThread();
7679
void checkPath(const QString &dataDir);

0 commit comments

Comments
 (0)