Skip to content

Commit

Permalink
Remove TTD Bellatrix merge configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Dec 20, 2024
1 parent 7551460 commit baf23a5
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannelStub;
import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult;
import tech.pegasys.teku.statetransition.BeaconChainUtil;
Expand Down Expand Up @@ -115,7 +114,7 @@ public static SyncingNodeManager create(
chainUtil.initializeStorage();

final MergeTransitionBlockValidator transitionBlockValidator =
new MergeTransitionBlockValidator(spec, recentChainData, ExecutionLayerChannel.NOOP);
new MergeTransitionBlockValidator(spec, recentChainData);

final ForkChoice forkChoice =
new ForkChoice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerBlockProductionManager;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel;
import tech.pegasys.teku.spec.generator.ChainBuilder;
import tech.pegasys.teku.statetransition.MappedOperationPool;
import tech.pegasys.teku.statetransition.OperationPool;
Expand Down Expand Up @@ -200,8 +199,7 @@ private void setupStorage(
recentChainData,
BlobSidecarManager.NOOP,
new NoopForkChoiceNotifier(),
new MergeTransitionBlockValidator(
spec, recentChainData, ExecutionLayerChannel.NOOP),
new MergeTransitionBlockValidator(spec, recentChainData),
storageSystem.getMetricsSystem());
final Function<UInt64, BeaconBlockBodySchema<?>> beaconBlockSchemaSupplier =
slot -> spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockBodySchema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void init() throws Exception {

recentChainData = MemoryOnlyRecentChainData.create(spec);
final MergeTransitionBlockValidator transitionBlockValidator =
new MergeTransitionBlockValidator(spec, recentChainData, ExecutionLayerChannel.NOOP);
new MergeTransitionBlockValidator(spec, recentChainData);
ForkChoice forkChoice =
new ForkChoice(
spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void importBlocks() throws Exception {
RecentChainData recentChainData = MemoryOnlyRecentChainData.create(spec);
recentChainData.initializeFromGenesis(initialState, UInt64.ZERO);
final MergeTransitionBlockValidator transitionBlockValidator =
new MergeTransitionBlockValidator(spec, recentChainData, ExecutionLayerChannel.NOOP);
new MergeTransitionBlockValidator(spec, recentChainData);
ForkChoice forkChoice =
new ForkChoice(
spec,
Expand Down Expand Up @@ -195,7 +195,7 @@ public void importBlocksMemProfiling() throws Exception {
recentChainData.initializeFromGenesis(initialState, UInt64.ZERO);
initialState = null;
final MergeTransitionBlockValidator transitionBlockValidator =
new MergeTransitionBlockValidator(spec, recentChainData, ExecutionLayerChannel.NOOP);
new MergeTransitionBlockValidator(spec, recentChainData);
ForkChoice forkChoice =
new ForkChoice(
spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void init() throws Exception {
wsValidator = WeakSubjectivityFactory.lenientValidator();
recentChainData = MemoryOnlyRecentChainData.create(spec);
final MergeTransitionBlockValidator transitionBlockValidator =
new MergeTransitionBlockValidator(spec, recentChainData, ExecutionLayerChannel.NOOP);
new MergeTransitionBlockValidator(spec, recentChainData);
ForkChoice forkChoice =
new ForkChoice(
spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import tech.pegasys.teku.spec.datastructures.state.AnchorPoint;
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannelStub;
import tech.pegasys.teku.spec.executionlayer.ExecutionPayloadStatus;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
Expand Down Expand Up @@ -123,7 +122,7 @@ spec, new SignedBlockAndState(anchorBlock, anchorState)),
spec.getSlotStartTime(anchorBlock.getSlot(), anchorState.getGenesisTime()));

final MergeTransitionBlockValidator transitionBlockValidator =
new MergeTransitionBlockValidator(spec, recentChainData, ExecutionLayerChannel.NOOP);
new MergeTransitionBlockValidator(spec, recentChainData);
final InlineEventThread eventThread = new InlineEventThread();
final KZG kzg = KzgRetriever.getKzgWithLoadedTrustedSetup(spec, testDefinition.getConfigName());
final StubBlobSidecarManager blobSidecarManager = new StubBlobSidecarManager(kzg);
Expand Down Expand Up @@ -251,7 +250,7 @@ private PowBlock parsePowBlock(final Bytes data) {
.toUnsignedBigInteger(ByteOrder.LITTLE_ENDIAN));
// We don't get a timestamp but as long as it's in the past that's fine
final UInt64 timestamp = UInt64.ZERO;
return new PowBlock(blockHash, parentHash, totalDifficulty, timestamp);
return new PowBlock(blockHash, parentHash, timestamp);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.EthBlock;
Expand Down Expand Up @@ -87,7 +86,6 @@ private static PowBlock eth1BlockToPowBlock(final EthBlock.Block eth1Block) {
: new PowBlock(
Bytes32.fromHexStringStrict(eth1Block.getHash()),
Bytes32.fromHexStringStrict(eth1Block.getParentHash()),
UInt256.valueOf(eth1Block.getTotalDifficulty()),
UInt64.valueOf(eth1Block.getTimestamp()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ void eth1GetPowBlock_shouldCallExecutionClient() {

private PowBlock createPowBlock(final Bytes32 blockHash) {
return new PowBlock(
blockHash,
dataStructureUtil.randomBytes32(),
dataStructureUtil.randomUInt256(),
dataStructureUtil.randomUInt64());
blockHash, dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64());
}

@SuppressWarnings("FutureReturnValueIgnored")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@

import com.google.common.base.MoreObjects;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class PowBlock {

private final Bytes32 blockHash;
private final Bytes32 parentHash;
private final UInt256 totalDifficulty;
private final UInt64 blockTimestamp;

public PowBlock(
final Bytes32 blockHash,
final Bytes32 parentHash,
final UInt256 totalDifficulty,
final UInt64 blockTimestamp) {
public PowBlock(final Bytes32 blockHash, final Bytes32 parentHash, final UInt64 blockTimestamp) {
this.blockHash = blockHash;
this.parentHash = parentHash;
this.totalDifficulty = totalDifficulty;
this.blockTimestamp = blockTimestamp;
}

Expand All @@ -44,10 +37,6 @@ public Bytes32 getParentHash() {
return parentHash;
}

public UInt256 getTotalDifficulty() {
return totalDifficulty;
}

public UInt64 getBlockTimestamp() {
return blockTimestamp;
}
Expand All @@ -57,7 +46,6 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("blockHash", blockHash)
.add("parentHash", parentHash)
.add("totalDifficulty", totalDifficulty)
.add("blockTimestamp", blockTimestamp)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ public SafeFuture<GetPayloadResponse> engineGetPayload(
new PowBlock(
executionPayload.getBlockHash(),
executionPayload.getParentHash(),
UInt256.ZERO,
payloadAttributes.getTimestamp()));

headAndAttrs.currentExecutionPayload = Optional.of(executionPayload);
Expand Down Expand Up @@ -586,11 +585,8 @@ private void prepareTransitionBlocks(final UInt64 bellatrixActivationTime) {
terminalBlockHash = configTerminalBlockHash;
}

terminalBlockParent =
new PowBlock(TERMINAL_BLOCK_PARENT_HASH, Bytes32.ZERO, UInt256.ZERO, UInt64.ZERO);
terminalBlock =
new PowBlock(
terminalBlockHash, TERMINAL_BLOCK_PARENT_HASH, terminalTotalDifficulty, transitionTime);
terminalBlockParent = new PowBlock(TERMINAL_BLOCK_PARENT_HASH, Bytes32.ZERO, UInt64.ZERO);
terminalBlock = new PowBlock(terminalBlockHash, TERMINAL_BLOCK_PARENT_HASH, transitionTime);
}

private HeadAndAttributes getCachedHeadAndAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
import static tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture;

import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfigBellatrix;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSummary;
import tech.pegasys.teku.spec.datastructures.execution.PowBlock;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;

public class BellatrixTransitionHelpers {
Expand All @@ -46,21 +43,19 @@ public BellatrixTransitionHelpers(
* <p>That is, the PoW chain stops as soon as one block has exceeded TTD and from that point on
* merges into the beacon chain.
*
* @param executionLayer the execution layer to use for verification
* @param executionPayloadSummary the first non-empty payload on the beacon chain
* @param blockSlot the slot of the block the executionPayload is from
* @return a future containing the validation result for the execution payload
*/
public SafeFuture<PayloadStatus> validateMergeBlock(
final ExecutionLayerChannel executionLayer,
final ExecutionPayloadSummary executionPayloadSummary,
final UInt64 blockSlot) {
final ExecutionPayloadSummary executionPayloadSummary, final UInt64 blockSlot) {
if (!specConfig.getTerminalBlockHash().isZero()) {
return validateWithTerminalBlockHash(executionPayloadSummary, blockSlot);
}
return executionLayer
.eth1GetPowBlock(executionPayloadSummary.getParentHash())
.thenCompose(maybePowBlock -> validatePowBlock(executionLayer, maybePowBlock));

return SafeFuture.completedFuture(
PayloadStatus.invalid(
Optional.empty(), Optional.of("Total difficulty check is no more supported")));
}

private SafeFuture<PayloadStatus> validateWithTerminalBlockHash(
Expand All @@ -76,44 +71,7 @@ private SafeFuture<PayloadStatus> validateWithTerminalBlockHash(
return SafeFuture.completedFuture(PayloadStatus.VALID);
}

private SafeFuture<PayloadStatus> validatePowBlock(
final ExecutionLayerChannel executionLayer, final Optional<PowBlock> maybePowBlock) {
if (maybePowBlock.isEmpty()) {
return completedFuture(PayloadStatus.SYNCING);
}
final PowBlock powBlock = maybePowBlock.get();
if (isBelowTotalDifficulty(powBlock)) {
return invalid("PowBlock has not reached terminal total difficulty");
}
return validateParentPowBlock(executionLayer, powBlock.getParentHash());
}

private static SafeFuture<PayloadStatus> invalid(final String message) {
return completedFuture(PayloadStatus.invalid(Optional.empty(), Optional.of(message)));
}

private SafeFuture<PayloadStatus> validateParentPowBlock(
final ExecutionLayerChannel executionLayer, final Bytes32 parentBlockHash) {
// fast check for genesis
if (parentBlockHash.isZero()) {
return completedFuture(PayloadStatus.VALID);
}
return executionLayer
.eth1GetPowBlock(parentBlockHash)
.thenCompose(
maybeParentPowBlock -> {
if (maybeParentPowBlock.isEmpty()) {
return completedFuture(PayloadStatus.SYNCING);
}
final PowBlock parentPowBlock = maybeParentPowBlock.get();
if (!isBelowTotalDifficulty(parentPowBlock)) {
return invalid("Parent PowBlock exceeds terminal total difficulty");
}
return completedFuture(PayloadStatus.VALID);
});
}

private boolean isBelowTotalDifficulty(final PowBlock powBlock) {
return powBlock.getTotalDifficulty().lessThan(specConfig.getTerminalTotalDifficulty());
}
}
Loading

0 comments on commit baf23a5

Please sign in to comment.