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

Implement ExecutionPayload processing #4592

Merged
merged 4 commits into from
Nov 9, 2021
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 @@ -39,6 +39,7 @@
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor;
import tech.pegasys.teku.spec.logic.common.statetransition.epoch.EpochProcessor;
import tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas;
Expand Down Expand Up @@ -109,7 +110,12 @@ public void init() throws Exception {
localChain.initializeStorage();

blockImporter =
new BlockImporter(blockImportNotifications, recentChainData, forkChoice, wsValidator);
new BlockImporter(
blockImportNotifications,
recentChainData,
forkChoice,
wsValidator,
ExecutionEngineChannel.NOOP);
blockIterator = BlockIO.createResourceReader(spec, blocksFile).iterator();
System.out.println("Importing 63 blocks from " + blocksFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import tech.pegasys.teku.spec.datastructures.state.Validator;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor;
import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult;
import tech.pegasys.teku.spec.util.DataStructureUtil;
Expand Down Expand Up @@ -92,7 +93,12 @@ public void importBlocks() throws Exception {
BeaconChainUtil localChain =
BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
BlockImporter blockImporter =
new BlockImporter(blockImportNotifications, recentChainData, forkChoice, wsValidator);
new BlockImporter(
blockImportNotifications,
recentChainData,
forkChoice,
wsValidator,
ExecutionEngineChannel.NOOP);

System.out.println("Start blocks import from " + blocksFile);
int blockCount = 0;
Expand Down Expand Up @@ -165,7 +171,12 @@ public void importBlocksMemProfiling() throws Exception {
initialState = null;
ForkChoice forkChoice = ForkChoice.create(spec, new InlineEventThread(), recentChainData);
BlockImporter blockImporter =
new BlockImporter(blockImportNotifications, recentChainData, forkChoice, wsValidator);
new BlockImporter(
blockImportNotifications,
recentChainData,
forkChoice,
wsValidator,
ExecutionEngineChannel.NOOP);

System.out.println("Start blocks import from " + blocksFile);
int counter = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.TestSpecFactory;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor;
import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult;
import tech.pegasys.teku.statetransition.BeaconChainUtil;
Expand Down Expand Up @@ -91,7 +92,12 @@ public void init() throws Exception {
localChain.initializeStorage();

blockImporter =
new BlockImporter(blockImportNotifications, recentChainData, forkChoice, wsValidator);
new BlockImporter(
blockImportNotifications,
recentChainData,
forkChoice,
wsValidator,
ExecutionEngineChannel.NOOP);
blockIterator = BlockIO.createResourceReader(spec, blocksFile).iterator();
System.out.println("Importing blocks from " + blocksFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public abstract class Eth2ReferenceTestCase {

// Disabled while work continues to bring over the merge work
.put("sanity/blocks", TestExecutor.IGNORE_TESTS)
.put("operations/execution_payload", TestExecutor.IGNORE_TESTS)
.put("fork_choice/on_merge_block", TestExecutor.IGNORE_TESTS)
.put("fork_choice/on_block", TestExecutor.IGNORE_TESTS)
.put("fork_choice/get_head", TestExecutor.IGNORE_TESTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ManualReferenceTestRunner extends Eth2ReferenceTestCase {
* <p>e.g. set to "ssz_static" to run only ssz static tests or "ssz_static/Attestation" for only
* attestation ssz tests.
*/
private static final String TEST_TYPE = "ssz_static";
private static final String TEST_TYPE = "operations/execution_payload";

/** Filter test to run to those from the specified spec. One of general, minimal or mainnet */
private static final String SPEC = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import tech.pegasys.teku.spec.config.SpecConfigLoader;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException;

public class TransitionTestExecutor implements TestExecutor {
Expand Down Expand Up @@ -76,7 +77,7 @@ private void processAltairUpgrade(final TestDefinition testDefinition, final Met

final BLSSignatureVerifier signatureVerifier =
metadata.blsSetting == 2 ? BLSSignatureVerifier.NO_OP : BLSSignatureVerifier.SIMPLE;
result = spec.processBlock(result, block, signatureVerifier);
result = spec.processBlock(result, block, signatureVerifier, ExecutionEngineChannel.NOOP);
} catch (final StateTransitionException e) {
Assertions.fail(
"Failed to process block " + i + " at slot " + block.getSlot() + ": " + e.getMessage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;

public class DefaultOperationProcessor implements OperationProcessor {
Expand Down Expand Up @@ -97,4 +99,14 @@ public void processSyncCommittee(final MutableBeaconState state, final SyncAggre
spec.getBlockProcessor(state.getSlot())
.processSyncAggregate(state, aggregate, BLSSignatureVerifier.SIMPLE);
}

@Override
public void processExecutionPayload(
final MutableBeaconState state,
final ExecutionPayload executionPayload,
final ExecutionEngineChannel executionEngine)
throws BlockProcessingException {
spec.getBlockProcessor(state.getSlot())
.processExecutionPayload(state, executionPayload, executionEngine);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;

public interface OperationProcessor {
Expand All @@ -39,9 +41,15 @@ void processBlockHeader(MutableBeaconState state, BeaconBlockSummary blockHeader
void processVoluntaryExit(MutableBeaconState state, SignedVoluntaryExit voluntaryExit)
throws BlockProcessingException;

void processAttestation(MutableBeaconState state, final Attestation attestation)
void processAttestation(MutableBeaconState state, Attestation attestation)
throws BlockProcessingException;

void processSyncCommittee(final MutableBeaconState state, final SyncAggregate aggregate)
void processSyncCommittee(MutableBeaconState state, SyncAggregate aggregate)
throws BlockProcessingException;

void processExecutionPayload(
MutableBeaconState state,
ExecutionPayload executionPayload,
ExecutionEngineChannel executionEngine)
throws BlockProcessingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,32 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static tech.pegasys.teku.reference.TestDataUtils.loadSsz;
import static tech.pegasys.teku.reference.TestDataUtils.loadStateFromSsz;
import static tech.pegasys.teku.reference.TestDataUtils.loadYaml;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import java.util.Optional;
import tech.pegasys.teku.ethtests.finder.TestDefinition;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.reference.TestExecutor;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSummary;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.BeaconBlockBodySchemaAltair;
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutePayloadResult;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.BlockProcessingException;
import tech.pegasys.teku.ssz.SszData;

Expand All @@ -45,7 +55,8 @@ private enum Operation {
DEPOSIT,
VOLUNTARY_EXIT,
ATTESTATION,
SYNC_AGGREGATE
SYNC_AGGREGATE,
EXECUTION_PAYLOAD
}

public static ImmutableMap<String, TestExecutor> OPERATIONS_TEST_TYPES =
Expand Down Expand Up @@ -76,6 +87,10 @@ private enum Operation {
.put(
"operations/sync_aggregate_random",
new OperationsTestExecutor<>("sync_aggregate.ssz_snappy", Operation.SYNC_AGGREGATE))
.put(
"operations/execution_payload",
new OperationsTestExecutor<>(
"execution_payload.ssz_snappy", Operation.EXECUTION_PAYLOAD))
.build();

private final String dataFileName;
Expand Down Expand Up @@ -184,6 +199,36 @@ private void processOperation(
.getSyncAggregateSchema());
processor.processSyncCommittee(state, syncAggregate);
break;
case EXECUTION_PAYLOAD:
final ExecutionEngineChannel executionEngine = mock(ExecutionEngineChannel.class);
final ExecutionMeta executionMeta =
loadYaml(testDefinition, "execution.yaml", ExecutionMeta.class);
final ExecutionPayload payload =
loadSsz(
testDefinition,
dataFileName,
testDefinition
.getSpec()
.getGenesisSchemaDefinitions()
.toVersionMerge()
.orElseThrow()
.getExecutionPayloadSchema());
when(executionEngine.executePayload(payload))
.thenReturn(
SafeFuture.completedFuture(
new ExecutePayloadResult(
executionMeta.executionValid
? ExecutionPayloadStatus.VALID
: ExecutionPayloadStatus.INVALID,
Optional.empty(),
Optional.empty())));
processor.processExecutionPayload(state, payload, executionEngine);
break;
}
}

private static class ExecutionMeta {
@JsonProperty(value = "execution_valid", required = true)
private boolean executionValid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoice;
import tech.pegasys.teku.storage.client.RecentChainData;
import tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder;
Expand Down Expand Up @@ -153,7 +154,7 @@ private void applyBlock(
TestDataUtils.loadSsz(
testDefinition, blockName + ".ssz_snappy", spec::deserializeSignedBeaconBlock);
LOG.info("Importing block {} at slot {}", block.getRoot(), block.getSlot());
assertThat(forkChoice.onBlock(block)).isCompleted();
assertThat(forkChoice.onBlock(block, ExecutionEngineChannel.NOOP)).isCompleted();
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.common.statetransition.exceptions.StateTransitionException;

public class SanityBlocksTestExecutor implements TestExecutor {
Expand Down Expand Up @@ -93,7 +94,8 @@ private BeaconState applyBlocks(
block,
metaData.getBlsSetting() == IGNORED
? BLSSignatureVerifier.NO_OP
: BLSSignatureVerifier.SIMPLE);
: BLSSignatureVerifier.SIMPLE,
ExecutionEngineChannel.NOOP);
}
return result;
} catch (StateTransitionException e) {
Expand Down
18 changes: 13 additions & 5 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import tech.pegasys.teku.spec.datastructures.state.beaconstate.common.BeaconStateInvariants;
import tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult;
import tech.pegasys.teku.spec.datastructures.util.ForkAndSpecMilestone;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.genesis.GenesisGenerator;
import tech.pegasys.teku.spec.logic.StateTransition;
import tech.pegasys.teku.spec.logic.common.block.BlockProcessor;
Expand Down Expand Up @@ -461,10 +462,11 @@ public BlockImportResult onBlock(
final MutableStore store,
final SignedBeaconBlock signedBlock,
final BeaconState blockSlotState,
final IndexedAttestationCache indexedAttestationCache) {
final IndexedAttestationCache indexedAttestationCache,
final ExecutionEngineChannel executionEngine) {
return atBlock(signedBlock)
.getForkChoiceUtil()
.onBlock(store, signedBlock, blockSlotState, indexedAttestationCache);
.onBlock(store, signedBlock, blockSlotState, indexedAttestationCache, executionEngine);
}

public boolean blockDescendsFromLatestFinalizedBlock(
Expand Down Expand Up @@ -504,13 +506,18 @@ public BlockProcessor getBlockProcessor(final UInt64 slot) {
public BeaconState processBlock(
final BeaconState preState,
final SignedBeaconBlock block,
final BLSSignatureVerifier signatureVerifier)
final BLSSignatureVerifier signatureVerifier,
final ExecutionEngineChannel executionEngine)
throws StateTransitionException {
try {
final BeaconState blockSlotState = stateTransition.processSlots(preState, block.getSlot());
return getBlockProcessor(block.getSlot())
.processAndValidateBlock(
block, blockSlotState, IndexedAttestationCache.NOOP, signatureVerifier);
block,
blockSlotState,
IndexedAttestationCache.NOOP,
signatureVerifier,
executionEngine);
} catch (SlotProcessingException | EpochProcessingException e) {
throw new StateTransitionException(e);
}
Expand All @@ -525,7 +532,8 @@ public BeaconState replayValidatedBlock(final BeaconState preState, final Signed
blockSlotState,
block.getMessage(),
IndexedAttestationCache.NOOP,
BLSSignatureVerifier.NO_OP);
BLSSignatureVerifier.NO_OP,
ExecutionEngineChannel.NOOP);
} catch (SlotProcessingException | EpochProcessingException | BlockProcessingException e) {
throw new StateTransitionException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.spec.executionengine;

import com.google.common.base.MoreObjects;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;

Expand All @@ -39,4 +40,13 @@ public Optional<Bytes32> getLatestValidHash() {
public Optional<String> getMessage() {
return message;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("status", status)
.add("latestValidHash", latestValidHash)
.add("message", message)
.toString();
}
}
Loading