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

[Merge] Spec v1.1.1 adoption #4445

Merged
merged 11 commits into from
Oct 6, 2021
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ allprojects {
}
}

def refTestVersion = 'v1.1.0'
def refTestVersion = 'v1.1.1'
def blsRefTestVersion = 'v0.1.0'
def refTestBaseUrl = 'https://github.com/ethereum/eth2.0-spec-tests/releases/download'
def blsRefTestBaseUrl = 'https://github.com/ethereum/bls12-381-tests/releases/download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ private void processMilestone(final SpecVersion spec) {
final Bytes4 forkVersion = maybeForkVersion.get();
final UInt64 forkSlot = spec.miscHelpers().computeStartSlotAtEpoch(forkEpoch);
final UInt64 genesisOffset = spec.getForkChoiceUtil().getSlotStartTime(forkSlot, UInt64.ZERO);
final Fork fork = new Fork(prevForkVersion.orElse(forkVersion), forkVersion, forkEpoch);
final Bytes4 prevForkVersionOrSame =
prevForkVersion.isPresent() && !forkEpoch.isZero() ? prevForkVersion.get() : forkVersion;
final Fork fork = new Fork(prevForkVersionOrSame, forkVersion, forkEpoch);

// Validate against prev fork
if (epochToMilestone.isEmpty() && !forkSlot.equals(UInt64.ZERO)) {
Expand Down
10 changes: 10 additions & 0 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodyBuilder;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.forkchoice.MutableStore;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyStore;
Expand Down Expand Up @@ -247,8 +248,17 @@ public int getSyncCommitteeSize(final UInt64 slot) {
// Genesis
public BeaconState initializeBeaconStateFromEth1(
Bytes32 eth1BlockHash, UInt64 eth1Timestamp, List<? extends Deposit> deposits) {
return initializeBeaconStateFromEth1(eth1BlockHash, eth1Timestamp, deposits, Optional.empty());
}

public BeaconState initializeBeaconStateFromEth1(
Bytes32 eth1BlockHash,
UInt64 eth1Timestamp,
List<? extends Deposit> deposits,
Optional<ExecutionPayloadHeader> payloadHeader) {
final GenesisGenerator genesisGenerator = createGenesisGenerator();
genesisGenerator.updateCandidateState(eth1BlockHash, eth1Timestamp, deposits);
payloadHeader.ifPresent(genesisGenerator::updateExecutionPayloadHeader);
return genesisGenerator.getGenesisState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,6 @@ public SpecConfigBuilder mergeBuilder(final Consumer<MergeBuilder> consumer) {

public class MergeBuilder {

// Genesis
private UInt64 genesisGasLimit;
private UInt256 genesisBaseFeePerGas;

// Fork
private Bytes4 mergeForkVersion;
private UInt64 mergeForkEpoch;
Expand All @@ -689,34 +685,15 @@ private MergeBuilder() {}

SpecConfigMerge build(final SpecConfigAltair specConfig) {
return new SpecConfigMerge(
specConfig,
genesisGasLimit,
genesisBaseFeePerGas,
mergeForkVersion,
mergeForkEpoch,
terminalTotalDifficulty);
specConfig, mergeForkVersion, mergeForkEpoch, terminalTotalDifficulty);
}

void validate() {
validateConstant("genesisGasLimit", genesisGasLimit);
validateConstant("genesisBaseFeePerGas", genesisBaseFeePerGas);
validateConstant("mergeForkVersion", mergeForkVersion);
validateConstant("mergeForkEpoch", mergeForkEpoch);
validateConstant("terminalTotalDifficulty", terminalTotalDifficulty);
}

public MergeBuilder genesisGasLimit(UInt64 genesisGasLimit) {
checkNotNull(genesisGasLimit);
this.genesisGasLimit = genesisGasLimit;
return this;
}

public MergeBuilder genesisBaseFeePerGas(UInt256 genesisBaseFeePerGas) {
checkNotNull(genesisBaseFeePerGas);
this.genesisBaseFeePerGas = genesisBaseFeePerGas;
return this;
}

public MergeBuilder mergeForkVersion(Bytes4 mergeForkVersion) {
checkNotNull(mergeForkVersion);
this.mergeForkVersion = mergeForkVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@

public class SpecConfigMerge extends DelegatingSpecConfigAltair {

// Genesis
private UInt64 genesisGasLimit;
private UInt256 genesisBaseFeePerGas;

// Fork
private final Bytes4 mergeForkVersion;
private final UInt64 mergeForkEpoch;
Expand All @@ -35,17 +31,13 @@ public class SpecConfigMerge extends DelegatingSpecConfigAltair {

public SpecConfigMerge(
SpecConfigAltair specConfig,
UInt64 genesisGasLimit,
UInt256 genesisBaseFeePerGas,
Bytes4 mergeForkVersion,
UInt64 mergeForkEpoch,
UInt256 terminalTotalDifficulty) {
super(specConfig);
this.mergeForkVersion = mergeForkVersion;
this.mergeForkEpoch = mergeForkEpoch;
this.terminalTotalDifficulty = terminalTotalDifficulty;
this.genesisBaseFeePerGas = genesisBaseFeePerGas;
this.genesisGasLimit = genesisGasLimit;
}

public static SpecConfigMerge required(final SpecConfig specConfig) {
Expand All @@ -70,14 +62,6 @@ public static <T> T required(
+ specConfig.getClass().getSimpleName())));
}

public UInt64 getGenesisGasLimit() {
return genesisGasLimit;
}

public UInt256 getGenesisBaseFeePerGas() {
return genesisBaseFeePerGas;
}

public Bytes4 getMergeForkVersion() {
return mergeForkVersion;
}
Expand All @@ -104,20 +88,13 @@ public boolean equals(Object o) {
return false;
}
SpecConfigMerge that = (SpecConfigMerge) o;
return Objects.equals(genesisGasLimit, that.genesisGasLimit)
&& Objects.equals(genesisBaseFeePerGas, that.genesisBaseFeePerGas)
&& Objects.equals(mergeForkVersion, that.mergeForkVersion)
return Objects.equals(mergeForkVersion, that.mergeForkVersion)
&& Objects.equals(mergeForkEpoch, that.mergeForkEpoch)
&& Objects.equals(terminalTotalDifficulty, that.terminalTotalDifficulty);
}

@Override
public int hashCode() {
return Objects.hash(
genesisGasLimit,
genesisBaseFeePerGas,
mergeForkVersion,
mergeForkEpoch,
terminalTotalDifficulty);
return Objects.hash(mergeForkVersion, mergeForkEpoch, terminalTotalDifficulty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
package tech.pegasys.teku.spec.datastructures.interop;

import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSKeyPair;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.DepositData;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.util.DepositGenerator;
Expand All @@ -37,7 +39,7 @@ public static BeaconState createMockedStartInitialBeaconState(
final long genesisTime,
List<BLSKeyPair> validatorKeys) {
return createMockedStartInitialBeaconState(
spec, eth1BlockHash, genesisTime, validatorKeys, true);
spec, eth1BlockHash, genesisTime, validatorKeys, Optional.empty(), true);
}

public static BeaconState createMockedStartInitialBeaconState(
Expand All @@ -50,6 +52,7 @@ public static BeaconState createMockedStartInitialBeaconState(
MockStartBeaconStateGenerator.INTEROP_ETH1_BLOCK_HASH,
genesisTime,
validatorKeys,
Optional.empty(),
signDeposits);
}

Expand All @@ -58,11 +61,13 @@ public static BeaconState createMockedStartInitialBeaconState(
final Bytes32 eth1BlockHash,
final long genesisTime,
List<BLSKeyPair> validatorKeys,
Optional<ExecutionPayloadHeader> payloadHeader,
boolean signDeposits) {
final List<DepositData> initialDepositData =
new MockStartDepositGenerator(new DepositGenerator(spec, signDeposits))
.createDeposits(validatorKeys);
return new MockStartBeaconStateGenerator(spec)
.createInitialBeaconState(eth1BlockHash, UInt64.valueOf(genesisTime), initialDepositData);
.createInitialBeaconState(
eth1BlockHash, UInt64.valueOf(genesisTime), initialDepositData, payloadHeader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.operations.DepositData;
import tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
Expand Down Expand Up @@ -47,14 +49,23 @@ public BeaconState createInitialBeaconState(
final Bytes32 eth1BlockHash,
final UInt64 genesisTime,
final List<DepositData> initialDepositData) {
return createInitialBeaconState(
eth1BlockHash, genesisTime, initialDepositData, Optional.empty());
}

public BeaconState createInitialBeaconState(
final Bytes32 eth1BlockHash,
final UInt64 genesisTime,
final List<DepositData> initialDepositData,
Optional<ExecutionPayloadHeader> payloadHeader) {
final List<DepositWithIndex> deposits = new ArrayList<>();
for (int index = 0; index < initialDepositData.size(); index++) {
final DepositData data = initialDepositData.get(index);
DepositWithIndex deposit = new DepositWithIndex(data, UInt64.valueOf(index));
deposits.add(deposit);
}
final BeaconState initialState =
spec.initializeBeaconStateFromEth1(eth1BlockHash, genesisTime, deposits);
spec.initializeBeaconStateFromEth1(eth1BlockHash, genesisTime, deposits, payloadHeader);
return initialState.updated(state -> state.setGenesis_time(genesisTime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand All @@ -38,7 +37,6 @@
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.ssz.SszMutableList;
import tech.pegasys.teku.ssz.schema.SszListSchema;
import tech.pegasys.teku.ssz.type.Bytes20;
import tech.pegasys.teku.util.config.Constants;

public class GenesisGenerator {
Expand Down Expand Up @@ -74,6 +72,12 @@ public GenesisGenerator(final SpecVersion genesisSpec, final Fork genesisFork) {
.createWritableCopy();
}

public void updateExecutionPayloadHeader(ExecutionPayloadHeader payloadHeader) {
state
.toMutableVersionMerge()
.ifPresent(stateMerge -> stateMerge.setLatestExecutionPayloadHeader(payloadHeader));
}

public void updateCandidateState(
Bytes32 eth1BlockHash, UInt64 eth1Timestamp, List<? extends Deposit> deposits) {
updateGenesisTime(eth1Timestamp);
Expand All @@ -82,27 +86,6 @@ public void updateCandidateState(
new Eth1Data(
Bytes32.ZERO, UInt64.valueOf(depositDataList.size() + deposits.size()), eth1BlockHash));

state
.toMutableVersionMerge()
.ifPresent(
stateMerge ->
stateMerge.setLatestExecutionPayloadHeader(
new ExecutionPayloadHeader(
Bytes32.ZERO,
Bytes20.ZERO,
Bytes32.ZERO,
Bytes32.ZERO,
Bytes.wrap(new byte[SpecConfig.BYTES_PER_LOGS_BLOOM]),
eth1BlockHash,
UInt64.ZERO,
specConfig.toVersionMerge().orElseThrow().getGenesisGasLimit(),
UInt64.ZERO,
eth1Timestamp,
Bytes.EMPTY,
specConfig.toVersionMerge().orElseThrow().getGenesisBaseFeePerGas(),
eth1BlockHash,
Bytes32.ZERO)));

// Process deposits
deposits.forEach(
deposit -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,10 @@ private ForkSchedule buildForkSchedule(final SpecConfig specConfig) {

private Fork getAltairFork(final SpecConfigAltair config) {
final UInt64 forkEpoch = config.getAltairForkEpoch();
return new Fork(config.getGenesisForkVersion(), config.getAltairForkVersion(), forkEpoch);
return new Fork(
forkEpoch.isZero() ? config.getAltairForkVersion() : config.getGenesisForkVersion(),
config.getAltairForkVersion(),
forkEpoch);
}

private Fork getPhase0Fork(final SpecConfig config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ GENESIS_FORK_VERSION: 0x00000001
# [customized] Faster to spin up testnets, but does not give validator reasonable warning time for genesis
GENESIS_DELAY: 300

# Genesis - Merge
GENESIS_GAS_LIMIT: 30000000
GENESIS_BASE_FEE_PER_GAS: 1000000000

# Forking
# ---------------------------------------------------------------
# Values provided for illustrative purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ GENESIS_FORK_VERSION: 0x00000001
# [customized] Faster to spin up testnets, but does not give validator reasonable warning time for genesis
GENESIS_DELAY: 300

# Genesis - Merge
GENESIS_GAS_LIMIT: 30000000
GENESIS_BASE_FEE_PER_GAS: 1000000000

# Forking
# ---------------------------------------------------------------
# Values provided for illustrative purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ GENESIS_FORK_VERSION: 0x00000000
# 604800 seconds (7 days)
GENESIS_DELAY: 604800

# Genesis - Merge
GENESIS_GAS_LIMIT: 30000000
GENESIS_BASE_FEE_PER_GAS: 1000000000

# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ GENESIS_FORK_VERSION: 0x00000000
# 604800 seconds (7 days)
GENESIS_DELAY: 604800

# Genesis - Merge
GENESIS_GAS_LIMIT: 30000000
GENESIS_BASE_FEE_PER_GAS: 1000000000

# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ GENESIS_FORK_VERSION: 0x00000001
# [customized] Faster to spin up testnets, but does not give validator reasonable warning time for genesis
GENESIS_DELAY: 300

# Genesis - Merge
GENESIS_GAS_LIMIT: 30000000
GENESIS_BASE_FEE_PER_GAS: 1000000000

# Forking
# ---------------------------------------------------------------
# Values provided for illustrative purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ GENESIS_FORK_VERSION: 0x00001020
# Customized for Prater: 1919188 seconds (Mar-23-2021 02:00:00 PM +UTC)
GENESIS_DELAY: 1919188

# Genesis - Merge
GENESIS_GAS_LIMIT: 30000000
GENESIS_BASE_FEE_PER_GAS: 1000000000

# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
Expand Down
Loading