Skip to content

Commit

Permalink
Minor PR updates, update config path for this feature
Browse files Browse the repository at this point in the history
  • Loading branch information
asoto-iov committed Jan 31, 2024
1 parent a74aa4f commit 64ea989
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class RskSystemProperties extends SystemProperties {
private static final String RPC_MODULES_PATH = "rpc.modules";
private static final String RPC_ETH_GET_LOGS_MAX_BLOCKS_TO_QUERY = "rpc.logs.maxBlocksToQuery";
private static final String RPC_ETH_GET_LOGS_MAX_LOGS_TO_RETURN = "rpc.logs.maxLogsToReturn";
public static final String MINER_GAS_PRICE_CALCULATOR_TYPE = "miner.gasPriceCalculatorType";
public static final String TX_GAS_PRICE_CALCULATOR_TYPE = "transaction.gasPriceCalculatorType";


private static final int CHUNK_SIZE = 192;
Expand Down Expand Up @@ -486,7 +486,7 @@ public double getTopBest() {
}

public GasPriceCalculator.GasCalculatorType getGasCalculatorType() {
String value = configFromFiles.getString(MINER_GAS_PRICE_CALCULATOR_TYPE);
String value = configFromFiles.getString(TX_GAS_PRICE_CALCULATOR_TYPE);
if (value == null || value.isEmpty()) {
return GasPriceCalculator.GasCalculatorType.PLAIN_PERCENTILE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public synchronized Coin getGasPrice() {
return defaultPrice;
}

logger.debug("Gas provided by GasWindowCalc: {}", gasPriceCalculator.getGasPrice());
logger.debug("Gas provided by GasWindowCalc: {}", gasPriceResult.get());

Coin bestBlockPrice = bestBlockPriceRef.get();
if (bestBlockPrice == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class PercentileGasPriceCalculator implements GasPriceCalculator {
private int txIdx = TX_WINDOW_SIZE - 1;
private Coin lastVal;

@Override
public synchronized Optional<Coin> getGasPrice() {
if (txWindow[0] == null) { // for some reason, not filled yet (i.e. not enough blocks on DB)
return Optional.empty();
Expand All @@ -49,7 +50,7 @@ public synchronized Optional<Coin> getGasPrice() {
}

@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
public synchronized void onBlock(Block block, List<TransactionReceipt> receipts) {
onBlock(block.getTransactionsList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.Collections;
import java.util.List;

public class WeightedPercentileCalc {
class WeightedPercentileCalc {

public Coin calculateWeightedPercentile(float percentile, List<WeightedPercentileGasPriceCalculator.GasEntry> gasEntries) {
Coin calculateWeightedPercentile(float percentile, List<WeightedPercentileGasPriceCalculator.GasEntry> gasEntries) {
if (gasEntries == null || gasEntries.isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

public class WeightedPercentileGasPriceCalculator implements GasPriceCalculator {

private static final Logger logger = LoggerFactory.getLogger("wpGasPriceTracker");
private static final int WINDOW_SIZE = 512;
public static final int REFERENCE_PERCENTILE = 25;

Expand All @@ -49,7 +45,7 @@ public WeightedPercentileGasPriceCalculator(WeightedPercentileCalc weightedPerce
}

@Override
public Optional<Coin> getGasPrice() {
public synchronized Optional<Coin> getGasPrice() {
if (cachedGasPrice == null) {
cachedGasPrice = calculateGasPrice();
}
Expand Down Expand Up @@ -87,8 +83,7 @@ private void addTx(Transaction tx, long gasUsed) {

if (txCount > WINDOW_SIZE) {
txCount = 0; // Reset the count
cachedGasPrice = calculateGasPrice();
logger.debug("Updated gas price -> {}", cachedGasPrice);
cachedGasPrice = null; // Invalidate the cached value to force recalculation when queried.
}
}

Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/main/resources/expected.conf
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ wallet = {
miner = {
gasUnitInDollars = <double>
minGasPrice = <minGasPrice>
gasPriceCalculatorType = <gasPriceCalculatorType>
server = {
enabled = <enabled>
isFixedClock = <isFixedClock>
Expand Down Expand Up @@ -203,6 +202,7 @@ transaction = {
threshold = <threshold>
timeout = <timeout>
}
gasPriceCalculatorType = <gasPriceCalculatorType>
gasPriceBump = <gasPriceBump>
accountSlots = <numOfAccountSlots>
accountTxRateLimit = {
Expand Down
4 changes: 3 additions & 1 deletion rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ peer {
miner {
# The default gas price
minGasPrice = 0
gasPriceCalculatorType = PLAIN_PERCENTILE
server {
enabled = false
isFixedClock = false
Expand Down Expand Up @@ -232,6 +231,9 @@ transaction.outdated.threshold = 10
# (suggested value: 10 blocks * 10 seconds by block = 100 seconds)
transaction.outdated.timeout = 650

# choose the type of gas price calculator being PLAIN_PERCENTILE or WEIGHTED_PERCENTILE. The gas used by tx is taken into account only in WEIGHTED_PERCENTILE
transaction.gasPriceCalculatorType = PLAIN_PERCENTILE

# the percentage increase of gasPrice defined to accept a new transaction
# with same nonce and sender while the previous one is not yet processed
transaction.gasPriceBump = 40
Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/test/java/co/rsk/NodeRunnerSmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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;

import org.ethereum.util.RskTestContext;
Expand Down

0 comments on commit 64ea989

Please sign in to comment.