Skip to content

Commit

Permalink
Merge branch 'main' into gha-publish-on-main
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesho authored Oct 23, 2024
2 parents 821b842 + baffb9c commit b2f0622
Show file tree
Hide file tree
Showing 74 changed files with 1,088 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.consensys.zkevm.ethereum.coordination.aggregation

import build.linea.domain.BlockIntervals
import kotlinx.datetime.Instant
import net.consensys.zkevm.domain.BlobAndBatchCounters
import net.consensys.zkevm.domain.BlobCounters
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.persistence.AggregationsRepository
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.consensys.zkevm.coordinator.clients.prover

import build.linea.domain.BlockInterval
import net.consensys.zkevm.coordinator.clients.ProverClient
import net.consensys.zkevm.domain.BlockInterval
import tech.pegasys.teku.infrastructure.async.SafeFuture

class StartBlockNumberBasedSwitchPredicate<ProofRequest>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.consensys.zkevm.coordinator.clients.prover

import build.linea.domain.BlockInterval
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.getOrElse
import com.github.michaelbull.result.map
import io.vertx.core.Vertx
import net.consensys.linea.errors.ErrorResponse
import net.consensys.zkevm.domain.BlockInterval
import net.consensys.zkevm.domain.ProofIndex
import net.consensys.zkevm.fileio.FileMonitor
import net.consensys.zkevm.fileio.FileReader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.consensys.zkevm.coordinator.clients.prover

import build.linea.domain.BlockInterval
import io.vertx.core.Vertx
import net.consensys.linea.contract.Web3JL2MessageServiceLogsClient
import net.consensys.linea.metrics.LineaMetricsCategory
Expand All @@ -9,7 +10,6 @@ import net.consensys.zkevm.coordinator.clients.BlobCompressionProverClientV2
import net.consensys.zkevm.coordinator.clients.ExecutionProverClientV2
import net.consensys.zkevm.coordinator.clients.ProofAggregationProverClientV2
import net.consensys.zkevm.coordinator.clients.ProverClient
import net.consensys.zkevm.domain.BlockInterval
import org.web3j.protocol.Web3j

