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