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