Skip to content

Commit

Permalink
switch to next best monerod if missing trade deposits #1090
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jul 6, 2024
1 parent 9cda597 commit 55b968d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions core/src/main/java/haveno/core/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -627,9 +628,7 @@ public void initialize(ProcessModelServiceProvider serviceProvider) {

// handle connection change on dedicated thread
xmrConnectionService.addConnectionListener(connection -> {
ThreadUtils.submitToPool(() -> { // TODO: remove this?
ThreadUtils.execute(() -> onConnectionChanged(connection), getConnectionChangedThreadId());
});
ThreadUtils.execute(() -> onConnectionChanged(connection), getConnectionChangedThreadId());
});

// reset buyer's payment sent state if no ack receive
Expand Down Expand Up @@ -1133,10 +1132,10 @@ private MoneroTxWallet doCreatePayoutTx() {
// check if multisig import needed
if (wallet.isMultisigImportNeeded()) throw new RuntimeException("Cannot create payout tx because multisig import is needed");

// TODO: wallet sometimes returns empty data, after disconnect?
List<MoneroTxWallet> txs = wallet.getTxs(); // TODO: this fetches from pool
if (txs.isEmpty()) {
log.warn("Restarting wallet for {} {} because deposit txs are missing to create payout tx", getClass().getSimpleName(), getId());
// TODO: wallet sometimes returns empty data, due to unreliable connection with specific daemons?
if (getMakerDepositTx() == null || getTakerDepositTx() == null) {
log.warn("Switching Monero connection and restarting trade wallet because deposit txs are missing to create payout tx for {} {}", getClass().getSimpleName(), getShortId());
switchToNextBestConnection();
forceRestartTradeWallet();
}

Expand Down Expand Up @@ -2236,10 +2235,6 @@ private void doPublishTradeStatistics() {
// Private
///////////////////////////////////////////////////////////////////////////////////////////

private String getConnectionChangedThreadId() {
return getId() + ".onConnectionChanged";
}

// lazy initialization
private ObjectProperty<BigInteger> getAmountProperty() {
if (tradeAmountProperty == null)
Expand All @@ -2255,6 +2250,17 @@ private ObjectProperty<Volume> getVolumeProperty() {
return tradeVolumeProperty;
}

private String getConnectionChangedThreadId() {
return getId() + ".onConnectionChanged";
}

private void switchToNextBestConnection() {
xmrConnectionService.switchToNextBestConnection();
CountDownLatch latch = new CountDownLatch(1);
ThreadUtils.execute(() -> latch.countDown(), getConnectionChangedThreadId()); // wait for connection change to complete
HavenoUtils.awaitLatch(latch);
}

private void onConnectionChanged(MoneroRpcConnection connection) {
synchronized (walletLock) {

Expand Down

0 comments on commit 55b968d

Please sign in to comment.