Skip to content

Commit

Permalink
Merge branch 'haveno-dex:master' into haveno-reto
Browse files Browse the repository at this point in the history
  • Loading branch information
boldsuck authored Jan 15, 2025
2 parents 1ae775a + 69da858 commit bf973ec
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/haveno/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class Config {
public static final String BTC_FEE_INFO = "bitcoinFeeInfo";
public static final String BYPASS_MEMPOOL_VALIDATION = "bypassMempoolValidation";
public static final String PASSWORD_REQUIRED = "passwordRequired";
public static final String UPDATE_XMR_BINARIES = "updateXmrBinaries";

// Default values for certain options
public static final int UNSPECIFIED_PORT = -1;
Expand Down Expand Up @@ -204,6 +205,7 @@ public enum UseTorForXmr {
public final boolean republishMailboxEntries;
public final boolean bypassMempoolValidation;
public final boolean passwordRequired;
public final boolean updateXmrBinaries;

// Properties derived from options but not exposed as options themselves
public final File torDir;
Expand Down Expand Up @@ -621,6 +623,13 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
.ofType(boolean.class)
.defaultsTo(false);

ArgumentAcceptingOptionSpec<Boolean> updateXmrBinariesOpt =
parser.accepts(UPDATE_XMR_BINARIES,
"Update Monero binaries if applicable")
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(true);

try {
CompositeOptionSet options = new CompositeOptionSet();

Expand Down Expand Up @@ -733,6 +742,7 @@ public Config(String defaultAppName, File defaultUserDataDir, String... args) {
this.republishMailboxEntries = options.valueOf(republishMailboxEntriesOpt);
this.bypassMempoolValidation = options.valueOf(bypassMempoolValidationOpt);
this.passwordRequired = options.valueOf(passwordRequiredOpt);
this.updateXmrBinaries = options.valueOf(updateXmrBinariesOpt);
} catch (OptionException ex) {
throw new ConfigException("problem parsing option '%s': %s",
ex.options().get(0),
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/haveno/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ public void stopCheckingXmrConnection() {
xmrConnectionService.stopCheckingConnection();
}

public MoneroRpcConnection getBestAvailableXmrConnection() {
return xmrConnectionService.getBestAvailableConnection();
public MoneroRpcConnection getBestXmrConnection() {
return xmrConnectionService.getBestConnection();
}

public void setXmrConnectionAutoSwitch(boolean autoSwitch) {
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/java/haveno/core/api/XmrConnectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,17 @@ public void stopCheckingConnection() {
updatePolling();
}

public MoneroRpcConnection getBestAvailableConnection() {
accountService.checkAccountOpen();
List<MoneroRpcConnection> ignoredConnections = new ArrayList<MoneroRpcConnection>();
addLocalNodeIfIgnored(ignoredConnections);
return connectionManager.getBestAvailableConnection(ignoredConnections.toArray(new MoneroRpcConnection[0]));
public MoneroRpcConnection getBestConnection() {
return getBestConnection(new ArrayList<MoneroRpcConnection>());
}

private MoneroRpcConnection getBestAvailableConnection(Collection<MoneroRpcConnection> ignoredConnections) {
private MoneroRpcConnection getBestConnection(Collection<MoneroRpcConnection> ignoredConnections) {
accountService.checkAccountOpen();
Set<MoneroRpcConnection> ignoredConnectionsSet = new HashSet<>(ignoredConnections);
addLocalNodeIfIgnored(ignoredConnectionsSet);
return connectionManager.getBestAvailableConnection(ignoredConnectionsSet.toArray(new MoneroRpcConnection[0]));
MoneroRpcConnection bestConnection = connectionManager.getBestAvailableConnection(ignoredConnectionsSet.toArray(new MoneroRpcConnection[0])); // checks connections
if (bestConnection == null && connectionManager.getConnections().size() == 1 && !ignoredConnectionsSet.contains(connectionManager.getConnections().get(0))) bestConnection = connectionManager.getConnections().get(0);
return bestConnection;
}

private void addLocalNodeIfIgnored(Collection<MoneroRpcConnection> ignoredConnections) {
Expand All @@ -278,7 +277,7 @@ private void switchToBestConnection() {
log.info("Skipping switch to best Monero connection because connection is fixed or auto switch is disabled");
return;
}
MoneroRpcConnection bestConnection = getBestAvailableConnection();
MoneroRpcConnection bestConnection = getBestConnection();
if (bestConnection != null) setConnection(bestConnection);
}

Expand Down Expand Up @@ -329,15 +328,15 @@ public synchronized boolean requestSwitchToNextBestConnection(MoneroRpcConnectio
if (currentConnection != null) excludedConnections.add(currentConnection);

// get connection to switch to
MoneroRpcConnection bestConnection = getBestAvailableConnection(excludedConnections);
MoneroRpcConnection bestConnection = getBestConnection(excludedConnections);

// remove from excluded connections after period
UserThread.runAfter(() -> {
if (currentConnection != null) excludedConnections.remove(currentConnection);
}, EXCLUDE_CONNECTION_SECONDS);

// return if no connection to switch to
if (bestConnection == null) {
if (bestConnection == null || !Boolean.TRUE.equals(bestConnection.isConnected())) {
log.warn("No connection to switch to");
return false;
}
Expand Down Expand Up @@ -545,7 +544,7 @@ public void onConnectionChanged(MoneroRpcConnection connection) {
if (isConnected) {
setConnection(connection.getUri());
} else if (getConnection() != null && getConnection().getUri().equals(connection.getUri())) {
MoneroRpcConnection bestConnection = getBestAvailableConnection();
MoneroRpcConnection bestConnection = getBestConnection();
if (bestConnection != null) setConnection(bestConnection); // switch to best connection
}
}
Expand Down Expand Up @@ -610,7 +609,7 @@ public void onConnectionChanged(MoneroRpcConnection connection) {

// update connection
if (connectionManager.getConnection() == null || connectionManager.getAutoSwitch()) {
MoneroRpcConnection bestConnection = getBestAvailableConnection();
MoneroRpcConnection bestConnection = getBestConnection();
if (bestConnection != null) setConnection(bestConnection);
}
} else if (!isInitialized) {
Expand Down Expand Up @@ -725,8 +724,8 @@ private void doPollDaemon() {

// poll daemon
if (daemon == null) switchToBestConnection();
if (daemon == null) throw new RuntimeException("No connection to Monero daemon");
try {
if (daemon == null) throw new RuntimeException("No connection to Monero daemon");
lastInfo = daemon.getInfo();
} catch (Exception e) {

Expand All @@ -753,6 +752,7 @@ private void doPollDaemon() {

// switch to best connection
switchToBestConnection();
if (daemon == null) throw new RuntimeException("No connection to Monero daemon after error handling");
lastInfo = daemon.getInfo(); // caught internally if still fails
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/haveno/core/app/HavenoSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private void maybeInstallDependencies() {
// install monerod
File monerodFile = new File(XmrLocalNode.MONEROD_PATH);
String monerodResourcePath = "bin/" + XmrLocalNode.MONEROD_NAME;
if (!monerodFile.exists() || !FileUtil.resourceEqualToFile(monerodResourcePath, monerodFile)) {
if (!monerodFile.exists() || (config.updateXmrBinaries && !FileUtil.resourceEqualToFile(monerodResourcePath, monerodFile))) {
log.info("Installing monerod");
monerodFile.getParentFile().mkdirs();
FileUtil.resourceToFile("bin/" + XmrLocalNode.MONEROD_NAME, monerodFile);
Expand All @@ -379,7 +379,7 @@ private void maybeInstallDependencies() {
// install monero-wallet-rpc
File moneroWalletRpcFile = new File(XmrWalletService.MONERO_WALLET_RPC_PATH);
String moneroWalletRpcResourcePath = "bin/" + XmrWalletService.MONERO_WALLET_RPC_NAME;
if (!moneroWalletRpcFile.exists() || !FileUtil.resourceEqualToFile(moneroWalletRpcResourcePath, moneroWalletRpcFile)) {
if (!moneroWalletRpcFile.exists() || (config.updateXmrBinaries && !FileUtil.resourceEqualToFile(moneroWalletRpcResourcePath, moneroWalletRpcFile))) {
log.info("Installing monero-wallet-rpc");
moneroWalletRpcFile.getParentFile().mkdirs();
FileUtil.resourceToFile(moneroWalletRpcResourcePath, moneroWalletRpcFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import haveno.proto.grpc.CheckConnectionsRequest;
import haveno.proto.grpc.GetAutoSwitchReply;
import haveno.proto.grpc.GetAutoSwitchRequest;
import haveno.proto.grpc.GetBestAvailableConnectionReply;
import haveno.proto.grpc.GetBestAvailableConnectionRequest;
import haveno.proto.grpc.GetBestConnectionReply;
import haveno.proto.grpc.GetBestConnectionRequest;
import haveno.proto.grpc.GetConnectionReply;
import haveno.proto.grpc.GetConnectionRequest;
import haveno.proto.grpc.GetConnectionsReply;
Expand All @@ -68,7 +68,7 @@
import static haveno.proto.grpc.XmrConnectionsGrpc.getAddConnectionMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getCheckConnectionMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getCheckConnectionsMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getGetBestAvailableConnectionMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getGetBestConnectionMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getGetConnectionMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getGetConnectionsMethod;
import static haveno.proto.grpc.XmrConnectionsGrpc.getRemoveConnectionMethod;
Expand Down Expand Up @@ -201,12 +201,12 @@ public void stopCheckingConnection(StopCheckingConnectionRequest request,
}

@Override
public void getBestAvailableConnection(GetBestAvailableConnectionRequest request,
StreamObserver<GetBestAvailableConnectionReply> responseObserver) {
public void getBestConnection(GetBestConnectionRequest request,
StreamObserver<GetBestConnectionReply> responseObserver) {
handleRequest(responseObserver, () -> {
MoneroRpcConnection connection = coreApi.getBestAvailableXmrConnection();
MoneroRpcConnection connection = coreApi.getBestXmrConnection();
UrlConnection replyConnection = toUrlConnection(connection);
GetBestAvailableConnectionReply.Builder builder = GetBestAvailableConnectionReply.newBuilder();
GetBestConnectionReply.Builder builder = GetBestConnectionReply.newBuilder();
if (replyConnection != null) {
builder.setConnection(replyConnection);
}
Expand Down Expand Up @@ -314,7 +314,7 @@ private Optional<ServerInterceptor> rateMeteringInterceptor() {
put(getCheckConnectionsMethod().getFullMethodName(), new GrpcCallRateMeter(allowedCallsPerTimeWindow, SECONDS));
put(getStartCheckingConnectionMethod().getFullMethodName(), new GrpcCallRateMeter(allowedCallsPerTimeWindow, SECONDS));
put(getStopCheckingConnectionMethod().getFullMethodName(), new GrpcCallRateMeter(allowedCallsPerTimeWindow, SECONDS));
put(getGetBestAvailableConnectionMethod().getFullMethodName(), new GrpcCallRateMeter(allowedCallsPerTimeWindow, SECONDS));
put(getGetBestConnectionMethod().getFullMethodName(), new GrpcCallRateMeter(allowedCallsPerTimeWindow, SECONDS));
put(getSetAutoSwitchMethod().getFullMethodName(), new GrpcCallRateMeter(allowedCallsPerTimeWindow, SECONDS));
}}
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public PasswordDialog(String errorMessage) {

// Set the dialog content
VBox vbox = new VBox(10);
vbox.getChildren().addAll(new ImageView(ImageUtil.getImageByPath("logo_splash.png")), versionField, passwordField, errorMessageField);
vbox.getChildren().addAll(new ImageView(ImageUtil.getImageByPath("logo_splash.png")), passwordField, errorMessageField, versionField);
vbox.setAlignment(Pos.TOP_CENTER);
getDialogPane().setContent(vbox);

Expand Down
6 changes: 3 additions & 3 deletions desktop/src/main/java/haveno/desktop/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,6 @@ private VBox createSplashScreen() {
ImageView logo = new ImageView();
logo.setId(Config.baseCurrencyNetwork() == BaseCurrencyNetwork.XMR_MAINNET ? "image-splash-logo" : "image-splash-testnet-logo");

Label versionLabel = new Label("v" + Version.VERSION);

// createBitcoinInfoBox
xmrSplashInfo = new AutoTooltipLabel();
xmrSplashInfo.textProperty().bind(model.getXmrInfo());
Expand Down Expand Up @@ -624,7 +622,9 @@ private VBox createSplashScreen() {
splashP2PNetworkBox.setPrefHeight(40);
splashP2PNetworkBox.getChildren().addAll(splashP2PNetworkLabel, splashP2PNetworkBusyAnimation, splashP2PNetworkIcon, showTorNetworkSettingsButton);

vBox.getChildren().addAll(logo, versionLabel, blockchainSyncBox, xmrSyncIndicator, splashP2PNetworkBox);
Label versionLabel = new Label("v" + Version.VERSION);

vBox.getChildren().addAll(logo, blockchainSyncBox, xmrSyncIndicator, splashP2PNetworkBox, versionLabel);
return vBox;
}

Expand Down
6 changes: 3 additions & 3 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ service XmrConnections {
}
rpc StopCheckingConnection(StopCheckingConnectionRequest) returns (StopCheckingConnectionReply) {
}
rpc GetBestAvailableConnection(GetBestAvailableConnectionRequest) returns (GetBestAvailableConnectionReply) {
rpc GetBestConnection(GetBestConnectionRequest) returns (GetBestConnectionReply) {
}
rpc SetAutoSwitch(SetAutoSwitchRequest) returns (SetAutoSwitchReply) {
}
Expand Down Expand Up @@ -400,9 +400,9 @@ message StopCheckingConnectionRequest {}

message StopCheckingConnectionReply {}

message GetBestAvailableConnectionRequest {}
message GetBestConnectionRequest {}

message GetBestAvailableConnectionReply {
message GetBestConnectionReply {
UrlConnection connection = 1;
}

Expand Down

0 comments on commit bf973ec

Please sign in to comment.