message: wallet: Handle concurrent wallet loading
diff: @@ -151,7 +151,8 @@ void UnloadWallet(std::shared_ptr<CWallet>&& wallet)
  }
  }
  -std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings)
  +namespace {
  +std::shared_ptr<CWallet> LoadWalletInternal(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings)
  {
  try {
  if (!CWallet::Verify(chain, location, error, warnings)) {
  @@ -172,6 +173,19 @@ std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocati
  return nullptr;
  }
  }
  +} // namespace
  +
  +std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const WalletLocation& location, bilingual_str& error, std::vector<bilingual_str>& warnings)
  +{
  + auto result = WITH_LOCK(g_loading_wallet_mutex, return g_loading_wallet_set.insert(location.GetName()));
  + if (!result.second) {
  + error = Untranslated("Wallet already being loading.");
  + return nullptr;
  + }
  + auto wallet = LoadWalletInternal(chain, location, error, warnings);
  + WITH_LOCK(g_loading_wallet_mutex, g_loading_wallet_set.erase(result.first));
  + return wallet;
  +}
  std::shared_ptr<CWallet> LoadWallet(interfaces::Chain& chain, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings)
  {
  