Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Added Genesis file support for specifying the maximum stack size. #1431

Merged
merged 1 commit into from
May 13, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ public interface GenesisConfigOptions {

OptionalInt getContractSizeLimit();

OptionalInt getEvmStackSize();

Map<String, Object> asMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public OptionalInt getContractSizeLimit() {
: OptionalInt.empty();
}

@Override
public OptionalInt getEvmStackSize() {
return configRoot.containsKey("evmstacksize")
? OptionalInt.of(configRoot.getInteger("evmstacksize"))
: OptionalInt.empty();
}

@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
Expand Down Expand Up @@ -163,6 +170,7 @@ public Map<String, Object> asMap() {
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getConstantinopleFixBlockNumber().ifPresent(l -> builder.put("constantinopleFixBlock", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmstacksize", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong constantinopleFixBlockNumber = OptionalLong.empty();
private Optional<BigInteger> chainId = Optional.empty();
private OptionalInt contractSizeLimit = OptionalInt.empty();
private OptionalInt stackSizeLimit = OptionalInt.empty();

@Override
public boolean isEthHash() {
Expand Down Expand Up @@ -112,6 +113,11 @@ public OptionalInt getContractSizeLimit() {
return contractSizeLimit;
}

@Override
public OptionalInt getEvmStackSize() {
return stackSizeLimit;
}

@Override
public Optional<BigInteger> getChainId() {
return chainId;
Expand Down Expand Up @@ -139,6 +145,7 @@ public Map<String, Object> asMap() {
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getConstantinopleFixBlockNumber().ifPresent(l -> builder.put("constantinopleFixBlock", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmStackSize", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}
Expand Down Expand Up @@ -198,4 +205,9 @@ public StubGenesisConfigOptions contractSizeLimit(final int contractSizeLimit) {
this.contractSizeLimit = OptionalInt.of(contractSizeLimit);
return this;
}

public StubGenesisConfigOptions stackSizeLimit(final int stackSizeLimit) {
this.stackSizeLimit = OptionalInt.of(stackSizeLimit);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public MessageFrame.Builder createMessageFrameBuilder() {
.isStatic(messageFrame.isStatic())
.completer(messageFrame -> {})
.miningBeneficiary(messageFrame.getMiningBeneficiary())
.maxStackSize(messageFrame.getMaxStackSize())
.blockHashLookup(messageFrame.getBlockHashLookup());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package tech.pegasys.pantheon.ethereum.mainnet;

import static tech.pegasys.pantheon.ethereum.vm.MessageFrame.DEFAULT_MAX_STACK_SIZE;

import tech.pegasys.pantheon.ethereum.MainnetBlockValidator;
import tech.pegasys.pantheon.ethereum.chain.Blockchain;
import tech.pegasys.pantheon.ethereum.core.Address;
Expand Down Expand Up @@ -63,8 +65,9 @@ public abstract class MainnetProtocolSpecs {
private MainnetProtocolSpecs() {}

public static ProtocolSpecBuilder<Void> frontierDefinition(
final OptionalInt configContractSizeLimit) {
int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit) {
final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
final int stackSizeLimit = configStackSizeLimit.orElse(DEFAULT_MAX_STACK_SIZE);
return new ProtocolSpecBuilder<Void>()
.gasCalculator(FrontierGasCalculator::new)
.evmBuilder(MainnetEvmRegistries::frontier)
Expand All @@ -87,7 +90,8 @@ public static ProtocolSpecBuilder<Void> frontierDefinition(
transactionValidator,
contractCreationProcessor,
messageCallProcessor,
false))
false,
stackSizeLimit))
.privateTransactionProcessorBuilder(
(gasCalculator,
transactionValidator,
Expand All @@ -98,7 +102,8 @@ public static ProtocolSpecBuilder<Void> frontierDefinition(
transactionValidator,
contractCreationProcessor,
messageCallProcessor,
false))
false,
stackSizeLimit))
.difficultyCalculator(MainnetDifficultyCalculators.FRONTIER)
.blockHeaderValidatorBuilder(MainnetBlockHeaderValidator::create)
.ommerHeaderValidatorBuilder(MainnetBlockHeaderValidator::createOmmerValidator)
Expand All @@ -115,9 +120,9 @@ public static ProtocolSpecBuilder<Void> frontierDefinition(
}

public static ProtocolSpecBuilder<Void> homesteadDefinition(
final OptionalInt configContractSizeLimit) {
int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
return frontierDefinition(configContractSizeLimit)
final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit) {
final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
return frontierDefinition(configContractSizeLimit, configStackSizeLimit)
.gasCalculator(HomesteadGasCalculator::new)
.evmBuilder(MainnetEvmRegistries::homestead)
.contractCreationProcessorBuilder(
Expand All @@ -131,8 +136,8 @@ public static ProtocolSpecBuilder<Void> homesteadDefinition(
}

public static ProtocolSpecBuilder<Void> daoRecoveryInitDefinition(
final OptionalInt contractSizeLimit) {
return homesteadDefinition(contractSizeLimit)
final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit) {
return homesteadDefinition(contractSizeLimit, configStackSizeLimit)
.blockHeaderValidatorBuilder(MainnetBlockHeaderValidator::createDaoValidator)
.blockProcessorBuilder(
(transactionProcessor,
Expand All @@ -149,24 +154,28 @@ public static ProtocolSpecBuilder<Void> daoRecoveryInitDefinition(
}

public static ProtocolSpecBuilder<Void> daoRecoveryTransitionDefinition(
final OptionalInt contractSizeLimit) {
return daoRecoveryInitDefinition(contractSizeLimit)
final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit) {
return daoRecoveryInitDefinition(contractSizeLimit, configStackSizeLimit)
.blockProcessorBuilder(MainnetBlockProcessor::new)
.name("DaoRecoveryTransition");
}

public static ProtocolSpecBuilder<Void> tangerineWhistleDefinition(
final OptionalInt contractSizeLimit) {
return homesteadDefinition(contractSizeLimit)
final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit) {
return homesteadDefinition(contractSizeLimit, configStackSizeLimit)
.gasCalculator(TangerineWhistleGasCalculator::new)
.name("TangerineWhistle");
}

public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(
final Optional<BigInteger> chainId, final OptionalInt configContractSizeLimit) {
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit) {
final int contractSizeLimit =
configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
return tangerineWhistleDefinition(OptionalInt.empty())
final int stackSizeLimit = configStackSizeLimit.orElse(DEFAULT_MAX_STACK_SIZE);

return tangerineWhistleDefinition(OptionalInt.empty(), configStackSizeLimit)
.gasCalculator(SpuriousDragonGasCalculator::new)
.messageCallProcessorBuilder(
(evm, precompileContractRegistry) ->
Expand Down Expand Up @@ -195,7 +204,8 @@ public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(
transactionValidator,
contractCreationProcessor,
messageCallProcessor,
true))
true,
stackSizeLimit))
.privateTransactionProcessorBuilder(
(gasCalculator,
transactionValidator,
Expand All @@ -206,13 +216,16 @@ public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(
transactionValidator,
contractCreationProcessor,
messageCallProcessor,
false))
false,
stackSizeLimit))
.name("SpuriousDragon");
}

public static ProtocolSpecBuilder<Void> byzantiumDefinition(
final Optional<BigInteger> chainId, final OptionalInt contractSizeLimit) {
return spuriousDragonDefinition(chainId, contractSizeLimit)
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit) {
return spuriousDragonDefinition(chainId, contractSizeLimit, configStackSizeLimit)
.evmBuilder(MainnetEvmRegistries::byzantium)
.precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium)
.difficultyCalculator(MainnetDifficultyCalculators.BYZANTIUM)
Expand All @@ -223,8 +236,10 @@ public static ProtocolSpecBuilder<Void> byzantiumDefinition(
}

public static ProtocolSpecBuilder<Void> constantinopleDefinition(
final Optional<BigInteger> chainId, final OptionalInt contractSizeLimit) {
return byzantiumDefinition(chainId, contractSizeLimit)
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit) {
return byzantiumDefinition(chainId, contractSizeLimit, configStackSizeLimit)
.difficultyCalculator(MainnetDifficultyCalculators.CONSTANTINOPLE)
.gasCalculator(ConstantinopleGasCalculator::new)
.evmBuilder(MainnetEvmRegistries::constantinople)
Expand All @@ -233,8 +248,10 @@ public static ProtocolSpecBuilder<Void> constantinopleDefinition(
}

public static ProtocolSpecBuilder<Void> constantinopleFixDefinition(
final Optional<BigInteger> chainId, final OptionalInt contractSizeLimit) {
return constantinopleDefinition(chainId, contractSizeLimit)
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit) {
return constantinopleDefinition(chainId, contractSizeLimit, configStackSizeLimit)
.gasCalculator(ConstantinopleFixGasCalculator::new)
.name("ConstantinopleFix");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MainnetTransactionProcessor implements TransactionProcessor {
private final AbstractMessageProcessor contractCreationProcessor;

private final AbstractMessageProcessor messageCallProcessor;
private final int maxStackSize;

public static class Result implements TransactionProcessor.Result {

Expand Down Expand Up @@ -126,12 +127,14 @@ public MainnetTransactionProcessor(
final TransactionValidator transactionValidator,
final AbstractMessageProcessor contractCreationProcessor,
final AbstractMessageProcessor messageCallProcessor,
final boolean clearEmptyAccounts) {
final boolean clearEmptyAccounts,
final int maxStackSize) {
this.gasCalculator = gasCalculator;
this.transactionValidator = transactionValidator;
this.contractCreationProcessor = contractCreationProcessor;
this.messageCallProcessor = messageCallProcessor;
this.clearEmptyAccounts = clearEmptyAccounts;
this.maxStackSize = maxStackSize;
}

@Override
Expand Down Expand Up @@ -214,6 +217,7 @@ public Result processTransaction(
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.isPersistingState(isPersistingState)
.maxStackSize(maxStackSize)
.build();

} else {
Expand Down Expand Up @@ -241,6 +245,7 @@ public Result processTransaction(
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.maxStackSize(maxStackSize)
.isPersistingState(isPersistingState)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ public ProtocolSchedule<C> createProtocolSchedule() {
addProtocolSpec(
protocolSchedule,
OptionalLong.of(0),
MainnetProtocolSpecs.frontierDefinition(config.getContractSizeLimit()));
MainnetProtocolSpecs.frontierDefinition(
config.getContractSizeLimit(), config.getEvmStackSize()));
addProtocolSpec(
protocolSchedule,
config.getHomesteadBlockNumber(),
MainnetProtocolSpecs.homesteadDefinition(config.getContractSizeLimit()));
MainnetProtocolSpecs.homesteadDefinition(
config.getContractSizeLimit(), config.getEvmStackSize()));

config
.getDaoForkBlock()
Expand All @@ -81,12 +83,13 @@ public ProtocolSchedule<C> createProtocolSchedule() {
addProtocolSpec(
protocolSchedule,
OptionalLong.of(daoBlockNumber),
MainnetProtocolSpecs.daoRecoveryInitDefinition(config.getContractSizeLimit()));
MainnetProtocolSpecs.daoRecoveryInitDefinition(
config.getContractSizeLimit(), config.getEvmStackSize()));
addProtocolSpec(
protocolSchedule,
OptionalLong.of(daoBlockNumber + 1),
MainnetProtocolSpecs.daoRecoveryTransitionDefinition(
config.getContractSizeLimit()));
config.getContractSizeLimit(), config.getEvmStackSize()));

// Return to the previous protocol spec after the dao fork has completed.
protocolSchedule.putMilestone(daoBlockNumber + 10, originalProtocolSpec);
Expand All @@ -95,23 +98,28 @@ public ProtocolSchedule<C> createProtocolSchedule() {
addProtocolSpec(
protocolSchedule,
config.getTangerineWhistleBlockNumber(),
MainnetProtocolSpecs.tangerineWhistleDefinition(config.getContractSizeLimit()));
MainnetProtocolSpecs.tangerineWhistleDefinition(
config.getContractSizeLimit(), config.getEvmStackSize()));
addProtocolSpec(
protocolSchedule,
config.getSpuriousDragonBlockNumber(),
MainnetProtocolSpecs.spuriousDragonDefinition(chainId, config.getContractSizeLimit()));
MainnetProtocolSpecs.spuriousDragonDefinition(
chainId, config.getContractSizeLimit(), config.getEvmStackSize()));
addProtocolSpec(
protocolSchedule,
config.getByzantiumBlockNumber(),
MainnetProtocolSpecs.byzantiumDefinition(chainId, config.getContractSizeLimit()));
MainnetProtocolSpecs.byzantiumDefinition(
chainId, config.getContractSizeLimit(), config.getEvmStackSize()));
addProtocolSpec(
protocolSchedule,
config.getConstantinopleBlockNumber(),
MainnetProtocolSpecs.constantinopleDefinition(chainId, config.getContractSizeLimit()));
MainnetProtocolSpecs.constantinopleDefinition(
chainId, config.getContractSizeLimit(), config.getEvmStackSize()));
addProtocolSpec(
protocolSchedule,
config.getConstantinopleFixBlockNumber(),
MainnetProtocolSpecs.constantinopleFixDefinition(chainId, config.getContractSizeLimit()));
MainnetProtocolSpecs.constantinopleFixDefinition(
chainId, config.getContractSizeLimit(), config.getEvmStackSize()));

LOG.info("Protocol schedule created with milestones: {}", protocolSchedule.listMilestones());
return protocolSchedule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class PrivateTransactionProcessor {

private final AbstractMessageProcessor messageCallProcessor;

private final int maxStackSize;

public static class Result implements TransactionProcessor.Result {

private final Status status;
Expand Down Expand Up @@ -135,12 +137,14 @@ public PrivateTransactionProcessor(
final TransactionValidator transactionValidator,
final AbstractMessageProcessor contractCreationProcessor,
final AbstractMessageProcessor messageCallProcessor,
final boolean clearEmptyAccounts) {
final boolean clearEmptyAccounts,
final int maxStackSize) {
this.gasCalculator = gasCalculator;
this.transactionValidator = transactionValidator;
this.contractCreationProcessor = contractCreationProcessor;
this.messageCallProcessor = messageCallProcessor;
this.clearEmptyAccounts = clearEmptyAccounts;
this.maxStackSize = maxStackSize;
}

@SuppressWarnings("unused")
Expand Down Expand Up @@ -213,6 +217,7 @@ public Result processTransaction(
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.maxStackSize(maxStackSize)
.build();

} else {
Expand Down Expand Up @@ -240,6 +245,7 @@ public Result processTransaction(
.completer(c -> {})
.miningBeneficiary(miningBeneficiary)
.blockHashLookup(blockHashLookup)
.maxStackSize(maxStackSize)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void execute(final MessageFrame frame) {
.completer(child -> complete(frame, child))
.miningBeneficiary(frame.getMiningBeneficiary())
.blockHashLookup(frame.getBlockHashLookup())
.maxStackSize(frame.getMaxStackSize())
.build();

frame.getMessageFrameStack().addFirst(childFrame);
Expand Down
Loading