diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 3bf8cfde..4c459077 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -1343,6 +1343,7 @@ public class XmrWalletService extends XmrWalletBase { try { doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS); } catch (Exception e) { + if (isShutDownStarted) return; log.warn("Error initializing main wallet: {}\n", e.getMessage(), e); HavenoUtils.setTopError(e.getMessage()); throw e; @@ -1510,10 +1511,11 @@ public class XmrWalletService extends XmrWalletBase { // try opening wallet config.setNetworkType(getMoneroNetworkType()); config.setServer(connection); - log.info("Opening full wallet " + config.getPath() + " with monerod=" + connection.getUri() + ", proxyUri=" + connection.getProxyUri()); + log.info("Opening full wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri()); try { walletFull = MoneroWalletFull.openWallet(config); } catch (Exception e) { + if (isShutDownStarted) throw e; log.warn("Failed to open full wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage()); boolean retrySuccessful = false; try { @@ -1551,7 +1553,7 @@ public class XmrWalletService extends XmrWalletBase { // retry opening wallet after cache deleted try { - log.warn("Failed to open full wallet using backup cache files, retrying with cache deleted"); + log.warn("Failed to open full wallet '{}' using backup cache files, retrying with cache deleted", config.getPath()); walletFull = MoneroWalletFull.openWallet(config); log.warn("Successfully opened full wallet after cache deleted"); retrySuccessful = true; @@ -1565,7 +1567,7 @@ public class XmrWalletService extends XmrWalletBase { } else { // restore original wallet cache - log.warn("Failed to open full wallet after deleting cache, restoring original cache"); + log.warn("Failed to open full wallet '{}' after deleting cache, restoring original cache", config.getPath()); File cacheFile = new File(cachePath); if (cacheFile.exists()) cacheFile.delete(); if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath)); @@ -1637,11 +1639,12 @@ public class XmrWalletService extends XmrWalletBase { if (!applyProxyUri) connection.setProxyUri(null); // try opening wallet - log.info("Opening RPC wallet " + config.getPath() + " with monerod=" + connection.getUri() + ", proxyUri=" + connection.getProxyUri()); + log.info("Opening RPC wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri()); config.setServer(connection); try { walletRpc.openWallet(config); } catch (Exception e) { + if (isShutDownStarted) throw e; log.warn("Failed to open RPC wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage()); boolean retrySuccessful = false; try { @@ -1679,7 +1682,7 @@ public class XmrWalletService extends XmrWalletBase { // retry opening wallet after cache deleted try { - log.warn("Failed to open RPC wallet using backup cache files, retrying with cache deleted"); + log.warn("Failed to open RPC wallet '{}' using backup cache files, retrying with cache deleted", config.getPath()); walletRpc.openWallet(config); log.warn("Successfully opened RPC wallet after cache deleted"); retrySuccessful = true; @@ -1693,7 +1696,7 @@ public class XmrWalletService extends XmrWalletBase { } else { // restore original wallet cache - log.warn("Failed to open RPC wallet after deleting cache, restoring original cache"); + log.warn("Failed to open RPC wallet '{}' after deleting cache, restoring original cache", config.getPath()); File cacheFile = new File(cachePath); if (cacheFile.exists()) cacheFile.delete(); if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath)); diff --git a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java index 80b37527..b15f43db 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/offerbook/OfferBookView.java @@ -424,7 +424,7 @@ abstract public class OfferBookView { }); - tableView.setItems(model.getOfferList()); + UserThread.execute(() -> tableView.setItems(model.getOfferList())); model.getOfferList().addListener(offerListListener); nrOfOffersLabel.setText(Res.get("offerbook.nrOffers", model.getOfferList().size())); @@ -788,13 +788,11 @@ abstract public class OfferBookView() { @Override public void updateItem(final OfferBookListItem item, boolean empty) { - UserThread.execute(() -> { - super.updateItem(item, empty); - if (item != null && !empty) - setGraphic(new ColoredDecimalPlacesWithZerosText(model.getAmount(item), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS)); - else - setGraphic(null); - }); + super.updateItem(item, empty); + if (item != null && !empty) + setGraphic(new ColoredDecimalPlacesWithZerosText(model.getAmount(item), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS)); + else + setGraphic(null); } }; } @@ -819,13 +817,11 @@ abstract public class OfferBookView { - super.updateItem(item, empty); - if (item != null && !empty) - setText(CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode())); - else - setText(""); - }); + super.updateItem(item, empty); + if (item != null && !empty) + setText(CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode())); + else + setText(""); } }; } @@ -855,15 +851,13 @@ abstract public class OfferBookView() { @Override public void updateItem(final OfferBookListItem item, boolean empty) { - UserThread.execute(() -> { - super.updateItem(item, empty); + super.updateItem(item, empty); - if (item != null && !empty) { - setGraphic(getPriceAndPercentage(item)); - } else { - setGraphic(null); - } - }); + if (item != null && !empty) { + setGraphic(getPriceAndPercentage(item)); + } else { + setGraphic(null); + } } private HBox getPriceAndPercentage(OfferBookListItem item) { @@ -939,23 +933,21 @@ abstract public class OfferBookView() { @Override public void updateItem(final OfferBookListItem item, boolean empty) { - UserThread.execute(() -> { - super.updateItem(item, empty); + super.updateItem(item, empty); - if (item != null && !empty) { - if (item.getOffer().getPrice() == null) { - setText(Res.get("shared.na")); - setGraphic(null); - } else { - setText(""); - setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item), - model.getNumberOfDecimalsForVolume(item))); - } + if (item != null && !empty) { + if (item.getOffer().getPrice() == null) { + setText(Res.get("shared.na")); + setGraphic(null); } else { setText(""); - setGraphic(null); + setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item), + model.getNumberOfDecimalsForVolume(item))); } - }); + } else { + setText(""); + setGraphic(null); + } } }; } @@ -981,32 +973,30 @@ abstract public class OfferBookView { - super.updateItem(item, empty); + super.updateItem(item, empty); - if (item != null && !empty) { + if (item != null && !empty) { - Offer offer = item.getOffer(); - if (model.isOfferBanned(offer)) { - setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item))); - } else { - if (offer.isXmrAutoConf()) { - field = new HyperlinkWithIcon(model.getPaymentMethod(item), AwesomeIcon.ROCKET); - } else { - field = new HyperlinkWithIcon(model.getPaymentMethod(item)); - } - field.setOnAction(event -> { - offerDetailsWindow.show(offer); - }); - field.setTooltip(new Tooltip(model.getPaymentMethodToolTip(item))); - setGraphic(field); - } + Offer offer = item.getOffer(); + if (model.isOfferBanned(offer)) { + setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item))); } else { - setGraphic(null); - if (field != null) - field.setOnAction(null); + if (offer.isXmrAutoConf()) { + field = new HyperlinkWithIcon(model.getPaymentMethod(item), AwesomeIcon.ROCKET); + } else { + field = new HyperlinkWithIcon(model.getPaymentMethod(item)); + } + field.setOnAction(event -> { + offerDetailsWindow.show(offer); + }); + field.setTooltip(new Tooltip(model.getPaymentMethodToolTip(item))); + setGraphic(field); } - }); + } else { + setGraphic(null); + if (field != null) + field.setOnAction(null); + } } }; } @@ -1035,28 +1025,26 @@ abstract public class OfferBookView() { @Override public void updateItem(final OfferBookListItem item, boolean empty) { - UserThread.execute(() -> { - super.updateItem(item, empty); + super.updateItem(item, empty); - if (item != null && !empty) { - var isSellOffer = item.getOffer().getDirection() == OfferDirection.SELL; - var deposit = isSellOffer ? item.getOffer().getMaxBuyerSecurityDeposit() : - item.getOffer().getMaxSellerSecurityDeposit(); - if (deposit == null) { - setText(Res.get("shared.na")); - setGraphic(null); - } else { - setText(""); - String rangePrefix = item.getOffer().isRange() ? "<= " : ""; - setGraphic(new ColoredDecimalPlacesWithZerosText(rangePrefix + model.formatDepositString( - deposit, item.getOffer().getAmount().longValueExact()), - GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS)); - } + if (item != null && !empty) { + var isSellOffer = item.getOffer().getDirection() == OfferDirection.SELL; + var deposit = isSellOffer ? item.getOffer().getMaxBuyerSecurityDeposit() : + item.getOffer().getMaxSellerSecurityDeposit(); + if (deposit == null) { + setText(Res.get("shared.na")); + setGraphic(null); } else { setText(""); - setGraphic(null); + String rangePrefix = item.getOffer().isRange() ? "<= " : ""; + setGraphic(new ColoredDecimalPlacesWithZerosText(rangePrefix + model.formatDepositString( + deposit, item.getOffer().getAmount().longValueExact()), + GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS)); } - }); + } else { + setText(""); + setGraphic(null); + } } }; } @@ -1083,114 +1071,112 @@ abstract public class OfferBookView { - super.updateItem(item, empty); + super.updateItem(item, empty); - final ImageView iconView = new ImageView(); - final AutoTooltipButton button = new AutoTooltipButton(); - - { - button.setGraphic(iconView); - button.setGraphicTextGap(10); - button.setPrefWidth(10000); - } - - final ImageView iconView2 = new ImageView(); - final AutoTooltipButton button2 = new AutoTooltipButton(); - - { - button2.setGraphic(iconView2); - button2.setGraphicTextGap(10); - button2.setPrefWidth(10000); - } - - final HBox hbox = new HBox(); - - { - hbox.setSpacing(8); - hbox.setAlignment(Pos.CENTER); - hbox.getChildren().add(button); - hbox.getChildren().add(button2); - HBox.setHgrow(button, Priority.ALWAYS); - HBox.setHgrow(button2, Priority.ALWAYS); - } + final ImageView iconView = new ImageView(); + final AutoTooltipButton button = new AutoTooltipButton(); - TableRow tableRow = getTableRow(); - if (item != null && !empty) { - Offer offer = item.getOffer(); - boolean myOffer = model.isMyOffer(offer); + { + button.setGraphic(iconView); + button.setGraphicTextGap(10); + button.setPrefWidth(10000); + } - // https://github.com/bisq-network/bisq/issues/4986 - if (tableRow != null) { - canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false); - tableRow.setOpacity(canTakeOfferResult.isValid() || myOffer ? 1 : 0.4); + final ImageView iconView2 = new ImageView(); + final AutoTooltipButton button2 = new AutoTooltipButton(); - if (myOffer) { - button.setDefaultButton(false); - tableRow.setOnMousePressed(null); - } else if (canTakeOfferResult.isValid()) { - // set first row button as default - button.setDefaultButton(getIndex() == 0); - tableRow.setOnMousePressed(null); - } else { - button.setDefaultButton(false); - tableRow.setOnMousePressed(e -> { - // ugly hack to get the icon clickable when deactivated - if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas)) - onShowInfo(offer, canTakeOfferResult); - }); - } - } + { + button2.setGraphic(iconView2); + button2.setGraphicTextGap(10); + button2.setPrefWidth(10000); + } - String title; + final HBox hbox = new HBox(); + + { + hbox.setSpacing(8); + hbox.setAlignment(Pos.CENTER); + hbox.getChildren().add(button); + hbox.getChildren().add(button2); + HBox.setHgrow(button, Priority.ALWAYS); + HBox.setHgrow(button2, Priority.ALWAYS); + } + + TableRow tableRow = getTableRow(); + if (item != null && !empty) { + Offer offer = item.getOffer(); + boolean myOffer = model.isMyOffer(offer); + + // https://github.com/bisq-network/bisq/issues/4986 + if (tableRow != null) { + canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false); + tableRow.setOpacity(canTakeOfferResult.isValid() || myOffer ? 1 : 0.4); + if (myOffer) { - iconView.setId("image-remove"); - title = Res.get("shared.remove"); - button.setOnAction(e -> onRemoveOpenOffer(offer)); - - iconView2.setId("image-edit"); - button2.updateText(Res.get("shared.edit")); - button2.setOnAction(e -> onEditOpenOffer(offer)); - button2.setManaged(true); - button2.setVisible(true); - } else { - boolean isSellOffer = OfferViewUtil.isShownAsSellOffer(offer); - boolean isPrivateOffer = offer.isPrivateOffer(); - iconView.setId(isPrivateOffer ? "image-lock2x" : isSellOffer ? "image-buy-white" : "image-sell-white"); - iconView.setFitHeight(16); - iconView.setFitWidth(16); - button.setId(isSellOffer ? "buy-button" : "sell-button"); - button.setStyle("-fx-text-fill: white"); - title = Res.get("offerbook.takeOffer"); - button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer)))); - button.setOnAction(e -> onTakeOffer(offer)); - button2.setManaged(false); - button2.setVisible(false); - } - - if (!myOffer) { - if (canTakeOfferResult == null) { - canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false); - } - - if (!canTakeOfferResult.isValid()) { - button.setOnAction(e -> onShowInfo(offer, canTakeOfferResult)); - } - } - - button.updateText(title); - setPadding(new Insets(0, 15, 0, 0)); - setGraphic(hbox); - } else { - setGraphic(null); - button.setOnAction(null); - button2.setOnAction(null); - if (tableRow != null) { - tableRow.setOpacity(1); + button.setDefaultButton(false); tableRow.setOnMousePressed(null); + } else if (canTakeOfferResult.isValid()) { + // set first row button as default + button.setDefaultButton(getIndex() == 0); + tableRow.setOnMousePressed(null); + } else { + button.setDefaultButton(false); + tableRow.setOnMousePressed(e -> { + // ugly hack to get the icon clickable when deactivated + if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas)) + onShowInfo(offer, canTakeOfferResult); + }); } } - }); + + String title; + if (myOffer) { + iconView.setId("image-remove"); + title = Res.get("shared.remove"); + button.setOnAction(e -> onRemoveOpenOffer(offer)); + + iconView2.setId("image-edit"); + button2.updateText(Res.get("shared.edit")); + button2.setOnAction(e -> onEditOpenOffer(offer)); + button2.setManaged(true); + button2.setVisible(true); + } else { + boolean isSellOffer = OfferViewUtil.isShownAsSellOffer(offer); + boolean isPrivateOffer = offer.isPrivateOffer(); + iconView.setId(isPrivateOffer ? "image-lock2x" : isSellOffer ? "image-buy-white" : "image-sell-white"); + iconView.setFitHeight(16); + iconView.setFitWidth(16); + button.setId(isSellOffer ? "buy-button" : "sell-button"); + button.setStyle("-fx-text-fill: white"); + title = Res.get("offerbook.takeOffer"); + button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer)))); + button.setOnAction(e -> onTakeOffer(offer)); + button2.setManaged(false); + button2.setVisible(false); + } + + if (!myOffer) { + if (canTakeOfferResult == null) { + canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false); + } + + if (!canTakeOfferResult.isValid()) { + button.setOnAction(e -> onShowInfo(offer, canTakeOfferResult)); + } + } + + button.updateText(title); + setPadding(new Insets(0, 15, 0, 0)); + setGraphic(hbox); + } else { + setGraphic(null); + button.setOnAction(null); + button2.setOnAction(null); + if (tableRow != null) { + tableRow.setOpacity(1); + tableRow.setOnMousePressed(null); + } + } } }; } @@ -1218,19 +1204,17 @@ abstract public class OfferBookView() { @Override public void updateItem(final OfferBookListItem item, boolean empty) { - UserThread.execute(() -> { - super.updateItem(item, empty); + super.updateItem(item, empty); - if (item != null && !empty) { - var witnessAgeData = item.getWitnessAgeData(accountAgeWitnessService, signedWitnessService); - var label = witnessAgeData.isSigningRequired() - ? new AccountStatusTooltipLabel(witnessAgeData) - : new InfoAutoTooltipLabel(witnessAgeData.getDisplayString(), witnessAgeData.getIcon(), ContentDisplay.RIGHT, witnessAgeData.getInfo()); - setGraphic(label); - } else { - setGraphic(null); - } - }); + if (item != null && !empty) { + var witnessAgeData = item.getWitnessAgeData(accountAgeWitnessService, signedWitnessService); + var label = witnessAgeData.isSigningRequired() + ? new AccountStatusTooltipLabel(witnessAgeData) + : new InfoAutoTooltipLabel(witnessAgeData.getDisplayString(), witnessAgeData.getIcon(), ContentDisplay.RIGHT, witnessAgeData.getInfo()); + setGraphic(label); + } else { + setGraphic(null); + } } }; } @@ -1256,26 +1240,24 @@ abstract public class OfferBookView() { @Override public void updateItem(final OfferBookListItem newItem, boolean empty) { - UserThread.execute(() -> { - super.updateItem(newItem, empty); - if (newItem != null && !empty) { - final Offer offer = newItem.getOffer(); - final NodeAddress makersNodeAddress = offer.getOwnerNodeAddress(); - String role = Res.get("peerInfoIcon.tooltip.maker"); - int numTrades = model.getNumTrades(offer); - PeerInfoIconTrading peerInfoIcon = new PeerInfoIconTrading(makersNodeAddress, - role, - numTrades, - privateNotificationManager, - offer, - model.preferences, - model.accountAgeWitnessService, - useDevPrivilegeKeys); - setGraphic(peerInfoIcon); - } else { - setGraphic(null); - } - }); + super.updateItem(newItem, empty); + if (newItem != null && !empty) { + final Offer offer = newItem.getOffer(); + final NodeAddress makersNodeAddress = offer.getOwnerNodeAddress(); + String role = Res.get("peerInfoIcon.tooltip.maker"); + int numTrades = model.getNumTrades(offer); + PeerInfoIconTrading peerInfoIcon = new PeerInfoIconTrading(makersNodeAddress, + role, + numTrades, + privateNotificationManager, + offer, + model.preferences, + model.accountAgeWitnessService, + useDevPrivilegeKeys); + setGraphic(peerInfoIcon); + } else { + setGraphic(null); + } } }; } diff --git a/p2p/src/main/java/haveno/network/p2p/peers/BroadcastHandler.java b/p2p/src/main/java/haveno/network/p2p/peers/BroadcastHandler.java index fca906ff..9320f978 100644 --- a/p2p/src/main/java/haveno/network/p2p/peers/BroadcastHandler.java +++ b/p2p/src/main/java/haveno/network/p2p/peers/BroadcastHandler.java @@ -277,9 +277,6 @@ public class BroadcastHandler implements PeerManager.Listener { @Override public void onFailure(@NotNull Throwable throwable) { - log.warn("Broadcast to " + connection.getPeersNodeAddressOptional() + " failed. ", throwable); - numOfFailedBroadcasts.incrementAndGet(); - if (stopped.get()) { return; } @@ -356,7 +353,8 @@ public class BroadcastHandler implements PeerManager.Listener { try { future.cancel(true); } catch (Exception e) { - if (!networkNode.isShutDownStarted()) throw e; + if (networkNode.isShutDownStarted()) return; // ignore if shut down + throw e; } }); sendMessageFutures.clear();