Search in sources :

Example 1 with HeadEvent

use of tech.pegasys.teku.api.response.v1.HeadEvent in project teku by ConsenSys.

the class EventSubscriptionManager method chainHeadUpdated.

@Override
public void chainHeadUpdated(final UInt64 slot, final Bytes32 stateRoot, final Bytes32 bestBlockRoot, final boolean epochTransition, final boolean executionOptimistic, final Bytes32 previousDutyDependentRoot, final Bytes32 currentDutyDependentRoot, final Optional<ReorgContext> optionalReorgContext) {
    final Boolean executionOptimisticForApi = getExecutionOptimisticForApi(executionOptimistic);
    optionalReorgContext.ifPresent(context -> {
        final ChainReorgEvent reorgEvent = new ChainReorgEvent(slot, slot.minus(context.getCommonAncestorSlot()), context.getOldBestBlockRoot(), bestBlockRoot, context.getOldBestStateRoot(), stateRoot, configProvider.computeEpochAtSlot(slot), executionOptimisticForApi);
        notifySubscribersOfEvent(EventType.chain_reorg, reorgEvent);
    });
    final HeadEvent headEvent = new HeadEvent(slot, bestBlockRoot, stateRoot, epochTransition, executionOptimisticForApi, previousDutyDependentRoot, currentDutyDependentRoot);
    notifySubscribersOfEvent(EventType.head, headEvent);
}
Also used : HeadEvent(tech.pegasys.teku.api.response.v1.HeadEvent) ChainReorgEvent(tech.pegasys.teku.api.response.v1.ChainReorgEvent)

Example 2 with HeadEvent

use of tech.pegasys.teku.api.response.v1.HeadEvent in project teku by ConsenSys.

the class EventSubscriptionManagerTest method shouldPropagateHeadEvent.

@Test
void shouldPropagateHeadEvent() throws IOException {
    when(req.getQueryString()).thenReturn("&topics=head");
    manager.registerClient(client1);
    triggerHeadEvent();
    final String eventString = outputStream.getString();
    assertThat(eventString).contains("event: head\n");
    final HeadEvent event = jsonProvider.jsonToObject(eventString.substring(eventString.indexOf("{")), HeadEvent.class);
    assertThat(event).isEqualTo(headEvent);
}
Also used : HeadEvent(tech.pegasys.teku.api.response.v1.HeadEvent) Test(org.junit.jupiter.api.Test)

Example 3 with HeadEvent

use of tech.pegasys.teku.api.response.v1.HeadEvent in project teku by ConsenSys.

the class EventSourceHandler method handleHeadEvent.

private void handleHeadEvent(final String data) throws JsonProcessingException {
    final HeadEvent headEvent = jsonProvider.jsonToObject(data, HeadEvent.class);
    validatorTimingChannel.onHeadUpdate(headEvent.slot, headEvent.previousDutyDependentRoot, headEvent.currentDutyDependentRoot, headEvent.block);
    if (generateEarlyAttestations) {
        validatorTimingChannel.onAttestationCreationDue(headEvent.slot);
    }
}
Also used : HeadEvent(tech.pegasys.teku.api.response.v1.HeadEvent)

Example 4 with HeadEvent

use of tech.pegasys.teku.api.response.v1.HeadEvent in project teku by ConsenSys.

the class EventSourceHandlerTest method onHeadEvent_shouldNotGenerateEarlyAttestationsIfNotEnabled.

@Test
void onHeadEvent_shouldNotGenerateEarlyAttestationsIfNotEnabled() throws Exception {
    final EventSourceHandler onTimeHandler = new EventSourceHandler(validatorTimingChannel, metricsSystem, false);
    final UInt64 slot = UInt64.valueOf(134);
    final Bytes32 blockRoot = dataStructureUtil.randomBytes32();
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    final HeadEvent event = new HeadEvent(slot, blockRoot, dataStructureUtil.randomBytes32(), false, false, previousDutyDependentRoot, currentDutyDependentRoot);
    onTimeHandler.onMessage(EventType.head.name(), new MessageEvent(jsonProvider.objectToJSON(event)));
    verify(validatorTimingChannel).onHeadUpdate(eq(slot), eq(previousDutyDependentRoot), eq(currentDutyDependentRoot), eq(blockRoot));
    verifyNoMoreInteractions(validatorTimingChannel);
}
Also used : HeadEvent(tech.pegasys.teku.api.response.v1.HeadEvent) MessageEvent(com.launchdarkly.eventsource.MessageEvent) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 5 with HeadEvent

use of tech.pegasys.teku.api.response.v1.HeadEvent in project teku by ConsenSys.

the class EventSourceHandlerTest method onMessage_shouldHandleHeadEvent.

@Test
void onMessage_shouldHandleHeadEvent() throws Exception {
    final UInt64 slot = UInt64.valueOf(134);
    final Bytes32 blockRoot = dataStructureUtil.randomBytes32();
    final Bytes32 previousDutyDependentRoot = dataStructureUtil.randomBytes32();
    final Bytes32 currentDutyDependentRoot = dataStructureUtil.randomBytes32();
    final HeadEvent event = new HeadEvent(slot, blockRoot, dataStructureUtil.randomBytes32(), false, false, previousDutyDependentRoot, currentDutyDependentRoot);
    handler.onMessage(EventType.head.name(), new MessageEvent(jsonProvider.objectToJSON(event)));
    verify(validatorTimingChannel).onHeadUpdate(eq(slot), eq(previousDutyDependentRoot), eq(currentDutyDependentRoot), eq(blockRoot));
    verify(validatorTimingChannel).onAttestationCreationDue(slot);
    verifyNoMoreInteractions(validatorTimingChannel);
}
Also used : HeadEvent(tech.pegasys.teku.api.response.v1.HeadEvent) MessageEvent(com.launchdarkly.eventsource.MessageEvent) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Aggregations

HeadEvent (tech.pegasys.teku.api.response.v1.HeadEvent)6 Test (org.junit.jupiter.api.Test)4 MessageEvent (com.launchdarkly.eventsource.MessageEvent)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 ChainReorgEvent (tech.pegasys.teku.api.response.v1.ChainReorgEvent)1