synchronize wallet poll and stop polling on shut down started

This commit is contained in:
woodser 2023-11-13 13:32:43 -05:00
parent fd0bf23867
commit 51d5f0e1d3

View file

@ -22,6 +22,7 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import haveno.common.UserThread;
import haveno.common.config.Config;
import haveno.common.crypto.Encryption;
import haveno.common.crypto.PubKeyRing;
import haveno.common.proto.ProtoUtil;
@ -1122,6 +1123,7 @@ public abstract class Trade implements Tradable, Model {
}
public void onShutDownStarted() {
stopPolling();
isShutDownStarted = true;
if (wallet != null) log.info("{} {} preparing for shut down", getClass().getSimpleName(), getId());
@ -1780,6 +1782,7 @@ public abstract class Trade implements Tradable, Model {
}
public void updateWalletRefreshPeriod() {
if (isShutDownStarted) return;
setWalletRefreshPeriod(getWalletRefreshPeriod());
}
@ -1824,13 +1827,14 @@ public abstract class Trade implements Tradable, Model {
}
private void pollWallet() {
synchronized (walletLock) {
MoneroWallet wallet = getWallet();
try {
// check if wallet's height is less than daemon's
// log warning if wallet is too far behind daemon
MoneroDaemonInfo lastInfo = xmrWalletService.getConnectionsService().getLastInfo();
if (lastInfo != null && wallet.getHeight() < lastInfo.getHeight() - 2) {
log.warn("Daemon's height is more than 2 blocks ahead of wallet's height; daemon height={}, wallet height={}, tradeId={}", lastInfo.getHeight(), wallet.getHeight(), getShortId());
if (!Config.baseCurrencyNetwork().isTestnet() && isDepositsPublished() && lastInfo != null && wallet.getHeight() < lastInfo.getHeight() - 3) {
log.warn("Wallet is more than 3 blocks behind monerod for {} {}, wallet height={}, monerod height={},", getClass().getSimpleName(), getShortId(), lastInfo.getHeight(), wallet.getHeight());
}
// skip if either deposit tx id is unknown
@ -1912,6 +1916,7 @@ public abstract class Trade implements Tradable, Model {
}
}
}
}
private long getWalletRefreshPeriod() {
if (isIdling()) return IDLE_SYNC_PERIOD_MS;