@@ -59,7 +59,7 @@ static const char* SettingName(OptionsModel::OptionID option)
59
59
}
60
60
61
61
/* * Call node.updateSetting() with Bitcoin 22.x workaround. */
62
- static void UpdateSetting (interfaces::Node& node, OptionsModel::OptionID option, const util::SettingsValue& value)
62
+ static void UpdateSetting (interfaces::Node& node, OptionsModel::OptionID option, const std::string& suffix, const util::SettingsValue& value)
63
63
{
64
64
if (value.isNum () &&
65
65
(option == OptionsModel::DatabaseCache ||
@@ -73,9 +73,9 @@ static void UpdateSetting(interfaces::Node& node, OptionsModel::OptionID option,
73
73
// in later releases by https://github.com/bitcoin/bitcoin/pull/24498.
74
74
// If new numeric settings are added, they can be written as numbers
75
75
// instead of strings, because bitcoin 22.x will not try to read these.
76
- node.updateSetting (SettingName (option), value.getValStr ());
76
+ node.updateSetting (SettingName (option) + suffix , value.getValStr ());
77
77
} else {
78
- node.updateSetting (SettingName (option), value);
78
+ node.updateSetting (SettingName (option) + suffix , value);
79
79
}
80
80
}
81
81
@@ -131,13 +131,6 @@ void OptionsModel::addOverriddenOption(const std::string &option)
131
131
bool OptionsModel::Init (bilingual_str& error)
132
132
{
133
133
// 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 ;
141
134
language = QString::fromStdString (SettingToString (node ().getPersistentSetting (" lang" ), " " ));
142
135
143
136
checkAndMigrate ();
@@ -317,8 +310,6 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
317
310
const util::SettingsValue cur_value = node ().getPersistentSetting (" prune" );
318
311
const util::SettingsValue new_value = PruneSetting (prune_target_gb > 0 , prune_target_gb);
319
312
320
- m_prune_size_gb = prune_target_gb;
321
-
322
313
// Force setting to take effect. It is still safe to change the value at
323
314
// this point because this function is only called after the intro screen is
324
315
// shown, before the node starts.
@@ -331,7 +322,12 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
331
322
PruneSizeGB (cur_value) != PruneSizeGB (new_value)) {
332
323
// Call UpdateSetting() instead of setOption() to avoid setting
333
324
// RestartRequired flag
334
- UpdateSetting (node (), Prune, new_value);
325
+ UpdateSetting (node (), Prune, " " , new_value);
326
+ }
327
+
328
+ // Keep previous pruning size, if pruning was disabled.
329
+ if (PruneEnabled (cur_value)) {
330
+ UpdateSetting (node (), Prune, " -prev" , PruneEnabled (new_value) ? util::SettingsValue{} : cur_value);
335
331
}
336
332
}
337
333
@@ -359,9 +355,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
359
355
return successful;
360
356
}
361
357
362
- QVariant OptionsModel::getOption (OptionID option) const
358
+ QVariant OptionsModel::getOption (OptionID option, const std::string& suffix ) const
363
359
{
364
- auto setting = [&]{ return node ().getPersistentSetting (SettingName (option)); };
360
+ auto setting = [&]{ return node ().getPersistentSetting (SettingName (option) + suffix ); };
365
361
366
362
QSettings settings;
367
363
switch (option) {
@@ -388,19 +384,30 @@ QVariant OptionsModel::getOption(OptionID option) const
388
384
389
385
// default proxy
390
386
case ProxyUse:
387
+ case ProxyUseTor:
391
388
return ParseProxyString (SettingToString (setting (), " " )).is_set ;
392
389
case ProxyIP:
393
- return m_proxy_ip;
390
+ case ProxyIPTor: {
391
+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
392
+ if (proxy.is_set ) {
393
+ return proxy.ip ;
394
+ } else if (suffix.empty ()) {
395
+ return getOption (option, " -prev" );
396
+ } else {
397
+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).ip ;
398
+ }
399
+ }
394
400
case ProxyPort:
395
- return m_proxy_port;
396
-
397
- // separate Tor proxy
398
- case ProxyUseTor:
399
- return ParseProxyString (SettingToString (setting (), " " )).is_set ;
400
- case ProxyIPTor:
401
- return m_onion_ip;
402
- case ProxyPortTor:
403
- return m_onion_port;
401
+ case ProxyPortTor: {
402
+ ProxySetting proxy = ParseProxyString (SettingToString (setting (), " " ));
403
+ if (proxy.is_set ) {
404
+ return proxy.port ;
405
+ } else if (suffix.empty ()) {
406
+ return getOption (option, " -prev" );
407
+ } else {
408
+ return ParseProxyString (GetDefaultProxyAddress ().toStdString ()).port ;
409
+ }
410
+ }
404
411
405
412
#ifdef ENABLE_WALLET
406
413
case SpendZeroConfChange:
@@ -425,7 +432,9 @@ QVariant OptionsModel::getOption(OptionID option) const
425
432
case Prune:
426
433
return PruneEnabled (setting ());
427
434
case PruneSize:
428
- return m_prune_size_gb;
435
+ return PruneEnabled (setting ()) ? PruneSizeGB (setting ()) :
436
+ suffix.empty () ? getOption (option, " -prev" ) :
437
+ DEFAULT_PRUNE_TARGET_GB;
429
438
case DatabaseCache:
430
439
return qlonglong (SettingToInt (setting (), nDefaultDbCache));
431
440
case ThreadsScriptVerif:
@@ -439,10 +448,10 @@ QVariant OptionsModel::getOption(OptionID option) const
439
448
}
440
449
}
441
450
442
- bool OptionsModel::setOption (OptionID option, const QVariant& value)
451
+ bool OptionsModel::setOption (OptionID option, const QVariant& value, const std::string& suffix )
443
452
{
444
- auto changed = [&] { return value.isValid () && value != getOption (option); };
445
- auto update = [&](const util::SettingsValue& value) { return UpdateSetting (node (), option, value); };
453
+ auto changed = [&] { return value.isValid () && value != getOption (option, suffix ); };
454
+ auto update = [&](const util::SettingsValue& value) { return UpdateSetting (node (), option, suffix, value); };
446
455
447
456
bool successful = true ; /* set to false on parse error */
448
457
QSettings settings;
@@ -480,51 +489,59 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
480
489
// default proxy
481
490
case ProxyUse:
482
491
if (changed ()) {
483
- update (ProxyString (value.toBool (), m_proxy_ip, m_proxy_port));
484
- setRestartRequired (true );
492
+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
493
+ update (ProxyString (value.toBool (), getOption (ProxyIP).toString (), getOption (ProxyPort).toString ()));
494
+ if (suffix.empty () && value.toBool ()) setOption (option, false , " -prev" );
495
+ if (suffix.empty ()) setRestartRequired (true );
485
496
}
486
497
break ;
487
498
case ProxyIP:
488
499
if (changed ()) {
489
- m_proxy_ip = value.toString ();
490
- if (getOption (ProxyUse).toBool ()) {
491
- update (ProxyString (true , m_proxy_ip, m_proxy_port));
492
- setRestartRequired (true );
500
+ if (!suffix.empty () || getOption (ProxyUse).toBool ()) {
501
+ update (ProxyString (true , value.toString (), getOption (ProxyPort).toString ()));
502
+ if (suffix.empty ()) setRestartRequired (true );
503
+ } else {
504
+ setOption (option, value, " -prev" );
493
505
}
494
506
}
495
507
break ;
496
508
case ProxyPort:
497
509
if (changed ()) {
498
- m_proxy_port = value.toString ();
499
- if (getOption (ProxyUse).toBool ()) {
500
- update (ProxyString (true , m_proxy_ip, m_proxy_port));
501
- setRestartRequired (true );
510
+ if (!suffix.empty () || getOption (ProxyUse).toBool ()) {
511
+ update (ProxyString (true , getOption (ProxyIP).toString (), value.toString ()));
512
+ if (suffix.empty ()) setRestartRequired (true );
513
+ } else {
514
+ setOption (option, value, " -prev" );
502
515
}
503
516
}
504
517
break ;
505
518
506
519
// separate Tor proxy
507
520
case ProxyUseTor:
508
521
if (changed ()) {
509
- update (ProxyString (value.toBool (), m_onion_ip, m_onion_port));
510
- setRestartRequired (true );
522
+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
523
+ update (ProxyString (value.toBool (), getOption (ProxyIPTor).toString (), getOption (ProxyPortTor).toString ()));
524
+ if (suffix.empty () && value.toBool ()) setOption (option, false , " -prev" );
525
+ if (suffix.empty ()) setRestartRequired (true );
511
526
}
512
527
break ;
513
528
case ProxyIPTor:
514
529
if (changed ()) {
515
- m_onion_ip = value.toString ();
516
- if (getOption (ProxyUseTor).toBool ()) {
517
- update (ProxyString (true , m_onion_ip, m_onion_port));
518
- setRestartRequired (true );
530
+ if (!suffix.empty () || getOption (ProxyUseTor).toBool ()) {
531
+ update (ProxyString (true , value.toString (), getOption (ProxyPortTor).toString ()));
532
+ if (suffix.empty ()) setRestartRequired (true );
533
+ } else {
534
+ setOption (option, value, " -prev" );
519
535
}
520
536
}
521
537
break ;
522
538
case ProxyPortTor:
523
539
if (changed ()) {
524
- m_onion_port = value.toString ();
525
- if (getOption (ProxyUseTor).toBool ()) {
526
- update (ProxyString (true , m_onion_ip, m_onion_port));
527
- setRestartRequired (true );
540
+ if (!suffix.empty () || getOption (ProxyUseTor).toBool ()) {
541
+ update (ProxyString (true , getOption (ProxyIPTor).toString (), value.toString ()));
542
+ if (suffix.empty ()) setRestartRequired (true );
543
+ } else {
544
+ setOption (option, value, " -prev" );
528
545
}
529
546
}
530
547
break ;
@@ -579,16 +596,19 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
579
596
break ;
580
597
case Prune:
581
598
if (changed ()) {
582
- update (PruneSetting (value.toBool (), m_prune_size_gb));
583
- setRestartRequired (true );
599
+ if (suffix.empty () && !value.toBool ()) setOption (option, true , " -prev" );
600
+ update (PruneSetting (value.toBool (), getOption (PruneSize).toInt ()));
601
+ if (suffix.empty () && value.toBool ()) setOption (option, false , " -prev" );
602
+ if (suffix.empty ()) setRestartRequired (true );
584
603
}
585
604
break ;
586
605
case PruneSize:
587
606
if (changed ()) {
588
- m_prune_size_gb = ParsePruneSizeGB (value);
589
- if (getOption (Prune).toBool ()) {
590
- update (PruneSetting (true , m_prune_size_gb));
591
- setRestartRequired (true );
607
+ if (!suffix.empty () || getOption (Prune).toBool ()) {
608
+ update (PruneSetting (true , ParsePruneSizeGB (value)));
609
+ if (suffix.empty ()) setRestartRequired (true );
610
+ } else {
611
+ setOption (option, value, " -prev" );
592
612
}
593
613
}
594
614
break ;
0 commit comments