-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blob Decompressor and Some Helpers (#230)
* adds Java/Kotlin blob decompressor and some common libs
- Loading branch information
Showing
25 changed files
with
405 additions
and
16 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
jvm-libs/generic/extensions/kotlin/src/main/kotlin/build/linea/URIExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package build.linea | ||
|
||
import java.net.URI | ||
|
||
fun URI.getPortWithSchemeDefaults(): Int { | ||
return if (port != -1) { | ||
port | ||
} else { | ||
when (scheme.lowercase()) { | ||
"http" -> 80 | ||
"https" -> 443 | ||
// Focous on HTTP as it is what we need for now | ||
else -> throw IllegalArgumentException("Unsupported scheme: $scheme") | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...kotlin/net/consensys/jvm/ResourcesUtil.kt → ...n/kotlin/build/linea/jvm/ResourcesUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package net.consensys.jvm | ||
package build.linea.jvm | ||
|
||
import java.io.File | ||
import java.nio.file.Files | ||
|
20 changes: 20 additions & 0 deletions
20
jvm-libs/generic/extensions/kotlin/src/test/kotlin/build/linea/URIExtensionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package build.linea | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.jupiter.api.Test | ||
import java.net.URI | ||
|
||
class URIExtensionsTest { | ||
@Test | ||
fun `getPortWithSchemaDefaults`() { | ||
assertThat(URI.create("http://example.com").getPortWithSchemeDefaults()).isEqualTo(80) | ||
assertThat(URI.create("https://example.com").getPortWithSchemeDefaults()).isEqualTo(443) | ||
assertThat(URI.create("http://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080) | ||
assertThat(URI.create("https://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080) | ||
assertThat(URI.create("myschema://example.com:8080").getPortWithSchemeDefaults()).isEqualTo(8080) | ||
assertThatThrownBy { (URI.create("mySchema://example.com").getPortWithSchemeDefaults()) } | ||
.isInstanceOf(IllegalArgumentException::class.java) | ||
.hasMessage("Unsupported scheme: mySchema") | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...in/net/consensys/jvm/ResourcesUtilTest.kt → ...tlin/build/linea/jvm/ResourcesUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugins { | ||
id 'net.consensys.zkevm.kotlin-library-conventions' | ||
} | ||
|
||
dependencies { | ||
api "io.tmio:tuweni-bytes:${libs.versions.tuweni.get()}" | ||
implementation(project(':jvm-libs:generic:extensions:kotlin')) | ||
testImplementation "io.tmio:tuweni-units:${libs.versions.tuweni.get()}" | ||
} |
9 changes: 9 additions & 0 deletions
9
jvm-libs/generic/extensions/tuweni/src/main/kotlin/build/linea/tuweni/Bytes32.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package build.linea.tuweni | ||
|
||
import net.consensys.toULong | ||
import org.apache.tuweni.bytes.Bytes32 | ||
import java.math.BigInteger | ||
|
||
fun ByteArray.toBytes32(): Bytes32 = Bytes32.wrap(this) | ||
fun ByteArray.sliceAsBytes32(sliceIndex: Int): Bytes32 = Bytes32.wrap(this, /*offset*/sliceIndex * 32) | ||
fun Bytes32.toULong(): ULong = BigInteger(this.toArray()).toULong() |
40 changes: 40 additions & 0 deletions
40
jvm-libs/generic/extensions/tuweni/src/test/kotlin/build/linea/tuweni/Bytes32Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package build.linea.tuweni | ||
|
||
import net.consensys.toBigInteger | ||
import org.apache.tuweni.bytes.Bytes32 | ||
import org.apache.tuweni.units.bigints.UInt256 | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import kotlin.random.Random | ||
|
||
class Bytes32Test { | ||
@BeforeEach | ||
fun setUp() { | ||
// workaround: need this to load the functions otherwise JUNit gets stuck ¯\_(ツ)_/¯ | ||
Random.Default.nextBytes(32).sliceAsBytes32(0) | ||
UInt256.ZERO.toBytes().toULong() | ||
} | ||
|
||
@Test | ||
fun testSliceAsBytes32() { | ||
val bytes = Random.Default.nextBytes(3 * 32 - 1) | ||
assertThat(bytes.sliceAsBytes32(0)).isEqualTo(Bytes32.wrap(bytes, 0)) | ||
assertThat(bytes.sliceAsBytes32(1)).isEqualTo(Bytes32.wrap(bytes, 32)) | ||
assertThatThrownBy { bytes.sliceAsBytes32(2) } | ||
.isInstanceOf(IllegalArgumentException::class.java) | ||
} | ||
|
||
@Test | ||
fun testToULong() { | ||
UInt256.ZERO.toBytes() | ||
.also { bytes -> assertThat(bytes.toULong()).isEqualTo(0uL) } | ||
UInt256.valueOf(Long.MAX_VALUE) | ||
.also { bytes -> assertThat(bytes.toULong()).isEqualTo(Long.MAX_VALUE.toULong()) } | ||
UInt256.valueOf(Long.MAX_VALUE).add(UInt256.ONE) | ||
.also { bytes -> assertThat(bytes.toULong()).isEqualTo(Long.MAX_VALUE.toULong() + 1UL) } | ||
UInt256.valueOf(ULong.MAX_VALUE.toBigInteger()) | ||
.also { bytes -> assertThat(bytes.toULong()).isEqualTo(ULong.MAX_VALUE) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
jvm-libs/generic/vertx-helper/src/main/kotlin/net/consensys/linea/vertx/ClientOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.consensys.linea.vertx | ||
|
||
import build.linea.getPortWithSchemeDefaults | ||
import io.vertx.core.http.HttpClientOptions | ||
import java.net.URI | ||
|
||
fun <T : HttpClientOptions> T.setDefaultsFrom(uri: URI): T { | ||
isSsl = uri.scheme.lowercase() == "https" | ||
defaultHost = uri.host | ||
defaultPort = uri.getPortWithSchemeDefaults() | ||
|
||
return this | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../linea/blob-compressor/src/main/kotlin/net/consensys/linea/blob/GoNativeBlobCompressor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-56.2 KB
...ea/blob-compressor/src/test/resources/net/consensys/linea/nativecompressor/rlp_blocks.bin
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
plugins { | ||
id 'net.consensys.zkevm.kotlin-library-conventions' | ||
id 'net.consensys.zkevm.linea-native-libs-helper' | ||
alias(libs.plugins.jreleaser) | ||
id 'java-test-fixtures' | ||
} | ||
|
||
description = 'Java JNA wrapper for Linea Blob Decompressor Library implemented in GO Lang' | ||
apply from: rootProject.file("gradle/publishing.gradle") | ||
|
||
dependencies { | ||
implementation "net.java.dev.jna:jna:${libs.versions.jna.get()}" | ||
implementation project(":jvm-libs:generic:extensions:kotlin") | ||
|
||
testImplementation project(":jvm-libs:linea:blob-compressor") | ||
testImplementation(testFixtures(project(":jvm-libs:linea:blob-compressor"))) | ||
testImplementation(project(":jvm-libs:linea:testing:file-system")) | ||
testImplementation("io.tmio:tuweni-bytes:${libs.versions.tuweni.get()}") | ||
testImplementation("org.hyperledger.besu:besu-datatypes:${libs.versions.besu.get()}") | ||
testImplementation "org.hyperledger.besu:evm:${libs.versions.besu.get()}" | ||
testImplementation("org.hyperledger.besu.internal:core:${libs.versions.besu.get()}") | ||
testImplementation("org.hyperledger.besu:plugin-api:${libs.versions.besu.get()}") | ||
testImplementation("org.hyperledger.besu.internal:rlp:${libs.versions.besu.get()}") | ||
} | ||
|
||
jar { | ||
dependsOn configurations.runtimeClasspath | ||
} | ||
|
||
test { | ||
// we cannot have more 1 compressor per JVM, hence we disable parallel execution | ||
// because multiple threads would cause issues with the native library | ||
systemProperties["junit.jupiter.execution.parallel.enabled"] = false | ||
maxParallelForks = 1 | ||
} | ||
|
||
def libsZipDownloadOutputDir = project.parent.layout.buildDirectory.asFile.get().absolutePath | ||
|
||
task downloadNativeLibs { | ||
doLast { | ||
fetchLibFromZip("https://github.com/Consensys/linea-monorepo/releases/download/blob-libs-v1.1.0-test8/linea-blob-libs-v1.1.0-test8.zip", "blob_decompressor", libsZipDownloadOutputDir) | ||
} | ||
} | ||
|
||
compileKotlin { | ||
dependsOn tasks.downloadNativeLibs | ||
} | ||
|
||
task cleanResources(type: Delete) { | ||
fileTree(project.layout.projectDirectory.dir('src/main/resources')) | ||
.filter { | ||
it.name.endsWith(".so") || it.name.endsWith(".dll") || it.name.endsWith(".dylib") | ||
}.each { | ||
println("Deleting: ${it}") | ||
delete it | ||
} | ||
} | ||
|
||
clean.dependsOn cleanResources |
Oops, something went wrong.