Search in sources :

Example 1 with PayloadStatus

use of tech.pegasys.teku.spec.executionengine.PayloadStatus in project teku by ConsenSys.

the class BellatrixTransitionHelpersTest method shouldBeValidWhenTerminalBlockHashMatchesInActivationEpoch.

@Test
void shouldBeValidWhenTerminalBlockHashMatchesInActivationEpoch() {
    final UInt64 activationEpoch = UInt64.valueOf(15);
    final Spec spec = createSpec(payload.getParentHash(), activationEpoch);
    final UInt64 blockSlot = spec.computeStartSlotAtEpoch(activationEpoch);
    final SafeFuture<PayloadStatus> result = spec.getGenesisSpec().getBellatrixTransitionHelpers().orElseThrow().validateMergeBlock(executionEngine, payload, blockSlot);
    assertPayloadResultStatus(result, ExecutionPayloadStatus.VALID);
}
Also used : ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test)

Example 2 with PayloadStatus

use of tech.pegasys.teku.spec.executionengine.PayloadStatus in project teku by ConsenSys.

the class BellatrixTransitionHelpersTest method shouldBeValidWhenTerminalBlockHashMatchesAfterActivationEpoch.

@Test
void shouldBeValidWhenTerminalBlockHashMatchesAfterActivationEpoch() {
    final UInt64 activationEpoch = UInt64.valueOf(15);
    final Spec spec = createSpec(payload.getParentHash(), activationEpoch);
    final UInt64 blockSlot = spec.computeStartSlotAtEpoch(activationEpoch.plus(1));
    final SafeFuture<PayloadStatus> result = spec.getGenesisSpec().getBellatrixTransitionHelpers().orElseThrow().validateMergeBlock(executionEngine, payload, blockSlot);
    assertPayloadResultStatus(result, ExecutionPayloadStatus.VALID);
}
Also used : ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test)

Example 3 with PayloadStatus

use of tech.pegasys.teku.spec.executionengine.PayloadStatus in project teku by ConsenSys.

the class ForkChoiceTest method setForkChoiceNotifierForkChoiceUpdatedResult.

private void setForkChoiceNotifierForkChoiceUpdatedResult(final Optional<PayloadStatus> status) {
    ForkChoiceUpdatedResult result = status.map(payloadStatus -> new ForkChoiceUpdatedResult(payloadStatus, Optional.empty())).orElse(null);
    when(forkChoiceNotifier.onForkChoiceUpdated(any())).thenReturn(SafeFuture.completedFuture(Optional.ofNullable(result)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ChainUpdater(tech.pegasys.teku.storage.client.ChainUpdater) ChainHead(tech.pegasys.teku.storage.client.ChainHead) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChainBuilder(tech.pegasys.teku.core.ChainBuilder) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) ONE(tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BlockOptions(tech.pegasys.teku.core.ChainBuilder.BlockOptions) ExecutionPayload(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload) UInt256(org.apache.tuweni.units.bigints.UInt256) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) VerificationMode(org.mockito.verification.VerificationMode) StateStorageMode(tech.pegasys.teku.storage.server.StateStorageMode) List(java.util.List) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) PowBlock(tech.pegasys.teku.spec.datastructures.execution.PowBlock) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AttestationProcessingResult(tech.pegasys.teku.spec.datastructures.util.AttestationProcessingResult) AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) StubExecutionEngineChannel(tech.pegasys.teku.spec.executionengine.StubExecutionEngineChannel) FailureReason(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult.FailureReason) ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) MinimalBeaconBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.MinimalBeaconBlockSummary) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) InMemoryStorageSystemBuilder(tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ZERO(tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO) Spec(tech.pegasys.teku.spec.Spec) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) ReorgEvent(tech.pegasys.teku.storage.api.TrackingChainHeadChannel.ReorgEvent) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) OptimisticHeadSubscriber(tech.pegasys.teku.statetransition.forkchoice.ForkChoice.OptimisticHeadSubscriber) Mockito.verify(org.mockito.Mockito.verify) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult) StorageSystem(tech.pegasys.teku.storage.storageSystem.StorageSystem) Mockito.reset(org.mockito.Mockito.reset) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult)

Example 4 with PayloadStatus

use of tech.pegasys.teku.spec.executionengine.PayloadStatus in project teku by ConsenSys.

the class ForkChoiceTest method onBlock_shouldUseLatestValidHashFromForkChoiceUpdated.

