Search in sources :

Example 1 with ForkChoiceState

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

the class ForkChoiceTest method assertForkChoiceUpdateNotification.

private void assertForkChoiceUpdateNotification(final SignedBlockAndState blockAndState, final boolean optimisticHead, final VerificationMode mode) {
    final ReadOnlyForkChoiceStrategy forkChoiceStrategy = recentChainData.getForkChoiceStrategy().orElseThrow();
    final Bytes32 headExecutionHash = forkChoiceStrategy.executionBlockHash(blockAndState.getRoot()).orElseThrow();
    final Bytes32 finalizedExecutionHash = forkChoiceStrategy.executionBlockHash(recentChainData.getFinalizedCheckpoint().orElseThrow().getRoot()).orElseThrow();
    verify(forkChoiceNotifier, mode).onForkChoiceUpdated(new ForkChoiceState(blockAndState.getRoot(), blockAndState.getSlot(), headExecutionHash, headExecutionHash, finalizedExecutionHash, optimisticHead));
}
Also used : ReadOnlyForkChoiceStrategy(tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 2 with ForkChoiceState

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

the class ForkChoiceNotifierTest method onForkChoiceUpdated_shouldNotSendNotificationWhenHeadBlockHashIsZero.

@Test
void onForkChoiceUpdated_shouldNotSendNotificationWhenHeadBlockHashIsZero() {
    assertThat(notifier.onForkChoiceUpdated(new ForkChoiceState(Bytes32.ZERO, UInt64.ZERO, Bytes32.ZERO, Bytes32.ZERO, Bytes32.ZERO, false))).isCompleted();
    verifyNoInteractions(executionEngineChannel);
}
Also used : ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) Test(org.junit.jupiter.api.Test)

Example 3 with ForkChoiceState

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

the class ForkChoiceNotifierTest method getPayloadId_shouldObtainAPayloadIdWhenProposingTheMergeBlock.

@Test
void getPayloadId_shouldObtainAPayloadIdWhenProposingTheMergeBlock() {
    reInitializePreMerge();
    Bytes32 terminalBlockHash = dataStructureUtil.randomBytes32();
    final Bytes8 payloadId = dataStructureUtil.randomBytes8();
    final BeaconState headState = getHeadState();
    final UInt64 blockSlot = headState.getSlot().plus(1);
    final Bytes32 blockRoot = recentChainData.getBestBlockRoot().orElseThrow();
    // we expect head block root and slot to be ZERO since in the test we do not send an
    // onForkChoiceUpdated before calling onTerminalBlock, so it will initialize ZEROED
    final ForkChoiceState forkChoiceState = new ForkChoiceState(Bytes32.ZERO, UInt64.ZERO, terminalBlockHash, terminalBlockHash, Bytes32.ZERO, false);
    final PayloadAttributes payloadAttributes = withProposerForSlot(headState, blockSlot);
    notifier.onTerminalBlockReached(terminalBlockHash);
    validateGetPayloadIdOnTheFlyRetrieval(blockSlot, blockRoot, forkChoiceState, payloadId, payloadAttributes, false);
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) 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 ForkChoiceState

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

the class ForkChoiceNotifierTest method onForkChoiceUpdated_shouldNotIncludePayloadAttributesWhileSyncing.

@Test
void onForkChoiceUpdated_shouldNotIncludePayloadAttributesWhileSyncing() {
    withProposerForSlot(recentChainData.getHeadSlot().plus(1));
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    notifier.onSyncingStatusChanged(false);
    assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
    // We're syncing so don't include payload attributes
    verify(executionEngineChannel).forkChoiceUpdated(forkChoiceState, Optional.empty());
}
Also used : ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) Test(org.junit.jupiter.api.Test)

Example 5 with ForkChoiceState

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

the class ForkChoiceNotifierTest method onAttestationsDue_shouldSendUpdateEvenWithAMissedBlockIfWeAreDueToProposeNextTwo.

@Test
void onAttestationsDue_shouldSendUpdateEvenWithAMissedBlockIfWeAreDueToProposeNextTwo() {
    final BeaconState headState = getHeadState();
    // slot 2
    final UInt64 blockSlot1 = headState.getSlot().plus(1);
    // slot 3
    final UInt64 blockSlot2 = headState.getSlot().plus(2);
    final List<PayloadAttributes> payloadAttributes = withProposerForTwoSlots(headState, blockSlot1, blockSlot2);
    // context:
    // current slot is 1
    // proposer index 1 proposes on slot 2
    // proposer index 0 proposes on slot 3
    // slot is 1 and is not empty -> sending forkChoiceUpdated
    final ForkChoiceState forkChoiceState = getCurrentForkChoiceState();
    assertThat(notifier.onForkChoiceUpdated(forkChoiceState)).isCompleted();
    // We are proposing block on slot 2
    verify(executionEngineChannel).forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes.get(0)));
    // onAttestationsDue for slot 1 (attributes for slot2)
    notifier.onAttestationsDue(headState.getSlot());
    verifyNoMoreInteractions(executionEngineChannel);
    // simulating we missed trying to produce a block: we are now in slot 2
    storageSystem.chainUpdater().setCurrentSlot(recentChainData.getCurrentSlot().orElseThrow().plus(1));
    // Slot 2 is now assumed empty so prepare to propose in slot 3
    notifier.onAttestationsDue(recentChainData.getCurrentSlot().orElseThrow());
    verify(executionEngineChannel).forkChoiceUpdated(forkChoiceState, Optional.of(payloadAttributes.get(1)));
    // Shouldn't resend with added payload attributes
    verifyNoMoreInteractions(executionEngineChannel);
}
Also used : PayloadAttributes(tech.pegasys.teku.spec.executionengine.PayloadAttributes) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Aggregations

ForkChoiceState (tech.pegasys.teku.spec.executionengine.ForkChoiceState)24 Test (org.junit.jupiter.api.Test)20 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)17 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)17 PayloadAttributes (tech.pegasys.teku.spec.executionengine.PayloadAttributes)14 Bytes32 (org.apache.tuweni.bytes.Bytes32)13 Bytes8 (tech.pegasys.teku.infrastructure.bytes.Bytes8)7 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)6 SafeFutureAssert.assertThatSafeFuture (tech.pegasys.teku.infrastructure.async.SafeFutureAssert.assertThatSafeFuture)5 ForkChoiceUpdatedResult (tech.pegasys.teku.spec.executionengine.ForkChoiceUpdatedResult)4 Optional (java.util.Optional)2 ReadOnlyForkChoiceStrategy (tech.pegasys.teku.spec.datastructures.forkchoice.ReadOnlyForkChoiceStrategy)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Throwables (com.google.common.base.Throwables)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ForkChoiceStrategy (tech.pegasys.teku.ethereum.forkchoice.ForkChoiceStrategy)1