Search in sources :

Example 1 with ChainReorgEvent

use of tech.pegasys.teku.api.response.v1.ChainReorgEvent 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 ChainReorgEvent

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

the class EventSubscriptionManagerTest method shouldPropagateReorgMessages.

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

Aggregations

ChainReorgEvent (tech.pegasys.teku.api.response.v1.ChainReorgEvent)2 Test (org.junit.jupiter.api.Test)1 HeadEvent (tech.pegasys.teku.api.response.v1.HeadEvent)1