From 751ff93923e31958e0d2d37c4861c256fa243c71 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Tue, 15 Oct 2024 19:28:18 +0300 Subject: [PATCH] feat(stableMinGasPrice): add extra logs --- rskj-core/src/main/java/co/rsk/RskContext.java | 2 +- .../java/co/rsk/mine/MinimumGasPriceCalculator.java | 2 +- .../gas/provider/MinGasPriceProviderFactory.java | 10 +++++++--- .../mine/gas/provider/StableMinGasPriceProvider.java | 12 +++++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/RskContext.java b/rskj-core/src/main/java/co/rsk/RskContext.java index 3ca9a4ac69e..e507d3bc5ce 100644 --- a/rskj-core/src/main/java/co/rsk/RskContext.java +++ b/rskj-core/src/main/java/co/rsk/RskContext.java @@ -1862,7 +1862,7 @@ private MinGasPriceProvider getMinGasPriceProvider() { StableMinGasPriceSystemConfig stableGasPriceSystemConfig = getRskSystemProperties().getStableGasPriceSystemConfig(); minGasPriceProvider = MinGasPriceProviderFactory.create(minGasPrice, stableGasPriceSystemConfig, this::getEthModule); } - logger.debug("MinGasPriceProvider type: {}", minGasPriceProvider.getType().name()); + return minGasPriceProvider; } diff --git a/rskj-core/src/main/java/co/rsk/mine/MinimumGasPriceCalculator.java b/rskj-core/src/main/java/co/rsk/mine/MinimumGasPriceCalculator.java index 38c16a6c3e8..eff3c8e9341 100644 --- a/rskj-core/src/main/java/co/rsk/mine/MinimumGasPriceCalculator.java +++ b/rskj-core/src/main/java/co/rsk/mine/MinimumGasPriceCalculator.java @@ -27,7 +27,7 @@ */ public class MinimumGasPriceCalculator { - private MinGasPriceProvider minGasPriceProvider; + private final MinGasPriceProvider minGasPriceProvider; public MinimumGasPriceCalculator(MinGasPriceProvider minGasPriceProvider) { this.minGasPriceProvider = minGasPriceProvider; diff --git a/rskj-core/src/main/java/co/rsk/mine/gas/provider/MinGasPriceProviderFactory.java b/rskj-core/src/main/java/co/rsk/mine/gas/provider/MinGasPriceProviderFactory.java index 844619cf4a5..ceedca6532e 100644 --- a/rskj-core/src/main/java/co/rsk/mine/gas/provider/MinGasPriceProviderFactory.java +++ b/rskj-core/src/main/java/co/rsk/mine/gas/provider/MinGasPriceProviderFactory.java @@ -37,28 +37,32 @@ public static MinGasPriceProvider create(long fixedMinGasPrice, StableMinGasPric FixedMinGasPriceProvider fixedMinGasPriceProvider = new FixedMinGasPriceProvider(fixedMinGasPrice); if (stableMinGasPriceSystemConfig == null) { - logger.warn("Could not find stable min gas price system config, using {} provider", fixedMinGasPriceProvider.getType().name()); + logger.warn("Could not find stable min gas price config. Falling back to {} with fixedMinGasPrice: {}", fixedMinGasPriceProvider.getType(), fixedMinGasPrice); return fixedMinGasPriceProvider; } if (!stableMinGasPriceSystemConfig.isEnabled()) { + logger.info("Stable min gas price is disabled. Falling back to {} with fixedMinGasPrice: {}", fixedMinGasPriceProvider.getType(), fixedMinGasPrice); return fixedMinGasPriceProvider; } MinGasPriceProviderType method = stableMinGasPriceSystemConfig.getMethod(); if (method == null) { - logger.error("Could not find valid method in config, using fallback provider: {}", fixedMinGasPriceProvider.getType().name()); + logger.warn("Could not find valid method in config. Falling back to {} with fixedMinGasPrice: {}", fixedMinGasPriceProvider.getType(), fixedMinGasPrice); return fixedMinGasPriceProvider; } switch (method) { case HTTP_GET: + logger.info("Creating 'Http-Get' stable min gas price provider"); return new HttpGetMinGasPriceProvider(stableMinGasPriceSystemConfig, fixedMinGasPriceProvider); case ETH_CALL: + logger.info("Creating 'Eth-Call' stable min gas price provider"); return new EthCallMinGasPriceProvider(fixedMinGasPriceProvider, stableMinGasPriceSystemConfig, ethModuleSupplier); case FIXED: + logger.info("Creating 'Fixed' min gas price provider with fixedMinGasPrice: {}", fixedMinGasPrice); return fixedMinGasPriceProvider; default: - logger.debug("Could not find a valid implementation for the method {}. Returning fallback provider {}", method, fixedMinGasPriceProvider.getType().name()); + logger.warn("Could not find a valid implementation for the method {}. Creating {} fallback provider with fixedMinGasPrice: {}", method, fixedMinGasPriceProvider.getType(), fixedMinGasPrice); return fixedMinGasPriceProvider; } } diff --git a/rskj-core/src/main/java/co/rsk/mine/gas/provider/StableMinGasPriceProvider.java b/rskj-core/src/main/java/co/rsk/mine/gas/provider/StableMinGasPriceProvider.java index 72f83d02a74..49a69c87c20 100644 --- a/rskj-core/src/main/java/co/rsk/mine/gas/provider/StableMinGasPriceProvider.java +++ b/rskj-core/src/main/java/co/rsk/mine/gas/provider/StableMinGasPriceProvider.java @@ -63,6 +63,7 @@ public long getMinGasPrice(boolean wait) { Future priceFuture = fetchPriceAsync(); if (wait || priceFuture.isDone()) { try { + logger.debug("getMinGasPrice returning fetched minGasPrice: {}", priceFuture.get()); return priceFuture.get(); } catch (InterruptedException e) { logger.error("Min gas price fetching was interrupted", e); @@ -73,7 +74,10 @@ public long getMinGasPrice(boolean wait) { } } - return getLastMinGasPrice(); + long minGasPrice = getLastMinGasPrice(); + logger.debug("getMinGasPrice returning cached minGasPrice: {}", minGasPrice); + + return minGasPrice; } @Override @@ -104,12 +108,14 @@ private long calculateMinGasPriceBasedOnBtcPrice(long btcValue) { private synchronized Future fetchPriceAsync() { Future future = priceFuture.get(); if (future != null) { + logger.debug("fetchPriceAsync skipped as there is already price fetching in progress..."); return future; } CompletableFuture newFuture = new CompletableFuture<>(); priceFuture.set(newFuture); + logger.debug("fetchPriceAsync..."); new Thread(() -> { Optional priceResponse = fetchPriceSync(); newFuture.complete(priceResponse.orElse(getLastMinGasPrice())); @@ -120,12 +126,16 @@ private synchronized Future fetchPriceAsync() { } private Optional fetchPriceSync() { + logger.debug("fetchPriceSync..."); Optional priceResponse = getBtcExchangeRate(); if (priceResponse.isPresent() && priceResponse.get() > 0) { long result = calculateMinGasPriceBasedOnBtcPrice(priceResponse.get()); lastMinGasPrice = result; lastUpdateTimeMillis = System.currentTimeMillis(); numOfFailures.set(0); + + logger.debug("fetchPriceSync completed with priceResponse: {}, lastMinGasPrice: {}", priceResponse, lastMinGasPrice); + return Optional.of(result); }