|
17 | 17 |
|
18 | 18 | #include <interfaces/node.h> |
19 | 19 | #include <util/system.h> |
| 20 | +#include <validation.h> |
20 | 21 |
|
21 | 22 | #include <QFileDialog> |
22 | 23 | #include <QSettings> |
@@ -139,17 +140,26 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si |
139 | 140 | ); |
140 | 141 | ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME)); |
141 | 142 |
|
| 143 | + const int min_prune_target_GB = std::ceil(MIN_DISK_SPACE_FOR_BLOCK_FILES / 1e9); |
| 144 | + ui->pruneGB->setRange(min_prune_target_GB, std::numeric_limits<int>::max()); |
142 | 145 | if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB |
143 | 146 | ui->prune->setChecked(true); |
144 | 147 | ui->prune->setEnabled(false); |
145 | 148 | } |
146 | | - ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(m_prune_target_gb)); |
| 149 | + ui->pruneGB->setValue(m_prune_target_gb); |
| 150 | + ui->pruneGB->setToolTip(ui->prune->toolTip()); |
| 151 | + ui->lblPruneSuffix->setToolTip(ui->prune->toolTip()); |
147 | 152 | UpdatePruneLabels(ui->prune->isChecked()); |
148 | 153 |
|
149 | 154 | connect(ui->prune, &QCheckBox::toggled, [this](bool prune_checked) { |
150 | 155 | UpdatePruneLabels(prune_checked); |
151 | 156 | UpdateFreeSpaceLabel(); |
152 | 157 | }); |
| 158 | + connect(ui->pruneGB, QOverload<int>::of(&QSpinBox::valueChanged), [this](int prune_GB) { |
| 159 | + m_prune_target_gb = prune_GB; |
| 160 | + UpdatePruneLabels(ui->prune->isChecked()); |
| 161 | + UpdateFreeSpaceLabel(); |
| 162 | + }); |
153 | 163 |
|
154 | 164 | startThread(); |
155 | 165 | } |
@@ -182,7 +192,17 @@ void Intro::setDataDirectory(const QString &dataDir) |
182 | 192 | } |
183 | 193 | } |
184 | 194 |
|
185 | | -bool Intro::showIfNeeded(bool& did_show_intro, bool& prune) |
| 195 | +int64_t Intro::getPruneMiB() const |
| 196 | +{ |
| 197 | + switch (ui->prune->checkState()) { |
| 198 | + case Qt::Checked: |
| 199 | + return PruneGBtoMiB(m_prune_target_gb); |
| 200 | + case Qt::Unchecked: default: |
| 201 | + return 0; |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) |
186 | 206 | { |
187 | 207 | did_show_intro = false; |
188 | 208 |
|
@@ -233,7 +253,7 @@ bool Intro::showIfNeeded(bool& did_show_intro, bool& prune) |
233 | 253 | } |
234 | 254 |
|
235 | 255 | // Additional preferences: |
236 | | - prune = intro.ui->prune->isChecked(); |
| 256 | + prune_MiB = intro.getPruneMiB(); |
237 | 257 |
|
238 | 258 | settings.setValue("strDataDir", dataDir); |
239 | 259 | settings.setValue("fReset", false); |
@@ -361,6 +381,11 @@ void Intro::UpdatePruneLabels(bool prune_checked) |
361 | 381 | storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory."); |
362 | 382 | } |
363 | 383 | ui->lblExplanation3->setVisible(prune_checked); |
| 384 | + ui->pruneGB->setEnabled(prune_checked); |
| 385 | + static constexpr uint64_t nPowTargetSpacing = 10 * 60; // from chainparams, which we don't have at this stage |
| 386 | + static constexpr uint32_t expected_block_data_size = 2250000; // includes undo data |
| 387 | + const uint64_t expected_backup_days = m_prune_target_gb * 1e9 / (uint64_t(expected_block_data_size) * 86400 / nPowTargetSpacing); |
| 388 | + ui->lblPruneSuffix->setText(tr("(sufficient to restore backups %n day(s) old)", "block chain pruning", expected_backup_days)); |
364 | 389 | ui->sizeWarningLabel->setText( |
365 | 390 | tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " + |
366 | 391 | storageRequiresMsg.arg(m_required_space_gb) + " " + |
|
0 commit comments