diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index b6f22ca6..bee6af5b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -60,7 +60,7 @@ public class Config { private boolean useProxy; private String proxyServer; private int maxServerTimeout = DEFAULT_MAX_TIMEOUT; - private int batchPageSize = DEFAULT_PAGE_SIZE; + private int maxPageSize = DEFAULT_PAGE_SIZE; private boolean usePayNym; private boolean sameAppMixing; private Double appWidth; @@ -503,8 +503,8 @@ public class Config { return maxServerTimeout; } - public int getBatchPageSize() { - return batchPageSize; + public int getMaxPageSize() { + return maxPageSize; } public boolean isUsePayNym() { diff --git a/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java b/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java index 9ab26f80..c97b3563 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/PagedBatchRequestBuilder.java @@ -17,7 +17,7 @@ import static com.sparrowwallet.sparrow.net.BatchedElectrumServerRpc.DEFAULT_MAX import static com.sparrowwallet.sparrow.net.BatchedElectrumServerRpc.RETRY_DELAY_SECS; public class PagedBatchRequestBuilder extends AbstractBuilder { - public static final int DEFAULT_PAGE_SIZE = 500; + public static final int DEFAULT_PAGE_SIZE = 100; private final AtomicLong counter; @@ -147,11 +147,19 @@ public class PagedBatchRequestBuilder extends AbstractBuilder { } private int getPageSize() { - int pageSize = Config.get().getBatchPageSize(); + int pageSize = Config.get().getMaxPageSize(); if(pageSize < 1) { pageSize = DEFAULT_PAGE_SIZE; } + //Halve the page size if there have been timeouts + if(transport instanceof TimeoutCounter timeoutCounter) { + int timeouts = timeoutCounter.getTimeoutCount(); + if(timeouts > 0) { + return pageSize / 2; + } + } + return pageSize; } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/TcpTransport.java b/src/main/java/com/sparrowwallet/sparrow/net/TcpTransport.java index 0d9504b9..b9dabb07 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/TcpTransport.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/TcpTransport.java @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; -public class TcpTransport implements Transport, Closeable { +public class TcpTransport implements Transport, Closeable, TimeoutCounter { private static final Logger log = LoggerFactory.getLogger(TcpTransport.class); public static final int DEFAULT_PORT = 50001; @@ -251,6 +251,11 @@ public class TcpTransport implements Transport, Closeable { } } + @Override + public int getTimeoutCount() { + return readTimeoutIndex; + } + private static class Rpc { public String id; diff --git a/src/main/java/com/sparrowwallet/sparrow/net/TimeoutCounter.java b/src/main/java/com/sparrowwallet/sparrow/net/TimeoutCounter.java new file mode 100644 index 00000000..450a9072 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/net/TimeoutCounter.java @@ -0,0 +1,5 @@ +package com.sparrowwallet.sparrow.net; + +public interface TimeoutCounter { + int getTimeoutCount(); +}