Skip to content

Commit

Permalink
feat(stableMinGasPrice): add extra logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk committed Oct 17, 2024
1 parent 1e3d877 commit 751ff93
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public class MinimumGasPriceCalculator {

private MinGasPriceProvider minGasPriceProvider;
private final MinGasPriceProvider minGasPriceProvider;

public MinimumGasPriceCalculator(MinGasPriceProvider minGasPriceProvider) {
this.minGasPriceProvider = minGasPriceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public long getMinGasPrice(boolean wait) {
Future<Long> 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);
Expand All @@ -73,7 +74,10 @@ public long getMinGasPrice(boolean wait) {
}
}

return getLastMinGasPrice();
long minGasPrice = getLastMinGasPrice();
logger.debug("getMinGasPrice returning cached minGasPrice: {}", minGasPrice);

return minGasPrice;
}

@Override
Expand Down Expand Up @@ -104,12 +108,14 @@ private long calculateMinGasPriceBasedOnBtcPrice(long btcValue) {
private synchronized Future<Long> fetchPriceAsync() {
Future<Long> future = priceFuture.get();
if (future != null) {
logger.debug("fetchPriceAsync skipped as there is already price fetching in progress...");
return future;
}

CompletableFuture<Long> newFuture = new CompletableFuture<>();
priceFuture.set(newFuture);

logger.debug("fetchPriceAsync...");
new Thread(() -> {
Optional<Long> priceResponse = fetchPriceSync();
newFuture.complete(priceResponse.orElse(getLastMinGasPrice()));
Expand All @@ -120,12 +126,16 @@ private synchronized Future<Long> fetchPriceAsync() {
}

private Optional<Long> fetchPriceSync() {
logger.debug("fetchPriceSync...");
Optional<Long> 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);
}

Expand Down

0 comments on commit 751ff93

Please sign in to comment.