use of tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32 in project teku by ConsenSys.
the class BeaconBlocksByRootMessageHandler method onIncomingMessage.
@Override
public void onIncomingMessage(final String protocolId, final Eth2Peer peer, final BeaconBlocksByRootRequestMessage message, final ResponseCallback<SignedBeaconBlock> callback) {
LOG.trace("Peer {} requested BeaconBlocks with roots: {}", peer.getId(), message);
if (storageClient.getStore() != null) {
SafeFuture<Void> future = SafeFuture.COMPLETE;
if (!peer.wantToMakeRequest() || !peer.wantToReceiveObjects(callback, message.size())) {
peer.disconnectCleanly(DisconnectReason.RATE_LIMITING).reportExceptions();
return;
}
for (SszBytes32 blockRoot : message) {
future = future.thenCompose(__ -> storageClient.getStore().retrieveSignedBlock(blockRoot.get()).thenCompose(block -> {
final Optional<RpcException> validationResult = block.flatMap(b -> validateResponse(protocolId, b));
if (validationResult.isPresent()) {
return SafeFuture.failedFuture(validationResult.get());
}
return block.map(callback::respond).orElse(SafeFuture.COMPLETE);
}));
}
future.finish(callback::completeSuccessfully, err -> handleError(callback, err));
} else {
callback.completeSuccessfully();
}
}
Aggregations