Skip to content

Commit

Permalink
fix: sanding
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Jul 12, 2024
1 parent 73b0ce0 commit 2950920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.hedera.block.protos.BlockStreamService.SubscribeStreamRequest;
import static com.hedera.block.protos.BlockStreamService.SubscribeStreamResponse;

import com.google.protobuf.Descriptors;
import com.hedera.block.protos.BlockStreamService;
import com.hedera.block.server.data.ObjectEvent;
import com.hedera.block.server.mediator.StreamMediator;
Expand All @@ -40,7 +39,8 @@ public class ConsumerBlockItemObserver

private final System.Logger LOGGER = System.getLogger(getClass().getName());

private final StreamObserver<BlockStreamService.SubscribeStreamResponse> subscribeStreamResponseObserver;
private final StreamObserver<BlockStreamService.SubscribeStreamResponse>
subscribeStreamResponseObserver;

private final long timeoutThresholdMillis;
private final InstantSource producerLivenessClock;
Expand Down Expand Up @@ -93,8 +93,7 @@ public ConsumerBlockItemObserver(

/** Pass the block to the observer provided by Helidon */
@Override
public void onEvent(final ObjectEvent<BlockItem> event, final long l, final boolean b)
throws Exception {
public void onEvent(final ObjectEvent<BlockItem> event, final long l, final boolean b) {

// Refresh the producer liveness and pass the block to the observer.
producerLivenessMillis = producerLivenessClock.millis();
Expand All @@ -105,10 +104,8 @@ public void onEvent(final ObjectEvent<BlockItem> event, final long l, final bool
}

if (isReachedFirstBlock) {
SubscribeStreamResponse subscribeStreamResponse = SubscribeStreamResponse
.newBuilder()
.setBlockItem(blockItem)
.build();
final SubscribeStreamResponse subscribeStreamResponse =
SubscribeStreamResponse.newBuilder().setBlockItem(blockItem).build();

subscribeStreamResponseObserver.onNext(subscribeStreamResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@

package com.hedera.block.server.producer;

import static com.hedera.block.protos.BlockStreamService.*;

import com.google.protobuf.ByteString;
import com.hedera.block.server.data.ObjectEvent;
import com.hedera.block.server.mediator.StreamMediator;
import io.grpc.stub.StreamObserver;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import static com.hedera.block.protos.BlockStreamService.*;

/**
* The ProducerBlockStreamObserver class plugs into Helidon's server-initiated bidirectional gRPC
* service implementation. Helidon calls methods on this class as networking events occur with the
Expand Down Expand Up @@ -72,9 +71,7 @@ public void onNext(final PublishStreamRequest publishStreamRequest) {
.setItemAck(ByteString.copyFrom(getFakeHash(blockItem)))
.build();
final PublishStreamResponse publishStreamResponse =
PublishStreamResponse.newBuilder()
.setAcknowledgement(itemAck)
.build();
PublishStreamResponse.newBuilder().setAcknowledgement(itemAck).build();
publishStreamResponseObserver.onNext(publishStreamResponse);
} catch (IOException | NoSuchAlgorithmException e) {
LOGGER.log(System.Logger.Level.ERROR, "Error calculating hash", e);
Expand Down Expand Up @@ -103,9 +100,11 @@ public void onCompleted() {
publishStreamResponseObserver.onCompleted();
}

private static byte[] getFakeHash(BlockItem blockItem) throws IOException, NoSuchAlgorithmException {
private static byte[] getFakeHash(BlockItem blockItem)
throws IOException, NoSuchAlgorithmException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
try (ObjectOutputStream objectOutputStream =
new ObjectOutputStream(byteArrayOutputStream)) {
objectOutputStream.writeObject(blockItem);
}

Expand Down

0 comments on commit 2950920

Please sign in to comment.