mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 11:39:29 +00:00
remove dedicated connection change thread for trade
This commit is contained in:
parent
82d586ab78
commit
5d739f912c
3 changed files with 29 additions and 27 deletions
|
@ -303,7 +303,7 @@ public final class XmrConnectionService {
|
|||
|
||||
// switch to best connection
|
||||
if (bestConnection == null) {
|
||||
log.warn("Could not get connection to switch to");
|
||||
log.warn("No connection to switch to");
|
||||
return false;
|
||||
}
|
||||
setConnection(bestConnection);
|
||||
|
|
|
@ -627,7 +627,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
|
||||
// handle connection change on dedicated thread
|
||||
xmrConnectionService.addConnectionListener(connection -> {
|
||||
ThreadUtils.execute(() -> onConnectionChanged(connection), getConnectionChangedThreadId());
|
||||
ThreadUtils.execute(() -> onConnectionChanged(connection), getId());
|
||||
});
|
||||
|
||||
// reset buyer's payment sent state if no ack receive
|
||||
|
@ -1501,7 +1501,6 @@ public abstract class Trade implements Tradable, Model {
|
|||
isShutDown = true;
|
||||
List<Runnable> shutDownThreads = new ArrayList<>();
|
||||
shutDownThreads.add(() -> ThreadUtils.shutDown(getId()));
|
||||
shutDownThreads.add(() -> ThreadUtils.shutDown(getConnectionChangedThreadId()));
|
||||
ThreadUtils.awaitTasks(shutDownThreads);
|
||||
}
|
||||
|
||||
|
@ -2326,10 +2325,6 @@ public abstract class Trade implements Tradable, Model {
|
|||
return tradeVolumeProperty;
|
||||
}
|
||||
|
||||
private String getConnectionChangedThreadId() {
|
||||
return getId() + ".onConnectionChanged";
|
||||
}
|
||||
|
||||
private void onConnectionChanged(MoneroRpcConnection connection) {
|
||||
synchronized (walletLock) {
|
||||
|
||||
|
@ -2399,24 +2394,29 @@ public abstract class Trade implements Tradable, Model {
|
|||
}
|
||||
|
||||
private void syncWallet(boolean pollWallet) {
|
||||
if (getWallet() == null) throw new RuntimeException("Cannot sync trade wallet because it doesn't exist for " + getClass().getSimpleName() + ", " + getId());
|
||||
if (getWallet().getDaemonConnection() == null) throw new RuntimeException("Cannot sync trade wallet because it's not connected to a Monero daemon for " + getClass().getSimpleName() + ", " + getId());
|
||||
if (isWalletBehind()) {
|
||||
log.info("Syncing wallet for {} {}", getClass().getSimpleName(), getShortId());
|
||||
long startTime = System.currentTimeMillis();
|
||||
syncWalletIfBehind();
|
||||
log.info("Done syncing wallet for {} {} in {} ms", getClass().getSimpleName(), getShortId(), System.currentTimeMillis() - startTime);
|
||||
}
|
||||
|
||||
// apply tor after wallet synced depending on configuration
|
||||
if (!wasWalletSynced) {
|
||||
wasWalletSynced = true;
|
||||
if (xmrWalletService.isProxyApplied(wasWalletSynced)) {
|
||||
onConnectionChanged(xmrConnectionService.getConnection());
|
||||
try {
|
||||
if (getWallet() == null) throw new RuntimeException("Cannot sync trade wallet because it doesn't exist for " + getClass().getSimpleName() + ", " + getId());
|
||||
if (getWallet().getDaemonConnection() == null) throw new RuntimeException("Cannot sync trade wallet because it's not connected to a Monero daemon for " + getClass().getSimpleName() + ", " + getId());
|
||||
if (isWalletBehind()) {
|
||||
log.info("Syncing wallet for {} {}", getClass().getSimpleName(), getShortId());
|
||||
long startTime = System.currentTimeMillis();
|
||||
syncWalletIfBehind();
|
||||
log.info("Done syncing wallet for {} {} in {} ms", getClass().getSimpleName(), getShortId(), System.currentTimeMillis() - startTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (pollWallet) pollWallet();
|
||||
// apply tor after wallet synced depending on configuration
|
||||
if (!wasWalletSynced) {
|
||||
wasWalletSynced = true;
|
||||
if (xmrWalletService.isProxyApplied(wasWalletSynced)) {
|
||||
onConnectionChanged(xmrConnectionService.getConnection());
|
||||
}
|
||||
}
|
||||
|
||||
if (pollWallet) pollWallet();
|
||||
} catch (Exception e) {
|
||||
ThreadUtils.execute(() -> requestSwitchToNextBestConnection(), getId());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePollPeriod() {
|
||||
|
@ -2593,7 +2593,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
boolean isWalletConnected = isWalletConnectedToDaemon();
|
||||
if (wallet != null && !isShutDownStarted && isWalletConnected) {
|
||||
log.warn("Error polling trade wallet for {} {}, errorMessage={}. Monerod={}", getClass().getSimpleName(), getShortId(), e.getMessage(), getXmrWalletService().getConnectionService().getConnection());
|
||||
requestSwitchToNextBestConnection();
|
||||
ThreadUtils.execute(() -> requestSwitchToNextBestConnection(), getId()); // do not block polling thread
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1285,7 +1285,9 @@ public class XmrWalletService {
|
|||
else log.info(appliedMsg);
|
||||
|
||||
// listen for connection changes
|
||||
xmrConnectionService.addConnectionListener(connection -> ThreadUtils.execute(() -> onConnectionChanged(connection), THREAD_ID));
|
||||
xmrConnectionService.addConnectionListener(connection -> ThreadUtils.execute(() -> {
|
||||
onConnectionChanged(connection);
|
||||
}, THREAD_ID));
|
||||
|
||||
// initialize main wallet when daemon synced
|
||||
walletInitListener = (obs, oldVal, newVal) -> initMainWalletIfConnected();
|
||||
|
@ -1669,7 +1671,7 @@ public class XmrWalletService {
|
|||
if (HavenoUtils.connectionConfigsEqual(connection, wallet.getDaemonConnection())) return;
|
||||
String oldProxyUri = wallet == null || wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getProxyUri();
|
||||
String newProxyUri = connection == null ? null : connection.getProxyUri();
|
||||
log.info("Setting daemon connection for main wallet: uri={}, proxyUri={}", connection == null ? null : connection.getUri(), newProxyUri);
|
||||
log.info("Setting daemon connection for main wallet, monerod={}, proxyUri={}", connection == null ? null : connection.getUri(), newProxyUri);
|
||||
|
||||
// force restart main wallet if connection changed before synced
|
||||
if (!wasWalletSynced) {
|
||||
|
@ -1706,7 +1708,7 @@ public class XmrWalletService {
|
|||
updatePollPeriod();
|
||||
}
|
||||
|
||||
log.info("Done setting main wallet monerod=" + (wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getUri()));
|
||||
log.info("Done setting daemon connection for main wallet, monerod=" + (wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getUri()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue