Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified protocol schedule tidy up #5375

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.forkid.ForkId;
import org.hyperledger.besu.ethereum.forkid.ForkIdManager;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -210,12 +209,12 @@ public void testForkId() {
private static MilestoneStreamingTransitionProtocolSchedule createSchedule(
final GenesisConfigFile genesisConfigFile) {
final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();
BlockNumberStreamingProtocolSchedule preMergeProtocolSchedule =
new BlockNumberStreamingProtocolSchedule(
(UnifiedProtocolSchedule) MainnetProtocolSchedule.fromConfig(configOptions));
BlockNumberStreamingProtocolSchedule postMergeProtocolSchedule =
new BlockNumberStreamingProtocolSchedule(
(UnifiedProtocolSchedule) MergeProtocolSchedule.create(configOptions, false));
MilestoneStreamingProtocolSchedule preMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule) MainnetProtocolSchedule.fromConfig(configOptions));
MilestoneStreamingProtocolSchedule postMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule) MergeProtocolSchedule.create(configOptions, false));
final MilestoneStreamingTransitionProtocolSchedule schedule =
new MilestoneStreamingTransitionProtocolSchedule(
preMergeProtocolSchedule, postMergeProtocolSchedule);
Expand All @@ -228,8 +227,8 @@ public static class MilestoneStreamingTransitionProtocolSchedule
private final TransitionUtils<MilestoneStreamingProtocolSchedule> transitionUtils;

