Skip to content

Commit

Permalink
make FeeMarket constructors package private
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner committed Jan 17, 2025
1 parent 13e15a9 commit 178135e
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
Expand Down Expand Up @@ -106,7 +106,7 @@ public class MergeBesuControllerBuilderTest {

BigInteger networkId = BigInteger.ONE;
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();
private final BaseFeeMarket feeMarket = new LondonFeeMarket(0, Optional.of(Wei.of(42)));
private final BaseFeeMarket feeMarket = FeeMarket.london(0, Optional.of(Wei.of(42)));
private final TransactionPoolConfiguration poolConfiguration =
TransactionPoolConfiguration.DEFAULT;
private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.StubMetricsSystem;
Expand Down Expand Up @@ -158,7 +158,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
private final Address suggestedFeeRecipient = Address.ZERO;
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();
private final BaseFeeMarket feeMarket =
new LondonFeeMarket(0, genesisState.getBlock().getHeader().getBaseFee());
FeeMarket.london(0, genesisState.getBlock().getHeader().getBaseFee());

private final org.hyperledger.besu.metrics.StubMetricsSystem metricsSystem =
new StubMetricsSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import org.hyperledger.besu.util.LogConfigurator;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class MergeReorgTest implements MergeGenesisConfigHelper {
private final Address coinbase = genesisAllocations(getPowGenesisConfig()).findFirst().get();
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();
private final BaseFeeMarket feeMarket =
new LondonFeeMarket(0, genesisState.getBlock().getHeader().getBaseFee());
FeeMarket.london(0, genesisState.getBlock().getHeader().getBaseFee());

@BeforeEach
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LegacyFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.evm.log.LogsBloomFilter;

import java.util.HashMap;
Expand Down Expand Up @@ -289,11 +286,11 @@ private void verifyGasPriceLimit(
}

private void mockBaseFeeMarket() {
mockFeeMarket(new LondonFeeMarket(0));
mockFeeMarket(FeeMarket.london(0));
}

private void mockGasPriceMarket() {
mockFeeMarket(new LegacyFeeMarket());
mockFeeMarket(FeeMarket.legacy());
}

private void mockFeeMarket(final FeeMarket feeMarket) {
Expand All @@ -313,7 +310,7 @@ private void mockBlockchain(
final var genesisBlock = createFakeBlock(0, 0, genesisBaseFee);
blocksByNumber.put(0L, genesisBlock);

final var baseFeeMarket = new CancunFeeMarket(0, Optional.empty());
final var baseFeeMarket = FeeMarket.cancun(0, Optional.empty());

var baseFee = genesisBaseFee;
for (long i = 1; i <= chainHeadBlockNumber; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.blockhash.FrontierBlockHashProcessor;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
Expand Down Expand Up @@ -322,7 +321,7 @@ private void mockBlockWithBlobTransaction(final Hash blockHash, final long block
}

private void mockProtocolSpec(final BlockHeader blockHeader) {
FeeMarket feeMarket = new CancunFeeMarket(0, Optional.empty());
FeeMarket feeMarket = FeeMarket.cancun(0, Optional.empty());
ProtocolSpec spec = mock(ProtocolSpec.class);
when(spec.getFeeMarket()).thenReturn(feeMarket);
when(spec.getGasCalculator()).thenReturn(new CancunGasCalculator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.evm.log.LogsBloomFilter;

import java.math.BigInteger;
Expand Down Expand Up @@ -148,7 +148,7 @@ private void mockBlockchain(final long chainHeadBlockNumber, final int txsNum) {
final var genesisBlock = createFakeBlock(0, 0, genesisBaseFee);
blocksByNumber.put(0L, genesisBlock);

final var baseFeeMarket = new CancunFeeMarket(0, Optional.empty());
final var baseFeeMarket = FeeMarket.cancun(0, Optional.empty());

var baseFee = genesisBaseFee;
for (long i = 1; i <= chainHeadBlockNumber; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class CancunFeeMarket extends LondonFeeMarket {
private static final Logger LOG = LoggerFactory.getLogger(CancunFeeMarket.class);
protected static final BigInteger BLOB_GAS_PRICE = BigInteger.ONE;

protected final BigInteger baseFeeUpdateFraction;
private final BigInteger baseFeeUpdateFraction;

public CancunFeeMarket(
CancunFeeMarket(
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride,
final long baseFeeUpdateFraction) {
Expand All @@ -39,8 +39,7 @@ public CancunFeeMarket(
this.baseFeeUpdateFraction = BigInteger.valueOf(baseFeeUpdateFraction);
}

public CancunFeeMarket(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
CancunFeeMarket(final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
this(
londonForkBlockNumber,
baseFeePerGasOverride,
Expand Down Expand Up @@ -80,4 +79,8 @@ protected BigInteger fakeExponential(
}
return output.divide(denominator);
}

protected BigInteger getBaseFeeUpdateFraction() {
return baseFeeUpdateFraction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class FixedBaseFeeMarket extends LondonFeeMarket {

public FixedBaseFeeMarket(final long londonForkBlockNumber, final Wei fixedBaseFee) {
FixedBaseFeeMarket(final long londonForkBlockNumber, final Wei fixedBaseFee) {
super(londonForkBlockNumber, Optional.of(fixedBaseFee));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LegacyFeeMarket implements FeeMarket {

private final TransactionPriceCalculator txPriceCalculator;

public LegacyFeeMarket() {
LegacyFeeMarket() {
this.txPriceCalculator = TransactionPriceCalculator.frontier();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ public class LondonFeeMarket implements BaseFeeMarket {
private final TransactionPriceCalculator txPriceCalculator;
private final Wei baseFeeFloor;

public LondonFeeMarket(final long londonForkBlockNumber) {
LondonFeeMarket(final long londonForkBlockNumber) {
this(londonForkBlockNumber, Optional.empty());
}

public LondonFeeMarket(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
LondonFeeMarket(final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
this(TransactionPriceCalculator.eip1559(), londonForkBlockNumber, baseFeePerGasOverride);
}

protected LondonFeeMarket(
LondonFeeMarket(
final TransactionPriceCalculator txPriceCalculator,
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
public class PragueFeeMarket extends CancunFeeMarket {
private static final Logger LOG = LoggerFactory.getLogger(PragueFeeMarket.class);

public PragueFeeMarket(
PragueFeeMarket(
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride,
final long baseFeeUpdateFraction) {
super(londonForkBlockNumber, baseFeePerGasOverride, baseFeeUpdateFraction);
}

public PragueFeeMarket(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
PragueFeeMarket(final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
this(
londonForkBlockNumber,
baseFeePerGasOverride,
Expand All @@ -45,7 +44,8 @@ public PragueFeeMarket(
public Wei blobGasPricePerGas(final BlobGas excessBlobGas) {
final var blobGasPrice =
Wei.of(
fakeExponential(BLOB_GAS_PRICE, excessBlobGas.toBigInteger(), baseFeeUpdateFraction));
fakeExponential(
BLOB_GAS_PRICE, excessBlobGas.toBigInteger(), getBaseFeeUpdateFraction()));
LOG.atTrace()
.setMessage("parentExcessBlobGas: {} blobGasPrice: {}")
.addArgument(excessBlobGas::toShortHexString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class ZeroBaseFeeMarket extends FixedBaseFeeMarket {

public ZeroBaseFeeMarket(final long londonForkBlockNumber) {
ZeroBaseFeeMarket(final long londonForkBlockNumber) {
super(londonForkBlockNumber, Wei.ZERO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CancunFeeMarketTest {

@Test
void dataPricePerGas() {
CancunFeeMarket cancunFeeMarket = new CancunFeeMarket(0, Optional.empty());
final BaseFeeMarket cancunFeeMarket = FeeMarket.cancun(0, Optional.empty());
// when no excess blob gas, data price per gas is 1
assertEquals(1, cancunFeeMarket.blobGasPricePerGas(BlobGas.ZERO).getAsBigInteger().intValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void satisfiesFloorTxCost() {
.gasPrice(Wei.of(7))
.createTransaction(KEY_PAIR1);

final LondonFeeMarket londonFeeMarket = new LondonFeeMarket(0);
final BaseFeeMarket londonFeeMarket = FeeMarket.london(0);
assertThat(londonFeeMarket.satisfiesFloorTxFee(transaction)).isTrue();
}

Expand All @@ -54,7 +54,7 @@ public void maxFeePerGasLessThanMinimumBaseFee() {
.gasPrice(null)
.createTransaction(KEY_PAIR1);

final LondonFeeMarket londonFeeMarket = new LondonFeeMarket(0);
final BaseFeeMarket londonFeeMarket = FeeMarket.london(0);
assertThat(londonFeeMarket.satisfiesFloorTxFee(transaction)).isFalse();
}

Expand All @@ -68,7 +68,7 @@ public void satisfiesFloorTxCostWhenBaseFeeInitialValueIsZero() {
.gasPrice(null)
.createTransaction(KEY_PAIR1);

final LondonFeeMarket londonFeeMarket = new LondonFeeMarket(0, Optional.of(Wei.ZERO));
final BaseFeeMarket londonFeeMarket = FeeMarket.london(0, Optional.of(Wei.ZERO));
assertThat(londonFeeMarket.satisfiesFloorTxFee(transaction)).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;

import java.util.Optional;

Expand All @@ -30,7 +29,7 @@
public class BaseFeeMarketBlockHeaderGasPriceValidationRuleTest {

private static final long FORK_BLOCK = 800L;
private final BaseFeeMarket baseFeeMarket = new LondonFeeMarket(FORK_BLOCK);
private final BaseFeeMarket baseFeeMarket = FeeMarket.london(FORK_BLOCK);
private BaseFeeMarketBlockHeaderGasPriceValidationRule validationRule;
private final BaseFeeMarket feeMarket = FeeMarket.london(FORK_BLOCK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FixedBaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;

import java.util.Optional;

Expand All @@ -32,7 +32,7 @@
public class GasLimitElasticityValidationRuleFixedBaseFeeMarketTest {

private static final Optional<BaseFeeMarket> fixedBaseFeeMarket =
Optional.of(new FixedBaseFeeMarket(10, Wei.ONE));
Optional.of(FeeMarket.fixedBaseFee(10, Wei.ONE));

public GasLimitRangeAndDeltaValidationRule uut =
new GasLimitRangeAndDeltaValidationRule(5000, MAX_VALUE, fixedBaseFeeMarket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;

import java.util.Optional;

Expand All @@ -30,7 +30,7 @@

public class GasLimitElasticityValidationRuleTest {

private static final Optional<BaseFeeMarket> baseFeeMarket = Optional.of(new LondonFeeMarket(10));
private static final Optional<BaseFeeMarket> baseFeeMarket = Optional.of(FeeMarket.london(10));

public GasLimitRangeAndDeltaValidationRule uut =
new GasLimitRangeAndDeltaValidationRule(5000, MAX_VALUE, baseFeeMarket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.ZeroBaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;

import java.util.Optional;

Expand All @@ -31,7 +31,7 @@
public class GasLimitElasticityValidationRuleZeroBaseFeeMarketTest {

private static final Optional<BaseFeeMarket> zeroBaseFeeMarket =
Optional.of(new ZeroBaseFeeMarket(10));
Optional.of(FeeMarket.zeroBaseFee(10));

public GasLimitRangeAndDeltaValidationRule uut =
new GasLimitRangeAndDeltaValidationRule(5000, MAX_VALUE, zeroBaseFeeMarket);
Expand Down

0 comments on commit 178135e

Please sign in to comment.