Skip to content

Commit 78cf8d0

Browse files
Nana-ECAlfredoG87
andauthored
chore: Setup local copies of block node protobuf (#891)
Currently the block node repo pulls in the protobuf from the central protobuf repo which itself was moved to consensus node repo. Block node like mirror node should maintain its own protobuf and publish it for use by consensus node and others. - rename `stream` module to `protobuf` for clarity - Update `build.gradle.kts` to remove block_service.proto from consensus node repo - Move `unparsed.proto` to `com.hiero.block.internal` package - Add explicit block node services proto files under `com.hiero.block.api`. Including block stream publisher and subscriber, block node, block access, state and reconnect services. - consolidate proto changes from consensus node repo that had yet to reach HIP - Resolve broken references to older packages - Rename `SingleBlock` to just `Block`. Block request is indicative enough - Fix some static warning on BlockRequest usage in some java files Signed-off-by: Nana Essilfie-Conduah <[email protected]> Signed-off-by: Alfredo Gutierrez Grajeda <[email protected]> Co-authored-by: Alfredo Gutierrez Grajeda <[email protected]>
1 parent 8c197fd commit 78cf8d0

File tree

81 files changed

+1630
-1404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1630
-1404
lines changed

block-node/app/src/testFixtures/java/module-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
requires com.swirlds.config.api;
99
requires com.swirlds.metrics.api;
1010
requires org.hiero.block.node.spi;
11-
requires org.hiero.block.stream;
11+
requires org.hiero.block.protobuf;
1212
requires io.helidon.webserver;
1313
requires java.logging;
1414
requires org.junit.jupiter.api;

block-node/app/src/testFixtures/java/org/hiero/block/node/app/fixtures/blocks/BlockItemUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Arrays;
77
import java.util.Collection;
88
import java.util.List;
9-
import org.hiero.hapi.block.node.BlockItemUnparsed;
9+
import org.hiero.block.internal.BlockItemUnparsed;
1010

1111
/**
1212
* Utility class for testing block items.

block-node/app/src/testFixtures/java/org/hiero/block/node/app/fixtures/blocks/BlockUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.hedera.pbj.runtime.io.buffer.Bytes;
77
import java.io.IOException;
88
import java.util.zip.GZIPInputStream;
9+
import org.hiero.block.internal.BlockUnparsed;
910
import org.hiero.block.node.app.fixtures.TestUtils;
10-
import org.hiero.hapi.block.node.BlockUnparsed;
1111

1212
/*
1313
* Utility class for getting test blocks.

block-node/app/src/testFixtures/java/org/hiero/block/node/app/fixtures/blocks/SimpleTestBlockItemBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import java.util.ArrayList;
1515
import java.util.Collections;
1616
import java.util.List;
17+
import org.hiero.block.internal.BlockItemUnparsed;
1718
import org.hiero.block.node.spi.blockmessaging.BlockItems;
18-
import org.hiero.hapi.block.node.BlockItemUnparsed;
1919

2020
/**
2121
* A utility class to create sample BlockItem objects for testing purposes.

block-node/base/src/test/java/org/hiero/block/node/base/ranges/CombinedBlockRangeSetTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CombinedBlockRangeSetTest {
2222

2323
@Test
2424
@DisplayName("contains() returns true if any underlying set contains the block number")
25-
void testContainsSingleBlock() {
25+
void testContainsBlock() {
2626
final BlockRangeSet set1 = mock(BlockRangeSet.class);
2727
final BlockRangeSet set2 = mock(BlockRangeSet.class);
2828
when(set1.contains(5L)).thenReturn(false);
@@ -37,7 +37,7 @@ void testContainsSingleBlock() {
3737

3838
@Test
3939
@DisplayName("contains() returns false if no underlying set contains the block number")
40-
void testContainsSingleBlockNotFound() {
40+
void testContainsBlockNotFound() {
4141
final BlockRangeSet set1 = mock(BlockRangeSet.class);
4242
final BlockRangeSet set2 = mock(BlockRangeSet.class);
4343
when(set1.contains(5L)).thenReturn(false);

block-node/block-access/src/main/java/module-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
requires transitive com.hedera.pbj.runtime;
88
requires transitive org.hiero.block.node.spi;
99
requires com.swirlds.metrics.api;
10-
requires org.hiero.block.stream;
10+
requires org.hiero.block.protobuf;
1111
requires com.github.spotbugs.annotations;
1212

1313
provides org.hiero.block.node.spi.BlockNodePlugin with

block-node/block-access/src/main/java/org/hiero/block/node/access/service/BlockAccessServicePlugin.java

+23-21
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
import edu.umd.cs.findbugs.annotations.NonNull;
1616
import java.util.Arrays;
1717
import java.util.List;
18+
import org.hiero.block.api.BlockRequest;
19+
import org.hiero.block.api.BlockResponse;
20+
import org.hiero.block.api.BlockResponse.Code;
21+
import org.hiero.block.api.protoc.BlockAccessServiceGrpc;
1822
import org.hiero.block.node.spi.BlockNodeContext;
1923
import org.hiero.block.node.spi.BlockNodePlugin;
2024
import org.hiero.block.node.spi.ServiceBuilder;
2125
import org.hiero.block.node.spi.historicalblocks.HistoricalBlockFacility;
22-
import org.hiero.hapi.block.node.SingleBlockRequest;
23-
import org.hiero.hapi.block.node.SingleBlockResponse;
24-
import org.hiero.hapi.block.node.SingleBlockResponseCode;
2526

2627
/**
27-
* Plugin that implements the BlockAccessService and provides the 'singleBlock' RPC.
28+
* Plugin that implements the BlockAccessService and provides the 'block' RPC.
2829
*/
2930
public class BlockAccessServicePlugin implements BlockNodePlugin, ServiceInterface {
3031

@@ -47,8 +48,8 @@ public class BlockAccessServicePlugin implements BlockNodePlugin, ServiceInterfa
4748
* @param request the request containing the block number or latest flag
4849
* @return the response containing the block or an error status
4950
*/
50-
private SingleBlockResponse handleSingleBlockRequest(SingleBlockRequest request) {
51-
LOGGER.log(DEBUG, "Received SingleBlockRequest for block number: {0}", request.blockNumber());
51+
private BlockResponse handleBlockRequest(BlockRequest request) {
52+
LOGGER.log(DEBUG, "Received BlockRequest for block number: {0}", request.blockNumber());
5253
requestCounter.increment();
5354

5455
try {
@@ -59,13 +60,13 @@ private SingleBlockResponse handleSingleBlockRequest(SingleBlockRequest request)
5960
"Both block_number and retrieve_latest set. Using retrieve_latest instead of block_number: {0}",
6061
request.blockNumber());
6162
responseCounterNotFound.increment();
62-
return new SingleBlockResponse(SingleBlockResponseCode.READ_BLOCK_NOT_FOUND, null);
63+
return new BlockResponse(Code.READ_BLOCK_NOT_FOUND, null);
6364
}
6465
// when block_number is -1 and retrieve_latest is false, return an NOT_FOUND error
6566
if (request.blockNumber() == -1 && !request.retrieveLatest()) {
6667
LOGGER.log(INFO, "Block number is -1 and retrieve_latest is false");
6768
responseCounterNotFound.increment();
68-
return new SingleBlockResponse(SingleBlockResponseCode.READ_BLOCK_NOT_FOUND, null);
69+
return new BlockResponse(Code.READ_BLOCK_NOT_FOUND, null);
6970
}
7071

7172
long blockNumberToRetrieve;
@@ -76,7 +77,7 @@ private SingleBlockResponse handleSingleBlockRequest(SingleBlockRequest request)
7677
if (blockNumberToRetrieve < 0) {
7778
LOGGER.log(INFO, "Latest block number not available");
7879
responseCounterNotAvailable.increment();
79-
return new SingleBlockResponse(SingleBlockResponseCode.READ_BLOCK_NOT_AVAILABLE, null);
80+
return new BlockResponse(Code.READ_BLOCK_NOT_AVAILABLE, null);
8081
}
8182
} else {
8283
blockNumberToRetrieve = request.blockNumber();
@@ -93,18 +94,18 @@ private SingleBlockResponse handleSingleBlockRequest(SingleBlockRequest request)
9394
lowestBlockNumber,
9495
highestBlockNumber);
9596
responseCounterNotAvailable.increment();
96-
return new SingleBlockResponse(SingleBlockResponseCode.READ_BLOCK_NOT_AVAILABLE, null);
97+
return new BlockResponse(Code.READ_BLOCK_NOT_AVAILABLE, null);
9798
}
9899

99100
// Retrieve the block
100101
Block block = blockProvider.block(blockNumberToRetrieve).block();
101102
responseCounterSuccess.increment();
102-
return new SingleBlockResponse(SingleBlockResponseCode.READ_BLOCK_SUCCESS, block);
103+
return new BlockResponse(Code.READ_BLOCK_SUCCESS, block);
103104

104105
} catch (RuntimeException e) {
105106
LOGGER.log(ERROR, "Failed to retrieve block number: {0}", request.blockNumber());
106107
responseCounterNotFound.increment();
107-
return new SingleBlockResponse(SingleBlockResponseCode.READ_BLOCK_NOT_FOUND, null);
108+
return new BlockResponse(Code.READ_BLOCK_NOT_FOUND, null);
108109
}
109110
}
110111

