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

Commit

Permalink
Make the contract size limit configurable in the genesis config, maki…
Browse files Browse the repository at this point in the history
…ng it possible to override milestone based configurations in a private network.
  • Loading branch information
rojotek committed Apr 6, 2019
1 parent 6f8ac6d commit 2414e79
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ public interface GenesisConfigOptions {

OptionalInt getChainId();

OptionalInt getContractSizeLimit();

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

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

@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
Expand Down Expand Up @@ -153,6 +160,7 @@ public Map<String, Object> asMap() {
getByzantiumBlockNumber().ifPresent(l -> builder.put("byzantiumBlock", l));
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getConstantinopleFixBlockNumber().ifPresent(l -> builder.put("constantinopleFixBlock", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}
Expand Down
3 changes: 2 additions & 1 deletion config/src/main/resources/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"constantinopleFixBlock": 0,
"contractSizeLimit": 2147483647,
"ethash": {
"fixeddifficulty": 100
}
},
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1000000",
"gasLimit": "0x1fffffffffffff",
"difficulty": "0x10000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong constantinopleBlockNumber = OptionalLong.empty();
private OptionalLong constantinopleFixBlockNumber = OptionalLong.empty();
private OptionalInt chainId = OptionalInt.empty();
private OptionalInt contractSizeLimit = OptionalInt.empty();

@Override
public boolean isEthHash() {
Expand Down Expand Up @@ -104,6 +105,11 @@ public OptionalLong getConstantinopleFixBlockNumber() {
return constantinopleFixBlockNumber;
}

@Override
public OptionalInt getContractSizeLimit() {
return contractSizeLimit;
}

@Override
public OptionalInt getChainId() {
return chainId;
Expand All @@ -130,6 +136,7 @@ public Map<String, Object> asMap() {
getByzantiumBlockNumber().ifPresent(l -> builder.put("byzantiumBlock", l));
getConstantinopleBlockNumber().ifPresent(l -> builder.put("constantinopleBlock", l));
getConstantinopleFixBlockNumber().ifPresent(l -> builder.put("constantinopleFixBlock", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
}
Expand Down Expand Up @@ -184,4 +191,9 @@ public StubGenesisConfigOptions chainId(final int chainId) {
this.chainId = OptionalInt.of(chainId);
return this;
}

public StubGenesisConfigOptions contractSizeLimit(final int contractSizeLimit) {
this.contractSizeLimit = OptionalInt.of(contractSizeLimit);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -59,7 +60,8 @@ public abstract class MainnetProtocolSpecs {

private MainnetProtocolSpecs() {}

public static ProtocolSpecBuilder<Void> frontierDefinition() {
public static ProtocolSpecBuilder<Void> frontierDefinition(final OptionalInt contractSizeLimit) {
int frontierContractSizeLimit = contractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
return new ProtocolSpecBuilder<Void>()
.gasCalculator(FrontierGasCalculator::new)
.evmBuilder(MainnetEvmRegistries::frontier)
Expand All @@ -68,7 +70,7 @@ public static ProtocolSpecBuilder<Void> frontierDefinition() {
.contractCreationProcessorBuilder(
(gasCalculator, evm) ->
new MainnetContractCreationProcessor(
gasCalculator, evm, false, FRONTIER_CONTRACT_SIZE_LIMIT, 0))
gasCalculator, evm, false, frontierContractSizeLimit, 0))
.transactionValidatorBuilder(
gasCalculator -> new MainnetTransactionValidator(gasCalculator, false))
.transactionProcessorBuilder(
Expand Down Expand Up @@ -108,22 +110,24 @@ public static ProtocolSpecBuilder<Void> frontierDefinition() {
.name("Frontier");
}

public static ProtocolSpecBuilder<Void> homesteadDefinition() {
return frontierDefinition()
public static ProtocolSpecBuilder<Void> homesteadDefinition(final OptionalInt contractSizeLimit) {
int frontierContractSizeLimit = contractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
return frontierDefinition(contractSizeLimit)
.gasCalculator(HomesteadGasCalculator::new)
.evmBuilder(MainnetEvmRegistries::homestead)
.contractCreationProcessorBuilder(
(gasCalculator, evm) ->
new MainnetContractCreationProcessor(
gasCalculator, evm, true, FRONTIER_CONTRACT_SIZE_LIMIT, 0))
gasCalculator, evm, true, frontierContractSizeLimit, 0))
.transactionValidatorBuilder(
gasCalculator -> new MainnetTransactionValidator(gasCalculator, true))
.difficultyCalculator(MainnetDifficultyCalculators.HOMESTEAD)
.name("Homestead");
}

public static ProtocolSpecBuilder<Void> daoRecoveryInitDefinition() {
return homesteadDefinition()
public static ProtocolSpecBuilder<Void> daoRecoveryInitDefinition(
final OptionalInt contractSizeLimit) {
return homesteadDefinition(contractSizeLimit)
.blockHeaderValidatorBuilder(MainnetBlockHeaderValidator::createDaoValidator)
.blockProcessorBuilder(
(transactionProcessor,
Expand All @@ -139,20 +143,25 @@ public static ProtocolSpecBuilder<Void> daoRecoveryInitDefinition() {
.name("DaoRecoveryInit");
}

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

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

public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(final int chainId) {
return tangerineWhistleDefinition()
public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(
final int chainId, final OptionalInt contractSizeLimit) {
final int spuriousDragonContractSizeLimit =
contractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
return tangerineWhistleDefinition(OptionalInt.empty())
.gasCalculator(SpuriousDragonGasCalculator::new)
.messageCallProcessorBuilder(
(evm, precompileContractRegistry) ->
Expand All @@ -166,7 +175,7 @@ public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(final int chain
gasCalculator,
evm,
true,
SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT,
spuriousDragonContractSizeLimit,
1,
SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES))
.transactionValidatorBuilder(
Expand Down Expand Up @@ -196,8 +205,9 @@ public static ProtocolSpecBuilder<Void> spuriousDragonDefinition(final int chain
.name("SpuriousDragon");
}

public static ProtocolSpecBuilder<Void> byzantiumDefinition(final int chainId) {
return spuriousDragonDefinition(chainId)
public static ProtocolSpecBuilder<Void> byzantiumDefinition(
final int chainId, final OptionalInt contractSizeLimit) {
return spuriousDragonDefinition(chainId, contractSizeLimit)
.evmBuilder(MainnetEvmRegistries::byzantium)
.precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium)
.difficultyCalculator(MainnetDifficultyCalculators.BYZANTIUM)
Expand All @@ -207,17 +217,19 @@ public static ProtocolSpecBuilder<Void> byzantiumDefinition(final int chainId) {
.name("Byzantium");
}

public static ProtocolSpecBuilder<Void> constantinopleDefinition(final int chainId) {
return byzantiumDefinition(chainId)
public static ProtocolSpecBuilder<Void> constantinopleDefinition(
final int chainId, final OptionalInt contractSizeLimit) {
return byzantiumDefinition(chainId, contractSizeLimit)
.difficultyCalculator(MainnetDifficultyCalculators.CONSTANTINOPLE)
.gasCalculator(ConstantinopleGasCalculator::new)
.evmBuilder(MainnetEvmRegistries::constantinople)
.blockReward(CONSTANTINOPLE_BLOCK_REWARD)
.name("Constantinople");
}

public static ProtocolSpecBuilder<Void> constantinopleFixDefinition(final int chainId) {
return constantinopleDefinition(chainId)
public static ProtocolSpecBuilder<Void> constantinopleFixDefinition(
final int chainId, final OptionalInt contractSizeLimit) {
return constantinopleDefinition(chainId, contractSizeLimit)
.gasCalculator(ConstantinopleFixGasCalculator::new)
.name("ConstantinopleFix");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public ProtocolSchedule<C> createProtocolSchedule() {
validateForkOrdering();

addProtocolSpec(
protocolSchedule, OptionalLong.of(0), MainnetProtocolSpecs.frontierDefinition());
protocolSchedule,
OptionalLong.of(0),
MainnetProtocolSpecs.frontierDefinition(config.getContractSizeLimit()));
addProtocolSpec(
protocolSchedule,
config.getHomesteadBlockNumber(),
MainnetProtocolSpecs.homesteadDefinition());
MainnetProtocolSpecs.homesteadDefinition(config.getContractSizeLimit()));

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

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

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 @@ -30,6 +30,7 @@

import java.util.ArrayDeque;
import java.util.Collection;
import java.util.OptionalInt;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -116,7 +117,7 @@ protected void runTest() {
final EnvironmentInformation execEnv = spec.getExec();

final ProtocolSpec<Void> protocolSpec =
MainnetProtocolSpecs.frontierDefinition()
MainnetProtocolSpecs.frontierDefinition(OptionalInt.empty())
.privacyParameters(PrivacyParameters.noPrivacy())
.build(new MutableProtocolSchedule<>(CHAIN_ID));

Expand Down

0 comments on commit 2414e79

Please sign in to comment.