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));
}
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);
}
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);
}
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());
}
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);
}
Aggregations