From 0460c61708f0d5dfbf200c5f146548cff1c87cfd Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Fri, 31 Jul 2020 12:50:45 +1000 Subject: [PATCH] Increase read timeout for ETH1 requests (#2485) --- .../teku/pow/DepositProcessingController.java | 2 +- .../services/powchain/PowchainService.java | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pow/src/main/java/tech/pegasys/teku/pow/DepositProcessingController.java b/pow/src/main/java/tech/pegasys/teku/pow/DepositProcessingController.java index 7a1692e8942..0634da795c7 100644 --- a/pow/src/main/java/tech/pegasys/teku/pow/DepositProcessingController.java +++ b/pow/src/main/java/tech/pegasys/teku/pow/DepositProcessingController.java @@ -107,7 +107,7 @@ private synchronized void fetchLatestSubscriptionDepositsOverRange() { active = true; fromBlock = latestSuccessfullyQueriedBlock.add(BigInteger.ONE); - toBlock = latestCanonicalBlockNumber; + toBlock = latestCanonicalBlockNumber.min(fromBlock.add(BigInteger.valueOf(500_000))); depositFetcher .fetchDepositsInRange(fromBlock, toBlock) diff --git a/services/powchain/src/main/java/tech/pegasys/teku/services/powchain/PowchainService.java b/services/powchain/src/main/java/tech/pegasys/teku/services/powchain/PowchainService.java index fdc9d7a9995..7930c2202e8 100644 --- a/services/powchain/src/main/java/tech/pegasys/teku/services/powchain/PowchainService.java +++ b/services/powchain/src/main/java/tech/pegasys/teku/services/powchain/PowchainService.java @@ -16,6 +16,11 @@ import static tech.pegasys.teku.pow.api.Eth1DataCachePeriodCalculator.calculateEth1DataCacheDurationPriorToCurrentTime; import static tech.pegasys.teku.util.config.Constants.MAXIMUM_CONCURRENT_ETH1_REQUESTS; +import java.util.concurrent.TimeUnit; +import okhttp3.OkHttpClient; +import okhttp3.logging.HttpLoggingInterceptor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.web3j.protocol.Web3j; import org.web3j.protocol.http.HttpService; import tech.pegasys.teku.infrastructure.async.AsyncRunner; @@ -40,6 +45,8 @@ public class PowchainService extends Service { + private static final Logger LOG = LogManager.getLogger(); + private final Eth1DepositManager eth1DepositManager; private final Eth1HeadTracker headTracker; @@ -48,9 +55,7 @@ public PowchainService(final ServiceConfig config) { AsyncRunner asyncRunner = config.createAsyncRunner("powchain"); - final HttpService web3jService = new HttpService(tekuConfig.getEth1Endpoint()); - web3jService.addHeader("User-Agent", VersionProvider.VERSION); - Web3j web3j = Web3j.build(web3jService); + Web3j web3j = createWeb3j(tekuConfig); final Eth1Provider eth1Provider = new ThrottlingEth1Provider( @@ -101,6 +106,26 @@ public PowchainService(final ServiceConfig config) { new MinimumGenesisTimeBlockFinder(eth1Provider)); } + private Web3j createWeb3j(final TekuConfiguration tekuConfig) { + final HttpService web3jService = + new HttpService(tekuConfig.getEth1Endpoint(), createOkHttpClient()); + web3jService.addHeader("User-Agent", VersionProvider.VERSION); + return Web3j.build(web3jService); + } + + private static OkHttpClient createOkHttpClient() { + final OkHttpClient.Builder builder = + new OkHttpClient.Builder() + // Increased read timeout allows ETH1 nodes time to process large log requests + .readTimeout(1, TimeUnit.MINUTES); + if (LOG.isTraceEnabled()) { + HttpLoggingInterceptor logging = new HttpLoggingInterceptor(LOG::trace); + logging.setLevel(HttpLoggingInterceptor.Level.BODY); + builder.addInterceptor(logging); + } + return builder.build(); + } + @Override protected SafeFuture doStart() { return SafeFuture.allOfFailFast(