Skip to content

Commit df60199

Browse files
chain: ensure updateRwSetting doesn't update to a null settings
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
1 parent c8e2eee commit df60199

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/interfaces/chain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ class Chain
356356
virtual common::SettingsValue getRwSetting(const std::string& name) = 0;
357357

358358
//! Updates a setting in <datadir>/settings.json.
359+
//! Null can be passed to erase the setting. There is intentionally no
360+
//! support for writing null values to settings.json.
359361
//! Depending on the action returned by the update function, this will either
360362
//! update the setting in memory or write the updated settings to disk.
361363
virtual bool updateRwSetting(const std::string& name, const SettingsUpdate& update_function) = 0;

src/node/interfaces.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,14 @@ class ChainImpl : public Chain
819819
{
820820
std::optional<interfaces::SettingsAction> action;
821821
args().LockSettings([&](common::Settings& settings) {
822-
auto* ptr_value = common::FindKey(settings.rw_settings, name);
823-
// Create value if it doesn't exist
824-
auto& value = ptr_value ? *ptr_value : settings.rw_settings[name];
825-
action = update_settings_func(value);
822+
if (auto* value = common::FindKey(settings.rw_settings, name)) {
823+
action = update_settings_func(*value);
824+
if (value->isNull()) settings.rw_settings.erase(name);
825+
} else {
826+
UniValue new_value;
827+
action = update_settings_func(new_value);
828+
if (!new_value.isNull()) settings.rw_settings[name] = std::move(new_value);
829+
}
826830
});
827831
if (!action) return false;
828832
// Now dump value to disk if requested

0 commit comments

Comments
 (0)