Search in sources :

Example 1 with ForkChoiceUpdatedResult

use of tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult 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 2 with ForkChoiceUpdatedResult

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

the class ForkChoiceNotifierTest method getPayloadId_shouldReturnExceptionallyLatestPayloadIdOnWrongRoot.

@Test
void getPayloadId_shouldReturnExceptionallyLatestPayloadIdOnWrongRoot() {
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    final BeaconState headState = getHeadState();
    final UInt64 blockSlot = headState.getSlot().plus(1);
    final Bytes32 wrongBlockRoot = dataStructureUtil.randomBytes32();
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
    when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
    assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
    responseFuture.complete(createForkChoiceUpdatedResult(ExecutionPayloadStatus.VALID, Optional.of(payloadId)));
    assertThatSafeFuture(notifier.getPayloadId(wrongBlockRoot, blockSlot)).isCompletedExceptionally();
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with ForkChoiceUpdatedResult

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

the class ForkChoiceNotifierTest method getPayloadId_shouldReturnExceptionallyBeforeTheFirstForkChoiceState.

@Test
void getPayloadId_shouldReturnExceptionallyBeforeTheFirstForkChoiceState() {
    final BeaconState headState = getHeadState();
    // proposing slot 3
    final UInt64 blockSlot = headState.getSlot().plus(2);
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
    storageSystem.chainUpdater().setCurrentSlot(blockSlot);
    // we are post-merge, we must have a payloadId
    assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isCompletedExceptionally();
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 4 with ForkChoiceUpdatedResult

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

the class ForkChoiceNotifierTest method getPayloadId_preMergeShouldReturnEmptyBeforeTheFirstForkChoiceState.

@Test
void getPayloadId_preMergeShouldReturnEmptyBeforeTheFirstForkChoiceState() {
    reInitializePreMerge();
    final BeaconState headState = getHeadState();
    // proposing slot 3
    final UInt64 blockSlot = headState.getSlot().plus(2);
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
    storageSystem.chainUpdater().setCurrentSlot(blockSlot);
    // we are pre-merge, we can continue producing blocks with no execution payload
    assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isCompletedWithEmptyOptional();
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 5 with ForkChoiceUpdatedResult

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

the class ForkChoiceNotifierTest method getPayloadId_shouldReturnLatestPayloadId.

@Test
void getPayloadId_shouldReturnLatestPayloadId() {
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    final BeaconState headState = getHeadState();
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    final UInt64 blockSlot = headState.getSlot().plus(1);
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    final SafeFuture<ForkChoiceUpdatedResult> responseFuture = new SafeFuture<>();
    when(executionEngineChannel.forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes))).thenReturn(responseFuture);
    assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
    // Initially has no payload ID.
    assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isNotCompleted();
    // But becomes available once we receive the response
    responseFuture.complete(createForkChoiceUpdatedResult(ExecutionPayloadStatus.VALID, Optional.of(payloadId)));
    assertThatSafeFuture(notifier.getPayloadId(blockRoot, blockSlot)).isCompletedWithOptionalContaining(payloadId);
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SafeFutureAssert.assertThatSafeFuture(tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture) ForkChoiceUpdatedResult(tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Aggregations

Bytes32 (org.apache.tuweni.bytes.Bytes32)5 Test (org.junit.jupiter.api.Test)5 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)5 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 ForkChoiceState (tech.pegasys.teku.spec.executionengine.ForkChoiceState)5 ForkChoiceUpdatedResult (tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult)5 SafeFutureAssert.assertThatSafeFuture (tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)4 PayloadAttributes (tech.pegasys.teku.spec.executionengine.PayloadAttributes)4 Bytes8 (tech.pegasys.teku.infrastructure.bytes.Bytes8)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 Mockito.reset (org.mockito.Mockito.reset)1