From df9ad93e7a776fdfc0eae61b512d8e6a19befd4b Mon Sep 17 00:00:00 2001 From: Gabriel Fukushima Date: Tue, 14 Mar 2023 09:22:28 +1100 Subject: [PATCH] Replace getByBlockNumber using existing builder data (#5195) Signed-off-by: Gabriel Fukushima --- .../AbstractProtocolScheduleBuilder.java | 23 +++++++++++++++---- .../mainnet/ProtocolScheduleBuilder.java | 18 ++++++++++++--- .../mainnet/TimestampScheduleBuilder.java | 5 +++- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractProtocolScheduleBuilder.java index f7e650f9cc..eadb75edd7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractProtocolScheduleBuilder.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 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 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 builders); protected static class BuilderMapEntry { @@ -188,5 +197,9 @@ public abstract class AbstractProtocolScheduleBuilder { public ProtocolSpecBuilder getBuilder() { return builder; } + + public Function getModifier() { + return modifier; + } } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index 0c7d17e24f..7d3c283038 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -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 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, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TimestampScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TimestampScheduleBuilder.java index fb78241b40..211455829b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TimestampScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TimestampScheduleBuilder.java @@ -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 builders) {} }