Skip to content

Commit

Permalink
Merge branch 'main' into coordinator-code-reuse-3
Browse files Browse the repository at this point in the history
# Conflicts:
#	jvm-libs/generic/extensions/kotlin/src/test/kotlin/build/linea/URIExtensionsTest.kt
#	jvm-libs/generic/vertx-helper/src/main/kotlin/net/consensys/linea/vertx/ClientOptions.kt
#	jvm-libs/linea/blob-decompressor/src/test/kotlin/net/consensys/linea/blob/BlobDecompressorDataDecodingTest.kt
#	jvm-libs/linea/blob-decompressor/src/test/kotlin/net/consensys/linea/blob/GoNativeBlobDecompressorTest.kt
  • Loading branch information
jpnovais committed Oct 23, 2024
2 parents 7ad31ba + 00ffc73 commit 8468afe
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import tech.pegasys.teku.ethereum.executionclient.schema.randomExecutionPayload
import tech.pegasys.teku.infrastructure.async.SafeFuture
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration

@ExtendWith(VertxExtension::class)
Expand Down Expand Up @@ -79,7 +79,7 @@ class BlockToBatchSubmissionCoordinatorTest {

val captor = argumentCaptor<Throwable>()
Assertions.assertThat(blockToBatchSubmissionCoordinator.acceptBlock(baseBlock)).isCompleted
Awaitility.await().atMost(200.milliseconds.toJavaDuration())
Awaitility.await().atMost(1.seconds.toJavaDuration())
.untilAsserted {
verify(testLogger, times(1)).error(
eq("Failed to conflate block={} errorMessage={}"),
Expand Down
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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import java.net.URI
class URIExtensionsTest {
@Test
fun `getPortWithSchemaDefaults`() {
assertThat(URI.create("http://example.com").getPortWithSchemaDefaults()).isEqualTo(80)
assertThat(URI.create("https://example.com").getPortWithSchemaDefaults()).isEqualTo(443)
assertThat(URI.create("http://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
assertThat(URI.create("https://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
assertThat(URI.create("myschema://example.com:8080").getPortWithSchemaDefaults()).isEqualTo(8080)
assertThatThrownBy { (URI.create("mySchema://example.com").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")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.consensys.linea.vertx

import build.linea.getPortWithSchemaDefaults
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.getPortWithSchemaDefaults()
defaultPort = uri.getPortWithSchemeDefaults()

return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package net.consensys.linea.blob

import net.consensys.linea.testing.filesystem.findPathTo
import org.apache.tuweni.bytes.Bytes
import org.assertj.core.api.Assertions.assertThat
import org.hyperledger.besu.ethereum.core.Block
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions
import org.hyperledger.besu.ethereum.rlp.RLP
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import kotlin.io.path.readBytes

class BlobDecompressorDataDecodingTest {
Expand All @@ -17,18 +19,21 @@ class BlobDecompressorDataDecodingTest {
decompressor = GoNativeBlobDecompressorFactory.getInstance(BlobDecompressorVersion.V1_1_0)
}

@Disabled("Until Besu supports deserializing transactions without signatures validation")
@Test
fun `can deserialize native lib testdata blobs`() {
val blob = findPathTo("prover")!!
.resolve("lib/compressor/blob/testdata/v0/sample-blob-0151eda71505187b5.bin")
.readBytes()
val decompressedBlob = decompressor.decompress(blob)
val blocksRlpEncoded = rlpDecodeAsListOfBytes(decompressedBlob)
blocksRlpEncoded.forEachIndexed { index, blockRlp ->
val rlpInput = RLP.input(Bytes.wrap(blockRlp))
val decodedBlock = Block.readFrom(rlpInput, MainnetBlockHeaderFunctions())
println("$index: $decodedBlock")
}
assertThat(blocksRlpEncoded).hasSize(254)
// TODO: enable after Besu supports deserializing transactions without signatures validation
//
// blocksRlpEncoded.forEachIndexed { index, blockRlp ->
// val rlpInput = RLP.input(Bytes.wrap(blockRlp))
// val decodedBlock = Block.readFrom(rlpInput, MainnetBlockHeaderFunctions())
// println("$index: $decodedBlock")
// }
}

@Disabled("for local dev validation")
Expand All @@ -42,26 +47,4 @@ class BlobDecompressorDataDecodingTest {
val decodedBlock = Block.readFrom(rlpInput, MainnetBlockHeaderFunctions())
println(decodedBlock)
}

private fun rlpEncode(list: List<ByteArray>): ByteArray {
return RLP.encode { rlpWriter ->
rlpWriter.startList()
list.forEach { bytes ->
rlpWriter.writeBytes(Bytes.wrap(bytes))
}
rlpWriter.endList()
}.toArray()
}

private fun rlpDecodeAsListOfBytes(rlpEncoded: ByteArray): List<ByteArray> {
val decodedBytes = mutableListOf<ByteArray>()
RLP.input(Bytes.wrap(rlpEncoded), true).also { rlpInput ->
rlpInput.enterList()
while (!rlpInput.isEndOfCurrentList) {
decodedBytes.add(rlpInput.readBytes().toArray())
}
rlpInput.leaveList()
}
return decodedBytes
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GoNativeBlobDecompressorTest {

@Test
fun `when blocks are compressed with compressor shall decompress them back`() {
val blocks = CompressorTestData.blocksRlpEncoded.slice(0..1)
val blocks = CompressorTestData.blocksRlpEncoded
assertTrue(compressor.Write(blocks[0], blocks[0].size))
assertTrue(compressor.Write(blocks[1], blocks[1].size))

Expand All @@ -36,6 +36,7 @@ class GoNativeBlobDecompressorTest {

val decompressedBlob = decompressor.decompress(compressedData)
assertThat(decompressedBlob.size).isGreaterThan(compressedData.size)
// TODO: assert decompressedDataBuffer content
val decompressedBlocks: List<ByteArray> = rlpDecodeAsListOfBytes(decompressedBlob)
assertThat(decompressedBlocks).hasSize(2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.consensys.linea.blob

import org.apache.tuweni.bytes.Bytes
import org.hyperledger.besu.ethereum.rlp.RLP

internal fun rlpEncode(list: List<ByteArray>): ByteArray {
return RLP.encode { rlpWriter ->
rlpWriter.startList()
list.forEach { bytes ->
rlpWriter.writeBytes(Bytes.wrap(bytes))
}
rlpWriter.endList()
}.toArray()
}

internal fun rlpDecodeAsListOfBytes(rlpEncoded: ByteArray): List<ByteArray> {
val decodedBytes = mutableListOf<ByteArray>()
RLP.input(Bytes.wrap(rlpEncoded), true).also { rlpInput ->
rlpInput.enterList()
while (!rlpInput.isEndOfCurrentList) {
decodedBytes.add(rlpInput.readBytes().toArray())
}
rlpInput.leaveList()
}
return decodedBytes
}

0 comments on commit 8468afe

Please sign in to comment.