Skip to content

Commit

Permalink
Make eth_gasPrice aware of the base fee market (hyperledger#7102)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
  • Loading branch information
fab-10 authored and jflo committed May 28, 2024
1 parent 74e87b4 commit 1758102
Show file tree
Hide file tree
Showing 35 changed files with 594 additions and 274 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Bug fixes
- Fix parsing `gasLimit` parameter when its value is > `Long.MAX_VALUE` [#7116](https://github.com/hyperledger/besu/pull/7116)
- Make `eth_gasPrice` aware of the base fee market [#7102](https://github.com/hyperledger/besu/pull/7102)
- Skip validation of withdrawals when importing BFT blocks since withdrawals don't apply to BFT chains [#7115](https://github.com/hyperledger/besu/pull/7115)

## 24.5.1
Expand Down
19 changes: 7 additions & 12 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.stratum.StratumServer;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.ethstats.EthStatsService;
import org.hyperledger.besu.ethstats.util.EthStatsConnectOptions;
import org.hyperledger.besu.metrics.MetricsService;
Expand Down Expand Up @@ -725,14 +724,17 @@ public Runner build() {

final TransactionPool transactionPool = besuController.getTransactionPool();
final MiningCoordinator miningCoordinator = besuController.getMiningCoordinator();
final MiningParameters miningParameters = besuController.getMiningParameters();

final BlockchainQueries blockchainQueries =
new BlockchainQueries(
protocolSchedule,
context.getBlockchain(),
context.getWorldStateArchive(),
Optional.of(dataDir.resolve(CACHE_PATH)),
Optional.of(besuController.getProtocolManager().ethContext().getScheduler()),
apiConfiguration);
apiConfiguration,
miningParameters);

final PrivacyParameters privacyParameters = besuController.getPrivacyParameters();

Expand All @@ -749,7 +751,6 @@ public Runner build() {

final P2PNetwork peerNetwork = networkRunner.getNetwork();

final MiningParameters miningParameters = besuController.getMiningParameters();
Optional<StratumServer> stratumServer = Optional.empty();

if (miningParameters.isStratumMiningEnabled()) {
Expand Down Expand Up @@ -957,10 +958,7 @@ public Runner build() {
rpcEndpointServiceImpl);

createLogsSubscriptionService(
context.getBlockchain(),
context.getWorldStateArchive(),
subscriptionManager,
privacyParameters);
context.getBlockchain(), subscriptionManager, privacyParameters, blockchainQueries);

createNewBlockHeadersSubscriptionService(
context.getBlockchain(), blockchainQueries, subscriptionManager);
Expand Down Expand Up @@ -1273,15 +1271,12 @@ private SubscriptionManager createSubscriptionManager(

private void createLogsSubscriptionService(
final Blockchain blockchain,
final WorldStateArchive worldStateArchive,
final SubscriptionManager subscriptionManager,
final PrivacyParameters privacyParameters) {
final PrivacyParameters privacyParameters,
final BlockchainQueries blockchainQueries) {

Optional<PrivacyQueries> privacyQueries = Optional.empty();
if (privacyParameters.isEnabled()) {
final BlockchainQueries blockchainQueries =
new BlockchainQueries(
blockchain, worldStateArchive, Optional.empty(), Optional.empty(), apiConfiguration);
privacyQueries =
Optional.of(
new PrivacyQueries(
Expand Down
44 changes: 24 additions & 20 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
Suppliers.memoize(this::readGenesisConfigFile);
private final Supplier<GenesisConfigOptions> genesisConfigOptionsSupplier =
Suppliers.memoize(this::readGenesisConfigOptions);
private final Supplier<MiningParameters> miningParametersSupplier =
Suppliers.memoize(this::getMiningParameters);

private RocksDBPlugin rocksDBPlugin;

Expand Down Expand Up @@ -898,7 +900,6 @@ static class MetricsOptionGroup {
private Collection<EnodeURL> staticNodes;
private BesuController besuController;
private BesuConfigurationImpl pluginCommonConfiguration;
private MiningParameters miningParameters;

private BesuComponent besuComponent;
private final Supplier<ObservableMetricsSystem> metricsSystem =
Expand Down Expand Up @@ -1351,8 +1352,10 @@ private void startPlugins() {
TraceService.class,
new TraceServiceImpl(
new BlockchainQueries(
besuController.getProtocolSchedule(),
besuController.getProtocolContext().getBlockchain(),
besuController.getProtocolContext().getWorldStateArchive()),
besuController.getProtocolContext().getWorldStateArchive(),
miningParametersSupplier.get()),
besuController.getProtocolSchedule()));

besuController.getAdditionalPluginServices().appendPluginServices(besuPluginContext);
Expand All @@ -1374,7 +1377,7 @@ private void validatePluginOptions() {
"--privacy-marker-transaction-signing-key-file can not be used in conjunction with a plugin that specifies a PrivateMarkerTransactionFactory");
}

if (Wei.ZERO.compareTo(getMiningParameters().getMinTransactionGasPrice()) < 0
if (Wei.ZERO.compareTo(miningParametersSupplier.get().getMinTransactionGasPrice()) < 0
&& (privacyOptionGroup.privateMarkerTransactionSigningKeyPath == null
&& (privacyPluginService == null
|| privacyPluginService.getPrivateMarkerTransactionFactory() == null))) {
Expand Down Expand Up @@ -1755,7 +1758,7 @@ private void configure() throws Exception {
unstableIpcOptions.isEnabled(),
unstableIpcOptions.getIpcPath(),
unstableIpcOptions.getRpcIpcApis());
apiConfiguration = apiConfigurationOptions.apiConfiguration(getMiningParameters());
apiConfiguration = apiConfigurationOptions.apiConfiguration();
dataStorageConfiguration = getDataStorageConfiguration();
// hostsWhitelist is a hidden option. If it is specified, add the list to hostAllowlist
if (!hostsWhitelist.isEmpty()) {
Expand Down Expand Up @@ -1844,7 +1847,7 @@ public BesuControllerBuilder getControllerBuilder() {
dataDir(),
dataDir().resolve(DATABASE_PATH),
getDataStorageConfiguration(),
getMiningParameters());
miningParametersSupplier.get());
final KeyValueStorageProvider storageProvider = keyValueStorageProvider(keyValueStorageName);
return controllerBuilderFactory
.fromEthNetworkConfig(updateNetworkConfig(network), getDefaultSyncModeIfNotSet())
Expand All @@ -1853,7 +1856,7 @@ public BesuControllerBuilder getControllerBuilder() {
.networkConfiguration(unstableNetworkingOptions.toDomainObject())
.dataDirectory(dataDir())
.dataStorageConfiguration(getDataStorageConfiguration())
.miningParameters(getMiningParameters())
.miningParameters(miningParametersSupplier.get())
.transactionPoolConfiguration(buildTransactionPoolConfiguration())
.nodeKey(new NodeKey(securityModule()))
.metricsSystem(metricsSystem.get())
Expand All @@ -1864,7 +1867,7 @@ public BesuControllerBuilder getControllerBuilder() {
.isRevertReasonEnabled(isRevertReasonEnabled)
.storageProvider(storageProvider)
.gasLimitCalculator(
getMiningParameters().getTargetGasLimit().isPresent()
miningParametersSupplier.get().getTargetGasLimit().isPresent()
? new FrontierTargetingGasLimitCalculator()
: GasLimitCalculator.constant())
.requiredBlocks(requiredBlocks)
Expand Down Expand Up @@ -2157,14 +2160,17 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() {
txPoolConfBuilder.priceBump(Percentage.ZERO);
}

if (getMiningParameters().getMinTransactionGasPrice().equals(Wei.ZERO)
if (miningParametersSupplier.get().getMinTransactionGasPrice().equals(Wei.ZERO)
&& !transactionPoolOptions.isPriceBumpSet(commandLine)) {
logger.info(
"Forcing price bump for transaction replacement to 0, since min-gas-price is set to 0");
txPoolConfBuilder.priceBump(Percentage.ZERO);
}

if (getMiningParameters().getMinTransactionGasPrice().lessThan(txPoolConf.getMinGasPrice())) {
if (miningParametersSupplier
.get()
.getMinTransactionGasPrice()
.lessThan(txPoolConf.getMinGasPrice())) {
if (transactionPoolOptions.isMinGasPriceSet(commandLine)) {
throw new ParameterException(
commandLine, "tx-pool-min-gas-price cannot be greater than the value of min-gas-price");
Expand All @@ -2175,23 +2181,21 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() {
// the user of the change
logger.warn(
"Forcing tx-pool-min-gas-price="
+ getMiningParameters().getMinTransactionGasPrice().toDecimalString()
+ miningParametersSupplier.get().getMinTransactionGasPrice().toDecimalString()
+ ", since it cannot be greater than the value of min-gas-price");
txPoolConfBuilder.minGasPrice(getMiningParameters().getMinTransactionGasPrice());
txPoolConfBuilder.minGasPrice(miningParametersSupplier.get().getMinTransactionGasPrice());
}
}

return txPoolConfBuilder.build();
}

private MiningParameters getMiningParameters() {
if (miningParameters == null) {
miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl);
miningParameters = miningOptions.toDomainObject();
getGenesisBlockPeriodSeconds(genesisConfigOptionsSupplier.get())
.ifPresent(miningParameters::setBlockPeriodSeconds);
initMiningParametersMetrics(miningParameters);
}
miningOptions.setTransactionSelectionService(transactionSelectionServiceImpl);
final var miningParameters = miningOptions.toDomainObject();
getGenesisBlockPeriodSeconds(genesisConfigOptionsSupplier.get())
.ifPresent(miningParameters::setBlockPeriodSeconds);
initMiningParametersMetrics(miningParameters);
return miningParameters;
}

Expand Down Expand Up @@ -2567,8 +2571,8 @@ private List<Integer> getEffectivePorts() {
effectivePorts, metricsOptionGroup.metricsPort, metricsOptionGroup.isMetricsEnabled);
addPortIfEnabled(
effectivePorts,
getMiningParameters().getStratumPort(),
getMiningParameters().isStratumMiningEnabled());
miningParametersSupplier.get().getStratumPort(),
miningParametersSupplier.get().isStratumMiningEnabled());
return effectivePorts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import static java.util.Arrays.asList;

import org.hyperledger.besu.cli.util.CommandLineUtils;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration;
import org.hyperledger.besu.ethereum.core.MiningParameters;

import org.slf4j.Logger;
import picocli.CommandLine;
Expand Down Expand Up @@ -119,17 +119,14 @@ private void checkApiOptionsDependencies(final CommandLine commandLine, final Lo
/**
* Creates an ApiConfiguration based on the provided options.
*
* @param miningParameters The mining parameters
* @return An ApiConfiguration instance
*/
public ApiConfiguration apiConfiguration(final MiningParameters miningParameters) {
public ApiConfiguration apiConfiguration() {
var builder =
ImmutableApiConfiguration.builder()
.gasPriceBlocks(apiGasPriceBlocks)
.gasPricePercentile(apiGasPricePercentile)
.gasPriceMinSupplier(
miningParameters.getMinTransactionGasPrice().getAsBigInteger()::longValueExact)
.gasPriceMax(apiGasPriceMax)
.gasPriceMax(Wei.of(apiGasPriceMax))
.maxLogsRange(rpcMaxLogsRange)
.gasCap(rpcGasCap)
.isGasAndPriorityFeeLimitingEnabled(apiGasAndPriorityFeeLimitingEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public BesuController build() {
createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager);

final JsonRpcMethods additionalJsonRpcMethodFactory =
createAdditionalJsonRpcMethodFactory(protocolContext);
createAdditionalJsonRpcMethodFactory(protocolContext, protocolSchedule, miningParameters);

if (dataStorageConfiguration.getUnstable().getBonsaiLimitTrieLogsEnabled()
&& DataStorageFormat.BONSAI.equals(dataStorageConfiguration.getDataStorageFormat())) {
Expand Down Expand Up @@ -884,10 +884,14 @@ protected void prepForBuild() {}
* Create additional json rpc method factory json rpc methods.
*
* @param protocolContext the protocol context
* @param protocolSchedule the protocol schedule
* @param miningParameters the mining parameters
* @return the json rpc methods
*/
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext protocolContext) {
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final MiningParameters miningParameters) {
return apis -> Collections.emptyMap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ protected void prepForBuild() {

@Override
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext protocolContext) {
return new CliqueJsonRpcMethods(protocolContext);
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final MiningParameters miningParameters) {
return new CliqueJsonRpcMethods(protocolContext, protocolSchedule, miningParameters);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ protected PluginServiceFactory createAdditionalPluginServices(

@Override
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext protocolContext) {
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final MiningParameters miningParameters) {
return besuControllerBuilderSchedule
.get(0L)
.createAdditionalJsonRpcMethodFactory(protocolContext);
.createAdditionalJsonRpcMethodFactory(protocolContext, protocolSchedule, miningParameters);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ protected void prepForBuild() {

@Override
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext protocolContext) {
return new IbftJsonRpcMethods(protocolContext);
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final MiningParameters miningParameters) {
return new IbftJsonRpcMethods(protocolContext, protocolSchedule, miningParameters);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ protected void prepForBuild() {

@Override
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory(
final ProtocolContext protocolContext) {
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final MiningParameters miningParameters) {

return new QbftJsonRpcMethods(
protocolContext, createReadOnlyValidatorProvider(protocolContext.getBlockchain()));
protocolContext,
protocolSchedule,
miningParameters,
createReadOnlyValidatorProvider(protocolContext.getBlockchain()));
}

private ValidatorProvider createReadOnlyValidatorProvider(final Blockchain blockchain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;

import java.util.List;

Expand Down Expand Up @@ -99,10 +101,13 @@ public void forkingValidatorProviderIsAvailableOnBftContext() {
@Test
public void missingTransactionValidatorProviderThrowsError() {
final ProtocolContext protocolContext = mock(ProtocolContext.class);
final ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class);
when(protocolContext.getBlockchain()).thenReturn(mock(MutableBlockchain.class));

assertThatThrownBy(
() -> bftBesuControllerBuilder.createAdditionalJsonRpcMethodFactory(protocolContext))
() ->
bftBesuControllerBuilder.createAdditionalJsonRpcMethodFactory(
protocolContext, protocolSchedule, MiningParameters.newDefault()))
.isInstanceOf(NullPointerException.class)
.hasMessage("transactionValidatorProvider should have been initialised");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.log.Log;
import org.hyperledger.besu.evm.worldstate.WorldView;
Expand Down Expand Up @@ -74,7 +75,12 @@ public void setup() {
blockchainSetupUtil.importAllBlocks();
blockchain = blockchainSetupUtil.getBlockchain();
worldStateArchive = blockchainSetupUtil.getWorldArchive();
blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive);
blockchainQueries =
new BlockchainQueries(
blockchainSetupUtil.getProtocolSchedule(),
blockchain,
worldStateArchive,
MiningParameters.newDefault());
traceService =
new TraceServiceImpl(blockchainQueries, blockchainSetupUtil.getProtocolSchedule());
}
Expand Down
Loading

0 comments on commit 1758102

Please sign in to comment.