public MilestoneStreamingTransitionProtocolSchedule(
final BlockNumberStreamingProtocolSchedule preMergeProtocolSchedule,
final BlockNumberStreamingProtocolSchedule postMergeProtocolSchedule) {
final MilestoneStreamingProtocolSchedule preMergeProtocolSchedule,
final MilestoneStreamingProtocolSchedule postMergeProtocolSchedule) {
super(preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get());
transitionUtils =
new TransitionUtils<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import static com.google.common.base.Preconditions.checkState;

import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec.BlockNumberProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;

import java.math.BigInteger;
import java.util.NavigableSet;
Expand All @@ -41,13 +41,13 @@ public BftProtocolSchedule create(
final NavigableSet<ForkSpec<ProtocolSchedule>> forkSpecs,
final Optional<BigInteger> chainId) {
final BftProtocolSchedule combinedProtocolSchedule =
new BftProtocolSchedule(new UnifiedProtocolSchedule(chainId));
new BftProtocolSchedule(new DefaultProtocolSchedule(chainId));
for (ForkSpec<ProtocolSchedule> spec : forkSpecs) {
checkState(
spec.getValue() instanceof UnifiedProtocolSchedule,
"Consensus migration requires a UnifiedProtocolSchedule");
spec.getValue() instanceof DefaultProtocolSchedule,
"Consensus migration requires a DefaultProtocolSchedule");
final BftProtocolSchedule protocolSchedule =
new BftProtocolSchedule((UnifiedProtocolSchedule) spec.getValue());
new BftProtocolSchedule((DefaultProtocolSchedule) spec.getValue());

final Optional<Long> endBlock =
Optional.ofNullable(forkSpecs.higher(spec)).map(ForkSpec::getBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
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.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.evm.internal.EvmConfiguration;

Expand Down Expand Up @@ -80,7 +80,7 @@ public BftProtocolSchedule createProtocolSchedule(
isRevertReasonEnabled,
evmConfiguration)
.createProtocolSchedule();
return new BftProtocolSchedule((UnifiedProtocolSchedule) protocolSchedule);
return new BftProtocolSchedule((DefaultProtocolSchedule) protocolSchedule);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@

import static com.google.common.base.Preconditions.checkArgument;

import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;

import java.util.List;

/**
* A Bft-specific wrapper around a ProtocolSchedule that is allowed to look up ProtocolSpecs by
* block number Extending UnifiedProtocolSchedule gives this class access to the protocolSpecs
* block number. Extending DefaultProtocolSchedule gives this class access to the protocolSpecs
*/
public class BftProtocolSchedule extends UnifiedProtocolSchedule {
public class BftProtocolSchedule extends DefaultProtocolSchedule {

/**
* Construct from an existing UnifiedProtocolSchedule
* Construct from an existing DefaultProtocolSchedule
*
* @param protocolSchedule a blockNumber-based ProtocolSchedule
* @param protocolSchedule a blockNumber-supporting ProtocolSchedule
*/
public BftProtocolSchedule(final UnifiedProtocolSchedule protocolSchedule) {
public BftProtocolSchedule(final DefaultProtocolSchedule protocolSchedule) {
super(protocolSchedule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.consensus.common.bft.BftProtocolSchedule;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;
import org.hyperledger.besu.evm.internal.EvmConfiguration;

import java.math.BigInteger;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void createsCombinedProtocolScheduleWithMilestonesFromSingleProtocolSched
.isSameAs(protocolSchedule.getByBlockNumber(10L));

assertThat(
new BlockNumberStreamingProtocolSchedule(combinedProtocolSchedule)
new MilestoneStreamingProtocolSchedule(combinedProtocolSchedule)
.streamMilestoneBlocks()
.collect(Collectors.toList()))
.isEqualTo(List.of(0L, 5L, 10L));
Expand Down Expand Up @@ -141,7 +141,7 @@ public void createsCombinedProtocolScheduleWithMilestonesFromMultipleSchedules()
.isSameAs(protocolSchedule3.getByBlockNumber(220L));

assertThat(
new BlockNumberStreamingProtocolSchedule(combinedProtocolSchedule)
new MilestoneStreamingProtocolSchedule(combinedProtocolSchedule)
.streamMilestoneBlocks()
.collect(Collectors.toList()))
.isEqualTo(List.of(0L, 5L, 10L, 100L, 105L, 110L, 200L, 220L));
Expand All @@ -159,6 +159,6 @@ private BftProtocolSchedule createProtocolSchedule(
EvmConfiguration.DEFAULT);

return new BftProtocolSchedule(
(UnifiedProtocolSchedule) protocolScheduleBuilder.createProtocolSchedule());
(DefaultProtocolSchedule) protocolScheduleBuilder.createProtocolSchedule());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.evm.internal.EvmConfiguration;

Expand Down Expand Up @@ -211,9 +211,9 @@ public void blockRewardSpecifiedInTransitionCreatesNewMilestone() {
new MutableBftConfigOptions(JsonBftConfigOptions.DEFAULT);
blockRewardTransition.setBlockRewardWei(forkBlockReward);

final BlockNumberStreamingProtocolSchedule schedule =
new BlockNumberStreamingProtocolSchedule(
(UnifiedProtocolSchedule)
final MilestoneStreamingProtocolSchedule schedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule)
createProtocolSchedule(
List.of(
new ForkSpec<>(0, configOptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void blockModeTransitionsCreatesBlockModeHeaderValidators() {
new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT),
new ForkSpec<>(1, arbitraryTransition),
new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT)));
assertThat(new BlockNumberStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count())
assertThat(new MilestoneStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count())
.isEqualTo(3);
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue();
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.MilestoneStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void contractModeTransitionsCreatesContractModeHeaderValidators() {
new ForkSpec<>(0, qbftConfigOptions),
new ForkSpec<>(1, arbitraryTransition),
new ForkSpec<>(2, contractTransition)));
assertThat(new BlockNumberStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count())
assertThat(new MilestoneStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count())
.isEqualTo(3);
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue();
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue();
Expand Down Expand Up @@ -118,7 +118,7 @@ public void blockModeTransitionsCreatesBlockModeHeaderValidators() {
new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT),
new ForkSpec<>(1, arbitraryTransition),
new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT)));
assertThat(new BlockNumberStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count())
assertThat(new MilestoneStreamingProtocolSchedule(schedule).streamMilestoneBlocks().count())
.isEqualTo(3);
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue();
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,21 @@ static WithdrawalsValidator getWithdrawalsValidator(
.timestamp(blockTimestamp)
.number(blockNumber)
.buildBlockHeader();
return Optional.ofNullable(protocolSchedule.getByBlockHeader(blockHeader))
.map(ProtocolSpec::getWithdrawalsValidator)
// TODO Withdrawals this is a quirk of the fact timestampSchedule doesn't fallback to the
// previous fork. This might be resolved when
// https://github.com/hyperledger/besu/issues/4789 is played
// and if we can combine protocolSchedule and timestampSchedule.
.orElseGet(WithdrawalsValidator.ProhibitedWithdrawals::new);
return getWithdrawalsValidator(protocolSchedule.getByBlockHeader(blockHeader));
}

static WithdrawalsValidator getWithdrawalsValidator(
final ProtocolSchedule protocolSchedule,
final BlockHeader parentBlockHeader,
final long timestampForNextBlock) {

return Optional.ofNullable(
protocolSchedule.getForNextBlockHeader(parentBlockHeader, timestampForNextBlock))
return getWithdrawalsValidator(
protocolSchedule.getForNextBlockHeader(parentBlockHeader, timestampForNextBlock));
}

private static WithdrawalsValidator getWithdrawalsValidator(final ProtocolSpec protocolSchedule) {
return Optional.ofNullable(protocolSchedule)
.map(ProtocolSpec::getWithdrawalsValidator)
// TODO Withdrawals this is a quirk of the fact timestampSchedule doesn't fallback to the
// previous fork. This might be resolved when
// https://github.com/hyperledger/besu/issues/4789 is played
// and if we can combine protocolSchedule and timestampSchedule.
.orElseGet(WithdrawalsValidator.ProhibitedWithdrawals::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.consensus.merge.MergeProtocolSchedule;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
Expand Down Expand Up @@ -107,7 +106,7 @@ public Map<String, JsonRpcMethod> methods(
blockchainQueries, protocolSchedule, transactionPool, privacyParameters),
new ExecutionEngineJsonRpcMethods(
miningCoordinator,
MergeProtocolSchedule.create(genesisConfigOptions, privacyParameters, false),
protocolSchedule,
protocolContext,
ethPeers,
consensusEngineServer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.mainnet.BlockImportResult;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec.BlockNumberProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.UnifiedProtocolSchedule;
import org.hyperledger.besu.util.Subscribers;

import java.math.BigInteger;
Expand Down Expand Up @@ -143,8 +143,8 @@ private static Subscribers<MinedBlockObserver> subscribersContaining(
}

private ProtocolSchedule singleSpecSchedule(final ProtocolSpec protocolSpec) {
final UnifiedProtocolSchedule protocolSchedule =
new UnifiedProtocolSchedule(Optional.of(BigInteger.valueOf(1234)));
final DefaultProtocolSchedule protocolSchedule =
new DefaultProtocolSchedule(Optional.of(BigInteger.valueOf(1234)));
protocolSchedule.putMilestone(BlockNumberProtocolSpec::create, 0, protocolSpec);
return protocolSchedule;
}
Expand Down
Loading