Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stableMinGasPrice): add extra logs #2807

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions rskj-core/src/main/java/co/rsk/mine/BlockGasPriceRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public Coin getUpperLimit() {
public Coin getLowerLimit() {
return lowerLimit;
}

@Override
public String toString() {
return "[" + lowerLimit + "; " + upperLimit + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@

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
* Created by mario on 22/12/16.
*/
public class MinimumGasPriceCalculator {

private MinGasPriceProvider minGasPriceProvider;
private static final Logger logger = LoggerFactory.getLogger(MinimumGasPriceCalculator.class);

private final MinGasPriceProvider minGasPriceProvider;

public MinimumGasPriceCalculator(MinGasPriceProvider minGasPriceProvider) {
this.minGasPriceProvider = minGasPriceProvider;
Expand All @@ -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();
}

}
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
Loading