@@ -45,6 +45,8 @@ static const char* SettingName(OptionsModel::OptionID option)
45
45
case OptionsModel::MapPortNatpmp: return " natpmp" ;
46
46
case OptionsModel::Listen: return " listen" ;
47
47
case OptionsModel::Server: return " server" ;
48
+ case OptionsModel::PruneSize: return " prune" ;
49
+ case OptionsModel::Prune: return " prune" ;
48
50
case OptionsModel::ProxyIP: return " proxy" ;
49
51
case OptionsModel::ProxyPort: return " proxy" ;
50
52
case OptionsModel::ProxyUse: return " proxy" ;
@@ -60,7 +62,9 @@ static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID optio
60
62
{
61
63
if (value.isNum () &&
62
64
(option == OptionsModel::DatabaseCache ||
63
- option == OptionsModel::ThreadsScriptVerif)) {
65
+ option == OptionsModel::ThreadsScriptVerif ||
66
+ option == OptionsModel::Prune ||
67
+ option == OptionsModel::PruneSize)) {
64
68
// Write certain old settings as strings, even though they are numbers,
65
69
// because Bitcoin 22.x releases try to read these specific settings as
66
70
// strings in addOverriddenOption() calls at startup, triggering
@@ -74,6 +78,36 @@ static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID optio
74
78
}
75
79
}
76
80
81
+ // ! Convert enabled/size values to bitcoin -prune setting.
82
+ static util::SettingsValue PruneSetting (bool prune_enabled, int prune_size_gb)
83
+ {
84
+ assert (!prune_enabled || prune_size_gb >= 1 ); // PruneSizeGB and ParsePruneSizeGB never return less
85
+ return prune_enabled ? PruneGBtoMiB (prune_size_gb) : 0 ;
86
+ }
87
+
88
+ // ! Get pruning enabled value to show in GUI from bitcoin -prune setting.
89
+ static bool PruneEnabled (const util::SettingsValue& prune_setting)
90
+ {
91
+ // -prune=1 setting is manual pruning mode, so disabled for purposes of the gui
92
+ return SettingToInt (prune_setting, 0 ) > 1 ;
93
+ }
94
+
95
+ // ! Get pruning size value to show in GUI from bitcoin -prune setting. If
96
+ // ! pruning is not enabled, just show default recommended pruning size (2GB).
97
+ static int PruneSizeGB (const util::SettingsValue& prune_setting)
98
+ {
99
+ int value = SettingToInt (prune_setting, 0 );
100
+ return value > 1 ? PruneMiBtoGB (value) : DEFAULT_PRUNE_TARGET_GB;
101
+ }
102
+
103
+ // ! Parse pruning size value provided by user in GUI or loaded from QSettings
104
+ // ! (windows registry key or qt .conf file). Smallest value that the GUI can
105
+ // ! display is 1 GB, so round up if anything less is parsed.
106
+ static int ParsePruneSizeGB (const QVariant& prune_size)
107
+ {
108
+ return std::max (1 , prune_size.toInt ());
109
+ }
110
+
77
111
struct ProxySetting {
78
112
bool is_set;
79
113
QString ip;
@@ -96,6 +130,7 @@ void OptionsModel::addOverriddenOption(const std::string &option)
96
130
bool OptionsModel::Init (bilingual_str& error)
97
131
{
98
132
// Initialize display settings from stored settings.
133
+ m_prune_size_gb = PruneSizeGB (node ().getPersistentSetting (" prune" ));
99
134
ProxySetting proxy = ParseProxyString (SettingToString (node ().getPersistentSetting (" proxy" ), GetDefaultProxyAddress ().toStdString ()));
100
135
m_proxy_ip = proxy.ip ;
101
136
m_proxy_port = proxy.port ;
@@ -155,7 +190,7 @@ bool OptionsModel::Init(bilingual_str& error)
155
190
// These are shared with the core or have a command-line parameter
156
191
// and we want command-line parameters to overwrite the GUI settings.
157
192
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
158
- MapPortNatpmp, Listen, Server, ProxyUse, ProxyUseTor}) {
193
+ MapPortNatpmp, Listen, Server, Prune, ProxyUse, ProxyUseTor}) {
159
194
std::string setting = SettingName (option);
160
195
if (node ().isSettingIgnored (setting)) addOverriddenOption (" -" + setting);
161
196
try {
@@ -174,11 +209,6 @@ bool OptionsModel::Init(bilingual_str& error)
174
209
// by command-line and show this in the UI.
175
210
176
211
// Main
177
- if (!settings.contains (" bPrune" ))
178
- settings.setValue (" bPrune" , false );
179
- if (!settings.contains (" nPruneSize" ))
180
- settings.setValue (" nPruneSize" , DEFAULT_PRUNE_TARGET_GB);
181
- SetPruneEnabled (settings.value (" bPrune" ).toBool ());
182
212
if (!settings.contains (" strDataDir" ))
183
213
settings.setValue (" strDataDir" , GUIUtil::getDefaultDataDirectory ());
184
214
@@ -287,29 +317,27 @@ static const QString GetDefaultProxyAddress()
287
317
return QString (" %1:%2" ).arg (DEFAULT_GUI_PROXY_HOST).arg (DEFAULT_GUI_PROXY_PORT);
288
318
}
289
319
290
- void OptionsModel::SetPruneEnabled ( bool prune, bool force )
320
+ void OptionsModel::SetPruneTargetGB ( int prune_target_gb )
291
321
{
292
- QSettings settings;
293
- settings.setValue (" bPrune" , prune);
294
- const int64_t prune_target_mib = PruneGBtoMiB (settings.value (" nPruneSize" ).toInt ());
295
- std::string prune_val = prune ? ToString (prune_target_mib) : " 0" ;
296
- if (force) {
297
- gArgs .ForceSetArg (" -prune" , prune_val);
298
- return ;
299
- }
300
- if (!gArgs .SoftSetArg (" -prune" , prune_val)) {
301
- addOverriddenOption (" -prune" );
302
- }
303
- }
304
-
305
- void OptionsModel::SetPruneTargetGB (int prune_target_gb, bool force)
306
- {
307
- const bool prune = prune_target_gb > 0 ;
308
- if (prune) {
309
- QSettings settings;
310
- settings.setValue (" nPruneSize" , prune_target_gb);
322
+ const util::SettingsValue cur_value = node ().getPersistentSetting (" prune" );
323
+ const util::SettingsValue new_value = PruneSetting (prune_target_gb > 0 , prune_target_gb);
324
+
325
+ m_prune_size_gb = prune_target_gb;
326
+
327
+ // Force setting to take effect. It is still safe to change the value at
328
+ // this point because this function is only called after the intro screen is
329
+ // shown, before the node starts.
330
+ node ().forceSetting (" prune" , new_value);
331
+
332
+ // Update settings.json if value configured in intro screen is different
333
+ // from saved value. Avoid writing settings.json if bitcoin.conf value
334
+ // doesn't need to be overridden.
335
+ if (PruneEnabled (cur_value) != PruneEnabled (new_value) ||
336
+ PruneSizeGB (cur_value) != PruneSizeGB (new_value)) {
337
+ // Call UpdateRwSetting() instead of setOption() to avoid setting
338
+ // RestartRequired flag
339
+ UpdateRwSetting (node (), Prune, new_value);
311
340
}
312
- SetPruneEnabled (prune, force);
313
341
}
314
342
315
343
// read QSettings values and return them
@@ -400,9 +428,9 @@ QVariant OptionsModel::getOption(OptionID option) const
400
428
case EnablePSBTControls:
401
429
return settings.value (" enable_psbt_controls" );
402
430
case Prune:
403
- return settings. value ( " bPrune " );
431
+ return PruneEnabled ( setting () );
404
432
case PruneSize:
405
- return settings. value ( " nPruneSize " ) ;
433
+ return m_prune_size_gb ;
406
434
case DatabaseCache:
407
435
return qlonglong (SettingToInt (setting (), nDefaultDbCache));
408
436
case ThreadsScriptVerif:
@@ -555,15 +583,18 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
555
583
settings.setValue (" enable_psbt_controls" , m_enable_psbt_controls);
556
584
break ;
557
585
case Prune:
558
- if (settings. value ( " bPrune " ) != value ) {
559
- settings. setValue ( " bPrune " , value );
586
+ if (changed () ) {
587
+ update ( PruneSetting (value. toBool (), m_prune_size_gb) );
560
588
setRestartRequired (true );
561
589
}
562
590
break ;
563
591
case PruneSize:
564
- if (settings.value (" nPruneSize" ) != value) {
565
- settings.setValue (" nPruneSize" , value);
566
- setRestartRequired (true );
592
+ if (changed ()) {
593
+ m_prune_size_gb = ParsePruneSizeGB (value);
594
+ if (getOption (Prune).toBool ()) {
595
+ update (PruneSetting (true , m_prune_size_gb));
596
+ setRestartRequired (true );
597
+ }
567
598
}
568
599
break ;
569
600
case DatabaseCache:
@@ -678,6 +709,8 @@ void OptionsModel::checkAndMigrate()
678
709
migrate_setting (MapPortNatpmp, " fUseNatpmp" );
679
710
migrate_setting (Listen, " fListen" );
680
711
migrate_setting (Server, " server" );
712
+ migrate_setting (PruneSize, " nPruneSize" );
713
+ migrate_setting (Prune, " bPrune" );
681
714
migrate_setting (ProxyIP, " addrProxy" );
682
715
migrate_setting (ProxyUse, " fUseProxy" );
683
716
migrate_setting (ProxyIPTor, " addrSeparateProxyTor" );
0 commit comments