Skip to content

Commit 2bede28

Browse files
committed
util: Add PruneGBtoMiB() function
This commit does not change behavior.
1 parent e35e4b2 commit 2bede28

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/qt/optionsmodel.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ void OptionsModel::SetPruneEnabled(bool prune, bool force)
240240
{
241241
QSettings settings;
242242
settings.setValue("bPrune", prune);
243-
// Convert prune size from GB to MiB:
244-
const uint64_t nPruneSizeMiB = (settings.value("nPruneSize").toInt() * GB_BYTES) >> 20;
245-
std::string prune_val = prune ? std::to_string(nPruneSizeMiB) : "0";
243+
const int64_t prune_target_mib = PruneGBtoMiB(settings.value("nPruneSize").toInt());
244+
std::string prune_val = prune ? std::to_string(prune_target_mib) : "0";
246245
if (force) {
247246
m_node.forceSetArg("-prune", prune_val);
248247
return;

src/qt/optionsmodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ static constexpr unsigned short DEFAULT_GUI_PROXY_PORT = 9050;
2222
*/
2323
static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
2424

25+
/**
26+
* Convert displayed prune target GB to configured MiB. Round down so roundtrip GB -> MiB -> GB conversion is stable.
27+
*/
28+
static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
29+
2530
/** Interface from Qt to configuration data structure for Bitcoin client.
2631
To Qt, the options are presented as a list with the different options
2732
laid out vertically.

0 commit comments

Comments
 (0)