From f7793443f326ca3a69702ce98c409286e150fb37 Mon Sep 17 00:00:00 2001 From: kennycud Date: Sat, 23 Mar 2024 06:25:31 -0700 Subject: [PATCH 1/2] call current blockchain height to ensure the current server is set to the blockchain provider and sort the servers to ensure the current server is listed first --- .../qortal/api/resource/CrossChainUtils.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/qortal/api/resource/CrossChainUtils.java b/src/main/java/org/qortal/api/resource/CrossChainUtils.java index b07a9d6c4..7410ca2b1 100644 --- a/src/main/java/org/qortal/api/resource/CrossChainUtils.java +++ b/src/main/java/org/qortal/api/resource/CrossChainUtils.java @@ -16,12 +16,7 @@ import org.qortal.repository.DataException; import org.qortal.repository.Repository; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @@ -31,10 +26,20 @@ public class CrossChainUtils { public static ServerConfigurationInfo buildServerConfigurationInfo(Bitcoiny blockchain) { BitcoinyBlockchainProvider blockchainProvider = blockchain.getBlockchainProvider(); + + // the only reason this is called is to ensure the current server is set on the blockchain provider, + // if there is an exception, then ignore it + try { + blockchainProvider.getCurrentHeight(); + } catch (ForeignBlockchainException e) { + } + ChainableServer currentServer = blockchainProvider.getCurrentServer(); return new ServerConfigurationInfo( - buildInfos(blockchainProvider.getServers(), currentServer), + buildInfos(blockchainProvider.getServers(), currentServer).stream() + .sorted(Comparator.comparing(ServerInfo::isCurrent).reversed()) + .collect(Collectors.toList()), buildInfos(blockchainProvider.getRemainingServers(), currentServer), buildInfos(blockchainProvider.getUselessServers(), currentServer) ); From e83b2263f06733ae7945c349088b0b77222d90c8 Mon Sep 17 00:00:00 2001 From: kennycud Date: Sat, 23 Mar 2024 09:42:33 -0700 Subject: [PATCH 2/2] some simple error logging --- src/main/java/org/qortal/api/resource/CrossChainUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/qortal/api/resource/CrossChainUtils.java b/src/main/java/org/qortal/api/resource/CrossChainUtils.java index 7410ca2b1..2c1fabc25 100644 --- a/src/main/java/org/qortal/api/resource/CrossChainUtils.java +++ b/src/main/java/org/qortal/api/resource/CrossChainUtils.java @@ -32,6 +32,7 @@ public static ServerConfigurationInfo buildServerConfigurationInfo(Bitcoiny bloc try { blockchainProvider.getCurrentHeight(); } catch (ForeignBlockchainException e) { + LOGGER.warn("Problems getting block height before building server configuration infos"); } ChainableServer currentServer = blockchainProvider.getCurrentServer();