@@ -141,9 +142,9 @@ public void init(BlockNodeContext context, ServiceBuilder serviceBuilder) {
141142
*/
142143
enum BlockAccessServiceMethod implements Method {
143144
/**
144-
* The singleBlock method retrieves a single block from the block node.
145+
* The getBlock method retrieves a single block from the block node.
145146
*/
146-
singleBlock
147+
getBlock
147148
}
148149

149150
/**
@@ -152,7 +153,8 @@ enum BlockAccessServiceMethod implements Method {
152153
@NonNull
153154
@Override
154155
public String serviceName() {
155-
return "BlockAccessService";
156+
String[] parts = fullName().split("\\.");
157+
return parts[parts.length - 1];
156158
}
157159

158160
/**
@@ -161,7 +163,7 @@ public String serviceName() {
161163
@NonNull
162164
@Override
163165
public String fullName() {
164-
return "com.hedera.hapi.block." + serviceName();
166+
return BlockAccessServiceGrpc.SERVICE_NAME;
165167
}
166168

167169
/**
@@ -185,11 +187,11 @@ public Pipeline<? super Bytes> open(
185187
throws GrpcException {
186188
final BlockAccessServiceMethod blockAccessServiceMethod = (BlockAccessServiceMethod) method;
187189
return switch (blockAccessServiceMethod) {
188-
case singleBlock:
189-
yield Pipelines.<SingleBlockRequest, SingleBlockResponse>unary()
190-
.mapRequest(SingleBlockRequest.PROTOBUF::parse)
191-
.method(this::handleSingleBlockRequest)
192-
.mapResponse(SingleBlockResponse.PROTOBUF::toBytes)
190+
case getBlock:
191+
yield Pipelines.<BlockRequest, BlockResponse>unary()
192+
.mapRequest(BlockRequest.PROTOBUF::parse)
193+
.method(this::handleBlockRequest)
194+
.mapResponse(BlockResponse.PROTOBUF::toBytes)
193195
.respondTo(pipeline)
194196
.build();
195197
};

block-node/block-access/src/test/java/org/hiero/block/node/access/service/BlockAccessServicePluginTest.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package org.hiero.block.node.access.service;
33

4-
import static org.hiero.block.node.access.service.BlockAccessServicePlugin.BlockAccessServiceMethod.singleBlock;
4+
import static org.hiero.block.node.access.service.BlockAccessServicePlugin.BlockAccessServiceMethod.getBlock;
55
import static org.hiero.block.node.app.fixtures.TestUtils.enableDebugLogging;
66
import static org.hiero.block.node.app.fixtures.blocks.BlockItemUtils.toBlockItemsUnparsed;
77
import static org.hiero.block.node.app.fixtures.blocks.SimpleTestBlockItemBuilder.createNumberOfVerySimpleBlocks;
@@ -10,13 +10,13 @@
1010
import static org.junit.jupiter.api.Assertions.assertNotNull;
1111
import static org.junit.jupiter.api.Assertions.assertNull;
1212

13-
import com.hedera.hapi.block.SingleBlockRequest;
14-
import com.hedera.hapi.block.SingleBlockResponse;
15-
import com.hedera.hapi.block.SingleBlockResponseCode;
1613
import com.hedera.hapi.block.stream.BlockItem;
1714
import com.hedera.pbj.runtime.ParseException;
1815
import com.hedera.pbj.runtime.grpc.ServiceInterface;
1916
import java.util.List;
17+
import org.hiero.block.api.BlockRequest;
18+
import org.hiero.block.api.BlockResponse;
19+
import org.hiero.block.api.BlockResponse.Code;
2020
import org.hiero.block.node.app.fixtures.plugintest.GrpcPluginTestBase;
2121
import org.hiero.block.node.app.fixtures.plugintest.SimpleInMemoryHistoricalBlockFacility;
2222
import org.hiero.block.node.spi.blockmessaging.BlockItems;
@@ -27,7 +27,7 @@
2727
public class BlockAccessServicePluginTest extends GrpcPluginTestBase<BlockAccessServicePlugin> {
2828

2929
public BlockAccessServicePluginTest() {
30-
super(new BlockAccessServicePlugin(), singleBlock, new SimpleInMemoryHistoricalBlockFacility());
30+
super(new BlockAccessServicePlugin(), getBlock, new SimpleInMemoryHistoricalBlockFacility());
3131
}
3232

3333
/**
@@ -53,64 +53,64 @@ void testServiceInterfaceBasics() {
5353
List<ServiceInterface.Method> methods = serviceInterface.methods();
5454
assertNotNull(methods);
5555
assertEquals(1, methods.size());
56-
assertEquals(singleBlock, methods.getFirst());
56+
assertEquals(getBlock, methods.getFirst());
5757
}
5858

5959
@Test
6060
@DisplayName("Happy Path Test, BlockAccessServicePlugin for an existing Block Number")
61-
void happyTestGetSingleBlock() throws ParseException {
61+
void happyTestGetBlock() throws ParseException {
6262
final long blockNumber = 1;
63-
final SingleBlockRequest request = SingleBlockRequest.newBuilder()
63+
final BlockRequest request = BlockRequest.newBuilder()
6464
.blockNumber(blockNumber)
6565
.allowUnverified(true)
6666
.retrieveLatest(false)
6767
.build();
68-
toPluginPipe.onNext(SingleBlockRequest.PROTOBUF.toBytes(request));
68+
toPluginPipe.onNext(BlockRequest.PROTOBUF.toBytes(request));
6969
// Check we get a response
7070
assertEquals(1, fromPluginBytes.size());
7171
// parse the response
72-
SingleBlockResponse response = SingleBlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
72+
BlockResponse response = BlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
7373
// check that the status is success
74-
assertEquals(SingleBlockResponseCode.READ_BLOCK_SUCCESS, response.status());
74+
assertEquals(Code.READ_BLOCK_SUCCESS, response.status());
7575
// check that the block number is correct
7676
assertEquals(1, response.block().items().getFirst().blockHeader().number());
7777
}
7878

7979
@Test
80-
@DisplayName("Negative Test, GetSingleBlock for a non-existing Block Number")
80+
@DisplayName("Negative Test, GetBlock for a non-existing Block Number")
8181
void negativeTestNonExistingBlock() throws ParseException {
8282
final long blockNumber = 1000;
83-
final SingleBlockRequest request = SingleBlockRequest.newBuilder()
83+
final BlockRequest request = BlockRequest.newBuilder()
8484
.blockNumber(blockNumber)
8585
.allowUnverified(true)
8686
.retrieveLatest(false)
8787
.build();
88-
toPluginPipe.onNext(SingleBlockRequest.PROTOBUF.toBytes(request));
88+
toPluginPipe.onNext(BlockRequest.PROTOBUF.toBytes(request));
8989
// Check we get a response
9090
assertEquals(1, fromPluginBytes.size());
9191
// parse the response
92-
SingleBlockResponse response = SingleBlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
92+
BlockResponse response = BlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
9393
// check that the status is NOT FOUND
94-
assertEquals(SingleBlockResponseCode.READ_BLOCK_NOT_AVAILABLE, response.status());
94+
assertEquals(Code.READ_BLOCK_NOT_AVAILABLE, response.status());
9595
// check block is null
9696
assertNull(response.block());
9797
}
9898

9999
@Test
100100
@DisplayName("Request Latest Block")
101101
void testRequestLatestBlock() throws ParseException {
102-
final SingleBlockRequest request = SingleBlockRequest.newBuilder()
102+
final BlockRequest request = BlockRequest.newBuilder()
103103
.blockNumber(-1)
104104
.allowUnverified(true)
105105
.retrieveLatest(true)
106106
.build();
107-
toPluginPipe.onNext(SingleBlockRequest.PROTOBUF.toBytes(request));
107+
toPluginPipe.onNext(BlockRequest.PROTOBUF.toBytes(request));
108108
// Check we get a response
109109
assertEquals(1, fromPluginBytes.size());
110110
// parse the response
111-
SingleBlockResponse response = SingleBlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
111+
BlockResponse response = BlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
112112
// check that the status is success
113-
assertEquals(SingleBlockResponseCode.READ_BLOCK_SUCCESS, response.status());
113+
assertEquals(Code.READ_BLOCK_SUCCESS, response.status());
114114
// check that the block number is correct
115115
assertEquals(24, response.block().items().getFirst().blockHeader().number());
116116
}
@@ -119,35 +119,35 @@ void testRequestLatestBlock() throws ParseException {
119119
@DisplayName("Request Latest and a specific Block different from latest, should fail with READ_BLOCK_NOT_FOUND")
120120
void testRequestLatestBlockDifferent() throws ParseException {
121121
final long blockNumber = 1;
122-
final SingleBlockRequest request = SingleBlockRequest.newBuilder()
122+
final BlockRequest request = BlockRequest.newBuilder()
123123
.blockNumber(blockNumber)
124124
.allowUnverified(true)
125125
.retrieveLatest(true)
126126
.build();
127-
toPluginPipe.onNext(SingleBlockRequest.PROTOBUF.toBytes(request));
127+
toPluginPipe.onNext(BlockRequest.PROTOBUF.toBytes(request));
128128
// Check we get a response
129129
assertEquals(1, fromPluginBytes.size());
130130
// parse the response
131-
SingleBlockResponse response = SingleBlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
131+
BlockResponse response = BlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
132132
// check that the status is success
133-
assertEquals(SingleBlockResponseCode.READ_BLOCK_NOT_FOUND, response.status());
133+
assertEquals(Code.READ_BLOCK_NOT_FOUND, response.status());
134134
}
135135

136136
@Test
137137
@DisplayName("block_number is -1 and retrieve_latest is false - should return READ_BLOCK_NOT_FOUND")
138138
void testBlockNumberIsMinusOneAndRetrieveLatestIsFalse() throws ParseException {
139-
final SingleBlockRequest request = SingleBlockRequest.newBuilder()
139+
final BlockRequest request = BlockRequest.newBuilder()
140140
.blockNumber(-1)
141141
.allowUnverified(true)
142142
.retrieveLatest(false)
143143
.build();
144-
toPluginPipe.onNext(SingleBlockRequest.PROTOBUF.toBytes(request));
144+
toPluginPipe.onNext(BlockRequest.PROTOBUF.toBytes(request));
145145
// Check we get a response
146146
assertEquals(1, fromPluginBytes.size());
147147
// parse the response
148-
SingleBlockResponse response = SingleBlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
148+
BlockResponse response = BlockResponse.PROTOBUF.parse(fromPluginBytes.get(0));
149149
// check that the status is READ_BLOCK_NOT_FOUND
150-
assertEquals(SingleBlockResponseCode.READ_BLOCK_NOT_FOUND, response.status());
150+
assertEquals(Code.READ_BLOCK_NOT_FOUND, response.status());
151151
}
152152

153153
private void sendBlocks(int numberOfBlocks) {

block-node/block-providers/files.historic/src/main/java/module-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
requires transitive org.hiero.block.node.spi;
1717
requires com.hedera.pbj.runtime;
1818
requires org.hiero.block.common;
19-
requires org.hiero.block.stream;
19+
requires org.hiero.block.protobuf;
2020
requires com.github.spotbugs.annotations;
2121

2222
provides org.hiero.block.node.spi.historicalblocks.BlockProviderPlugin with

block-node/block-providers/files.historic/src/main/java/org/hiero/block/node/blocks/files/historic/ZipBlockAccessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import java.util.Objects;
1717
import java.util.zip.ZipEntry;
1818
import java.util.zip.ZipFile;
19+
import org.hiero.block.internal.BlockUnparsed;
1920
import org.hiero.block.node.base.CompressionType;
2021
import org.hiero.block.node.spi.historicalblocks.BlockAccessor;
21-
import org.hiero.hapi.block.node.BlockUnparsed;
2222

2323
/**
2424
* The ZipBlockAccessor class provides access to a block stored in a zip file.

block-node/block-providers/files.historic/src/test/java/org/hiero/block/node/blocks/files/historic/ZipBlockAccessorTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import java.util.zip.ZipEntry;
2424
import java.util.zip.ZipFile;
2525
import java.util.zip.ZipOutputStream;
26+
import org.hiero.block.internal.BlockItemUnparsed;
27+
import org.hiero.block.internal.BlockUnparsed;
2628
import org.hiero.block.node.app.fixtures.blocks.SimpleTestBlockItemBuilder;
2729
import org.hiero.block.node.base.CompressionType;
2830
import org.hiero.block.node.spi.historicalblocks.BlockAccessor.Format;
29-
import org.hiero.hapi.block.node.BlockItemUnparsed;
30-
import org.hiero.hapi.block.node.BlockUnparsed;
3131
import org.junit.jupiter.api.AfterEach;
3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.DisplayName;

0 commit comments

Comments
 (0)