Skip to content

Commit

Permalink
Fix asan error in withdrawal fees crawler
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Mar 13, 2024
1 parent 6d0cd3f commit abbbb16
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/common/include/commonapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CommonAPI : public ExchangeBase {
bool queryIsCurrencyCodeFiat(CurrencyCode currencyCode);

/// Query withdrawal fees from crawler sources. It's not guaranteed to work though.
WithdrawalFeesCrawler::WithdrawalInfoMaps queryWithdrawalFees(std::string_view exchangeName);
const WithdrawalFeesCrawler::WithdrawalInfoMaps &queryWithdrawalFees(std::string_view exchangeName);

void updateCacheFile() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/api/common/include/withdrawalfees-crawler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WithdrawalFeesCrawler {
using WithdrawalMinMap = std::unordered_map<CurrencyCode, MonetaryAmount>;
using WithdrawalInfoMaps = std::pair<MonetaryAmountByCurrencySet, WithdrawalMinMap>;

WithdrawalInfoMaps get(std::string_view exchangeName) { return _withdrawalFeesCache.get(exchangeName); }
const WithdrawalInfoMaps& get(std::string_view exchangeName) { return _withdrawalFeesCache.get(exchangeName); }

void updateCacheFile() const;

Expand Down
2 changes: 1 addition & 1 deletion src/api/common/src/commonapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CommonAPI::Fiats CommonAPI::queryFiats() {

bool CommonAPI::queryIsCurrencyCodeFiat(CurrencyCode currencyCode) { return queryFiats().contains(currencyCode); }

WithdrawalFeesCrawler::WithdrawalInfoMaps CommonAPI::queryWithdrawalFees(std::string_view exchangeName) {
const WithdrawalFeesCrawler::WithdrawalInfoMaps& CommonAPI::queryWithdrawalFees(std::string_view exchangeName) {
std::lock_guard<std::mutex> guard(_globalMutex);
return _withdrawalFeesCrawler.get(exchangeName);
}
Expand Down
10 changes: 9 additions & 1 deletion src/api/common/src/withdrawalfees-crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ WithdrawalFeesCrawler::WithdrawalFeesCrawler(const CoincenterInfo& coincenterInf
withdrawalInfoMaps.second.insert_or_assign(cur, withdrawMin);
}

_withdrawalFeesCache.set(std::move(withdrawalInfoMaps), lastUpdatedTime, exchangeName);
// Warning: we store a std::string_view in the cache, and 'exchangeName' will be destroyed at the end
// of this function. So we need to retrieve the 'constant' std::string_view of this exchange (in static memory)
// to store in the cache.
auto constantExchangeNameSVIt = std::ranges::find(kSupportedExchanges, exchangeName);
if (constantExchangeNameSVIt == std::end(kSupportedExchanges)) {
throw exception("unknown exchange name {}", exchangeName);
}

_withdrawalFeesCache.set(std::move(withdrawalInfoMaps), lastUpdatedTime, *constantExchangeNameSVIt);
}
}
}
Expand Down

0 comments on commit abbbb16

Please sign in to comment.