Repository: bitcoin/bitcoin
File: src/node/interfaces.cpp (C++)

Code before:
    common::SettingsValue getSetting(const std::string& name) override
    {
        return args().GetSetting(name);
    }
    std::vector<common::SettingsValue> getSettingsList(const std::string& name) override
    {
        return args().GetSettingsList(name);
    }
    common::SettingsValue getRwSetting(const std::string& name) override
    {
        common::SettingsValue result;
        args().LockSettings([&](const common::Settings& settings) {
            if (const common::SettingsValue* value = common::FindKey(settings.rw_settings, name)) {
                result = *value;
            }
        });
        return result;
    }
    bool updateRwSetting(const std::string& name, const common::SettingsValue& value, bool write) override
    {
        args().LockSettings([&](common::Settings& settings) {
            if (value.isNull()) {
                settings.rw_settings.erase(name);
            } else {
                settings.rw_settings[name] = value;
            }
        });
        return !write || args().WriteSettingsFile();
    }
    void requestMempoolTransactions(Notifications& notifications) override
    {
        if (!m_node.mempool) return;
        LOCK2(::cs_main, m_node.mempool->cs);
        for (const CTxMemPoolEntry& entry : m_node.mempool->entryAll()) {
            notifications.transactionAddedToMempool(entry.GetSharedTx());
        }
    }
    bool hasAssumedValidChain() override
    {
        return chainman().IsSnapshotActive();
    }

    NodeContext* context() override { return &m_node; }
    ArgsManager& args() { return *Assert(m_node.args); }
    ChainstateManager& chainman() { return *Assert(m_node.chainman); }
    ValidationSignals& validation_signals() { return *Assert(m_node.validation_signals); }
    NodeContext& m_node;
};

class MinerImpl : public Mining
{

Review comment (suggestion):
I think this should be simplified to:

<details>
<summary>git diff on 1b41d45d46</summary>

```diff
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 54b986c926..b1699bc7ae 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -819,10 +819,8 @@ public:
     {
         std::optional<interfaces::SettingsAction> action;
         args().LockSettings([&](common::Settings& settings) {
-            auto* ptr_value = common::FindKey(settings.rw_settings, name);
-            // Create value if it doesn't exist
-            auto& value = ptr_value ? *ptr_value : settings.rw_settings[name];
-            action = update_settings_func(value);
+            auto& existing_value{settings.rw_settings[name]};
+            action = update_settings_func(existing_value);
         });
         if (!action) return false;
         // Now dump value to disk if requested

```
</details>


Code after:
    common::SettingsValue getSetting(const std::string& name) override
    {
        return args().GetSetting(name);
    }
    std::vector<common::SettingsValue> getSettingsList(const std::string& name) override
    {
        return args().GetSettingsList(name);
    }
    common::SettingsValue getRwSetting(const std::string& name) override
    {
        common::SettingsValue result;
        args().LockSettings([&](const common::Settings& settings) {
            if (const common::SettingsValue* value = common::FindKey(settings.rw_settings, name)) {
                result = *value;
            }
        });
        return result;
    }
    bool updateRwSetting(const std::string& name,
                         const interfaces::SettingsUpdate& update_settings_func) override
    {
        std::optional<interfaces::SettingsAction> action;
        args().LockSettings([&](common::Settings& settings) {
            auto* ptr_value = common::FindKey(settings.rw_settings, name);
            // Create value if it doesn't exist
            auto& value = ptr_value ? *ptr_value : settings.rw_settings[name];
            action = update_settings_func(value);
        });
        if (!action) return false;
        // Now dump value to disk if requested
        return *action == interfaces::SettingsAction::SKIP_WRITE || args().WriteSettingsFile();
    }
    bool overwriteRwSetting(const std::string& name, common::SettingsValue& value, bool write) override
    {
        if (value.isNull()) return deleteRwSettings(name, write);
        return updateRwSetting(name, [&](common::SettingsValue& settings) {
            settings = std::move(value);
            return write ? interfaces::SettingsAction::WRITE : interfaces::SettingsAction::SKIP_WRITE;
        });
    }
    bool deleteRwSettings(const std::string& name, bool write) override
    {
        args().LockSettings([&](common::Settings& settings) {
            settings.rw_settings.erase(name);
        });
        return !write || args().WriteSettingsFile();
    }
    void requestMempoolTransactions(Notifications& notifications) override
    {
        if (!m_node.mempool) return;
        LOCK2(::cs_main, m_node.mempool->cs);