Repository: bitcoin/bitcoin (language: cpp)

Issue:
Double lock detected in `Warnings::GetMessages()`
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

Running `bitcoin-qt -testnet` results in it eventually deadlocking due to a double lock in the warnings code.

### Expected behaviour

Should not double lock.

### Steps to reproduce

1. Build with `--enable-debug` (or define `DEBUG_LOCKORDER`
2. Run `bitcoin-qt -testnet`, and either sync or reindex
3. It will assert and crash on its own (without `DEBUG_LOCKORDER`, it will eventually hang)

### Relevant log output


```
2024-07-05T23:22:12.212000Z [scheduler] [../../../src/qt/bitcoin.cpp:215] [DebugMessageHandler] [qt] GUI: ClientModel: NotifyAlertChanged
2024-07-05T23:22:12.212029Z [scheduler] [../../../src/sync.cpp:129] [double_lock_detected] DOUBLE LOCK DETECTED
2024-07-05T23:22:12.212052Z [scheduler] [../../../src/sync.cpp:130] [double_lock_detected] Lock order:
2024-07-05T23:22:12.212072Z [scheduler] [../../../src/sync.cpp:136] [double_lock_detected]  (*) 'm_mutex' in ../../../src/node/warnings.cpp:31 (in thread 'scheduler')
2024-07-05T23:22:12.212092Z [scheduler] [../../../src/sync.cpp:136] [double_lock_detected]  (*) 'm_mutex' in ../../../src/node/warnings.cpp:46 (in thread 'scheduler')
Assertion failed: detected double lock for 'm_mutex' in ../../../src/node/warnings.cpp:46 (in thread 'scheduler'), details in debug log.
```

### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

bd5d1688b4311e21c0e0ff89a3ae02ef7d0543b8

### Operating system and version

Arch

### Machine specifications

_No response_


Discussion / hints:
cc @stickies-v as you were the last to touch the warnings code.

Fix patch:
diff --git a/src/node/warnings.cpp b/src/node/warnings.cpp
index b99c845900abf..87389e472b934 100644
--- a/src/node/warnings.cpp
+++ b/src/node/warnings.cpp
@@ -28,8 +28,7 @@ Warnings::Warnings()
 }
 bool Warnings::Set(warning_type id, bilingual_str message)
 {
-    LOCK(m_mutex);
-    const auto& [_, inserted]{m_warnings.insert({id, std::move(message)})};
+    const auto& [_, inserted]{WITH_LOCK(m_mutex, return m_warnings.insert({id, std::move(message)}))};
     if (inserted) uiInterface.NotifyAlertChanged();
     return inserted;
 }


Test patch: