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

Reconfigure how Protocol Specs are created WRT EVM condiguration #7245

Merged
merged 8 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Reduce lock contention on transaction pool when building a block [#7180](https://github.com/hyperledger/besu/pull/7180)
- Update Docker base image to Ubuntu 24.04 [#7251](https://github.com/hyperledger/besu/pull/7251)
- Add LUKSO as predefined network name [#7223](https://github.com/hyperledger/besu/pull/7223)
- Refactored how code, initcode, and max stack size are configured in forks. [#7245](https://github.com/hyperledger/besu/pull/7245)

### Bug fixes
- Validation errors ignored in accounts-allowlist and empty list [#7138](https://github.com/hyperledger/besu/issues/7138)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hyperledger.besu.evm.MainnetEVMs;
import org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule;
import org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator;
import org.hyperledger.besu.evm.gascalculator.DieHardGasCalculator;
import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator;
Expand All @@ -44,7 +43,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;

Expand All @@ -56,50 +54,38 @@ private ClassicProtocolSpecs() {
}

public static ProtocolSpecBuilder classicRecoveryInitDefinition(
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final EvmConfiguration evmConfiguration) {
return MainnetProtocolSpecs.homesteadDefinition(
contractSizeLimit, configStackSizeLimit, evmConfiguration)
return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration)
.blockHeaderValidatorBuilder(
feeMarket -> MainnetBlockHeaderValidator.createClassicValidator())
.name("ClassicRecoveryInit");
}

public static ProtocolSpecBuilder tangerineWhistleDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final EvmConfiguration evmConfiguration) {
return MainnetProtocolSpecs.homesteadDefinition(
contractSizeLimit, configStackSizeLimit, evmConfiguration)
final Optional<BigInteger> chainId, final EvmConfiguration evmConfiguration) {
return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration)
.isReplayProtectionSupported(true)
.gasCalculator(TangerineWhistleGasCalculator::new)
.transactionValidatorFactoryBuilder(
(gasCalculator, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId))
(evm, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(
evm.getGasCalculator(), gasLimitCalculator, true, chainId))
.name("ClassicTangerineWhistle");
}

public static ProtocolSpecBuilder dieHardDefinition(
final Optional<BigInteger> chainId,
final OptionalInt ignoredConfigContractSizeLimit,
final OptionalInt configStackSizeLimit,
final EvmConfiguration evmConfiguration) {
return tangerineWhistleDefinition(
chainId, OptionalInt.empty(), configStackSizeLimit, evmConfiguration)
final Optional<BigInteger> chainId, final EvmConfiguration evmConfiguration) {
return tangerineWhistleDefinition(chainId, evmConfiguration)
.gasCalculator(DieHardGasCalculator::new)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_PAUSED)
.name("DieHard");
}

public static ProtocolSpecBuilder gothamDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return dieHardDefinition(chainId, contractSizeLimit, configStackSizeLimit, evmConfiguration)
return dieHardDefinition(chainId, evmConfiguration)
.blockReward(MAX_BLOCK_REWARD)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_DELAYED)
.blockProcessorBuilder(
Expand All @@ -122,35 +108,23 @@ public static ProtocolSpecBuilder gothamDefinition(

public static ProtocolSpecBuilder defuseDifficultyBombDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return gothamDefinition(
chainId, contractSizeLimit, configStackSizeLimit, ecip1017EraRounds, evmConfiguration)
return gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_REMOVED)
.transactionValidatorFactoryBuilder(
(gasCalculator, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId))
(evm, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(
evm.getGasCalculator(), gasLimitCalculator, true, chainId))
.name("DefuseDifficultyBomb");
}

public static ProtocolSpecBuilder atlantisDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
final int contractSizeLimit =
configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return gothamDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
ecip1017EraRounds,
evmConfiguration)
return gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration)
.evmBuilder(MainnetEVMs::byzantium)
.evmConfiguration(evmConfiguration)
.gasCalculator(SpuriousDragonGasCalculator::new)
Expand All @@ -163,13 +137,9 @@ public static ProtocolSpecBuilder atlantisDefinition(
? ClassicProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled
: ClassicProtocolSpecs::byzantiumTransactionReceiptFactory)
.contractCreationProcessorBuilder(
(gasCalculator, evm) ->
evm ->
new ContractCreationProcessor(
gasCalculator,
evm,
true,
Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
1))
evm, true, Collections.singletonList(MaxCodeSizeRule.from(evm)), 1))
.transactionProcessorBuilder(
(gasCalculator,
feeMarket,
Expand All @@ -183,26 +153,18 @@ public static ProtocolSpecBuilder atlantisDefinition(
messageCallProcessor,
true,
false,
stackSizeLimit,
evmConfiguration.evmStackSize(),
feeMarket,
CoinbaseFeePriceCalculator.frontier()))
.name("Atlantis");
}

public static ProtocolSpecBuilder aghartaDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return atlantisDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return atlantisDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.evmBuilder(MainnetEVMs::constantinople)
.gasCalculator(PetersburgGasCalculator::new)
.evmBuilder(MainnetEVMs::constantinople)
Expand All @@ -212,18 +174,10 @@ public static ProtocolSpecBuilder aghartaDefinition(

public static ProtocolSpecBuilder phoenixDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return aghartaDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return aghartaDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.gasCalculator(IstanbulGasCalculator::new)
.evmBuilder(
(gasCalculator, evmConfig) ->
Expand All @@ -235,18 +189,10 @@ public static ProtocolSpecBuilder phoenixDefinition(

public static ProtocolSpecBuilder thanosDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return phoenixDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return phoenixDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.blockHeaderValidatorBuilder(
feeMarket ->
MainnetBlockHeaderValidator.createPgaBlockHeaderValidator(
Expand Down Expand Up @@ -280,23 +226,15 @@ private static TransactionReceipt byzantiumTransactionReceiptFactoryWithReasonEn

public static ProtocolSpecBuilder magnetoDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return thanosDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return thanosDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.gasCalculator(BerlinGasCalculator::new)
.transactionValidatorFactoryBuilder(
(gasCalculator, gasLimitCalculator, feeMarket) ->
(evm, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(
gasCalculator,
evm.getGasCalculator(),
gasLimitCalculator,
true,
chainId,
Expand All @@ -310,47 +248,24 @@ public static ProtocolSpecBuilder magnetoDefinition(

public static ProtocolSpecBuilder mystiqueDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
final int contractSizeLimit =
configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
return magnetoDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return magnetoDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.gasCalculator(LondonGasCalculator::new)
.contractCreationProcessorBuilder(
(gasCalculator, evm) ->
evm ->
new ContractCreationProcessor(
gasCalculator,
evm,
true,
List.of(MaxCodeSizeRule.of(contractSizeLimit), PrefixCodeRule.of()),
1))
evm, true, List.of(MaxCodeSizeRule.from(evm), PrefixCodeRule.of()), 1))
.name("Mystique");
}

public static ProtocolSpecBuilder spiralDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return mystiqueDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return mystiqueDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
// EIP-3860
.gasCalculator(ShanghaiGasCalculator::new)
// EIP-3855
Expand All @@ -372,7 +287,7 @@ public static ProtocolSpecBuilder spiralDefinition(
messageCallProcessor,
true,
true,
stackSizeLimit,
evmConfiguration.evmStackSize(),
feeMarket,
CoinbaseFeePriceCalculator.frontier()))
.name("Spiral");
Expand Down
Loading
Loading