@@ -59,7 +59,7 @@ static const char* SettingName(OptionsModel::OptionID option)
5959}
6060
6161/* * Call node.updateRwSetting() with Bitcoin 22.x workaround. */
62- static void UpdateRwSetting (interfaces::Node& node, OptionsModel::OptionID option, const util::SettingsValue& value)
62+ static void UpdateRwSetting (interfaces::Node& node, OptionsModel::OptionID option, const std::string& suffix, const util::SettingsValue& value)
6363{
6464 if (value.isNum () &&
6565 (option == OptionsModel::DatabaseCache ||
@@ -73,9 +73,9 @@ static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID optio
7373 // in later releases by https://github.com/bitcoin/bitcoin/pull/24498.
7474 // If new numeric settings are added, they can be written as numbers
7575 // instead of strings, because bitcoin 22.x will not try to read these.
76- node.updateRwSetting (SettingName (option), value.getValStr ());
76+ node.updateRwSetting (SettingName (option) + suffix , value.getValStr ());
7777 } else {
78- node.updateRwSetting (SettingName (option), value);
78+ node.updateRwSetting (SettingName (option) + suffix , value);
7979 }
8080}
8181
@@ -131,13 +131,6 @@ void OptionsModel::addOverriddenOption(const std::string &option)
131131bool OptionsModel::Init (bilingual_str& error)
132132{
133133 // Initialize display settings from stored settings.
134- m_prune_size_gb = PruneSizeGB (node ().getPersistentSetting (" prune" ));
135- ProxySetting proxy = ParseProxyString (SettingToString (node ().getPersistentSetting (" proxy" ), GetDefaultProxyAddress ().toStdString ()));
136- m_proxy_ip = proxy.ip ;
137- m_proxy_port = proxy.port ;
138- ProxySetting onion = ParseProxyString (SettingToString (node ().getPersistentSetting (" onion" ), GetDefaultProxyAddress ().toStdString ()));
139- m_onion_ip = onion.ip ;
140- m_onion_port = onion.port ;
141134 language = QString::fromStdString (SettingToString (node ().getPersistentSetting (" lang" ), " " ));
142135
143136 checkAndMigrate ();
@@ -320,8 +313,6 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
320313 const util::SettingsValue cur_value = node ().getPersistentSetting (" prune" );
321314 const util::SettingsValue new_value = PruneSetting (prune_target_gb > 0 , prune_target_gb);
322315
323- m_prune_size_gb = prune_target_gb;
324-
325316 // Force setting to take effect. It is still safe to change the value at
326317 // this point because this function is only called after the intro screen is
327318 // shown, before the node starts.
@@ -334,7 +325,12 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
334325 PruneSizeGB (cur_value) != PruneSizeGB (new_value)) {
335326 // Call UpdateRwSetting() instead of setOption() to avoid setting
336327 // RestartRequired flag
337- UpdateRwSetting (node (), Prune, new_value);
328+ UpdateRwSetting (node (), Prune, " " , new_value);
329+ }
330+
331+ // Keep previous pruning size, if pruning was disabled.
332+ if (PruneEnabled (cur_value)) {
333+ UpdateRwSetting (node (), Prune, " -prev" , PruneEnabled (new_value) ? util::SettingsValue{} : cur_value);
338334 }
339335}
340336
@@ -362,9 +358,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
362358 return successful;
363359}
364360
365- QVariant OptionsModel::getOption (OptionID option) const
361+ QVariant OptionsModel::getOption (OptionID option, const std::string& suffix ) const
366362{
367- auto setting = [&]{ return node ().getPersistentSetting (SettingName (option)); };
363+ auto setting = [&]{ return node ().getPersistentSetting (SettingName (option) + suffix ); };
368364
369365 QSettings settings;
370366 switch (option) {
@@ -391,19 +387,30 @@ QVariant OptionsModel::getOption(OptionID option) const
391387
392388 // default proxy
393389 case ProxyUse:
390+ case ProxyUseTor:
394391 return ParseProxyString (SettingToString (setting (), " " )).is_set ;
395392 case ProxyIP:
396- return m_proxy_ip;
393+ case ProxyIPTor: {
394+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
395+ if (proxy.is_set ) {
396+ return proxy.ip ;
397+ } else if (suffix.empty ()) {
398+ return getOption (option, " -prev" );
399+ } else {
400+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).ip ;
401+ }
402+ }
397403 case ProxyPort:
398- return m_proxy_port;
399-
400- // separate Tor proxy
401- case ProxyUseTor:
402- return ParseProxyString (SettingToString (setting (), " " )).is_set ;
403- case ProxyIPTor:
404- return m_onion_ip;
405- case ProxyPortTor:
406- return m_onion_port;
404+ case ProxyPortTor: {
405+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
406+ if (proxy.is_set ) {
407+ return proxy.port ;
408+ } else if (suffix.empty ()) {
409+ return getOption (option, " -prev" );
410+ } else {
411+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).port ;
412+ }
413+ }
407414
408415#ifdef ENABLE_WALLET
409416 case SpendZeroConfChange:
@@ -428,7 +435,9 @@ QVariant OptionsModel::getOption(OptionID option) const
428435 case Prune:
429436 return PruneEnabled (setting ());
430437 case PruneSize:
431- return m_prune_size_gb;
438+ return PruneEnabled (setting ()) ? PruneSizeGB (setting ()) :
439+ suffix.empty () ? getOption (option, " -prev" ) :
440+ DEFAULT_PRUNE_TARGET_GB;
432441 case DatabaseCache:
433442 return qlonglong (SettingToInt (setting (), nDefaultDbCache));
434443 case ThreadsScriptVerif:
@@ -444,10 +453,10 @@ QVariant OptionsModel::getOption(OptionID option) const
444453 }
445454}
446455
447- bool OptionsModel::setOption (OptionID option, const QVariant& value)
456+ bool OptionsModel::setOption (OptionID option, const QVariant& value, const std::string& suffix )
448457{
449- auto changed = [&] { return value.isValid () && value != getOption (option); };
450- auto update = [&](const util::SettingsValue& value) { return UpdateRwSetting (node (), option, value); };
458+ auto changed = [&] { return value.isValid () && value != getOption (option, suffix ); };
459+ auto update = [&](const util::SettingsValue& value) { return UpdateRwSetting (node (), option, suffix, value); };
451460
452461 bool successful = true ; /* set to false on parse error */
453462 QSettings settings;
@@ -485,52 +494,60 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
485494 // default proxy
486495 case ProxyUse:
487496 if (changed ()) {
488- update (ProxyString (value.toBool (), m_proxy_ip, m_proxy_port));
489- setRestartRequired (true );
497+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
498+ update (ProxyString (value.toBool (), getOption (ProxyIP).toString (), getOption (ProxyPort).toString ()));
499+ if (suffix.empty () && value.toBool ()) UpdateRwSetting (node (), option, " -prev" , {});
500+ if (suffix.empty ()) setRestartRequired (true );
490501 }
491502 break ;
492503 case ProxyIP:
493504 if (changed ()) {
494- m_proxy_ip = value. toString ();
495- if ( getOption (ProxyUse). toBool ()) {
496- update ( ProxyString ( true , m_proxy_ip, m_proxy_port));
497- setRestartRequired ( true );
505+ if (suffix. empty () && ! getOption (ProxyUse). toBool ()) {
506+ setOption (option, value, " -prev " );
507+ } else {
508+ update ( ProxyString ( true , value. toString (), getOption (ProxyPort). toString ()) );
498509 }
510+ if (suffix.empty () && getOption (ProxyUse).toBool ()) setRestartRequired (true );
499511 }
500512 break ;
501513 case ProxyPort:
502514 if (changed ()) {
503- m_proxy_port = value. toString ();
504- if ( getOption (ProxyUse). toBool ()) {
505- update ( ProxyString ( true , m_proxy_ip, m_proxy_port));
506- setRestartRequired ( true );
515+ if (suffix. empty () && ! getOption (ProxyUse). toBool ()) {
516+ setOption (option, value, " -prev " );
517+ } else {
518+ update ( ProxyString ( true , getOption (ProxyIP). toString (), value. toString ()) );
507519 }
520+ if (suffix.empty () && getOption (ProxyUse).toBool ()) setRestartRequired (true );
508521 }
509522 break ;
510523
511524 // separate Tor proxy
512525 case ProxyUseTor:
513526 if (changed ()) {
514- update (ProxyString (value.toBool (), m_onion_ip, m_onion_port));
515- setRestartRequired (true );
527+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
528+ update (ProxyString (value.toBool (), getOption (ProxyIPTor).toString (), getOption (ProxyPortTor).toString ()));
529+ if (suffix.empty () && value.toBool ()) UpdateRwSetting (node (), option, " -prev" , {});
530+ if (suffix.empty ()) setRestartRequired (true );
516531 }
517532 break ;
518533 case ProxyIPTor:
519534 if (changed ()) {
520- m_onion_ip = value. toString ();
521- if ( getOption (ProxyUseTor). toBool ()) {
522- update ( ProxyString ( true , m_onion_ip, m_onion_port));
523- setRestartRequired ( true );
535+ if (suffix. empty () && ! getOption (ProxyUseTor). toBool ()) {
536+ setOption (option, value, " -prev " );
537+ } else {
538+ update ( ProxyString ( true , value. toString (), getOption (ProxyPortTor). toString ()) );
524539 }
540+ if (suffix.empty () && getOption (ProxyUseTor).toBool ()) setRestartRequired (true );
525541 }
526542 break ;
527543 case ProxyPortTor:
528544 if (changed ()) {
529- m_onion_port = value. toString ();
530- if ( getOption (ProxyUseTor). toBool ()) {
531- update ( ProxyString ( true , m_onion_ip, m_onion_port));
532- setRestartRequired ( true );
545+ if (suffix. empty () && ! getOption (ProxyUseTor). toBool ()) {
546+ setOption (option, value, " -prev " );
547+ } else {
548+ update ( ProxyString ( true , getOption (ProxyIPTor). toString (), value. toString ()) );
533549 }
550+ if (suffix.empty () && getOption (ProxyUseTor).toBool ()) setRestartRequired (true );
534551 }
535552 break ;
536553
@@ -584,17 +601,20 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
584601 break ;
585602 case Prune:
586603 if (changed ()) {
587- update (PruneSetting (value.toBool (), m_prune_size_gb));
588- setRestartRequired (true );
604+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
605+ update (PruneSetting (value.toBool (), getOption (PruneSize).toInt ()));
606+ if (suffix.empty () && value.toBool ()) UpdateRwSetting (node (), option, " -prev" , {});
607+ if (suffix.empty ()) setRestartRequired (true );
589608 }
590609 break ;
591610 case PruneSize:
592611 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 );
612+ if (suffix. empty () && ! getOption (Prune). toBool ()) {
613+ setOption (option, value, " -prev " );
614+ } else {
615+ update ( PruneSetting ( true , ParsePruneSizeGB (value)) );
597616 }
617+ if (suffix.empty () && getOption (Prune).toBool ()) setRestartRequired (true );
598618 }
599619 break ;
600620 case DatabaseCache:
0 commit comments