Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-prometheus-1.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusMetricsSystem.java
#	metrics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/PrometheusSuppliedValueCollector.java
  • Loading branch information
fab-10 committed Nov 20, 2024
2 parents 70b767c + fe46289 commit 591a123
Show file tree
Hide file tree
Showing 32 changed files with 95 additions and 139 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Changelog

## [Unreleased]
- Added isLabelsObserved to LabelledGauge in plugin-api. Default implementation returns false.

### Breaking Changes
- Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783)
Expand All @@ -12,6 +11,7 @@ besu_blockchain_difficulty_total
if you use these metrics you have to update your custom solution, to support the new name.

### Upcoming Breaking Changes
- `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge`

### Additions and Improvements
- Fine tune already seen txs tracker when a tx is removed from the pool [#7755](https://github.com/hyperledger/besu/pull/7755)
Expand All @@ -21,6 +21,7 @@ if you use these metrics you have to update your custom solution, to support the
- Add a method to get all the transaction in the pool, to the `TransactionPoolService`, to easily access the transaction pool content from plugins [#7813](https://github.com/hyperledger/besu/pull/7813)
- Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832)
- Add account and state overrides to `eth_call` and `eth_estimateGas` [#7801](https://github.com/hyperledger/besu/pull/7801)
- Add a new metric collector for counters which get their value from suppliers [#7894](https://github.com/hyperledger/besu/pull/7894)
- Prometheus Java Metrics library upgraded to version 1.3.3 [#7880](https://github.com/hyperledger/besu/pull/7880)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
*/
package org.hyperledger.besu.controller;

import static org.hyperledger.besu.consensus.clique.CliqueHelpers.installCliqueBlockChoiceRule;

import org.hyperledger.besu.config.CliqueConfigOptions;
import org.hyperledger.besu.consensus.clique.CliqueBlockInterface;
import org.hyperledger.besu.consensus.clique.CliqueContext;
import org.hyperledger.besu.consensus.clique.CliqueForksSchedulesFactory;
import org.hyperledger.besu.consensus.clique.CliqueHelpers;
import org.hyperledger.besu.consensus.clique.CliqueMiningTracker;
import org.hyperledger.besu.consensus.clique.CliqueProtocolSchedule;
import org.hyperledger.besu.consensus.clique.blockcreation.CliqueBlockScheduler;
Expand Down Expand Up @@ -167,7 +166,8 @@ protected CliqueContext createConsensusContext(
blockchain, epochManager, blockInterface),
epochManager,
blockInterface);
installCliqueBlockChoiceRule(blockchain, cliqueContext);
CliqueHelpers.setCliqueContext(cliqueContext);
CliqueHelpers.installCliqueBlockChoiceRule(blockchain, cliqueContext);
return cliqueContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.consensus.clique;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator;

Expand All @@ -39,12 +38,9 @@ public CliqueDifficultyCalculator(final Address localAddress) {
}

@Override
public BigInteger nextDifficulty(
final long time, final BlockHeader parent, final ProtocolContext context) {
public BigInteger nextDifficulty(final long time, final BlockHeader parent) {

final Address nextProposer =
CliqueHelpers.getProposerForBlockAfter(
parent, context.getConsensusContext(CliqueContext.class).getValidatorProvider());
final Address nextProposer = CliqueHelpers.getProposerForBlockAfter(parent);
return nextProposer.equals(localAddress) ? IN_TURN_DIFFICULTY : OUT_OF_TURN_DIFFICULTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@

/** The Clique helpers. */
public class CliqueHelpers {
private static CliqueContext cliqueContext;

/** Default constructor. */
CliqueHelpers() {}

/**
* Set the clique consensus context
*
* @param cliqueContext the clique consensus context
*/
public static void setCliqueContext(final CliqueContext cliqueContext) {
CliqueHelpers.cliqueContext = cliqueContext;
}

/**
* Gets proposer of block.
*
Expand All @@ -45,12 +56,11 @@ public static Address getProposerOfBlock(final BlockHeader header) {
* Gets proposer for block after.
*
* @param parent the parent
* @param validatorProvider the validator provider
* @return the proposer for block after
*/
static Address getProposerForBlockAfter(
final BlockHeader parent, final ValidatorProvider validatorProvider) {
final CliqueProposerSelector proposerSelector = new CliqueProposerSelector(validatorProvider);
static Address getProposerForBlockAfter(final BlockHeader parent) {
final CliqueProposerSelector proposerSelector =
new CliqueProposerSelector(cliqueContext.getValidatorProvider());
return proposerSelector.selectProposerForNextBlock(parent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public CliqueMiningTracker(final Address localAddress, final ProtocolContext pro
* @return the boolean
*/
public boolean isProposerAfter(final BlockHeader header) {
final Address nextProposer =
CliqueHelpers.getProposerForBlockAfter(
header,
protocolContext.getConsensusContext(CliqueContext.class).getValidatorProvider());
final Address nextProposer = CliqueHelpers.getProposerForBlockAfter(header);
return localAddress.equals(nextProposer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import java.util.Optional;
import java.util.function.Function;

import com.google.common.annotations.VisibleForTesting;

/** Defines the protocol behaviours for a blockchain using Clique. */
public class CliqueProtocolSchedule {

Expand All @@ -63,7 +61,7 @@ public class CliqueProtocolSchedule {
* @param privacyParameters the privacy parameters
* @param isRevertReasonEnabled the is revert reason enabled
* @param evmConfiguration the evm configuration
* @param miningConfiguration the mining parameters
* @param miningConfiguration the mining configuration
* @param badBlockManager the cache to use to keep invalid blocks
* @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled
* @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying
Expand Down Expand Up @@ -122,45 +120,6 @@ public static ProtocolSchedule create(
.createProtocolSchedule();
}

/**
* Create protocol schedule.
*
* @param config the config
* @param forksSchedule the transitions
* @param nodeKey the node key
* @param isRevertReasonEnabled the is revert reason enabled
* @param evmConfiguration the evm configuration
* @param miningConfiguration the mining parameters
* @param badBlockManager the cache to use to keep invalid blocks
* @param isParallelTxProcessingEnabled indicates whether parallel transaction is enabled
* @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying
* calls
* @return the protocol schedule
*/
@VisibleForTesting
public static ProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<CliqueConfigOptions> forksSchedule,
final NodeKey nodeKey,
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration,
final MiningConfiguration miningConfiguration,
final BadBlockManager badBlockManager,
final boolean isParallelTxProcessingEnabled,
final MetricsSystem metricsSystem) {
return create(
config,
forksSchedule,
nodeKey,
PrivacyParameters.DEFAULT,
isRevertReasonEnabled,
evmConfiguration,
miningConfiguration,
badBlockManager,
isParallelTxProcessingEnabled,
metricsSystem);
}

private static ProtocolSpecBuilder applyCliqueSpecificModifications(
final EpochManager epochManager,
final long secondsBetweenBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ public CliqueDifficultyValidationRule() {}
public boolean validate(
final BlockHeader header, final BlockHeader parent, final ProtocolContext protocolContext) {
final Address actualBlockCreator = CliqueHelpers.getProposerOfBlock(header);

final CliqueDifficultyCalculator diffCalculator =
new CliqueDifficultyCalculator(actualBlockCreator);
final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent, protocolContext);
final BigInteger expectedDifficulty = diffCalculator.nextDifficulty(0, parent);

final BigInteger actualDifficulty = header.getDifficulty().toBigInteger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
Expand All @@ -43,9 +41,7 @@ public class CliqueDifficultyCalculatorTest {
private Address localAddr;

private final List<Address> validatorList = Lists.newArrayList();
private ProtocolContext cliqueProtocolContext;
private BlockHeaderTestFixture blockHeaderBuilder;
private final CliqueBlockInterface blockInterface = new CliqueBlockInterface();

@BeforeEach
public void setup() {
Expand All @@ -56,9 +52,7 @@ public void setup() {

final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);

final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
CliqueHelpers.setCliqueContext(new CliqueContext(validatorProvider, null, null));
blockHeaderBuilder = new BlockHeaderTestFixture();
}

Expand All @@ -68,8 +62,7 @@ public void inTurnValidatorProducesDifficultyOfTwo() {

final BlockHeader parentHeader = blockHeaderBuilder.number(1).buildHeader();

assertThat(calculator.nextDifficulty(0, parentHeader, cliqueProtocolContext))
.isEqualTo(BigInteger.valueOf(2));
assertThat(calculator.nextDifficulty(0, parentHeader)).isEqualTo(BigInteger.valueOf(2));
}

@Test
Expand All @@ -78,7 +71,6 @@ public void outTurnValidatorProducesDifficultyOfOne() {

final BlockHeader parentHeader = blockHeaderBuilder.number(2).buildHeader();

assertThat(calculator.nextDifficulty(0, parentHeader, cliqueProtocolContext))
.isEqualTo(BigInteger.valueOf(1));
assertThat(calculator.nextDifficulty(0, parentHeader)).isEqualTo(BigInteger.valueOf(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
config,
new ForksSchedule<>(List.of()),
NODE_KEY,
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningConfiguration.MINING_DISABLED,
Expand All @@ -92,6 +94,7 @@ public void parametersAlignWithMainnetWithAdjustments() {
GenesisConfigFile.DEFAULT.getConfigOptions(),
forksSchedule,
NODE_KEY,
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningConfiguration.MINING_DISABLED,
Expand All @@ -118,6 +121,7 @@ public void zeroEpochLengthThrowsException() {
genesisConfig,
new ForksSchedule<>(List.of()),
NODE_KEY,
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningConfiguration.MINING_DISABLED,
Expand All @@ -140,6 +144,7 @@ public void negativeEpochLengthThrowsException() {
genesisConfig,
new ForksSchedule<>(List.of()),
NODE_KEY,
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningConfiguration.MINING_DISABLED,
Expand All @@ -166,6 +171,7 @@ public void shouldValidateBaseFeeMarketTransition() {
config,
forksSchedule,
NODE_KEY,
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningConfiguration.MINING_DISABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void setup() {
new NoOpMetricsSystem());

final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
CliqueHelpers.setCliqueContext(cliqueContext);

final Block genesis =
GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock();
Expand Down Expand Up @@ -149,7 +150,7 @@ public void proposerAddressCanBeExtractFromAConstructedBlock() {

final Address coinbase = AddressHelpers.ofValue(1);

final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase);
final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase);

final CliqueBlockCreator blockCreator =
new CliqueBlockCreator(
Expand Down Expand Up @@ -178,7 +179,7 @@ public void insertsValidVoteIntoConstructedBlock() {
when(voteProvider.getVoteAfterBlock(any(), any()))
.thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1)));

final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase);
final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase);

final CliqueBlockCreator blockCreator =
new CliqueBlockCreator(
Expand Down Expand Up @@ -212,7 +213,7 @@ public void insertsNoVoteWhenAtEpoch() {
when(mockVoteProvider.getVoteAfterBlock(any(), any()))
.thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, coinbase, a1)));

final MiningConfiguration miningConfiguration = createMiningParameters(extraData, coinbase);
final MiningConfiguration miningConfiguration = createMiningConfiguration(extraData, coinbase);

final CliqueBlockCreator blockCreator =
new CliqueBlockCreator(
Expand Down Expand Up @@ -255,7 +256,7 @@ private TransactionPool createTransactionPool() {
return transactionPool;
}

private static MiningConfiguration createMiningParameters(
private static MiningConfiguration createMiningConfiguration(
final Bytes extraData, final Address coinbase) {
final MiningConfiguration miningConfiguration =
ImmutableMiningConfiguration.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hyperledger.besu.consensus.clique.CliqueBlockInterface;
import org.hyperledger.besu.consensus.clique.CliqueContext;
import org.hyperledger.besu.consensus.clique.CliqueExtraData;
import org.hyperledger.besu.consensus.clique.CliqueHelpers;
import org.hyperledger.besu.consensus.clique.CliqueProtocolSchedule;
import org.hyperledger.besu.consensus.common.EpochManager;
import org.hyperledger.besu.consensus.common.ForksSchedule;
Expand Down Expand Up @@ -98,6 +99,7 @@ public void setup() {
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validatorList);

final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
CliqueHelpers.setCliqueContext(cliqueContext);
cliqueProtocolContext = new ProtocolContext(null, null, cliqueContext, new BadBlockManager());
cliqueProtocolSchedule =
CliqueProtocolSchedule.create(
Expand All @@ -119,7 +121,7 @@ public void setup() {
public void extraDataCreatedOnEpochBlocksContainsValidators() {
final Bytes vanityData = generateRandomVanityData();

final MiningConfiguration miningConfiguration = createMiningParameters(vanityData);
final MiningConfiguration miningConfiguration = createMiningConfiguration(vanityData);

final CliqueMinerExecutor executor =
new CliqueMinerExecutor(
Expand Down Expand Up @@ -155,7 +157,7 @@ public void extraDataCreatedOnEpochBlocksContainsValidators() {
public void extraDataForNonEpochBlocksDoesNotContainValidaors() {
final Bytes vanityData = generateRandomVanityData();

final MiningConfiguration miningConfiguration = createMiningParameters(vanityData);
final MiningConfiguration miningConfiguration = createMiningConfiguration(vanityData);

final CliqueMinerExecutor executor =
new CliqueMinerExecutor(
Expand Down Expand Up @@ -191,7 +193,7 @@ public void shouldUseLatestVanityData() {
final Bytes initialVanityData = generateRandomVanityData();
final Bytes modifiedVanityData = generateRandomVanityData();

final MiningConfiguration miningConfiguration = createMiningParameters(initialVanityData);
final MiningConfiguration miningConfiguration = createMiningConfiguration(initialVanityData);

final CliqueMinerExecutor executor =
new CliqueMinerExecutor(
Expand Down Expand Up @@ -255,7 +257,7 @@ private Bytes generateRandomVanityData() {
return Bytes.wrap(vanityData);
}

private static MiningConfiguration createMiningParameters(final Bytes vanityData) {
private static MiningConfiguration createMiningConfiguration(final Bytes vanityData) {
return ImmutableMiningConfiguration.builder()
.mutableInitValues(
MutableInitValues.builder()
Expand Down
Loading

0 comments on commit 591a123

Please sign in to comment.