Skip to content

Commit

Permalink
Build fix(fingers crossed) and review changes
Browse files Browse the repository at this point in the history
Signed-off-by: jasperpotts <[email protected]>
  • Loading branch information
jasperpotts committed Dec 20, 2024
1 parent 0c8dac0 commit d39bd03
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 24 deletions.
5 changes: 1 addition & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencyResolutionManagement {
val protobufVersion = "4.28.2"
val helidonVersion = "4.1.1"
val grpcIoVersion = "1.65.1"
var pbjVersion = "0.9.11"
val pbjVersion = "0.9.11"

// Compile time dependencies
version("io.helidon.webserver.http2", helidonVersion)
Expand All @@ -68,9 +68,6 @@ dependencyResolutionManagement {
version("com.google.auto.service", "1.1.1")
version("org.hyperledger.besu.nativelib.secp256k1", "0.8.2")
version("info.picocli", "4.7.6")
version("com.github.luben.zstd_jni", "1.5.6-8")
version("com.google.cloud.core", "2.48.0")
version("com.google.cloud.storage", "2.45.0")

// gRPC dependencies for the stream subproject
version("io.grpc", grpcIoVersion)
Expand Down
2 changes: 1 addition & 1 deletion tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ JAR=$(find build/libs -name 'tools-*-all.jar')
# run the command line tool built jar file forwarding all arguments
java -jar $JAR "$@"
# change back to the original directory
popd > /dev/null
popd > /dev/null
27 changes: 19 additions & 8 deletions tools/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.internal.DefaultDependencyFilter
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradlex.javamodule.dependencies.tasks.ModuleDirectivesScopeCheck

/*
Expand Down Expand Up @@ -29,7 +31,7 @@ application {
}

// Generate Manifest with Main-Class and Implementation-Title
tasks.withType<Jar> {
tasks.withType<Jar>().configureEach {
manifest {
attributes(
"Main-Class" to application.mainClass.get(),
Expand All @@ -39,13 +41,6 @@ tasks.withType<Jar> {
}
}

// Switch compilation from modules back to classpath because 3rd party libraries are not modularized
tasks.compileJava {
// Do not use '--module-path' despite `module-info.java`
modularity.inferModulePath = false
// Do not compile module-info, we use it only to extract dependencies for now
exclude("module-info.java")
}

// Allow non-module Jar
extraJavaModuleInfo {
Expand Down Expand Up @@ -73,4 +68,20 @@ dependencies {
implementation("info.picocli:picocli:4.7.6")
// depend on peer streams gradle module to get access to protobuf generated classes
implementation(project(":stream"))
}

tasks.withType<ShadowJar>().configureEach {
group = "shadow"

// There is an issue in the shadow plugin that it automatically accesses the
// files in 'runtimeClasspath' while Gradle is building the task graph.
// See: https://github.com/GradleUp/shadow/issues/882
dependencyFilter = NoResolveDependencyFilter()
}

// Disable dependency resolution as it conflicts with shadow plugin
class NoResolveDependencyFilter : DefaultDependencyFilter(project) {
override fun resolve(configuration: FileCollection): FileCollection {
return configuration
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@
/**
* Command line command that converts a record stream to blocks
* <p>
* Example block ranges for testing:
* <ul>
* <li><code>-s 0 -e 10</code> - Record File v2</li>
* <li><code>-s 12877843 -e 12877853</code> - Record File v5</li>
* <li><code>-s 72756872 -e 72756882</code> - Record File v6 with sidecars</li>
* </ul>
* Record files start at V2 at block 0 then change to V5 at block 12370838 and V6 at block 38210031
* </p>
* Example block ranges for testing:
* <ul>
* <li><code>-s 0 -e 10</code> - Record File v2</li>
* <li><code>-s 12877843 -e 12877853</code> - Record File v5</li>
* <li><code>-s 72756872 -e 72756882</code> - Record File v6 with sidecars</li>
* </ul>
* Record files start at V2 at block 0 then change to V5 at block 12370838 and V6 at block 38210031
*/
@SuppressWarnings({"FieldCanBeLocal", "CallToPrintStackTrace"})
@Command(name = "record2block", description = "Converts a record stream files into blocks")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public void run() {
if (!blockFileNameFromMirrorNode.equals(lastRecordFileName)) {
throw new RuntimeException("Last block of day number mismatch");
}
// System.exit(0);
// next day
day = day.plus(1, ChronoUnit.DAYS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ private static JsonObject readUrl(String url) {
}
}

/** Test main method */
/**
* Test main method
*
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Fetching block query...");
int blockNumber = 69333000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,50 @@ public static class ProgressOutputStream extends FilterOutputStream {
private final String name;
private long bytesWritten = 0;

/**
* Create new progress output stream.
*
* @param out the output stream to wrap
* @param size the size of the output stream
* @param name the name of the output stream
*/
public ProgressOutputStream(OutputStream out, long size, String name) {
super(out);
this.size = size;
this.name = name;
}

/**
* Write a byte to the output stream.
*
* @param b the byte to write
* @throws IOException if an error occurs writing the byte
*/
@Override
public void write(int b) throws IOException {
super.write(b);
bytesWritten++;
printProgress();
}

/**
* Write a byte array to the output stream.
*
* @param b the byte array to write
* @param off the offset in the byte array to start writing
* @param len the number of bytes to write
* @throws IOException if an error occurs writing the byte array
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
super.write(b, off, len);
bytesWritten += len;
printProgress();
}

/**
* Print the progress of the output stream to the console.
*/
private void printProgress() {
if (bytesWritten % MB == 0) {
System.out.printf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@

/**
* BlockInfo represents a Hedera block with its associated record files, sidecar files and signature files.
*
* @param blockNum the block number
* @param blockTime the block time
* @param recordFiles the record files associated with the block
* @param mostCommonRecordFile the record file with the most occurrences
* @param sidecarFiles the sidecar files associated with the block
* @param signatureFiles the signature files associated with the block
*/
@SuppressWarnings("unused")
public record BlockInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
* <td>byte[48]</td>
* <td>Metadata Hash of the corresponding stream file</td>
* </tr>
* <tr>
* <td>Signature on hash bytes of Metadata Hash</td>
* <td>byte[]</td>
* <td>A signature object generated by signing the hash bytes of Metadata Hash</td>
Expand Down Expand Up @@ -148,6 +149,7 @@
* <td>int (4)</td>
* <td>101 - length of signature bytes</td>
* </tr>
* <tr>
* <td>Signature bytes</td>
* <td>byte[]</td>
* <td>Serialized Signature bytes</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.security.MessageDigest;

/**
* Represents the version & block hash information of a record file.
* Represents the version and block hash information of a record file.
* <p>
* The old record file formats are documented in the
* <a href="https://github.com/search?q=repo%3Ahashgraph%2Fhedera-mirror-node%20%22implements%20RecordFileReader%22&type=code">
Expand All @@ -39,6 +39,7 @@
*
* @param hapiProtoVersion the HAPI protocol version
* @param blockHash the block hash
* @param recordFileContents the record file contents
*/
public record RecordFileInfo(SemanticVersion hapiProtoVersion, Bytes blockHash, byte[] recordFileContents) {
/* The length of the header in a v2 record file */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public record BlockPath(Path dirPath, String zipFileName, String blockNumStr, St
* @param baseDirectory The base directory for the block files
* @param block The block to write
* @throws IOException If an error occurs writing the block
* @return The path to the block file
*/
public static BlockPath writeBlock(final Path baseDirectory, final Block block) throws IOException {
// get block number from block header
Expand Down Expand Up @@ -115,6 +116,8 @@ private static BlockPath computeBlockPath(final Path baseDirectory, long blockNu

/**
* Simple main method to test the block path computation
*
* @param args The command line arguments
*/
public static void main(String[] args) {
for (long blockNumber = 0; blockNumber < 3002; blockNumber++) {
Expand Down

0 comments on commit d39bd03

Please sign in to comment.