@@ -97,7 +97,7 @@ static bool RequiresNumWorkaround(OptionsModel::OptionID option)
9797}
9898
9999/* * Call node.updateRwSetting() with Bitcoin 22.x workaround. */
100- static void UpdateRwSetting (interfaces::Node& node, OptionsModel::OptionID option, const util::SettingsValue& value)
100+ static void UpdateRwSetting (interfaces::Node& node, OptionsModel::OptionID option, const std::string& suffix, const util::SettingsValue& value)
101101{
102102 if (value.isNum () && RequiresNumWorkaround (option)) {
103103 // Write certain old settings as strings, even though they are numbers,
@@ -107,9 +107,9 @@ static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID optio
107107 // in later releases by https://github.com/bitcoin/bitcoin/pull/24498.
108108 // If new numeric settings are added, they can be written as numbers
109109 // instead of strings, because bitcoin 22.x will not try to read these.
110- node.updateRwSetting (SettingName (option), value.getValStr ());
110+ node.updateRwSetting (SettingName (option) + suffix , value.getValStr ());
111111 } else {
112- node.updateRwSetting (SettingName (option), value);
112+ node.updateRwSetting (SettingName (option) + suffix , value);
113113 }
114114}
115115
@@ -188,13 +188,6 @@ void OptionsModel::addOverriddenOption(const std::string &option)
188188bool OptionsModel::Init (bilingual_str& error)
189189{
190190 // Initialize display settings from stored settings.
191- m_prune_size_gb = PruneSizeGB (node ().getPersistentSetting (" prune" ));
192- ProxySetting proxy = ParseProxyString (SettingToString (node ().getPersistentSetting (" proxy" ), GetDefaultProxyAddress ().toStdString ()));
193- m_proxy_ip = proxy.ip ;
194- m_proxy_port = proxy.port ;
195- ProxySetting onion = ParseProxyString (SettingToString (node ().getPersistentSetting (" onion" ), GetDefaultProxyAddress ().toStdString ()));
196- m_onion_ip = onion.ip ;
197- m_onion_port = onion.port ;
198191 language = QString::fromStdString (SettingToString (node ().getPersistentSetting (" lang" ), " " ));
199192
200193 checkAndMigrate ();
@@ -434,8 +427,6 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
434427 const util::SettingsValue cur_value = node ().getPersistentSetting (" prune" );
435428 const util::SettingsValue new_value = PruneSetting (prune_target_gb > 0 , prune_target_gb);
436429
437- m_prune_size_gb = prune_target_gb;
438-
439430 // Force setting to take effect. It is still safe to change the value at
440431 // this point because this function is only called after the intro screen is
441432 // shown, before the node starts.
@@ -454,7 +445,12 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
454445 PruneSizeGB (cur_value) != PruneSizeGB (new_value)) {
455446 // Call UpdateRwSetting() instead of setOption() to avoid setting
456447 // RestartRequired flag
457- UpdateRwSetting (node (), Prune, new_value);
448+ UpdateRwSetting (node (), Prune, " " , new_value);
449+ }
450+
451+ // Keep previous pruning size, if pruning was disabled.
452+ if (PruneEnabled (cur_value)) {
453+ UpdateRwSetting (node (), Prune, " -prev" , PruneEnabled (new_value) ? util::SettingsValue{} : cur_value);
458454 }
459455}
460456
@@ -482,9 +478,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
482478 return successful;
483479}
484480
485- QVariant OptionsModel::getOption (OptionID option) const
481+ QVariant OptionsModel::getOption (OptionID option, const std::string& suffix ) const
486482{
487- auto setting = [&]{ return node ().getPersistentSetting (SettingName (option)); };
483+ auto setting = [&]{ return node ().getPersistentSetting (SettingName (option) + suffix ); };
488484
489485 QSettings settings;
490486 switch (option) {
@@ -511,19 +507,30 @@ QVariant OptionsModel::getOption(OptionID option) const
511507
512508 // default proxy
513509 case ProxyUse:
510+ case ProxyUseTor:
514511 return ParseProxyString (SettingToString (setting (), " " )).is_set ;
515512 case ProxyIP:
516- return m_proxy_ip;
513+ case ProxyIPTor: {
514+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
515+ if (proxy.is_set ) {
516+ return proxy.ip ;
517+ } else if (suffix.empty ()) {
518+ return getOption (option, " -prev" );
519+ } else {
520+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).ip ;
521+ }
522+ }
517523 case ProxyPort:
518- return m_proxy_port;
519-
520- // separate Tor proxy
521- case ProxyUseTor:
522- return ParseProxyString (SettingToString (setting (), " " )).is_set ;
523- case ProxyIPTor:
524- return m_onion_ip;
525- case ProxyPortTor:
526- return m_onion_port;
524+ case ProxyPortTor: {
525+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
526+ if (proxy.is_set ) {
527+ return proxy.port ;
528+ } else if (suffix.empty ()) {
529+ return getOption (option, " -prev" );
530+ } else {
531+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).port ;
532+ }
533+ }
527534
528535#ifdef ENABLE_WALLET
529536 case SpendZeroConfChange:
@@ -586,7 +593,9 @@ QVariant OptionsModel::getOption(OptionID option) const
586593 case Prune:
587594 return PruneEnabled (setting ());
588595 case PruneSize:
589- return m_prune_size_gb;
596+ return PruneEnabled (setting ()) ? PruneSizeGB (setting ()) :
597+ suffix.empty () ? getOption (option, " -prev" ) :
598+ DEFAULT_PRUNE_TARGET_GB;
590599 case DatabaseCache:
591600 return qlonglong (SettingToInt (setting (), nDefaultDbCache));
592601 case ThreadsScriptVerif:
@@ -602,10 +611,10 @@ QVariant OptionsModel::getOption(OptionID option) const
602611 }
603612}
604613
605- bool OptionsModel::setOption (OptionID option, const QVariant& value)
614+ bool OptionsModel::setOption (OptionID option, const QVariant& value, const std::string& suffix )
606615{
607- auto changed = [&] { return value.isValid () && value != getOption (option); };
608- auto update = [&](const util::SettingsValue& value) { return UpdateRwSetting (node (), option, value); };
616+ auto changed = [&] { return value.isValid () && value != getOption (option, suffix ); };
617+ auto update = [&](const util::SettingsValue& value) { return UpdateRwSetting (node (), option, suffix, value); };
609618
610619 bool successful = true ; /* set to false on parse error */
611620 QSettings settings;
@@ -643,52 +652,60 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
643652 // default proxy
644653 case ProxyUse:
645654 if (changed ()) {
646- update (ProxyString (value.toBool (), m_proxy_ip, m_proxy_port));
647- setRestartRequired (true );
655+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
656+ update (ProxyString (value.toBool (), getOption (ProxyIP).toString (), getOption (ProxyPort).toString ()));
657+ if (suffix.empty () && value.toBool ()) UpdateRwSetting (node (), option, " -prev" , {});
658+ if (suffix.empty ()) setRestartRequired (true );
648659 }
649660 break ;
650661 case ProxyIP:
651662 if (changed ()) {
652- m_proxy_ip = value. toString ();
653- if ( getOption (ProxyUse). toBool ()) {
654- update ( ProxyString ( true , m_proxy_ip, m_proxy_port));
655- setRestartRequired ( true );
663+ if (suffix. empty () && ! getOption (ProxyUse). toBool ()) {
664+ setOption (option, value, " -prev " );
665+ } else {
666+ update ( ProxyString ( true , value. toString (), getOption (ProxyPort). toString ()) );
656667 }
668+ if (suffix.empty () && getOption (ProxyUse).toBool ()) setRestartRequired (true );
657669 }
658670 break ;
659671 case ProxyPort:
660672 if (changed ()) {
661- m_proxy_port = value. toString ();
662- if ( getOption (ProxyUse). toBool ()) {
663- update ( ProxyString ( true , m_proxy_ip, m_proxy_port));
664- setRestartRequired ( true );
673+ if (suffix. empty () && ! getOption (ProxyUse). toBool ()) {
674+ setOption (option, value, " -prev " );
675+ } else {
676+ update ( ProxyString ( true , getOption (ProxyIP). toString (), value. toString ()) );
665677 }
678+ if (suffix.empty () && getOption (ProxyUse).toBool ()) setRestartRequired (true );
666679 }
667680 break ;
668681
669682 // separate Tor proxy
670683 case ProxyUseTor:
671684 if (changed ()) {
672- update (ProxyString (value.toBool (), m_onion_ip, m_onion_port));
673- setRestartRequired (true );
685+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
686+ update (ProxyString (value.toBool (), getOption (ProxyIPTor).toString (), getOption (ProxyPortTor).toString ()));
687+ if (suffix.empty () && value.toBool ()) UpdateRwSetting (node (), option, " -prev" , {});
688+ if (suffix.empty ()) setRestartRequired (true );
674689 }
675690 break ;
676691 case ProxyIPTor:
677692 if (changed ()) {
678- m_onion_ip = value. toString ();
679- if ( getOption (ProxyUseTor). toBool ()) {
680- update ( ProxyString ( true , m_onion_ip, m_onion_port));
681- setRestartRequired ( true );
693+ if (suffix. empty () && ! getOption (ProxyUseTor). toBool ()) {
694+ setOption (option, value, " -prev " );
695+ } else {
696+ update ( ProxyString ( true , value. toString (), getOption (ProxyPortTor). toString ()) );
682697 }
698+ if (suffix.empty () && getOption (ProxyUseTor).toBool ()) setRestartRequired (true );
683699 }
684700 break ;
685701 case ProxyPortTor:
686702 if (changed ()) {
687- m_onion_port = value. toString ();
688- if ( getOption (ProxyUseTor). toBool ()) {
689- update ( ProxyString ( true , m_onion_ip, m_onion_port));
690- setRestartRequired ( true );
703+ if (suffix. empty () && ! getOption (ProxyUseTor). toBool ()) {
704+ setOption (option, value, " -prev " );
705+ } else {
706+ update ( ProxyString ( true , getOption (ProxyIPTor). toString (), value. toString ()) );
691707 }
708+ if (suffix.empty () && getOption (ProxyUseTor).toBool ()) setRestartRequired (true );
692709 }
693710 break ;
694711
@@ -842,17 +859,20 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
842859 break ;
843860 case Prune:
844861 if (changed ()) {
845- update (PruneSetting (value.toBool (), m_prune_size_gb));
846- setRestartRequired (true );
862+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
863+ update (PruneSetting (value.toBool (), getOption (PruneSize).toInt ()));
864+ if (suffix.empty () && value.toBool ()) UpdateRwSetting (node (), option, " -prev" , {});
865+ if (suffix.empty ()) setRestartRequired (true );
847866 }
848867 break ;
849868 case PruneSize:
850869 if (changed ()) {
851- m_prune_size_gb = ParsePruneSizeGB (value);
852- if ( getOption (Prune). toBool ()) {
853- update ( PruneSetting ( true , m_prune_size_gb));
854- setRestartRequired ( true );
870+ if (suffix. empty () && ! getOption (Prune). toBool ()) {
871+ setOption (option, value, " -prev " );
872+ } else {
873+ update ( PruneSetting ( true , ParsePruneSizeGB (value)) );
855874 }
875+ if (suffix.empty () && getOption (Prune).toBool ()) setRestartRequired (true );
856876 }
857877 break ;
858878#endif // ENABLE_WALLET
0 commit comments