Skip to content

Commit

Permalink
Rename minGasPrice to ethGasPrice from the extraData and track its va…
Browse files Browse the repository at this point in the history
…lue (#103)

* Rename minGasPrice to ethGasPrice from the extraData.

Signed-off-by: Ade Lucas <[email protected]>
  • Loading branch information
cloudspores authored Oct 23, 2024
1 parent eca0286 commit 4357e54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class LineaProfitabilityConfiguration implements LineaOptionsConfiguratio
/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long variableCostWei;

private long ethGasPriceWei;

private double minMargin;
private double estimateGasMinMargin;
private double txPoolMinMargin;
Expand All @@ -46,11 +48,13 @@ public class LineaProfitabilityConfiguration implements LineaOptionsConfiguratio
*
* @param fixedCostWei fixed cost in Wei
* @param variableCostWei variable cost in Wei
* @param ethGasPriceWei gas price in Wei
*/
public synchronized void updateFixedAndVariableCost(
final long fixedCostWei, final long variableCostWei) {
public synchronized void updateFixedVariableAndGasPrice(
final long fixedCostWei, final long variableCostWei, final long ethGasPriceWei) {
this.fixedCostWei = fixedCostWei;
this.variableCostWei = variableCostWei;
this.ethGasPriceWei = ethGasPriceWei;
}

public synchronized long fixedCostWei() {
Expand All @@ -60,4 +64,8 @@ public synchronized long fixedCostWei() {
public synchronized long variableCostWei() {
return variableCostWei;
}

public synchronized long ethGasPriceWei() {
return ethGasPriceWei;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private class Version1Consumer implements ExtraDataConsumer {
private final FieldConsumer[] fieldsSequence;
private final MutableLong currFixedCostKWei = new MutableLong();
private final MutableLong currVariableCostKWei = new MutableLong();
private final MutableLong currEthGasPriceKWei = new MutableLong();

public Version1Consumer(final LineaProfitabilityConfiguration profitabilityConf) {
this.profitabilityConf = profitabilityConf;
Expand All @@ -113,11 +114,11 @@ public Version1Consumer(final LineaProfitabilityConfiguration profitabilityConf)
final FieldConsumer variableGasCostField =
new FieldConsumer<>(
"variableGasCost", 4, ExtraDataConsumer::toLong, currVariableCostKWei::setValue);
final FieldConsumer minGasPriceField =
new FieldConsumer<>("minGasPrice", 4, ExtraDataConsumer::toLong, this::updateMinGasPrice);
final FieldConsumer ethGasPriceField =
new FieldConsumer<>("ethGasPrice", 4, ExtraDataConsumer::toLong, this::updateEthGasPrice);

this.fieldsSequence =
new FieldConsumer[] {fixedGasCostField, variableGasCostField, minGasPriceField};
new FieldConsumer[] {fixedGasCostField, variableGasCostField, ethGasPriceField};
}

public boolean canConsume(final Bytes rawExtraData) {
Expand All @@ -132,14 +133,16 @@ public synchronized void accept(final Bytes extraData) {
startIndex += fieldConsumer.length;
}

profitabilityConf.updateFixedAndVariableCost(
profitabilityConf.updateFixedVariableAndGasPrice(
currFixedCostKWei.longValue() * WEI_IN_KWEI,
currVariableCostKWei.longValue() * WEI_IN_KWEI);
currVariableCostKWei.longValue() * WEI_IN_KWEI,
currEthGasPriceKWei.longValue() * WEI_IN_KWEI);
}

void updateMinGasPrice(final Long minGasPriceKWei) {
void updateEthGasPrice(final Long ethGasPriceKWei) {
currEthGasPriceKWei.setValue(ethGasPriceKWei);
if (profitabilityConf.extraDataSetMinGasPriceEnabled()) {
final var minGasPriceWei = Wei.of(minGasPriceKWei).multiply(WEI_IN_KWEI);
final var minGasPriceWei = Wei.of(ethGasPriceKWei).multiply(WEI_IN_KWEI);
final var resp =
rpcEndpointService.call(
"miner_setMinGasPrice", new Object[] {minGasPriceWei.toShortHexString()});
Expand Down

0 comments on commit 4357e54

Please sign in to comment.