@@ -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 ();
@@ -320,8 +313,6 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
320
313
const util::SettingsValue cur_value = node ().getPersistentSetting (" prune" );
321
314
const util::SettingsValue new_value = PruneSetting (prune_target_gb > 0 , prune_target_gb);
322
315
323
- m_prune_size_gb = prune_target_gb;
324
-
325
316
// Force setting to take effect. It is still safe to change the value at
326
317
// this point because this function is only called after the intro screen is
327
318
// shown, before the node starts.
@@ -334,7 +325,12 @@ void OptionsModel::SetPruneTargetGB(int prune_target_gb)
334
325
PruneSizeGB (cur_value) != PruneSizeGB (new_value)) {
335
326
// Call UpdateRwSetting() instead of setOption() to avoid setting
336
327
// 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);
338
334
}
339
335
}
340
336
@@ -362,9 +358,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
362
358
return successful;
363
359
}
364
360
365
- QVariant OptionsModel::getOption (OptionID option) const
361
+ QVariant OptionsModel::getOption (OptionID option, const std::string& suffix ) const
366
362
{
367
- auto setting = [&]{ return node ().getPersistentSetting (SettingName (option)); };
363
+ auto setting = [&]{ return node ().getPersistentSetting (SettingName (option) + suffix ); };
368
364
369
365
QSettings settings;
370
366
switch (option) {
@@ -391,19 +387,30 @@ QVariant OptionsModel::getOption(OptionID option) const
391
387
392
388
// default proxy
393
389
case ProxyUse:
390
+ case ProxyUseTor:
394
391
return ParseProxyString (SettingToString (setting (), " " )).is_set ;
395
392
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
+ }
397
403
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
+ }
407
414
408
415
#ifdef ENABLE_WALLET
409
416
case SpendZeroConfChange:
@@ -428,7 +435,9 @@ QVariant OptionsModel::getOption(OptionID option) const
428
435
case Prune:
429
436
return PruneEnabled (setting ());
430
437
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;
432
441
case DatabaseCache:
433
442
return qlonglong (SettingToInt (setting (), nDefaultDbCache));
434
443
case ThreadsScriptVerif:
@@ -444,10 +453,10 @@ QVariant OptionsModel::getOption(OptionID option) const
444
453
}
445
454
}
446
455
447
- bool OptionsModel::setOption (OptionID option, const QVariant& value)
456
+ bool OptionsModel::setOption (OptionID option, const QVariant& value, const std::string& suffix )
448
457
{
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); };
451
460
452
461
bool successful = true ; /* set to false on parse error */
453
462
QSettings settings;
@@ -485,52 +494,60 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
485
494
// default proxy
486
495
case ProxyUse:
487
496
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 );
490
501
}
491
502
break ;
492
503
case ProxyIP:
493
504
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 ()) );
498
509
}
510
+ if (suffix.empty () && getOption (ProxyUse).toBool ()) setRestartRequired (true );
499
511
}
500
512
break ;
501
513
case ProxyPort:
502
514
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 ()) );
507
519
}
520
+ if (suffix.empty () && getOption (ProxyUse).toBool ()) setRestartRequired (true );
508
521
}
509
522
break ;
510
523
511
524
// separate Tor proxy
512
525
case ProxyUseTor:
513
526
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 );
516
531
}
517
532
break ;
518
533
case ProxyIPTor:
519
534
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 ()) );
524
539
}
540
+ if (suffix.empty () && getOption (ProxyUseTor).toBool ()) setRestartRequired (true );
525
541
}
526
542
break ;
527
543
case ProxyPortTor:
528
544
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 ()) );
533
549
}
550
+ if (suffix.empty () && getOption (ProxyUseTor).toBool ()) setRestartRequired (true );
534
551
}
535
552
break ;
536
553
@@ -584,17 +601,20 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value)
584
601
break ;
585
602
case Prune:
586
603
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 );
589
608
}
590
609
break ;
591
610
case PruneSize:
592
611
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)) );
597
616
}
617
+ if (suffix.empty () && getOption (Prune).toBool ()) setRestartRequired (true );
598
618
}
599
619
break ;
600
620
case DatabaseCache:
0 commit comments