mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 00:15:18 -04:00
prompt to start local node or fallback on startup
This commit is contained in:
parent
9668dd2369
commit
7e3a47de4a
7 changed files with 129 additions and 41 deletions
|
@ -24,7 +24,6 @@ import haveno.common.UserThread;
|
|||
import haveno.common.app.DevEnv;
|
||||
import haveno.common.config.BaseCurrencyNetwork;
|
||||
import haveno.common.config.Config;
|
||||
import haveno.core.locale.Res;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.user.Preferences;
|
||||
import haveno.core.xmr.model.EncryptedConnectionList;
|
||||
|
@ -73,6 +72,11 @@ public final class XmrConnectionService {
|
|||
private static final long REFRESH_PERIOD_HTTP_MS = 20000; // refresh period when connected to remote node over http
|
||||
private static final long REFRESH_PERIOD_ONION_MS = 30000; // refresh period when connected to remote node over tor
|
||||
|
||||
public enum XmrConnectionError {
|
||||
LOCAL,
|
||||
CUSTOM
|
||||
}
|
||||
|
||||
private final Object lock = new Object();
|
||||
private final Object pollLock = new Object();
|
||||
private final Object listenerLock = new Object();
|
||||
|
@ -90,7 +94,7 @@ public final class XmrConnectionService {
|
|||
private final LongProperty chainHeight = new SimpleLongProperty(0);
|
||||
private final DownloadListener downloadListener = new DownloadListener();
|
||||
@Getter
|
||||
private final SimpleStringProperty connectionServiceFallbackHandler = new SimpleStringProperty();
|
||||
private final ObjectProperty<XmrConnectionError> connectionServiceError = new SimpleObjectProperty<>();
|
||||
@Getter
|
||||
private final StringProperty connectionServiceErrorMsg = new SimpleStringProperty();
|
||||
private final LongProperty numUpdates = new SimpleLongProperty(0);
|
||||
|
@ -119,7 +123,7 @@ public final class XmrConnectionService {
|
|||
private int numRequestsLastMinute;
|
||||
private long lastSwitchTimestamp;
|
||||
private Set<MoneroRpcConnection> excludedConnections = new HashSet<>();
|
||||
private static final long FALLBACK_INVOCATION_PERIOD_MS = 1000 * 60 * 1; // offer to fallback up to once every minute
|
||||
private static final long FALLBACK_INVOCATION_PERIOD_MS = 1000 * 30 * 1; // offer to fallback up to once every 30s
|
||||
private boolean fallbackApplied;
|
||||
|
||||
@Inject
|
||||
|
@ -260,7 +264,14 @@ public final class XmrConnectionService {
|
|||
|
||||
private MoneroRpcConnection getBestConnection(Collection<MoneroRpcConnection> ignoredConnections) {
|
||||
accountService.checkAccountOpen();
|
||||
if (!fallbackApplied && lastUsedLocalSyncingNode() && !xmrLocalNode.isDetected()) return null; // user needs to explicitly allow fallback after syncing local node
|
||||
|
||||
// user needs to authorize fallback on startup after using locally synced node
|
||||
if (lastInfo == null && !fallbackApplied && lastUsedLocalSyncingNode() && !xmrLocalNode.isDetected()) {
|
||||
log.warn("Cannot get best connection on startup because we last synced local node and user has not opted to fallback");
|
||||
return null;
|
||||
}
|
||||
|
||||
// get best connection
|
||||
Set<MoneroRpcConnection> ignoredConnectionsSet = new HashSet<>(ignoredConnections);
|
||||
addLocalNodeIfIgnored(ignoredConnectionsSet);
|
||||
MoneroRpcConnection bestConnection = connectionManager.getBestAvailableConnection(ignoredConnectionsSet.toArray(new MoneroRpcConnection[0])); // checks connections
|
||||
|
@ -543,6 +554,11 @@ public final class XmrConnectionService {
|
|||
// update connection
|
||||
if (isConnected) {
|
||||
setConnection(connection.getUri());
|
||||
|
||||
// reset error connecting to local node
|
||||
if (connectionServiceError.get() == XmrConnectionError.LOCAL && isConnectionLocalHost()) {
|
||||
connectionServiceError.set(null);
|
||||
}
|
||||
} else if (getConnection() != null && getConnection().getUri().equals(connection.getUri())) {
|
||||
MoneroRpcConnection bestConnection = getBestConnection();
|
||||
if (bestConnection != null) setConnection(bestConnection); // switch to best connection
|
||||
|
@ -632,6 +648,27 @@ public final class XmrConnectionService {
|
|||
return connectionManager.getConnection() != null && xmrLocalNode.equalsUri(connectionManager.getConnection().getUri()) && !xmrLocalNode.isDetected() && !xmrLocalNode.shouldBeIgnored();
|
||||
}
|
||||
|
||||
public void startLocalNode() {
|
||||
|
||||
// cannot start local node as seed node
|
||||
if (HavenoUtils.isSeedNode()) {
|
||||
throw new RuntimeException("Cannot start local node on seed node");
|
||||
}
|
||||
|
||||
// start local node if offline and used as last connection
|
||||
if (connectionManager.getConnection() != null && xmrLocalNode.equalsUri(connectionManager.getConnection().getUri()) && !xmrLocalNode.isDetected() && !xmrLocalNode.shouldBeIgnored()) {
|
||||
try {
|
||||
log.info("Starting local node");
|
||||
xmrLocalNode.start();
|
||||
} catch (Exception e) {
|
||||
log.error("Unable to start local monero node, error={}\n", e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Local node is not offline and used as last connection");
|
||||
}
|
||||
}
|
||||
|
||||
private void onConnectionChanged(MoneroRpcConnection currentConnection) {
|
||||
if (isShutDownStarted || !accountService.isAccountOpen()) return;
|
||||
if (currentConnection == null) {
|
||||
|
@ -717,14 +754,14 @@ public final class XmrConnectionService {
|
|||
// invoke fallback handling on startup error
|
||||
boolean canFallback = isFixedConnection() || isCustomConnections() || lastUsedLocalSyncingNode();
|
||||
if (lastInfo == null && canFallback) {
|
||||
if (connectionServiceFallbackHandler.get() == null || connectionServiceFallbackHandler.equals("") && (lastFallbackInvocation == null || System.currentTimeMillis() - lastFallbackInvocation > FALLBACK_INVOCATION_PERIOD_MS)) {
|
||||
if (connectionServiceError.get() == null && (lastFallbackInvocation == null || System.currentTimeMillis() - lastFallbackInvocation > FALLBACK_INVOCATION_PERIOD_MS)) {
|
||||
lastFallbackInvocation = System.currentTimeMillis();
|
||||
if (lastUsedLocalSyncingNode()) {
|
||||
log.warn("Failed to fetch daemon info from local connection on startup: " + e.getMessage());
|
||||
connectionServiceFallbackHandler.set(Res.get("connectionFallback.localNode"));
|
||||
connectionServiceError.set(XmrConnectionError.LOCAL);
|
||||
} else {
|
||||
log.warn("Failed to fetch daemon info from custom connection on startup: " + e.getMessage());
|
||||
connectionServiceFallbackHandler.set(Res.get("connectionFallback.customNode"));
|
||||
connectionServiceError.set(XmrConnectionError.CUSTOM);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -75,7 +75,7 @@ public class HavenoHeadlessApp implements HeadlessApp {
|
|||
log.info("onDisplayTacHandler: We accept the tacs automatically in headless mode");
|
||||
acceptedHandler.run();
|
||||
});
|
||||
havenoSetup.setDisplayMoneroConnectionFallbackHandler(show -> log.info("onDisplayMoneroConnectionFallbackHandler: show={}", show));
|
||||
havenoSetup.setDisplayMoneroConnectionErrorHandler(show -> log.warn("onDisplayMoneroConnectionErrorHandler: show={}", show));
|
||||
havenoSetup.setDisplayTorNetworkSettingsHandler(show -> log.info("onDisplayTorNetworkSettingsHandler: show={}", show));
|
||||
havenoSetup.setChainFileLockedExceptionHandler(msg -> log.error("onChainFileLockedExceptionHandler: msg={}", msg));
|
||||
tradeManager.setLockedUpFundsHandler(msg -> log.info("onLockedUpFundsHandler: msg={}", msg));
|
||||
|
|
|
@ -55,6 +55,7 @@ import haveno.core.alert.PrivateNotificationManager;
|
|||
import haveno.core.alert.PrivateNotificationPayload;
|
||||
import haveno.core.api.CoreContext;
|
||||
import haveno.core.api.XmrConnectionService;
|
||||
import haveno.core.api.XmrConnectionService.XmrConnectionError;
|
||||
import haveno.core.api.XmrLocalNode;
|
||||
import haveno.core.locale.Res;
|
||||
import haveno.core.offer.OpenOfferManager;
|
||||
|
@ -158,7 +159,7 @@ public class HavenoSetup {
|
|||
rejectedTxErrorMessageHandler;
|
||||
@Setter
|
||||
@Nullable
|
||||
private Consumer<String> displayMoneroConnectionFallbackHandler;
|
||||
private Consumer<XmrConnectionError> displayMoneroConnectionErrorHandler;
|
||||
@Setter
|
||||
@Nullable
|
||||
private Consumer<Boolean> displayTorNetworkSettingsHandler;
|
||||
|
@ -430,9 +431,9 @@ public class HavenoSetup {
|
|||
getXmrWalletSyncProgress().addListener((observable, oldValue, newValue) -> resetStartupTimeout());
|
||||
|
||||
// listen for fallback handling
|
||||
getConnectionServiceFallbackHandler().addListener((observable, oldValue, newValue) -> {
|
||||
if (displayMoneroConnectionFallbackHandler == null) return;
|
||||
displayMoneroConnectionFallbackHandler.accept(newValue);
|
||||
getConnectionServiceError().addListener((observable, oldValue, newValue) -> {
|
||||
if (displayMoneroConnectionErrorHandler == null) return;
|
||||
displayMoneroConnectionErrorHandler.accept(newValue);
|
||||
});
|
||||
|
||||
log.info("Init P2P network");
|
||||
|
@ -734,8 +735,8 @@ public class HavenoSetup {
|
|||
return xmrConnectionService.getConnectionServiceErrorMsg();
|
||||
}
|
||||
|
||||
public StringProperty getConnectionServiceFallbackHandler() {
|
||||
return xmrConnectionService.getConnectionServiceFallbackHandler();
|
||||
public ObjectProperty<XmrConnectionError> getConnectionServiceError() {
|
||||
return xmrConnectionService.getConnectionServiceError();
|
||||
}
|
||||
|
||||
public StringProperty getTopErrorMsg() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue