From 31be92891b0af62e75d3d617588f41e1a6707754 Mon Sep 17 00:00:00 2001 From: Matt Peterson Date: Tue, 16 Jul 2024 14:07:24 -0600 Subject: [PATCH] added minimal BlockProof type to add intermediate BlockItem type Signed-off-by: Matt Peterson --- protos/src/main/protobuf/blockstream.proto | 11 ++++++++--- .../hedera/block/server/persistence/Util.java | 2 +- .../storage/FileSystemBlockStorage.java | 4 ++-- .../server/persistence/PersistTestUtils.java | 2 +- .../block/server/persistence/RangeTest.java | 17 +++++++---------- server/src/test/resources/producer.sh | 8 +++++--- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/protos/src/main/protobuf/blockstream.proto b/protos/src/main/protobuf/blockstream.proto index 35e9b0e6d..f6c1f7ab3 100644 --- a/protos/src/main/protobuf/blockstream.proto +++ b/protos/src/main/protobuf/blockstream.proto @@ -58,17 +58,22 @@ message Block { message BlockItem { oneof items { - BlockHeader block_header = 1; - BlockProof state_proof = 2; + BlockHeader header = 1; + EventMetadata start_event = 2; + BlockProof state_proof = 3; } - string value = 3; + string value = 4; } message BlockHeader { uint64 block_number = 1; } +message EventMetadata { + uint64 creator_id = 1; +} + message BlockProof { uint64 block = 1; } \ No newline at end of file diff --git a/server/src/main/java/com/hedera/block/server/persistence/Util.java b/server/src/main/java/com/hedera/block/server/persistence/Util.java index cde8792f3..7c5afcdf9 100644 --- a/server/src/main/java/com/hedera/block/server/persistence/Util.java +++ b/server/src/main/java/com/hedera/block/server/persistence/Util.java @@ -27,6 +27,6 @@ public static long getBlockNumber(final Block block) { } public static BlockHeader getBlockHeader(final Block block) { - return block.getBlockItems(0).getBlockHeader(); + return block.getBlockItems(0).getHeader(); } } diff --git a/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java b/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java index bcd5073b8..9cb96c01c 100644 --- a/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java +++ b/server/src/main/java/com/hedera/block/server/persistence/storage/FileSystemBlockStorage.java @@ -143,11 +143,11 @@ private Optional readBlockItem(final String blockItemPath) { private String getAbsoluteFilePath(final BlockItem blockItem) throws IOException { - if (blockItem.hasBlockHeader()) { + if (blockItem.hasHeader()) { // A "block" is a directory of blockItems. Create the "block" // based on the block_number - currentBlockDir = Path.of(String.valueOf(blockItem.getBlockHeader().getBlockNumber())); + currentBlockDir = Path.of(String.valueOf(blockItem.getHeader().getBlockNumber())); final Path blockPath = blockNodeRootPath.resolve(currentBlockDir); createPath(blockPath); diff --git a/server/src/test/java/com/hedera/block/server/persistence/PersistTestUtils.java b/server/src/test/java/com/hedera/block/server/persistence/PersistTestUtils.java index ee320c877..e2b20d939 100644 --- a/server/src/test/java/com/hedera/block/server/persistence/PersistTestUtils.java +++ b/server/src/test/java/com/hedera/block/server/persistence/PersistTestUtils.java @@ -38,7 +38,7 @@ public static List generateBlocks(int numOfBlocks) { case 0: blockItems.add( BlockItem.newBuilder() - .setBlockHeader( + .setHeader( BlockStreamService.BlockHeader.newBuilder() .setBlockNumber(i + 1) .build()) diff --git a/server/src/test/java/com/hedera/block/server/persistence/RangeTest.java b/server/src/test/java/com/hedera/block/server/persistence/RangeTest.java index 2a86d1205..1e50610cc 100644 --- a/server/src/test/java/com/hedera/block/server/persistence/RangeTest.java +++ b/server/src/test/java/com/hedera/block/server/persistence/RangeTest.java @@ -32,11 +32,10 @@ public class RangeTest { @Test public void testReadRangeWithEvenEntries() { - int maxEntries = 100; int numOfBlocks = 100; BlockPersistenceHandler blockPersistenceHandler = - generateInMemoryTestBlockPersistenceHandler(maxEntries); + generateInMemoryTestBlockPersistenceHandler(); for (Block block : generateBlocks(numOfBlocks)) { for (BlockItem blockItem : block.getBlockItemsList()) { @@ -52,10 +51,9 @@ public void testReadRangeWithEvenEntries() { @Test public void testReadRangeWithNoBlocks() { - int maxEntries = 100; BlockPersistenceHandler blockPersistenceHandler = - generateInMemoryTestBlockPersistenceHandler(maxEntries); + generateInMemoryTestBlockPersistenceHandler(); Queue results = blockPersistenceHandler.readRange(1, 100); assertNotNull(results); assertEquals(0, results.size()); @@ -63,11 +61,10 @@ public void testReadRangeWithNoBlocks() { @Test public void testReadRangeWhenBlocksLessThanWindow() { - int maxEntries = 100; int numOfBlocks = 9; BlockPersistenceHandler blockPersistenceHandler = - generateInMemoryTestBlockPersistenceHandler(maxEntries); + generateInMemoryTestBlockPersistenceHandler(); List blocks = generateBlocks(numOfBlocks); for (Block block : blocks) { for (BlockItem blockItem : block.getBlockItemsList()) { @@ -96,13 +93,13 @@ private static void verifyReadRange( for (int i = startBlockId; i <= endBlockId && results.peek() != null; ++i) { Block block = results.poll(); assertNotNull(block); - assertEquals(i, block.getBlockItems(0).getBlockHeader().getBlockNumber()); + assertEquals(i, block.getBlockItems(0).getHeader().getBlockNumber()); } } } private static BlockPersistenceHandler - generateInMemoryTestBlockPersistenceHandler(int maxEntries) { + generateInMemoryTestBlockPersistenceHandler() { // Mock up a simple, in-memory persistence handler BlockStorage blockStorage = new NoOpTestBlockStorage(); @@ -120,8 +117,8 @@ public NoOpTestBlockStorage() { @Override public void write(BlockItem blockItem) { - if (blockItem.hasBlockHeader()) { - index = blockItem.getBlockHeader().getBlockNumber(); + if (blockItem.hasHeader()) { + index = blockItem.getHeader().getBlockNumber(); } cache.compute( diff --git a/server/src/test/resources/producer.sh b/server/src/test/resources/producer.sh index a74621a57..9d9345f47 100755 --- a/server/src/test/resources/producer.sh +++ b/server/src/test/resources/producer.sh @@ -48,10 +48,12 @@ trap cleanup SIGINT for ((i=1; i<=10; i++)) do - if [[ i -eq 1 ]]; then - echo "{\"block_item\": {\"block_header\": $iter,\"value\": \"Payload[...]\"}}" + if [[ $i -eq 1 ]]; then + echo "{\"block_item\": {\"header\": {\"block_number\": $iter},\"value\": \"Payload[...]\"}}" + elif [[ $i -eq 10 ]]; then + echo "{\"block_item\": {\"state_proof\": {\"block\": $iter},\"value\": \"Payload[...]\"}}" else - echo "{\"block_item\": {\"block_header\": 0,\"value\": \"Payload[...]\"}}" + echo "{\"block_item\": {\"start_event\": {\"creator_id\": $i},\"value\": \"Payload[...]\"}}" fi sleep 0.5