Skip to content

Commit

Permalink
Increase read timeout for ETH1 requests (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton authored Jul 31, 2020
1 parent 4c4a83b commit 0460c61
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +45,8 @@

public class PowchainService extends Service {

private static final Logger LOG = LogManager.getLogger();

private final Eth1DepositManager eth1DepositManager;
private final Eth1HeadTracker headTracker;

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0460c61

Please sign in to comment.