Skip to content

Commit

Permalink
Include BlockHeader and RoundHeader for block root hash calculation (#…
Browse files Browse the repository at this point in the history
…10322)

This PR updates the types of items included for block root hash calculation

* Include BlockHeader and RoundHeader for block root hash calcuation

---------

Signed-off-by: Xin Li <[email protected]>
  • Loading branch information
xin-hedera authored Feb 10, 2025
1 parent 66d8d19 commit ed7574e
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ public BlockItem readBlockItemFor(ItemCase itemCase) {

index++;
switch (itemCase) {
case EVENT_HEADER, EVENT_TRANSACTION -> blockRootHashDigest.addInputBlockItem(blockItem);
case STATE_CHANGES, TRANSACTION_OUTPUT, TRANSACTION_RESULT -> blockRootHashDigest.addOutputBlockItem(
blockItem);
case EVENT_HEADER, EVENT_TRANSACTION, ROUND_HEADER -> blockRootHashDigest.addInputBlockItem(blockItem);
case BLOCK_HEADER, STATE_CHANGES, TRANSACTION_OUTPUT, TRANSACTION_RESULT -> blockRootHashDigest
.addOutputBlockItem(blockItem);
default -> {
// other block items aren't considered input / output
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void disabled() {

@ParameterizedTest(name = "startBlockNumber={0}")
@NullSource
@ValueSource(longs = {7858855L})
@ValueSource(longs = {981L})
@SneakyThrows
void poll(Long startBlockNumber, CapturedOutput output) {
// given
Expand All @@ -205,7 +205,7 @@ void poll(Long startBlockNumber, CapturedOutput output) {

// then
verify(blockStreamVerifier)
.verify(argThat(b -> b.getBytes() == null && b.getIndex() == 7858853L && b.getNodeId() == 0L));
.verify(argThat(b -> b.getBytes() == null && b.getIndex() == blockNumber(0) && b.getNodeId() == 0L));
verify(consensusNodeService).getNodes();
verify(recordFileRepository).findLatest();

Expand All @@ -225,8 +225,9 @@ void poll(Long startBlockNumber, CapturedOutput output) {
byte[] expectedBytes = FileUtils.readFileToByteArray(
fileCopier.getTo().resolve("2").resolve(blockFile(1).getName()).toFile());
verify(blockStreamVerifier)
.verify(argThat(b ->
Arrays.equals(b.getBytes(), expectedBytes) && b.getIndex() == 7858854L && b.getNodeId() == 2L));
.verify(argThat(b -> Arrays.equals(b.getBytes(), expectedBytes)
&& b.getIndex() == blockNumber(1)
&& b.getNodeId() == 2L));
verify(consensusNodeService, times(2)).getNodes();
verify(recordFileRepository).findLatest();

Expand Down Expand Up @@ -307,7 +308,7 @@ void startBlockNumber(CapturedOutput output) {

// then
verify(blockStreamVerifier)
.verify(argThat(b -> b.getBytes() == null && b.getIndex() == 7858853 && b.getNodeId() == 0L));
.verify(argThat(b -> b.getBytes() == null && b.getIndex() == blockNumber(0) && b.getNodeId() == 0L));
verify(consensusNodeService).getNodes();
verify(recordFileRepository).findLatest();

Expand Down Expand Up @@ -370,7 +371,7 @@ void verifyFailure(CapturedOutput output) {
blockStreamPoller.poll();

// then
verify(blockStreamVerifier, times(2)).verify(argThat(b -> b.getIndex() == 7858853L));
verify(blockStreamVerifier, times(2)).verify(argThat(b -> b.getIndex() == blockNumber(0)));
verify(consensusNodeService).getNodes();
verify(recordFileRepository).findLatest();

Expand Down Expand Up @@ -410,7 +411,7 @@ void verifyFailureThenSuccess(CapturedOutput output) {
blockStreamPoller.poll();

// then
verify(blockStreamVerifier, times(2)).verify(argThat(b -> b.getIndex() == 7858853L));
verify(blockStreamVerifier, times(2)).verify(argThat(b -> b.getIndex() == blockNumber(0)));
verify(consensusNodeService).getNodes();
verify(recordFileRepository).findLatest();

Expand All @@ -430,6 +431,10 @@ private static BlockFile blockFile(int index) {
return TEST_BLOCK_FILES.get(index);
}

private long blockNumber(int index) {
return blockFile(index).getIndex();
}

@SneakyThrows
private void verifyArchivedFile(String filename, long nodeId) {
byte[] expected = FileUtils.readFileToByteArray(fileCopier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.hedera.mirror.importer.downloader.provider;

import static com.hedera.mirror.importer.domain.StreamFilename.SIDECAR_FOLDER;
import static com.hedera.mirror.importer.reader.block.ProtoBlockFileReaderTest.TEST_BLOCK_FILES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

Expand Down Expand Up @@ -136,7 +137,7 @@ void getBlockFile() {
properties.setPathType(PathType.NODE_ID);
createBlockStreamFileCopier().copy();
var node = node("0.0.3");
String filename = BlockFile.getBlockStreamFilename(7858853);
String filename = TEST_BLOCK_FILES.getFirst().getName();
var expected = streamFileData(node, filename);

// when, then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,38 @@

public class ProtoBlockFileReaderTest {

private static final long TIMESTAMP = 1738889423L;
public static final List<BlockFile> TEST_BLOCK_FILES = List.of(
BlockFile.builder()
.consensusStart(1736197012160646000L)
.consensusEnd(1736197012160646001L)
.count(2L)
.consensusStart(1738953031945593129L)
.consensusEnd(1738953032202698150L)
.count(7L)
.digestAlgorithm(DigestAlgorithm.SHA_384)
.hash(
"581caa8ab1fad535a0fac97957c5c0cf44c528ee55724353b4bab9093083fda32429f73248bc3128e329bbdfa1967d20")
.index(7858853L)
.name(BlockFile.getBlockStreamFilename(7858853))
"847ec86e6da4d279e0445a983f198ccf1883a2c32a7f8c8f87361e1311417b2b8d7531211aa52454a7de2aa06c162bf4")
.index(981L)
.name(BlockFile.getBlockStreamFilename(981))
.previousHash(
"ba1a0222099d542425f6915053b7f15e3b75fd680b0d84ca6d41fbffcd38f8fb5ac6ab6a235e69f7ae23118d1996c7f1")
.roundStart(7858854L)
.roundEnd(7858854L)
"2b223b895e1a847579150a85a86e32e4aa42de0cc17a9f4e73f7f330e231515ece0fbf1818c29160a5f46da0268138d3")
.roundStart(982L)
.roundEnd(982L)
.version(ProtoBlockFileReader.VERSION)
.build(),
BlockFile.builder()
.consensusStart(null)
.consensusEnd(null)
.count(0L)
.consensusStart(1738953032298721606L)
.consensusEnd(1738953032428026822L)
.count(6L)
.digestAlgorithm(DigestAlgorithm.SHA_384)
.hash(
"ef32f163bee6553087002310467b970b1de2c8cbec2eab46f0d0c58ff34043d080f43c9e3c759956fda19fc9f5a5966b")
.index(7858854L)
.name(BlockFile.getBlockStreamFilename(7858854))
"df7c5f12ca2ee96bd42c4f08c52450bb5ee334092fdab4fc2b632b03bca9b6aebeabe77ff93b08685d4df20f99af13d6")
.index(982L)
.name(BlockFile.getBlockStreamFilename(982))
.previousHash(
"581caa8ab1fad535a0fac97957c5c0cf44c528ee55724353b4bab9093083fda32429f73248bc3128e329bbdfa1967d20")
.roundStart(7858855L)
.roundEnd(7858855L)
"847ec86e6da4d279e0445a983f198ccf1883a2c32a7f8c8f87361e1311417b2b8d7531211aa52454a7de2aa06c162bf4")
.roundStart(983L)
.roundEnd(983L)
.version(ProtoBlockFileReader.VERSION)
.build());
private static final long TIMESTAMP = 1738889423L;

private final ProtoBlockFileReader reader = new ProtoBlockFileReader();

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit ed7574e

Please sign in to comment.