class ProverClientFactory(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.consensys.zkevm.coordinator.clients.prover

import build.linea.domain.BlockInterval
import io.vertx.core.Vertx
import io.vertx.junit5.VertxExtension
import net.consensys.zkevm.coordinator.clients.prover.serialization.JsonSerialization
import net.consensys.zkevm.domain.BlockInterval
import net.consensys.zkevm.domain.ProofIndex
import net.consensys.zkevm.fileio.FileReader
import net.consensys.zkevm.fileio.FileWriter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.consensys.zkevm.coordinator.clients.prover

import build.linea.domain.BlockIntervals
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import io.vertx.core.Vertx
Expand All @@ -8,7 +9,6 @@ import kotlinx.datetime.Clock
import net.consensys.ByteArrayExt
import net.consensys.linea.metrics.MetricsFacade
import net.consensys.linea.metrics.micrometer.MicrometerMetricsFacade
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.domain.ProofIndex
import net.consensys.zkevm.domain.ProofsToAggregate
import org.assertj.core.api.Assertions.assertThat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.consensys.zkevm.coordinator.clients.prover.serialization

import build.linea.domain.BlockIntervals
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
Expand All @@ -13,7 +14,6 @@ import net.consensys.decodeHex
import net.consensys.encodeHex
import net.consensys.zkevm.coordinator.clients.BlobCompressionProof
import net.consensys.zkevm.coordinator.clients.BlobCompressionProofRequest
import net.consensys.zkevm.domain.BlockIntervals

internal class ByteArrayDeserializer : JsonDeserializer<ByteArray>() {
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): ByteArray {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.consensys.zkevm.coordinator.clients.prover.serialization

import build.linea.domain.BlockIntervals
import net.consensys.zkevm.coordinator.clients.prover.serialization.JsonSerialization.proofResponseMapperV1
import net.consensys.zkevm.domain.BlockIntervals
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.consensys.zkevm.coordinator.clients

import net.consensys.zkevm.domain.BlockInterval
import build.linea.domain.BlockInterval
import net.consensys.zkevm.toULong
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.consensys.zkevm.coordinator.clients

import net.consensys.zkevm.domain.BlockInterval
import net.consensys.zkevm.domain.BlockIntervals
import build.linea.domain.BlockInterval
import build.linea.domain.BlockIntervals
import net.consensys.zkevm.domain.ConflationCalculationResult
import net.consensys.zkevm.ethereum.coordination.blob.ShnarfResult

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.consensys.zkevm.domain

import build.linea.domain.BlockInterval
import build.linea.domain.BlockIntervals
import kotlinx.datetime.Instant

typealias BlobsToAggregate = BlockIntervalData
typealias BlobsToAggregate = BlockInterval

/**
* Represents an Aggregation request to the Prover
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.consensys.zkevm.domain

import build.linea.domain.BlockInterval
import build.linea.domain.BlockIntervals
import kotlinx.datetime.Instant
import net.consensys.linea.CommonDomainFunctions
import net.consensys.zkevm.coordinator.clients.BlobCompressionProof
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,13 @@
package net.consensys.zkevm.domain

import build.linea.domain.BlockInterval
import kotlinx.datetime.Instant
import net.consensys.isSortedBy
import net.consensys.linea.CommonDomainFunctions
import net.consensys.linea.traces.TracesCounters
import net.consensys.zkevm.toULong
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1

/**
* Represents a block interval, with inclusive start and end block numbers
* @property startBlockNumber start block number, inclusive
* @property endBlockNumber end block number, inclusive
*/
interface BlockInterval {
val startBlockNumber: ULong
val endBlockNumber: ULong
val blocksRange: ULongRange
get() = startBlockNumber..endBlockNumber
fun intervalString(): String = CommonDomainFunctions.blockIntervalString(startBlockNumber, endBlockNumber)

companion object {
fun between(
startBlockNumber: ULong,
endBlockNumber: ULong
): BlockInterval {
return BlockIntervalData(startBlockNumber, endBlockNumber)
}
}
}

fun List<BlockInterval>.toBlockIntervalsString(): String {
return this.joinToString(
separator = ", ",
prefix = "[",
postfix = "]$size",
transform = BlockInterval::intervalString
)
}

fun <T : BlockInterval> List<T>.filterOutWithEndBlockNumberBefore(
endBlockNumberInclusive: ULong
): List<T> {
return this.filter { int -> int.endBlockNumber > endBlockNumberInclusive }
}

fun assertConsecutiveIntervals(intervals: List<BlockInterval>) {
require(intervals.isSortedBy { it.startBlockNumber }) { "Intervals must be sorted by startBlockNumber" }
require(intervals.zipWithNext().all { (a, b) -> a.endBlockNumber + 1u == b.startBlockNumber }) {
"Intervals must be consecutive: intervals=${intervals.toBlockIntervalsString()}"
}
}

data class BlocksConflation(
val blocks: List<ExecutionPayloadV1>,
val conflationResult: ConflationCalculationResult
Expand Down Expand Up @@ -148,52 +105,3 @@ data class BlockCounters(
"blockRLPEncoded=${blockRLPEncoded.size}bytes)"
}
}

/**
* Represents a block interval
* @property startBlockNumber starting block number inclusive
* @property endBlockNumber ending block number inclusive
*/
data class BlockIntervalData(
override val startBlockNumber: ULong,
override val endBlockNumber: ULong
) : BlockInterval

/**
* Data class that represents sequential blocks intervals for either Conflations, Blobs or Aggregations.
* Example:
* conflations: [100..110], [111..120], [121..130] --> BlockIntervals(100, [110, 120, 130])
* Blobs with
* Blob1 2 conflations above: [100..110], [111..120]
* Blob2 1 conflations: [121..130]
* --> BlockIntervals(100, [120, 130])
*/
data class BlockIntervals(
val startingBlockNumber: ULong,
val upperBoundaries: List<ULong>
) {
// This default constructor is to avoid the parse error when deserializing
constructor() : this(0UL, listOf())

fun toIntervalList(): List<BlockInterval> {
var previousBlockNumber = startingBlockNumber
val intervals = mutableListOf<BlockInterval>()
upperBoundaries.forEach {
intervals.add(BlockIntervalData(previousBlockNumber, it))
previousBlockNumber = it + 1u
}
return intervals
}

fun toBlockInterval(): BlockInterval {
return BlockIntervalData(startingBlockNumber, upperBoundaries.last())
}
}

fun List<BlockInterval>.toBlockIntervals(): BlockIntervals {
require(isNotEmpty()) { "BlockIntervals list must not be empty" }
return BlockIntervals(
startingBlockNumber = first().startBlockNumber,
upperBoundaries = map { it.endBlockNumber }
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.consensys.zkevm.domain

import build.linea.domain.BlockInterval

data class ProofIndex(
override val startBlockNumber: ULong,
override val endBlockNumber: ULong,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.consensys.zkevm.ethereum.coordination.aggregation

import build.linea.domain.BlockInterval
import net.consensys.zkevm.domain.BlobCounters
import net.consensys.zkevm.domain.BlobsToAggregate
import net.consensys.zkevm.domain.BlockInterval
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.consensys.zkevm.ethereum.coordination.aggregation

import build.linea.domain.BlockIntervals
import build.linea.domain.toBlockIntervalsString
import io.vertx.core.Vertx
import kotlinx.datetime.Clock
import net.consensys.linea.metrics.MetricsFacade
Expand All @@ -10,10 +12,8 @@ import net.consensys.zkevm.coordinator.clients.ProofAggregationProverClientV2
import net.consensys.zkevm.domain.Aggregation
import net.consensys.zkevm.domain.BlobAndBatchCounters
import net.consensys.zkevm.domain.BlobsToAggregate
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.domain.ProofIndex
import net.consensys.zkevm.domain.ProofsToAggregate
import net.consensys.zkevm.domain.toBlockIntervalsString
import net.consensys.zkevm.ethereum.coordination.blockcreation.SafeBlockProvider
import net.consensys.zkevm.persistence.AggregationsRepository
import org.apache.logging.log4j.LogManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.consensys.zkevm.ethereum.coordination.blob

import build.linea.domain.BlockInterval
import build.linea.domain.BlockIntervals
import build.linea.domain.toBlockIntervalsString
import io.vertx.core.Handler
import io.vertx.core.Vertx
import kotlinx.datetime.Instant
Expand All @@ -11,10 +14,7 @@ import net.consensys.zkevm.coordinator.clients.BlobCompressionProverClientV2
import net.consensys.zkevm.domain.Blob
import net.consensys.zkevm.domain.BlobRecord
import net.consensys.zkevm.domain.BlobStatus
import net.consensys.zkevm.domain.BlockInterval
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.domain.ConflationCalculationResult
import net.consensys.zkevm.domain.toBlockIntervalsString
import net.consensys.zkevm.ethereum.coordination.conflation.BlobCreationHandler
import net.consensys.zkevm.persistence.BlobsRepository
import org.apache.logging.log4j.LogManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.consensys.zkevm.ethereum.coordination.blob

import build.linea.domain.BlockInterval
import net.consensys.zkevm.coordinator.clients.BlobCompressionProof
import net.consensys.zkevm.domain.BlockInterval
import tech.pegasys.teku.infrastructure.async.SafeFuture

data class BlobCompressionProofUpdate(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.consensys.zkevm.ethereum.coordination.blob

import build.linea.domain.BlockIntervals
import net.consensys.decodeHex
import net.consensys.encodeHex
import net.consensys.linea.blob.GoNativeBlobShnarfCalculator
import net.consensys.linea.blob.GoNativeShnarfCalculatorFactory
import net.consensys.linea.blob.ShnarfCalculatorVersion
import net.consensys.zkevm.domain.BlockIntervals
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import java.util.Base64
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.consensys.zkevm.ethereum.coordination.blob

import build.linea.domain.BlockInterval
import build.linea.domain.BlockIntervals
import com.github.michaelbull.result.getOrThrow
import com.github.michaelbull.result.map
import com.github.michaelbull.result.onSuccess
import com.github.michaelbull.result.recover
import com.github.michaelbull.result.runCatching
import net.consensys.encodeHex
import net.consensys.zkevm.domain.BlobRecord
import net.consensys.zkevm.domain.BlockInterval
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.persistence.BlobsRepository
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.consensys.zkevm.ethereum.coordination.conflation

import build.linea.domain.toBlockIntervalsString
import net.consensys.linea.CommonDomainFunctions.blockIntervalString
import net.consensys.zkevm.domain.Blob
import net.consensys.zkevm.domain.BlockCounters
import net.consensys.zkevm.domain.ConflationCalculationResult
import net.consensys.zkevm.domain.ConflationTrigger
import net.consensys.zkevm.domain.toBlockIntervalsString
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import tech.pegasys.teku.infrastructure.async.SafeFuture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.consensys.zkevm.coordination.blob

import build.linea.domain.BlockIntervals
import net.consensys.decodeHex
import net.consensys.encodeHex
import net.consensys.linea.blob.CalculateShnarfResult
import net.consensys.linea.blob.GoNativeBlobShnarfCalculator
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.ethereum.coordination.blob.GoBackedBlobShnarfCalculator
import net.consensys.zkevm.ethereum.coordination.blob.ShnarfResult
import org.apache.tuweni.bytes.Bytes32
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.consensys.zkevm.ethereum.coordination.aggregation

import build.linea.domain.BlockIntervals
import io.vertx.core.Vertx
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
Expand All @@ -9,7 +10,6 @@ import net.consensys.zkevm.domain.Aggregation
import net.consensys.zkevm.domain.BlobAndBatchCounters
import net.consensys.zkevm.domain.BlobCounters
import net.consensys.zkevm.domain.BlobsToAggregate
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.domain.ProofIndex
import net.consensys.zkevm.domain.ProofToFinalize
import net.consensys.zkevm.domain.ProofsToAggregate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.consensys.zkevm.ethereum.coordination.blob

import build.linea.domain.BlockIntervals
import net.consensys.zkevm.domain.BlobRecord
import net.consensys.zkevm.domain.BlockIntervals
import net.consensys.zkevm.persistence.BlobsRepository
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
Expand Down
Loading

0 comments on commit b2f0622

Please sign in to comment.