-
Notifications
You must be signed in to change notification settings - Fork 139
feat(coordinator): add debug_executionWitness JSON-RPC client #3248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gauravahuja
wants to merge
4
commits into
main
Choose a base branch
from
feature/execution-witness-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+669
−15
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ffe8013
feat(coordinator): add debug_executionWitness JSON-RPC client
gauravahuja 702c568
fix(state-recovery): fix build
gauravahuja ab8aa98
chore(misc): address cursorbot comments
gauravahuja 0464554
chore(misc): add BlockParameter parse test
gauravahuja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,55 @@ | ||
| # Execution witness JSON-RPC client | ||
|
|
||
| Kotlin client for Besu's `debug_executionWitness` RPC (provided by [besu-zkevm-plugin](https://github.com/Consensys/besu-zkevm-plugin)). | ||
|
|
||
| ## Interface | ||
|
|
||
| [`ExecutionWitnessClient`](../../../jvm-libs/linea/clients/interfaces/src/main/kotlin/linea/executionwitness/ExecutionWitnessClient.kt) in `jvm-libs:linea:clients:interfaces`. | ||
|
|
||
| Implementation: [`ExecutionWitnessJsonRpcClient`](src/main/kotlin/linea/coordinator/clients/executionwitness/ExecutionWitnessJsonRpcClient.kt). | ||
|
|
||
| ## RPC | ||
|
|
||
| **Request** | ||
|
|
||
| ```json | ||
| { | ||
| "jsonrpc": "2.0", | ||
| "method": "debug_executionWitness", | ||
| "params": ["<block>"], | ||
| "id": 1 | ||
| } | ||
| ``` | ||
|
|
||
| **Response** (`result` object, or `null` if witness unavailable): | ||
|
|
||
| ```json | ||
| { | ||
| "state": ["..."], | ||
| "keys": ["..."], | ||
| "codes": ["..."], | ||
| "headers": ["..."] | ||
| } | ||
| ``` | ||
|
|
||
| Hex strings may be with or without a `0x` prefix. | ||
|
|
||
| ## Block parameter mapping | ||
|
|
||
| | `BlockParameter` | RPC `params[0]` | | ||
| |------------------|-----------------| | ||
| | `Tag.LATEST` (etc.) | tag string | | ||
| | `BlockNumber(n)` | decimal `n.toString()` | | ||
| | `BlockHash(h)` | `0x` + hex (32 bytes) | | ||
|
|
||
| ## Node prerequisites | ||
|
|
||
| - `besu-zkevm-plugin` loaded | ||
| - Trie-log plugin enabled | ||
| - `--rpc-http-api=DEBUG` | ||
|
|
||
| ## Tests | ||
|
|
||
| ```bash | ||
| ./gradlew :coordinator:clients:execution-witness-client:test | ||
| ``` |
This file contains hidden or 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 @@ | ||
| plugins { | ||
| id 'net.consensys.zkevm.kotlin-library-conventions' | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation project(':jvm-libs:linea:clients:interfaces') | ||
| implementation project(':jvm-libs:generic:extensions:futures') | ||
| implementation project(':jvm-libs:generic:extensions:kotlin') | ||
| implementation project(':jvm-libs:generic:json-rpc') | ||
| implementation project(':jvm-libs:generic:errors') | ||
| api "io.vertx:vertx-core" | ||
|
|
||
| testImplementation "io.vertx:vertx-junit5" | ||
| testImplementation project(':jvm-libs:linea:metrics:micrometer') | ||
| testImplementation "org.wiremock:wiremock:${libs.versions.wiremock.get()}" | ||
| } |
11 changes: 11 additions & 0 deletions
11
...nt/src/main/kotlin/linea/coordinator/clients/executionwitness/BlockParameterExtensions.kt
This file contains hidden or 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,11 @@ | ||
| package linea.coordinator.clients.executionwitness | ||
|
|
||
| import linea.domain.BlockParameter | ||
| import linea.kotlin.encodeHex | ||
|
|
||
| internal fun BlockParameter.toDebugExecutionWitnessRpcParam(): String = | ||
| when (this) { | ||
| is BlockParameter.Tag -> getTag() | ||
| is BlockParameter.BlockNumber -> getNumber().toString() | ||
| is BlockParameter.BlockHash -> getHash().encodeHex(prefix = true) | ||
| } |
69 changes: 69 additions & 0 deletions
69
...c/main/kotlin/linea/coordinator/clients/executionwitness/ExecutionWitnessJsonRpcClient.kt
This file contains hidden or 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,69 @@ | ||
| package linea.coordinator.clients.executionwitness | ||
|
|
||
| import com.github.michaelbull.result.Err | ||
| import com.github.michaelbull.result.Result | ||
| import com.github.michaelbull.result.fold | ||
| import io.vertx.core.Vertx | ||
| import linea.domain.BlockParameter | ||
| import linea.error.ErrorResponse | ||
| import linea.executionwitness.ExecutionWitness | ||
| import linea.executionwitness.ExecutionWitnessClient | ||
| import linea.executionwitness.ExecutionWitnessError | ||
| import net.consensys.linea.async.toSafeFuture | ||
| import net.consensys.linea.jsonrpc.JsonRpcRequestListParams | ||
| import net.consensys.linea.jsonrpc.client.JsonRpcClient | ||
| import net.consensys.linea.jsonrpc.client.JsonRpcRequestRetryer | ||
| import net.consensys.linea.jsonrpc.client.RequestRetryConfig | ||
| import org.apache.logging.log4j.LogManager | ||
| import org.apache.logging.log4j.Logger | ||
| import tech.pegasys.teku.infrastructure.async.SafeFuture | ||
| import java.util.concurrent.atomic.AtomicInteger | ||
|
|
||
| class ExecutionWitnessJsonRpcClient( | ||
| private val rpcClient: JsonRpcClient, | ||
| ) : ExecutionWitnessClient { | ||
|
|
||
| constructor( | ||
| vertx: Vertx, | ||
| rpcClient: JsonRpcClient, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
| retryConfig: RequestRetryConfig, | ||
| log: Logger = LogManager.getLogger(ExecutionWitnessJsonRpcClient::class.java), | ||
| ) : this( | ||
| JsonRpcRequestRetryer( | ||
| vertx, | ||
| rpcClient, | ||
| config = JsonRpcRequestRetryer.Config( | ||
| methodsToRetry = retryableMethods, | ||
| requestRetry = retryConfig, | ||
| ), | ||
| log = log, | ||
| ), | ||
| ) | ||
|
|
||
| private val requestId = AtomicInteger(0) | ||
|
|
||
| override fun getExecutionWitness( | ||
| block: BlockParameter, | ||
| ): SafeFuture<Result<ExecutionWitness, ErrorResponse<ExecutionWitnessError>>> { | ||
| val jsonRequest = JsonRpcRequestListParams( | ||
| jsonrpc = "2.0", | ||
| id = requestId.incrementAndGet(), | ||
| method = "debug_executionWitness", | ||
| params = listOf(block.toDebugExecutionWitnessRpcParam()), | ||
| ) | ||
|
|
||
| return rpcClient | ||
| .makeRequest(jsonRequest) | ||
| .toSafeFuture() | ||
| .thenApply { responseResult -> | ||
| responseResult.fold( | ||
| { success -> ExecutionWitnessResponseParser.parseExecutionWitness(success) }, | ||
| { error -> Err(ExecutionWitnessResponseParser.mapRpcError(error)) }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| internal val retryableMethods = setOf("debug_executionWitness") | ||
| } | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
.../main/kotlin/linea/coordinator/clients/executionwitness/ExecutionWitnessResponseParser.kt
This file contains hidden or 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,63 @@ | ||
| package linea.coordinator.clients.executionwitness | ||
|
|
||
| import com.github.michaelbull.result.Err | ||
| import com.github.michaelbull.result.Ok | ||
| import com.github.michaelbull.result.Result | ||
| import io.vertx.core.json.JsonArray | ||
| import io.vertx.core.json.JsonObject | ||
| import linea.error.ErrorResponse | ||
| import linea.executionwitness.ExecutionWitness | ||
| import linea.executionwitness.ExecutionWitnessError | ||
| import linea.kotlin.decodeHex | ||
| import net.consensys.linea.jsonrpc.JsonRpcErrorResponse | ||
| import net.consensys.linea.jsonrpc.JsonRpcSuccessResponse | ||
|
|
||
| object ExecutionWitnessResponseParser { | ||
|
|
||
| fun mapRpcError(jsonRpcErrorResponse: JsonRpcErrorResponse): ErrorResponse<ExecutionWitnessError> { | ||
| return ErrorResponse( | ||
| ExecutionWitnessError.RPC_ERROR, | ||
| "${jsonRpcErrorResponse.error.code}: ${jsonRpcErrorResponse.error.message}", | ||
| ) | ||
| } | ||
|
|
||
| fun parseExecutionWitness( | ||
| jsonRpcResponse: JsonRpcSuccessResponse, | ||
| ): Result<ExecutionWitness, ErrorResponse<ExecutionWitnessError>> { | ||
| if (jsonRpcResponse.result == null) { | ||
| return Err( | ||
| ErrorResponse( | ||
| ExecutionWitnessError.NULL_RESULT, | ||
| "debug_executionWitness returned null (witness unavailable for block)", | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| return try { | ||
| val json = jsonRpcResponse.result as JsonObject | ||
| Ok( | ||
| ExecutionWitness( | ||
| state = parseHexList(json, "state"), | ||
| keys = parseHexList(json, "keys"), | ||
| codes = parseHexList(json, "codes"), | ||
| headers = parseHexList(json, "headers"), | ||
| ), | ||
| ) | ||
| } catch (throwable: Throwable) { | ||
| Err( | ||
| ErrorResponse( | ||
| ExecutionWitnessError.PARSE_ERROR, | ||
| throwable.message ?: "failed to parse execution witness", | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun parseHexList(json: JsonObject, field: String): List<ByteArray> { | ||
| val array = json.getValue(field) as? JsonArray | ||
| ?: throw IllegalArgumentException("missing or invalid field: $field") | ||
| return array.map { element -> | ||
| (element as String).decodeHex() | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't much value/motivation for the existence of this file. It feels generated by AI with obvious info.
The non-obvious part is
Node prerequisitessection, which can be added as commentExecutionWitnessClient.ktdirectly.@Filter94 @jonesho Any take on this?