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

Configurable Fiat-Based Stable MinGasPrice #2310

Merged
merged 26 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2031de7
Adding Default Min Gas Price provider
asoto-iov May 3, 2024
760908a
Adding StableMinGasPrice related class structure for a future impleme…
asoto-iov May 10, 2024
db7750c
Updated structure
asoto-iov May 15, 2024
3bc0a57
Adding tests
asoto-iov May 17, 2024
bf975c5
fixing sonar issue
asoto-iov May 17, 2024
923447f
feat(smgp): adds context fetching callback to providers
jurajpiar Jun 6, 2024
3dab053
feat(stableMinGasPrice): makes only ethCall use context
jurajpiar Jun 7, 2024
f7a212e
Merge pull request #2454 from rsksmart/juraj/eth_call_stableGasPrice_…
Vovchyk Jun 13, 2024
39d0e26
Adding new Stable Gas Price Web Provider
asoto-iov Jun 7, 2024
26fa303
Updating tests
asoto-iov Jun 13, 2024
6b10626
Addressing pr comments with a small refactor
asoto-iov Jun 20, 2024
4d5e1d8
fix test
asoto-iov Jun 20, 2024
002510e
Addressing PR improvement and unifiying refresh rate logic into the a…
asoto-iov Jun 20, 2024
087e6a0
Merge pull request #2455 from rsksmart/adding_web_provider
Vovchyk Jun 26, 2024
a3118a5
Merge branch 'master' into feature/include_stable_minGasPrice_provider
Vovchyk Jun 26, 2024
fdf71ad
Merge branch 'master' into feature/include_stable_minGasPrice_provider
Vovchyk Jul 8, 2024
08c7e9a
Merge branch 'master' into feature/include_stable_minGasPrice_provider
Vovchyk Jul 12, 2024
9c5f722
feat(stableMinGasPrice): refactoring
Vovchyk Jul 17, 2024
e360b7e
feat(stableMinGasPrice): review suggestions
Vovchyk Jul 18, 2024
144e718
Merge pull request #2598 from rsksmart/vovchyk/stablemingasprice-ref
Vovchyk Jul 18, 2024
30a0ee8
Merge branch 'master' into feature/include_stable_minGasPrice_provider
Vovchyk Jul 18, 2024
f8fbcaa
Merge pull request #2722 from rsksmart/master
Vovchyk Sep 12, 2024
1bf9d53
fix(stableMinGasPrice): fix time units conversion
Vovchyk Sep 12, 2024
1265ac9
fix(stableMinGasPrice): fetch prices in background
Vovchyk Sep 13, 2024
8cecf43
fix(stableMinGasPrice): apply naming suggestions
Vovchyk Sep 16, 2024
eede703
Merge branch 'master' into feature/include_stable_minGasPrice_provider
Vovchyk Sep 19, 2024
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
22 changes: 17 additions & 5 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.cli.CliArgs;
import co.rsk.cli.RskCli;
import co.rsk.config.*;
import co.rsk.config.mining.StableMinGasPriceSystemConfig;
import co.rsk.core.*;
import co.rsk.core.bc.*;
import co.rsk.crypto.Keccak256;
Expand All @@ -40,6 +41,8 @@
import co.rsk.metrics.HashRateCalculatorMining;
import co.rsk.metrics.HashRateCalculatorNonMining;
import co.rsk.mine.*;
import co.rsk.mine.gas.provider.MinGasPriceProvider;
import co.rsk.mine.gas.provider.MinGasPriceProviderFactory;
import co.rsk.net.*;
import co.rsk.net.discovery.KnownPeersHandler;
import co.rsk.net.discovery.PeerExplorer;
Expand Down Expand Up @@ -253,6 +256,7 @@ public class RskContext implements NodeContext, NodeBootstrapper {
private TxQuotaChecker txQuotaChecker;
private GasPriceTracker gasPriceTracker;
private BlockChainFlusher blockChainFlusher;
private MinGasPriceProvider minGasPriceProvider;
private final Map<String, DbKind> dbPathToDbKindMap = new HashMap<>();

private volatile boolean closed;
Expand Down Expand Up @@ -1842,7 +1846,7 @@ private BlockToMineBuilder getBlockToMineBuilder() {
getMinerClock(),
getBlockFactory(),
getBlockExecutor(),
new MinimumGasPriceCalculator(Coin.valueOf(getMiningConfig().getMinGasPriceTarget())),
new MinimumGasPriceCalculator(getMinGasPriceProvider()),
new MinerUtils(),
getBlockTxSignatureCache()
);
Expand All @@ -1851,6 +1855,16 @@ private BlockToMineBuilder getBlockToMineBuilder() {
return blockToMineBuilder;
}

private MinGasPriceProvider getMinGasPriceProvider() {
if (minGasPriceProvider == null) {
long minGasPrice = getRskSystemProperties().minerMinGasPrice();
StableMinGasPriceSystemConfig stableGasPriceSystemConfig = getRskSystemProperties().getStableGasPriceSystemConfig();
minGasPriceProvider = MinGasPriceProviderFactory.create(minGasPrice, stableGasPriceSystemConfig, this::getEthModule);
}
logger.debug("MinGasPriceProvider type: {}", minGasPriceProvider.getType().name());
return minGasPriceProvider;
}

private BlockNodeInformation getBlockNodeInformation() {
if (blockNodeInformation == null) {
blockNodeInformation = new BlockNodeInformation();
Expand Down Expand Up @@ -2142,7 +2156,6 @@ private MiningConfig getMiningConfig() {
rskSystemProperties.coinbaseAddress(),
rskSystemProperties.minerMinFeesNotifyInDollars(),
rskSystemProperties.minerGasUnitInDollars(),
rskSystemProperties.minerMinGasPrice(),
rskSystemProperties.getNetworkConstants().getUncleListLimit(),
rskSystemProperties.getNetworkConstants().getUncleGenerationLimit(),
new GasLimitConfig(
Expand All @@ -2151,8 +2164,7 @@ private MiningConfig getMiningConfig() {
rskSystemProperties.getForceTargetGasLimit()
),
rskSystemProperties.isMinerServerFixedClock(),
rskSystemProperties.workSubmissionRateLimitInMills()
);
rskSystemProperties.workSubmissionRateLimitInMills());
}

return miningConfig;
Expand Down Expand Up @@ -2207,4 +2219,4 @@ private void checkIfNotClosed() {
throw new IllegalStateException("RSK Context is closed and cannot be in use anymore");
}
}
}
}
8 changes: 1 addition & 7 deletions rskj-core/src/main/java/co/rsk/config/MiningConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ public class MiningConfig {
private final RskAddress coinbaseAddress;
private final double minFeesNotifyInDollars;
private final double minerGasUnitInDollars;
private final long minGasPriceTarget;
private final int uncleListLimit;
private final int uncleGenerationLimit;
private final GasLimitConfig gasLimit;
private final boolean isFixedClock;
private final long workSubmissionRateLimitInMills;

public MiningConfig(RskAddress coinbaseAddress, double minFeesNotifyInDollars, double minerGasUnitInDollars,
long minGasPriceTarget, int uncleListLimit, int uncleGenerationLimit, GasLimitConfig gasLimit,
int uncleListLimit, int uncleGenerationLimit, GasLimitConfig gasLimit,
boolean isFixedClock, long workSubmissionRateLimitInMills) {
this.coinbaseAddress = coinbaseAddress;
this.minFeesNotifyInDollars = minFeesNotifyInDollars;
this.minerGasUnitInDollars = minerGasUnitInDollars;
this.minGasPriceTarget= minGasPriceTarget;
this.uncleListLimit = uncleListLimit;
this.uncleGenerationLimit = uncleGenerationLimit;
this.gasLimit = gasLimit;
Expand All @@ -62,10 +60,6 @@ public double getGasUnitInDollars() {
return minerGasUnitInDollars;
}

public long getMinGasPriceTarget() {
return minGasPriceTarget;
}

public int getUncleListLimit() {
return uncleListLimit;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of RskJ
* Copyright (C) 2024 RSK Labs Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package co.rsk.config.mining;

import com.typesafe.config.Config;

public class EthCallMinGasPriceSystemConfig {
private static final String FROM_PROPERTY = "from";
private static final String TO_PROPERTY = "to";
private static final String DATA_PROPERTY = "data";
private final String address;
private final String from;
private final String data;

public EthCallMinGasPriceSystemConfig(Config config) {
address = config.getString(TO_PROPERTY);
from = config.getString(FROM_PROPERTY);
data = config.getString(DATA_PROPERTY);
}

public String getAddress() {
return address;
}

public String getFrom() {
return from;
}

public String getData() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of RskJ
* Copyright (C) 2024 RSK Labs Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package co.rsk.config.mining;

import com.typesafe.config.Config;

import java.time.Duration;
import java.util.Objects;

public class HttpGetStableMinGasSystemConfig {
private static final String URL_PROPERTY = "url";
private static final String JSON_PATH = "jsonPath";
private static final String TIMEOUT_PROPERTY = "timeout";

private final String url;
private final String jsonPath;
private final Duration timeout;

public HttpGetStableMinGasSystemConfig(Config config) {
this.url = Objects.requireNonNull(config.getString(URL_PROPERTY));
this.jsonPath = Objects.requireNonNull(config.getString(JSON_PATH));
this.timeout = Objects.requireNonNull(config.getDuration(TIMEOUT_PROPERTY));
}

public String getUrl() {
return url;
}

public String getJsonPath() {
return jsonPath;
}

public Duration getTimeout() {
return timeout;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of RskJ
* Copyright (C) 2024 RSK Labs Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package co.rsk.config.mining;

import co.rsk.mine.gas.provider.MinGasPriceProviderType;
import com.typesafe.config.Config;

import java.time.Duration;

public class StableMinGasPriceSystemConfig {
public static final String STABLE_GAS_PRICE_CONFIG_PATH_PROPERTY = "miner.stableGasPrice";

private static final String ENABLED_PROPERTY = "enabled";
private static final String REFRESH_RATE_PROPERTY = "refreshRate";
private static final String MIN_STABLE_GAS_PRICE_PROPERTY = "minStableGasPrice";
private static final String METHOD_PROPERTY = "source.method";
private static final String PARAMS_PROPERTY = "source.params";

private final Duration refreshRate;
private final Long minStableGasPrice;
private final boolean enabled;
private final MinGasPriceProviderType method;
private final Config config;

public StableMinGasPriceSystemConfig(Config config) {
this.enabled = config.hasPath(ENABLED_PROPERTY) && config.getBoolean(ENABLED_PROPERTY);
this.refreshRate = this.enabled && config.hasPath(REFRESH_RATE_PROPERTY) ? config.getDuration(REFRESH_RATE_PROPERTY) : Duration.ZERO;
this.minStableGasPrice = this.enabled && config.hasPath(MIN_STABLE_GAS_PRICE_PROPERTY) ? config.getLong(MIN_STABLE_GAS_PRICE_PROPERTY) : 0;
this.method = this.enabled ? config.getEnum(MinGasPriceProviderType.class, METHOD_PROPERTY) : MinGasPriceProviderType.FIXED;
this.config = config;
}

public Duration getRefreshRate() {
return refreshRate;
}

public Long getMinStableGasPrice() {
return minStableGasPrice;
}

public boolean isEnabled() {
return enabled;
}

public HttpGetStableMinGasSystemConfig getHttpGetConfig() {
return new HttpGetStableMinGasSystemConfig(config.getConfig(PARAMS_PROPERTY));
}

public EthCallMinGasPriceSystemConfig getEthCallConfig() {
return new EthCallMinGasPriceSystemConfig(config.getConfig(PARAMS_PROPERTY));
}

public MinGasPriceProviderType getMethod() {
return method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@
package co.rsk.mine;

import co.rsk.core.Coin;
import co.rsk.mine.gas.provider.MinGasPriceProvider;

/**
* This is the implementation of RSKIP-09
* Created by mario on 22/12/16.
*/
public class MinimumGasPriceCalculator {

private final Coin targetMGP;
private MinGasPriceProvider minGasPriceProvider;

public MinimumGasPriceCalculator(Coin targetMGP) {
this.targetMGP = targetMGP;
public MinimumGasPriceCalculator(MinGasPriceProvider minGasPriceProvider) {
this.minGasPriceProvider = minGasPriceProvider;
}

public Coin calculate(Coin previousMGP) {
BlockGasPriceRange priceRange = new BlockGasPriceRange(previousMGP);
Coin targetMGP = minGasPriceProvider.getMinGasPriceAsCoin();
if (priceRange.inRange(targetMGP)) {
return targetMGP;
}
Expand All @@ -44,4 +46,5 @@ public Coin calculate(Coin previousMGP) {

return priceRange.getLowerLimit();
}

}
Loading
Loading