From 751ff93923e31958e0d2d37c4861c256fa243c71 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Tue, 15 Oct 2024 19:28:18 +0300 Subject: [PATCH 1/2] 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); } From de6014f60a57511692d63a3032575b764303053a Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Wed, 16 Oct 2024 14:10:08 +0300 Subject: [PATCH 2/2] feat(stableMinGasPrice): add extra logs to MinimumGasPriceCalculator --- .../src/main/java/co/rsk/mine/BlockGasPriceRange.java | 5 +++++ .../main/java/co/rsk/mine/MinimumGasPriceCalculator.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rskj-core/src/main/java/co/rsk/mine/BlockGasPriceRange.java b/rskj-core/src/main/java/co/rsk/mine/BlockGasPriceRange.java index e69c688ffd1..340a83b9b12 100644 --- a/rskj-core/src/main/java/co/rsk/mine/BlockGasPriceRange.java +++ b/rskj-core/src/main/java/co/rsk/mine/BlockGasPriceRange.java @@ -51,4 +51,9 @@ public Coin getUpperLimit() { public Coin getLowerLimit() { return lowerLimit; } + + @Override + public String toString() { + return "[" + lowerLimit + "; " + upperLimit + "]"; + } } 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 eff3c8e9341..c0569a9f443 100644 --- a/rskj-core/src/main/java/co/rsk/mine/MinimumGasPriceCalculator.java +++ b/rskj-core/src/main/java/co/rsk/mine/MinimumGasPriceCalculator.java @@ -20,6 +20,8 @@ import co.rsk.core.Coin; import co.rsk.mine.gas.provider.MinGasPriceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is the implementation of RSKIP-09 @@ -27,6 +29,8 @@ */ public class MinimumGasPriceCalculator { + private static final Logger logger = LoggerFactory.getLogger(MinimumGasPriceCalculator.class); + private final MinGasPriceProvider minGasPriceProvider; public MinimumGasPriceCalculator(MinGasPriceProvider minGasPriceProvider) { @@ -37,14 +41,16 @@ public Coin calculate(Coin previousMGP) { BlockGasPriceRange priceRange = new BlockGasPriceRange(previousMGP); Coin targetMGP = minGasPriceProvider.getMinGasPriceAsCoin(); if (priceRange.inRange(targetMGP)) { + logger.debug("Previous MGP: {}. Target MGP: {} is in range: {}. Returning target MGP", previousMGP, targetMGP, priceRange); return targetMGP; } if (previousMGP.compareTo(targetMGP) < 0) { + logger.debug("Previous MGP: {}. Target MGP: {} is not in range: {}. Returning upper boundary: {}", previousMGP, targetMGP, priceRange, priceRange.getUpperLimit()); return priceRange.getUpperLimit(); } + logger.debug("Previous MGP: {}. Target MGP: {} is not in range: {}. Returning lower boundary: {}", previousMGP, targetMGP, priceRange, priceRange.getLowerLimit()); return priceRange.getLowerLimit(); } - }