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