Replace getByBlockNumber using existing builder data (#5195)

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
pull/5226/head
Gabriel Fukushima 2 years ago committed by GitHub
parent d500a77335
commit df9ad93e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractProtocolScheduleBuilder.java
  2. 18
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java
  3. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TimestampScheduleBuilder.java

@ -99,7 +99,7 @@ public abstract class AbstractProtocolScheduleBuilder {
addProtocolSpec(
protocolSchedule, e.getBlockIdentifier(), e.getBuilder(), e.modifier));
postBuildStep(specFactory);
postBuildStep(specFactory, builders);
LOG.info("Protocol schedule created with milestones: {}", protocolSchedule.listMilestones());
}
@ -149,9 +149,8 @@ public abstract class AbstractProtocolScheduleBuilder {
new BuilderMapEntry(blockVal, builder, protocolSpecAdapters.getModifierForBlock(blockVal)));
}
protected void addProtocolSpec(
protected ProtocolSpec getProtocolSpec(
final HeaderBasedProtocolSchedule protocolSchedule,
final long blockNumberOrTimestamp,
final ProtocolSpecBuilder definition,
final Function<ProtocolSpecBuilder, ProtocolSpecBuilder> modifier) {
definition
@ -160,11 +159,21 @@ public abstract class AbstractProtocolScheduleBuilder {
.privateTransactionValidatorBuilder(
() -> new PrivateTransactionValidator(protocolSchedule.getChainId()));
return modifier.apply(definition).build(protocolSchedule);
}
protected void addProtocolSpec(
final HeaderBasedProtocolSchedule protocolSchedule,
final long blockNumberOrTimestamp,
final ProtocolSpecBuilder definition,
final Function<ProtocolSpecBuilder, ProtocolSpecBuilder> modifier) {
protocolSchedule.putMilestone(
blockNumberOrTimestamp, modifier.apply(definition).build(protocolSchedule));
blockNumberOrTimestamp, getProtocolSpec(protocolSchedule, definition, modifier));
}
abstract void postBuildStep(final MainnetProtocolSpecFactory specFactory);
abstract void postBuildStep(
final MainnetProtocolSpecFactory specFactory, final TreeMap<Long, BuilderMapEntry> builders);
protected static class BuilderMapEntry {
@ -188,5 +197,9 @@ public abstract class AbstractProtocolScheduleBuilder {
public ProtocolSpecBuilder getBuilder() {
return builder;
}
public Function<ProtocolSpecBuilder, ProtocolSpecBuilder> getModifier() {
return modifier;
}
}
}

@ -21,6 +21,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration;
import java.math.BigInteger;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.stream.Stream;
@ -184,15 +185,21 @@ public class ProtocolScheduleBuilder extends AbstractProtocolScheduleBuilder {
}
@Override
protected void postBuildStep(final MainnetProtocolSpecFactory specFactory) {
protected void postBuildStep(
final MainnetProtocolSpecFactory specFactory, final TreeMap<Long, BuilderMapEntry> builders) {
// NOTE: It is assumed that Daofork blocks will not be used for private networks
// as too many risks exist around inserting a protocol-spec between daoBlock and daoBlock+10.
config
.getDaoForkBlock()
.ifPresent(
daoBlockNumber -> {
final BuilderMapEntry previousSpecBuilder =
builders.floorEntry(daoBlockNumber).getValue();
final ProtocolSpec originalProtocolSpec =
protocolSchedule.getByBlockNumber(daoBlockNumber);
getProtocolSpec(
protocolSchedule,
previousSpecBuilder.getBuilder(),
previousSpecBuilder.getModifier());
addProtocolSpec(
protocolSchedule,
daoBlockNumber,
@ -212,8 +219,13 @@ public class ProtocolScheduleBuilder extends AbstractProtocolScheduleBuilder {
.getClassicForkBlock()
.ifPresent(
classicBlockNumber -> {
final BuilderMapEntry previousSpecBuilder =
builders.floorEntry(classicBlockNumber).getValue();
final ProtocolSpec originalProtocolSpec =
protocolSchedule.getByBlockNumber(classicBlockNumber);
getProtocolSpec(
protocolSchedule,
previousSpecBuilder.getBuilder(),
previousSpecBuilder.getModifier());
addProtocolSpec(
protocolSchedule,
classicBlockNumber,

@ -20,6 +20,7 @@ import org.hyperledger.besu.evm.internal.EvmConfiguration;
import java.math.BigInteger;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Stream;
public class TimestampScheduleBuilder extends AbstractProtocolScheduleBuilder {
@ -84,5 +85,7 @@ public class TimestampScheduleBuilder extends AbstractProtocolScheduleBuilder {
}
@Override
protected void postBuildStep(final MainnetProtocolSpecFactory specFactory) {}
protected void postBuildStep(
final MainnetProtocolSpecFactory specFactory,
final TreeMap<Long, BuilderMapEntry> builders) {}
}

Loading…
Cancel
Save