@Test
void onBlock_shouldUseLatestValidHashFromForkChoiceUpdated() {
    doMerge();
    finalizeEpoch(2);
    assertThat(recentChainData.isChainHeadOptimistic()).isFalse();
    final UInt64 nextBlockSlot = storageSystem.chainBuilder().getLatestSlot().plus(1);
    storageSystem.chainUpdater().setCurrentSlot(nextBlockSlot);
    final SignedBlockAndState blockAndState = storageSystem.chainBuilder().generateBlockAtSlot(nextBlockSlot);
    executionEngine.setPayloadStatus(PayloadStatus.SYNCING);
    setForkChoiceNotifierForkChoiceUpdatedResult(PayloadStatus.SYNCING);
    final SafeFuture<BlockImportResult> result = forkChoice.onBlock(blockAndState.getBlock(), executionEngine);
    assertBlockImportedSuccessfully(result, true);
    assertForkChoiceUpdateNotification(blockAndState, true);
    // let's import a new block on top the optimistic head
    // let's make the EL return ACCEPTED on newPayload call but return INVALID on forkChoiceUpdated
    // call
    // INVALID will give us a lastValidHash corresponding to the previous block payload (imported
    // optimistically)
    executionEngine.setPayloadStatus(PayloadStatus.ACCEPTED);
    PayloadStatus invalidWithLastValidBlockHash = PayloadStatus.create(ExecutionPayloadStatus.INVALID, blockAndState.getBlock().getMessage().getBody().getOptionalExecutionPayload().map(ExecutionPayload::getBlockHash), Optional.empty());
    setForkChoiceNotifierForkChoiceUpdatedResult(invalidWithLastValidBlockHash);
    storageSystem.chainUpdater().setCurrentSlot(nextBlockSlot.increment());
    final SignedBlockAndState blockAndStatePlus1 = storageSystem.chainBuilder().generateBlockAtSlot(nextBlockSlot.increment());
    // before importing, previous block is optimistic
    assertThat(isFullyValidated(blockAndState.getRoot())).isFalse();
    importBlockOptimistically(blockAndStatePlus1);
    // after importing, previous block is fully valid
    assertThat(isFullyValidated(blockAndState.getRoot())).isTrue();
    // processing the head
    setForkChoiceNotifierForkChoiceUpdatedResult(PayloadStatus.VALID);
    processHead(blockAndStatePlus1.getSlot());
    // we have now no optimistic head
    assertHeadIsFullyValidated(blockAndState);
}
Also used : ExecutionPayloadStatus(tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus) PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Test(org.junit.jupiter.api.Test)

Example 5 with PayloadStatus

use of tech.pegasys.teku.spec.executionengine.PayloadStatus in project teku by ConsenSys.

the class MergeTransitionBlockValidatorTest method shouldReportRootForInvalidNonFinalizedAncestorTransitionBlock.

@Test
void shouldReportRootForInvalidNonFinalizedAncestorTransitionBlock() {
    final SignedBlockAndState transitionBlock = generateNonfinalizedTransition();
    final SignedBlockAndState chainHead = storageSystem.chainBuilder().getLatestBlockAndState();
    final SignedBlockAndState blockToVerify = storageSystem.chainBuilder().generateNextBlock();
    withInvalidTransitionBlock(transitionBlock);
    final MergeTransitionBlockValidator transitionVerifier = createTransitionValidator();
    assertThat(storageSystem.recentChainData().getForkChoiceStrategy().orElseThrow().getOptimisticallySyncedTransitionBlockRoot(chainHead.getRoot())).isPresent();
    final SafeFuture<PayloadValidationResult> result = transitionVerifier.verifyTransitionBlock(chainHead.getState().toVersionBellatrix().orElseThrow().getLatestExecutionPayloadHeader(), blockToVerify.getBlock());
    assertThat(executionEngine.getRequestedPowBlocks()).contains(getExecutionPayload(transitionBlock).getParentHash());
    assertThat(result).isCompleted();
    final PayloadValidationResult validationResult = result.join();
    assertThat(validationResult.getInvalidTransitionBlockRoot()).contains(transitionBlock.getRoot());
    assertThat(validationResult.getStatus()).matches(PayloadStatus::hasInvalidStatus);
}
Also used : PayloadStatus(tech.pegasys.teku.spec.executionengine.PayloadStatus) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Aggregations

PayloadStatus (tech.pegasys.teku.spec.executionengine.PayloadStatus)11 ExecutionPayloadStatus (tech.pegasys.teku.spec.executionengine.ExecutionPayloadStatus)9 Test (org.junit.jupiter.api.Test)8 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)7 Spec (tech.pegasys.teku.spec.Spec)5 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)3 BlockImportResult (tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 TestTemplate (org.junit.jupiter.api.TestTemplate)2 PayloadStatusV1 (tech.pegasys.teku.ethereum.executionlayer.client.schema.PayloadStatusV1)2 ReadOnlyForkChoiceStrategy (tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy)2 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 UInt256 (org.apache.tuweni.units.bigints.UInt256)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertDoesNotThrow (org.junit.jupiter.api.Assertions.assertDoesNotThrow)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.mock (org.mockito.Mockito.mock)1