Isolate getByBlockNumber for BFT use cases (#5254)

Introduce BftProtocolSchedule with a copy of MutableProtocolSchedule.getByBlockNumber.
This method will be deleted from the ProtocolSchedule interfaces and so will only exist in BftProtocolSchedule.

Use BftProtocolSchedule in CombinedProtocolScheduleFactory.
Move getScheduledProtocolSpecs into BftProtocolSchedule since it is only used by CombinedProtocolScheduleFactory.
Rename existing BftProtocolSchedule classes to append Builder for clarity.

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
This commit is contained in:
Simon Dudley
2023-03-22 14:42:25 +10:00
committed by GitHub
parent 5bd75b43ae
commit c955eb290a
18 changed files with 146 additions and 72 deletions

View File

@@ -25,6 +25,7 @@ import org.hyperledger.besu.consensus.common.bft.BftEventQueue;
import org.hyperledger.besu.consensus.common.bft.BftExecutors;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProcessor;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BlockTimer;
import org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
@@ -44,7 +45,7 @@ import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidator
import org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec;
import org.hyperledger.besu.consensus.ibft.IbftForksSchedulesFactory;
import org.hyperledger.besu.consensus.ibft.IbftGossip;
import org.hyperledger.besu.consensus.ibft.IbftProtocolSchedule;
import org.hyperledger.besu.consensus.ibft.IbftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.ibft.jsonrpc.IbftJsonRpcMethods;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.protocol.IbftSubProtocol;
@@ -142,11 +143,12 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder {
BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.IBFT);
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftProtocolSchedule bftProtocolSchedule = (BftProtocolSchedule) protocolSchedule;
final BftBlockCreatorFactory<?> blockCreatorFactory =
new BftBlockCreatorFactory<>(
transactionPool.getPendingTransactions(),
protocolContext,
protocolSchedule,
bftProtocolSchedule,
forksSchedule,
miningParameters,
localAddress,
@@ -181,7 +183,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder {
final MessageValidatorFactory messageValidatorFactory =
new MessageValidatorFactory(
proposerSelector, protocolSchedule, protocolContext, bftExtraDataCodec().get());
proposerSelector, bftProtocolSchedule, protocolContext, bftExtraDataCodec().get());
final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
minedBlockObservers.subscribe(ethProtocolManager);
@@ -206,7 +208,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder {
new IbftRoundFactory(
finalState,
protocolContext,
protocolSchedule,
bftProtocolSchedule,
minedBlockObservers,
messageValidatorFactory,
messageFactory,
@@ -245,7 +247,7 @@ public class IbftBesuControllerBuilder extends BftBesuControllerBuilder {
@Override
protected ProtocolSchedule createProtocolSchedule() {
return IbftProtocolSchedule.create(
return IbftProtocolScheduleBuilder.create(
configOptionsSupplier.get(),
forksSchedule,
privacyParameters,

View File

@@ -27,6 +27,7 @@ import org.hyperledger.besu.consensus.common.bft.BftEventQueue;
import org.hyperledger.besu.consensus.common.bft.BftExecutors;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProcessor;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BlockTimer;
import org.hyperledger.besu.consensus.common.bft.EthSynchronizerUpdater;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
@@ -47,7 +48,7 @@ import org.hyperledger.besu.consensus.qbft.QbftContext;
import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec;
import org.hyperledger.besu.consensus.qbft.QbftForksSchedulesFactory;
import org.hyperledger.besu.consensus.qbft.QbftGossip;
import org.hyperledger.besu.consensus.qbft.QbftProtocolSchedule;
import org.hyperledger.besu.consensus.qbft.QbftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory;
import org.hyperledger.besu.consensus.qbft.jsonrpc.QbftJsonRpcMethods;
import org.hyperledger.besu.consensus.qbft.payload.MessageFactory;
@@ -180,11 +181,12 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
BftExecutors.create(metricsSystem, BftExecutors.ConsensusType.QBFT);
final Address localAddress = Util.publicKeyToAddress(nodeKey.getPublicKey());
final BftProtocolSchedule bftProtocolSchedule = (BftProtocolSchedule) protocolSchedule;
final BftBlockCreatorFactory<?> blockCreatorFactory =
new QbftBlockCreatorFactory(
transactionPool.getPendingTransactions(),
protocolContext,
protocolSchedule,
bftProtocolSchedule,
qbftForksSchedule,
miningParameters,
localAddress,
@@ -219,7 +221,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
final MessageValidatorFactory messageValidatorFactory =
new MessageValidatorFactory(
proposerSelector, protocolSchedule, protocolContext, bftExtraDataCodec().get());
proposerSelector, bftProtocolSchedule, protocolContext, bftExtraDataCodec().get());
final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
minedBlockObservers.subscribe(ethProtocolManager);
@@ -244,7 +246,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
new QbftRoundFactory(
finalState,
protocolContext,
protocolSchedule,
bftProtocolSchedule,
minedBlockObservers,
messageValidatorFactory,
messageFactory,
@@ -285,7 +287,7 @@ public class QbftBesuControllerBuilder extends BftBesuControllerBuilder {
@Override
protected ProtocolSchedule createProtocolSchedule() {
return QbftProtocolSchedule.create(
return QbftProtocolScheduleBuilder.create(
configOptionsSupplier.get(),
qbftForksSchedule,
privacyParameters,

View File

@@ -16,6 +16,7 @@ package org.hyperledger.besu.consensus.common;
import static com.google.common.base.Preconditions.checkState;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec;
@@ -43,7 +44,8 @@ public class CombinedProtocolScheduleFactory {
checkState(
spec.getValue() instanceof MutableProtocolSchedule,
"Consensus migration requires a MutableProtocolSchedule");
final MutableProtocolSchedule protocolSchedule = (MutableProtocolSchedule) spec.getValue();
final BftProtocolSchedule protocolSchedule =
new BftProtocolSchedule((MutableProtocolSchedule) spec.getValue());
final Optional<Long> endBlock =
Optional.ofNullable(forkSpecs.higher(spec)).map(ForkSpec::getBlock);

View File

@@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockBodyValidator;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;
@@ -36,7 +36,7 @@ import java.util.Map;
import java.util.function.Function;
/** Defines the protocol behaviours for a blockchain using a BFT consensus mechanism. */
public abstract class BaseBftProtocolSchedule {
public abstract class BaseBftProtocolScheduleBuilder {
private static final BigInteger DEFAULT_CHAIN_ID = BigInteger.ONE;
@@ -51,7 +51,7 @@ public abstract class BaseBftProtocolSchedule {
* @param evmConfiguration the evm configuration
* @return the protocol schedule
*/
public ProtocolSchedule createProtocolSchedule(
public BftProtocolSchedule createProtocolSchedule(
final GenesisConfigOptions config,
final ForksSchedule<? extends BftConfigOptions> forksSchedule,
final PrivacyParameters privacyParameters,
@@ -72,15 +72,18 @@ public abstract class BaseBftProtocolSchedule {
final ProtocolSpecAdapters specAdapters = new ProtocolSpecAdapters(specMap);
return new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
specAdapters,
privacyParameters,
isRevertReasonEnabled,
config.isQuorum(),
evmConfiguration)
.createProtocolSchedule();
final MutableProtocolSchedule mutableProtocolSchedule =
(MutableProtocolSchedule)
new ProtocolScheduleBuilder(
config,
DEFAULT_CHAIN_ID,
specAdapters,
privacyParameters,
isRevertReasonEnabled,
config.isQuorum(),
evmConfiguration)
.createProtocolSchedule();
return new BftProtocolSchedule(mutableProtocolSchedule);
}
/**

View File

@@ -0,0 +1,72 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.consensus.common.bft;
import static com.google.common.base.Preconditions.checkArgument;
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec;
import java.util.List;
/**
* A Bft-specific wrapper around a ProtocolSchedule that is allowed to look up ProtocolSpecs by
* block number Extending MutableProtocolSchedule gives this class access to the protocolSpecs
*/
public class BftProtocolSchedule extends MutableProtocolSchedule {
/**
* Construct from an existing MutableProtocolSchedule
*
* @param mutableProtocolSchedule a blockNumber-based ProtocolSchedule
*/
public BftProtocolSchedule(final MutableProtocolSchedule mutableProtocolSchedule) {
super(mutableProtocolSchedule);
}
/**
* Look up ProtocolSpec by block number
*
* @param number block number
* @return the protocol spec for that block number
*/
@Override
public ProtocolSpec getByBlockNumber(final long number) {
checkArgument(number >= 0, "number must be non-negative");
checkArgument(
!protocolSpecs.isEmpty(), "At least 1 milestone must be provided to the protocol schedule");
checkArgument(
protocolSpecs.last().milestone() == 0, "There must be a milestone starting from block 0");
// protocolSpecs is sorted in descending block order, so the first one we find that's lower than
// the requested level will be the most appropriate spec
for (final ScheduledProtocolSpec s : protocolSpecs) {
if (number >= s.milestone()) {
return s.spec();
}
}
return null;
}
/**
* return the ordered list of scheduled protocol specs
*
* @return the scheduled protocol specs
*/
public List<ScheduledProtocolSpec> getScheduledProtocolSpecs() {
return protocolSpecs.stream().toList();
}
}

View File

@@ -43,7 +43,7 @@ import java.util.Optional;
import org.junit.Test;
public class BaseBftProtocolScheduleTest {
public class BaseBftProtocolScheduleBuilderTest {
private final GenesisConfigOptions genesisConfig = mock(GenesisConfigOptions.class);
private final BftExtraDataCodec bftExtraDataCodec = mock(BftExtraDataCodec.class);
@@ -226,8 +226,8 @@ public class BaseBftProtocolScheduleTest {
}
private ProtocolSchedule createProtocolSchedule(final List<ForkSpec<BftConfigOptions>> forks) {
final BaseBftProtocolSchedule bftProtocolSchedule =
new BaseBftProtocolSchedule() {
final BaseBftProtocolScheduleBuilder bftProtocolSchedule =
new BaseBftProtocolScheduleBuilder() {
@Override
protected BlockHeaderValidator.Builder createBlockHeaderRuleset(
final BftConfigOptions config, final FeeMarket feeMarket) {

View File

@@ -31,6 +31,7 @@ import org.hyperledger.besu.consensus.common.bft.BftEventQueue;
import org.hyperledger.besu.consensus.common.bft.BftExecutors;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BlockTimer;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.Gossiper;
@@ -54,7 +55,7 @@ import org.hyperledger.besu.consensus.common.validator.blockbased.BlockValidator
import org.hyperledger.besu.consensus.ibft.IbftExtraDataCodec;
import org.hyperledger.besu.consensus.ibft.IbftForksSchedulesFactory;
import org.hyperledger.besu.consensus.ibft.IbftGossip;
import org.hyperledger.besu.consensus.ibft.IbftProtocolSchedule;
import org.hyperledger.besu.consensus.ibft.IbftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftBlockHeightManagerFactory;
import org.hyperledger.besu.consensus.ibft.statemachine.IbftController;
@@ -77,7 +78,6 @@ import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
@@ -310,8 +310,8 @@ public class TestContextBuilder {
final ForksSchedule<BftConfigOptions> forksSchedule =
IbftForksSchedulesFactory.create(genesisConfigOptions);
final ProtocolSchedule protocolSchedule =
IbftProtocolSchedule.create(
final BftProtocolSchedule protocolSchedule =
IbftProtocolScheduleBuilder.create(
genesisConfigOptions, forksSchedule, IBFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
/////////////////////////////////////////////////////////////////////////////////////

View File

@@ -17,11 +17,11 @@ package org.hyperledger.besu.consensus.ibft;
import org.hyperledger.besu.config.BftConfigOptions;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
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.FeeMarket;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
@@ -29,7 +29,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration;
import java.util.Optional;
/** Defines the protocol behaviours for a blockchain using a BFT consensus mechanism. */
public class IbftProtocolSchedule extends BaseBftProtocolSchedule {
public class IbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder {
/**
* Create protocol schedule.
@@ -42,14 +42,14 @@ public class IbftProtocolSchedule extends BaseBftProtocolSchedule {
* @param evmConfiguration the evm configuration
* @return the protocol schedule
*/
public static ProtocolSchedule create(
public static BftProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<BftConfigOptions> forksSchedule,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
return new IbftProtocolSchedule()
return new IbftProtocolScheduleBuilder()
.createProtocolSchedule(
config,
forksSchedule,
@@ -68,7 +68,7 @@ public class IbftProtocolSchedule extends BaseBftProtocolSchedule {
* @param evmConfiguration the evm configuration
* @return the protocol schedule
*/
public static ProtocolSchedule create(
public static BftProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<BftConfigOptions> forksSchedule,
final BftExtraDataCodec bftExtraDataCodec,

View File

@@ -15,6 +15,7 @@
package org.hyperledger.besu.consensus.ibft.statemachine;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState;
@@ -25,7 +26,6 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.util.Subscribers;
/** The Ibft round factory. */
@@ -34,7 +34,7 @@ public class IbftRoundFactory {
private final BftFinalState finalState;
private final BftBlockCreatorFactory<?> blockCreatorFactory;
private final ProtocolContext protocolContext;
private final ProtocolSchedule protocolSchedule;
private final BftProtocolSchedule protocolSchedule;
private final Subscribers<MinedBlockObserver> minedBlockObservers;
private final MessageValidatorFactory messageValidatorFactory;
private final MessageFactory messageFactory;
@@ -54,7 +54,7 @@ public class IbftRoundFactory {
public IbftRoundFactory(
final BftFinalState finalState,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final BftProtocolSchedule protocolSchedule,
final Subscribers<MinedBlockObserver> minedBlockObservers,
final MessageValidatorFactory messageValidatorFactory,
final MessageFactory messageFactory,

View File

@@ -18,13 +18,13 @@ import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import java.util.Collection;
@@ -33,7 +33,7 @@ public class MessageValidatorFactory {
private final ProposerSelector proposerSelector;
private final ProtocolContext protocolContext;
private final ProtocolSchedule protocolSchedule;
private final BftProtocolSchedule protocolSchedule;
private final BftExtraDataCodec bftExtraDataCodec;
/**
@@ -46,7 +46,7 @@ public class MessageValidatorFactory {
*/
public MessageValidatorFactory(
final ProposerSelector proposerSelector,
final ProtocolSchedule protocolSchedule,
final BftProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final BftExtraDataCodec bftExtraDataCodec) {
this.proposerSelector = proposerSelector;

View File

@@ -95,7 +95,7 @@ public class IbftProtocolScheduleTest {
final GenesisConfigOptions genesisConfig, final List<ForkSpec<BftConfigOptions>> forks) {
return new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule)
IbftProtocolSchedule.create(
IbftProtocolScheduleBuilder.create(
genesisConfig,
new ForksSchedule<>(forks),
PrivacyParameters.DEFAULT,

View File

@@ -26,7 +26,7 @@ import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.common.ForkSpec;
import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.common.bft.BftBlockHashing;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreator;
@@ -87,8 +87,8 @@ public class BftBlockCreatorTest {
final IbftExtraDataCodec bftExtraDataEncoder = new IbftExtraDataCodec();
final BaseBftProtocolSchedule bftProtocolSchedule =
new BaseBftProtocolSchedule() {
final BaseBftProtocolScheduleBuilder bftProtocolSchedule =
new BaseBftProtocolScheduleBuilder() {
@Override
public BlockHeaderValidator.Builder createBlockHeaderRuleset(
final BftConfigOptions config, final FeeMarket feeMarket) {

View File

@@ -36,6 +36,7 @@ import org.hyperledger.besu.consensus.common.bft.BftExecutors;
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BlockTimer;
import org.hyperledger.besu.consensus.common.bft.EventMultiplexer;
import org.hyperledger.besu.consensus.common.bft.Gossiper;
@@ -61,7 +62,7 @@ import org.hyperledger.besu.consensus.qbft.QbftContext;
import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec;
import org.hyperledger.besu.consensus.qbft.QbftForksSchedulesFactory;
import org.hyperledger.besu.consensus.qbft.QbftGossip;
import org.hyperledger.besu.consensus.qbft.QbftProtocolSchedule;
import org.hyperledger.besu.consensus.qbft.QbftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.qbft.blockcreation.QbftBlockCreatorFactory;
import org.hyperledger.besu.consensus.qbft.payload.MessageFactory;
import org.hyperledger.besu.consensus.qbft.statemachine.QbftBlockHeightManagerFactory;
@@ -91,7 +92,6 @@ import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
@@ -411,8 +411,8 @@ public class TestContextBuilder {
final ForksSchedule<QbftConfigOptions> forksSchedule =
QbftForksSchedulesFactory.create(genesisConfigOptions);
final ProtocolSchedule protocolSchedule =
QbftProtocolSchedule.create(
final BftProtocolSchedule protocolSchedule =
QbftProtocolScheduleBuilder.create(
genesisConfigOptions, forksSchedule, BFT_EXTRA_DATA_ENCODER, EvmConfiguration.DEFAULT);
final BftValidatorOverrides validatorOverrides = convertBftForks(qbftForks);

View File

@@ -20,8 +20,9 @@ import org.hyperledger.besu.config.BftConfigOptions;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.QbftConfigOptions;
import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.BaseBftProtocolScheduleBuilder;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@@ -32,7 +33,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration;
import java.util.Optional;
/** Defines the protocol behaviours for a blockchain using a QBFT consensus mechanism. */
public class QbftProtocolSchedule extends BaseBftProtocolSchedule {
public class QbftProtocolScheduleBuilder extends BaseBftProtocolScheduleBuilder {
/**
* Create protocol schedule.
@@ -45,14 +46,14 @@ public class QbftProtocolSchedule extends BaseBftProtocolSchedule {
* @param evmConfiguration the evm configuration
* @return the protocol schedule
*/
public static ProtocolSchedule create(
public static BftProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<QbftConfigOptions> qbftForksSchedule,
final PrivacyParameters privacyParameters,
final boolean isRevertReasonEnabled,
final BftExtraDataCodec bftExtraDataCodec,
final EvmConfiguration evmConfiguration) {
return new QbftProtocolSchedule()
return new QbftProtocolScheduleBuilder()
.createProtocolSchedule(
config,
qbftForksSchedule,
@@ -71,7 +72,7 @@ public class QbftProtocolSchedule extends BaseBftProtocolSchedule {
* @param evmConfiguration the evm configuration
* @return the protocol schedule
*/
public static ProtocolSchedule create(
public static BftProtocolSchedule create(
final GenesisConfigOptions config,
final ForksSchedule<QbftConfigOptions> qbftForksSchedule,
final BftExtraDataCodec bftExtraDataCodec,
@@ -112,7 +113,8 @@ public class QbftProtocolSchedule extends BaseBftProtocolSchedule {
protected BlockHeaderValidator.Builder createBlockHeaderRuleset(
final BftConfigOptions config, final FeeMarket feeMarket) {
checkArgument(
config instanceof QbftConfigOptions, "QbftProtocolSchedule must use QbftConfigOptions");
config instanceof QbftConfigOptions,
"QbftProtocolScheduleBuilder must use QbftConfigOptions");
final QbftConfigOptions qbftConfigOptions = (QbftConfigOptions) config;
final Optional<BaseFeeMarket> baseFeeMarket =
Optional.of(feeMarket).filter(FeeMarket::implementsBaseFee).map(BaseFeeMarket.class::cast);

View File

@@ -15,6 +15,7 @@
package org.hyperledger.besu.consensus.qbft.statemachine;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.blockcreation.BftBlockCreatorFactory;
import org.hyperledger.besu.consensus.common.bft.statemachine.BftFinalState;
@@ -25,7 +26,6 @@ import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.blockcreation.BlockCreator;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.util.Subscribers;
/** The Qbft round factory. */
@@ -34,7 +34,7 @@ public class QbftRoundFactory {
private final BftFinalState finalState;
private final BftBlockCreatorFactory<?> blockCreatorFactory;
private final ProtocolContext protocolContext;
private final ProtocolSchedule protocolSchedule;
private final BftProtocolSchedule protocolSchedule;
private final Subscribers<MinedBlockObserver> minedBlockObservers;
private final MessageValidatorFactory messageValidatorFactory;
private final MessageFactory messageFactory;
@@ -54,7 +54,7 @@ public class QbftRoundFactory {
public QbftRoundFactory(
final BftFinalState finalState,
final ProtocolContext protocolContext,
final ProtocolSchedule protocolSchedule,
final BftProtocolSchedule protocolSchedule,
final Subscribers<MinedBlockObserver> minedBlockObservers,
final MessageValidatorFactory messageValidatorFactory,
final MessageFactory messageFactory,

View File

@@ -18,6 +18,7 @@ import org.hyperledger.besu.consensus.common.bft.BftBlockInterface;
import org.hyperledger.besu.consensus.common.bft.BftContext;
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
import org.hyperledger.besu.consensus.common.bft.BftHelpers;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.common.bft.blockcreation.ProposerSelector;
import org.hyperledger.besu.consensus.qbft.validation.MessageValidator.SubsequentMessageValidator;
@@ -25,7 +26,6 @@ import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import java.util.Collection;
@@ -33,7 +33,7 @@ import java.util.Collection;
public class MessageValidatorFactory {
private final ProposerSelector proposerSelector;
private final ProtocolSchedule protocolSchedule;
private final BftProtocolSchedule protocolSchedule;
private final ProtocolContext protocolContext;
private final BftExtraDataCodec bftExtraDataCodec;
@@ -47,7 +47,7 @@ public class MessageValidatorFactory {
*/
public MessageValidatorFactory(
final ProposerSelector proposerSelector,
final ProtocolSchedule protocolSchedule,
final BftProtocolSchedule protocolSchedule,
final ProtocolContext protocolContext,
final BftExtraDataCodec bftExtraDataCodec) {
this.proposerSelector = proposerSelector;

View File

@@ -128,7 +128,7 @@ public class QbftProtocolScheduleTest {
final GenesisConfigOptions genesisConfig, final List<ForkSpec<QbftConfigOptions>> forks) {
return new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule)
QbftProtocolSchedule.create(
QbftProtocolScheduleBuilder.create(
genesisConfig,
new ForksSchedule<>(forks),
PrivacyParameters.DEFAULT,

View File

@@ -22,18 +22,14 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.List;
import java.util.NavigableSet;
import java.util.Optional;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import com.google.common.annotations.VisibleForTesting;
public class MutableProtocolSchedule implements ProtocolSchedule {
@VisibleForTesting
protected NavigableSet<ScheduledProtocolSpec> protocolSpecs =
new TreeSet<>(Comparator.comparing(ScheduledProtocolSpec::milestone).reversed());
@@ -43,7 +39,6 @@ public class MutableProtocolSchedule implements ProtocolSchedule {
this.chainId = chainId;
}
@VisibleForTesting
protected MutableProtocolSchedule(final MutableProtocolSchedule protocolSchedule) {
this.chainId = protocolSchedule.chainId;
this.protocolSpecs = protocolSchedule.protocolSpecs;
@@ -115,8 +110,4 @@ public class MutableProtocolSchedule implements ProtocolSchedule {
.setPublicWorldStateArchive(publicWorldStateArchive);
});
}
public List<ScheduledProtocolSpec> getScheduledProtocolSpecs() {
return protocolSpecs.stream().toList();
}
}