Skip to content

Commit

Permalink
Remove TransitionStore and targetSecondsToMerge, minAnchorPowBlockDif…
Browse files Browse the repository at this point in the history
…ficulty constants
  • Loading branch information
Nashatyrev committed Sep 24, 2021
1 parent a66b18a commit 6d41bca
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 257 deletions.
9 changes: 1 addition & 8 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import tech.pegasys.teku.spec.datastructures.forkchoice.MutableStore;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyStore;
import tech.pegasys.teku.spec.datastructures.forkchoice.TransitionStore;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
Expand Down Expand Up @@ -481,16 +480,10 @@ public BlockImportResult onBlock(
final BeaconState blockSlotState,
final IndexedAttestationCache indexedAttestationCache) {
SpecVersion specVersion = atBlock(signedBlock);
Optional<TransitionStore> maybeTransitionStore = specVersion.getTransitionStore();
return specVersion
.getForkChoiceUtil()
.onBlock(
executionEngineChannel,
store,
signedBlock,
blockSlotState,
indexedAttestationCache,
maybeTransitionStore);
executionEngineChannel, store, signedBlock, blockSlotState, indexedAttestationCache);
}

public boolean blockDescendsFromLatestFinalizedBlock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,25 +679,19 @@ public class MergeBuilder {
private UInt64 mergeForkEpoch;

// Transition
private UInt64 targetSecondsToMerge;
private UInt256 minAnchorPowBlockDifficulty;
private UInt256 terminalTotalDifficulty;

private MergeBuilder() {}

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

void validate() {
validateConstant("mergeForkVersion", mergeForkVersion);
validateConstant("mergeForkEpoch", mergeForkEpoch);
validateConstant("targetSecondsToMerge", targetSecondsToMerge);
validateConstant("minAnchorPowBlockDifficulty", minAnchorPowBlockDifficulty);
validateConstant("terminalTotalDifficulty", terminalTotalDifficulty);
}

public MergeBuilder mergeForkVersion(Bytes4 mergeForkVersion) {
Expand All @@ -712,13 +706,8 @@ public MergeBuilder mergeForkEpoch(UInt64 mergeForkEpoch) {
return this;
}

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

public MergeBuilder minAnchorPowBlockDifficulty(UInt256 minAnchorPowBlockDifficulty) {
this.minAnchorPowBlockDifficulty = minAnchorPowBlockDifficulty;
public MergeBuilder terminalTotalDifficulty(UInt256 terminalTotalDifficulty) {
this.terminalTotalDifficulty = terminalTotalDifficulty;
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ public class SpecConfigMerge extends DelegatingSpecConfigAltair {
private final UInt64 mergeForkEpoch;

// Transition
private final UInt64 targetSecondsToMerge;
private final UInt256 minAnchorPowBlockDifficulty;
private final UInt256 terminalTotalDifficulty;

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

public static SpecConfigMerge required(final SpecConfig specConfig) {
Expand Down Expand Up @@ -73,12 +70,8 @@ public UInt64 getMergeForkEpoch() {
return mergeForkEpoch;
}

public UInt64 getTargetSecondsToMerge() {
return targetSecondsToMerge;
}

public UInt256 getMinAnchorPowBlockDifficulty() {
return minAnchorPowBlockDifficulty;
public UInt256 getTerminalTotalDifficulty() {
return terminalTotalDifficulty;
}

@Override
Expand All @@ -97,13 +90,11 @@ public boolean equals(Object o) {
SpecConfigMerge that = (SpecConfigMerge) o;
return Objects.equals(mergeForkVersion, that.mergeForkVersion)
&& Objects.equals(mergeForkEpoch, that.mergeForkEpoch)
&& Objects.equals(targetSecondsToMerge, that.targetSecondsToMerge)
&& Objects.equals(minAnchorPowBlockDifficulty, that.minAnchorPowBlockDifficulty);
&& Objects.equals(terminalTotalDifficulty, that.terminalTotalDifficulty);
}

@Override
public int hashCode() {
return Objects.hash(
mergeForkVersion, mergeForkEpoch, targetSecondsToMerge, minAnchorPowBlockDifficulty);
return Objects.hash(mergeForkVersion, mergeForkEpoch, terminalTotalDifficulty);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
package tech.pegasys.teku.spec.logic;

import java.util.Optional;
import tech.pegasys.teku.spec.datastructures.forkchoice.TransitionStore;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.block.BlockProcessor;
import tech.pegasys.teku.spec.logic.common.forktransition.StateUpgrade;
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors;
Expand Down Expand Up @@ -48,12 +45,6 @@ public Optional<StateUpgrade<?>> getStateUpgrade() {
return specLogic.getStateUpgrade();
}

@Override
public void initializeTransitionStore(
ExecutionEngineChannel executionEngineChannel, BeaconState state) {
specLogic.initializeTransitionStore(executionEngineChannel, state);
}

@Override
public ValidatorsUtil getValidatorsUtil() {
return specLogic.getValidatorsUtil();
Expand Down Expand Up @@ -134,11 +125,6 @@ public Optional<MergeTransitionHelpers> getMergeTransitionHelpers() {
return specLogic.getMergeTransitionHelpers();
}

@Override
public Optional<TransitionStore> getTransitionStore() {
return specLogic.getTransitionStore();
}

@Override
public OperationSignatureVerifier operationSignatureVerifier() {
return specLogic.operationSignatureVerifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
package tech.pegasys.teku.spec.logic;

import java.util.Optional;
import tech.pegasys.teku.spec.datastructures.forkchoice.TransitionStore;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.block.BlockProcessor;
import tech.pegasys.teku.spec.logic.common.forktransition.StateUpgrade;
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors;
Expand All @@ -39,8 +36,6 @@
public interface SpecLogic {
Optional<StateUpgrade<?>> getStateUpgrade();

void initializeTransitionStore(ExecutionEngineChannel executionEngineChannel, BeaconState state);

ValidatorsUtil getValidatorsUtil();

BeaconStateUtil getBeaconStateUtil();
Expand Down Expand Up @@ -74,6 +69,4 @@ public interface SpecLogic {
Optional<ExecutionPayloadUtil> getExecutionPayloadUtil();

Optional<MergeTransitionHelpers> getMergeTransitionHelpers();

Optional<TransitionStore> getTransitionStore();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public BeaconState processSlots(
.orElse(prevMilestoneState);
// Update spec
currentSpec = newSpec;
newSpec.initializeTransitionStore(executionEngineChannel, state);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@

import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.spec.config.SpecConfigMerge;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
import tech.pegasys.teku.spec.datastructures.forkchoice.TransitionStore;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.versions.merge.helpers.MiscHelpersMerge;

public class MergeTransitionHelpers {

private final MiscHelpersMerge miscHelpers;
private final SpecConfigMerge specConfig;

public MergeTransitionHelpers(MiscHelpersMerge miscHelpers) {
public MergeTransitionHelpers(MiscHelpersMerge miscHelpers, SpecConfigMerge specConfig) {
this.miscHelpers = miscHelpers;
this.specConfig = specConfig;
}

public boolean isMergeComplete(BeaconState state) {
Expand All @@ -37,9 +39,9 @@ public boolean isMergeBlock(BeaconState state, BeaconBlock block) {
return miscHelpers.isMergeBlock(state, block);
}

public boolean isValidTerminalPowBlock(PowBlock powBlock, TransitionStore transitionStore) {
public boolean isValidTerminalPowBlock(PowBlock powBlock) {
boolean isTotalDifficultyReached =
powBlock.totalDifficulty.compareTo(transitionStore.getTransitionTotalDifficulty()) >= 0;
powBlock.totalDifficulty.compareTo(specConfig.getTerminalTotalDifficulty()) >= 0;
return powBlock.isValid && isTotalDifficultyReached;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import tech.pegasys.teku.spec.datastructures.forkchoice.MutableStore;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy;
import tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyStore;
import tech.pegasys.teku.spec.datastructures.forkchoice.TransitionStore;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
Expand Down Expand Up @@ -333,8 +332,7 @@ public BlockImportResult onBlock(
final MutableStore store,
final SignedBeaconBlock signedBlock,
final BeaconState blockSlotState,
final IndexedAttestationCache indexedAttestationCache,
final Optional<TransitionStore> maybeTransitionStore) {
final IndexedAttestationCache indexedAttestationCache) {
checkArgument(
blockSlotState.getSlot().equals(signedBlock.getSlot()),
"State must have slots processed up to the block slot");
Expand All @@ -349,8 +347,7 @@ public BlockImportResult onBlock(

// [Merge] Return if transition condition checks fail
final Optional<BlockImportResult> maybeTerminalPowBlockFailure =
checkOnTerminalPowBlockConditions(
executionEngineChannel, block, blockSlotState, maybeTransitionStore);
checkOnTerminalPowBlockConditions(executionEngineChannel, block, blockSlotState);
if (maybeTerminalPowBlockFailure.isPresent()) {
return maybeTerminalPowBlockFailure.get();
}
Expand Down Expand Up @@ -422,10 +419,10 @@ private UInt64 getFinalizedCheckpointStartSlot(final ReadOnlyStore store) {
private Optional<BlockImportResult> checkOnTerminalPowBlockConditions(
final ExecutionEngineChannel executionEngineChannel,
final BeaconBlock block,
final BeaconState blockSlotState,
final Optional<TransitionStore> maybeTransitionStore) {
final BeaconState blockSlotState) {

// not a merge version of the spec
if (maybeTransitionStore.isEmpty() || mergeTransitionHelpers == null) {
if (mergeTransitionHelpers == null) {
return Optional.empty();
}

Expand All @@ -439,7 +436,7 @@ private Optional<BlockImportResult> checkOnTerminalPowBlockConditions(
if (!powBlock.isProcessed) {
return Optional.of(BlockImportResult.FAILED_UNKNOWN_TERMINAL_POW_BLOCK);
}
if (!mergeTransitionHelpers.isValidTerminalPowBlock(powBlock, maybeTransitionStore.get())) {
if (!mergeTransitionHelpers.isValidTerminalPowBlock(powBlock)) {
return Optional.of(BlockImportResult.FAILED_INVALID_TERMINAL_POW_BLOCK);
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfigAltair;
import tech.pegasys.teku.spec.datastructures.forkchoice.TransitionStore;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators;
import tech.pegasys.teku.spec.logic.common.helpers.MergeTransitionHelpers;
Expand Down Expand Up @@ -166,12 +163,6 @@ public static SpecLogicAltair create(
stateUpgrade);
}

@Override
public void initializeTransitionStore(
ExecutionEngineChannel executionEngineChannel, BeaconState state) {
// no transition store in Altair
}

@Override
public Optional<SyncCommitteeUtil> getSyncCommitteeUtil() {
return syncCommitteeUtil;
Expand All @@ -186,9 +177,4 @@ public Optional<MergeTransitionHelpers> getMergeTransitionHelpers() {
public Optional<ExecutionPayloadUtil> getExecutionPayloadUtil() {
return Optional.empty();
}

@Override
public Optional<TransitionStore> getTransitionStore() {
return Optional.empty();
}
}
Loading

0 comments on commit 6d41bca

Please sign in to comment.