From ea8657e8e0916b6e2a3a3e7d7f840754b6c2a949 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Fri, 15 May 2020 12:07:59 -0500 Subject: [PATCH] Fix trade withdraw to external wallet step 4 The routine `cleanUpAddressEntries` in TradeManager was prematurely releasing funds associated with trades when they reach the last step of the process (Step 4, Withdraw to External Wallet). Usually, with a single trade active this would not be an issue because `cleanUpAddressEntries` is called after the withdrawal, but if you have more than one trade at Step 4 then the first withdrawal would go though, but all the others would fail with an error box "Missing x.xxx BTC" (the trade proceeds or deposit amount). Alternatively, if you restart the bisq app with a trade in Step 4, the same cleanup will occur and the attempt to withdraw to external wallet will fail. The change here considers any trade held by the TradeManager to be in use and therefore will not have their associated address entries freed up. After Step 4 has passed, the trade is no longer held by the TradeManager, and so cleanUpAddressEntries will at that point free up the address. --- core/src/main/java/bisq/core/trade/TradeManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index e755789b312..31bb507e44f 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -360,12 +360,12 @@ private void onTradesChanged() { private void cleanUpAddressEntries() { // We check if we have address entries which are not in our pending trades and clean up those entries. // They might be either from closed or failed trades or from trades we do not have at all in our data base files. - Set tradesIdSet = getTradesStreamWithFundsLockedIn() + Set activeTrades = getTradableList().stream() .map(Tradable::getId) .collect(Collectors.toSet()); btcWalletService.getAddressEntriesForTrade().stream() - .filter(e -> !tradesIdSet.contains(e.getOfferId())) + .filter(e -> !activeTrades.contains(e.getOfferId())) .forEach(e -> { log.warn("We found an outdated addressEntry for trade {}: entry={}", e.getOfferId(), e); btcWalletService.resetAddressEntriesForPendingTrade(e.getOfferId());