set isInitialized after initialization, add isShutDown flag to Trade
fix bug opening wallet while shutting down
This commit is contained in:
parent
f64b12e615
commit
8ec76aa1cd
@ -1,5 +1,6 @@
|
|||||||
package bisq.core.api;
|
package bisq.core.api;
|
||||||
|
|
||||||
|
import bisq.common.app.DevEnv;
|
||||||
import bisq.common.config.BaseCurrencyNetwork;
|
import bisq.common.config.BaseCurrencyNetwork;
|
||||||
import bisq.common.config.Config;
|
import bisq.common.config.Config;
|
||||||
import bisq.core.btc.model.EncryptedConnectionList;
|
import bisq.core.btc.model.EncryptedConnectionList;
|
||||||
@ -442,6 +443,7 @@ public final class CoreMoneroConnectionsService {
|
|||||||
numPeers.set(peers.get().size());
|
numPeers.set(peers.get().size());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Could not update daemon info: " + e.getMessage());
|
log.warn("Could not update daemon info: " + e.getMessage());
|
||||||
|
if (DevEnv.isDevMode()) e.printStackTrace();
|
||||||
if (connectionManager.getAutoSwitch()) connectionManager.setConnection(connectionManager.getBestAvailableConnection());
|
if (connectionManager.getAutoSwitch()) connectionManager.setConnection(connectionManager.getBestAvailableConnection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -398,6 +398,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
// Mutable
|
// Mutable
|
||||||
@Getter
|
@Getter
|
||||||
transient private boolean isInitialized;
|
transient private boolean isInitialized;
|
||||||
|
transient private boolean isShutDown;
|
||||||
|
|
||||||
// Added in v1.2.0
|
// Added in v1.2.0
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -589,8 +590,6 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public void initialize(ProcessModelServiceProvider serviceProvider) {
|
public void initialize(ProcessModelServiceProvider serviceProvider) {
|
||||||
isInitialized = true;
|
|
||||||
|
|
||||||
serviceProvider.getArbitratorManager().getDisputeAgentByNodeAddress(getArbitratorNodeAddress()).ifPresent(arbitrator -> {
|
serviceProvider.getArbitratorManager().getDisputeAgentByNodeAddress(getArbitratorNodeAddress()).ifPresent(arbitrator -> {
|
||||||
getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
||||||
});
|
});
|
||||||
@ -639,6 +638,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
|
|
||||||
// cleanup when payout unlocks
|
// cleanup when payout unlocks
|
||||||
if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) {
|
if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) {
|
||||||
|
if (!isInitialized) return;
|
||||||
log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId());
|
log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId());
|
||||||
deleteWallet();
|
deleteWallet();
|
||||||
if (txPollLooper != null) {
|
if (txPollLooper != null) {
|
||||||
@ -674,6 +674,8 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
UserThread.execute(() -> latch.countDown());
|
UserThread.execute(() -> latch.countDown());
|
||||||
HavenoUtils.awaitLatch(latch);
|
HavenoUtils.awaitLatch(latch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestPersistence() {
|
public void requestPersistence() {
|
||||||
@ -718,7 +720,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
if (wallet != null) return wallet;
|
if (wallet != null) return wallet;
|
||||||
if (!walletExists()) return null;
|
if (!walletExists()) return null;
|
||||||
if (isInitialized) wallet = xmrWalletService.openWallet(getWalletName());
|
if (!isShutDown) wallet = xmrWalletService.openWallet(getWalletName());
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,7 +762,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
try {
|
try {
|
||||||
syncWallet();
|
syncWallet();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (isInitialized) {
|
if (!isShutDown) {
|
||||||
log.warn("Error syncing trade wallet for {} {}: {}", getClass().getSimpleName(), getId(), e.getMessage());
|
log.warn("Error syncing trade wallet for {} {}: {}", getClass().getSimpleName(), getId(), e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -771,7 +773,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
syncNormalStartTime = System.currentTimeMillis();
|
syncNormalStartTime = System.currentTimeMillis();
|
||||||
setWalletRefreshPeriod(xmrWalletService.getConnectionsService().getDefaultRefreshPeriodMs());
|
setWalletRefreshPeriod(xmrWalletService.getConnectionsService().getDefaultRefreshPeriodMs());
|
||||||
UserThread.runAfter(() -> {
|
UserThread.runAfter(() -> {
|
||||||
if (isInitialized && System.currentTimeMillis() >= syncNormalStartTime + syncNormalDuration) updateWalletRefreshPeriod();
|
if (!isShutDown && System.currentTimeMillis() >= syncNormalStartTime + syncNormalDuration) updateWalletRefreshPeriod();
|
||||||
}, syncNormalDuration);
|
}, syncNormalDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,7 +1110,9 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
|
|
||||||
public void shutDown() {
|
public void shutDown() {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
|
log.info("Shutting down {} {}", getClass().getSimpleName(), getId());
|
||||||
isInitialized = false;
|
isInitialized = false;
|
||||||
|
isShutDown = true;
|
||||||
if (wallet != null) closeWallet();
|
if (wallet != null) closeWallet();
|
||||||
if (txPollLooper != null) {
|
if (txPollLooper != null) {
|
||||||
txPollLooper.stop();
|
txPollLooper.stop();
|
||||||
@ -1638,13 +1642,14 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateSyncing() {
|
private void updateSyncing() {
|
||||||
|
if (isShutDown) return;
|
||||||
if (!isIdling()) {
|
if (!isIdling()) {
|
||||||
trySyncWallet();
|
trySyncWallet();
|
||||||
updateWalletRefreshPeriod();
|
updateWalletRefreshPeriod();
|
||||||
} else {
|
} else {
|
||||||
long startSyncingInMs = ThreadLocalRandom.current().nextLong(0, getWalletRefreshPeriod()); // random time to start syncing
|
long startSyncingInMs = ThreadLocalRandom.current().nextLong(0, getWalletRefreshPeriod()); // random time to start syncing
|
||||||
UserThread.runAfter(() -> {
|
UserThread.runAfter(() -> {
|
||||||
if (isInitialized) {
|
if (!isShutDown) {
|
||||||
trySyncWallet();
|
trySyncWallet();
|
||||||
updateWalletRefreshPeriod();
|
updateWalletRefreshPeriod();
|
||||||
}
|
}
|
||||||
@ -1657,6 +1662,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setWalletRefreshPeriod(long walletRefreshPeriod) {
|
private void setWalletRefreshPeriod(long walletRefreshPeriod) {
|
||||||
|
if (this.isShutDown) return;
|
||||||
if (this.walletRefreshPeriod != null && this.walletRefreshPeriod == walletRefreshPeriod) return;
|
if (this.walletRefreshPeriod != null && this.walletRefreshPeriod == walletRefreshPeriod) return;
|
||||||
log.info("Setting wallet refresh rate for {} {} to {}", getClass().getSimpleName(), getId(), walletRefreshPeriod);
|
log.info("Setting wallet refresh rate for {} {} to {}", getClass().getSimpleName(), getId(), walletRefreshPeriod);
|
||||||
this.walletRefreshPeriod = walletRefreshPeriod;
|
this.walletRefreshPeriod = walletRefreshPeriod;
|
||||||
@ -1743,7 +1749,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (isInitialized && getWallet() != null && isWalletConnected()) log.warn("Error polling trade wallet {}: {}", getId(), e.getMessage()); // TODO (monero-java): poller.isPolling() and then don't need to use isInitialized here as shutdown flag
|
if (!isShutDown && getWallet() != null && isWalletConnected()) log.warn("Error polling trade wallet {}: {}", getId(), e.getMessage()); // TODO (monero-java): poller.isPolling()?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1822,7 +1828,7 @@ public abstract class Trade implements Tradable, Model {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
processing = false;
|
processing = false;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (isInitialized && !isWalletConnected()) throw e;
|
if (isInitialized && !isShutDown && !isWalletConnected()) throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user