Skip to content
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

fix: hard forked to canyon #76

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ x-logging: &logging

services:
hildr-node:
image: optimism-java/hildr-node:latest
image: ghcr.io/optimism-java/hildr:latest
container_name: hildr-node
build:
dockerfile: ./docker/Dockerfile
dockerfile: ./docker/jvm.dock
context: ../
profiles:
- hildr-node
restart: unless-stopped
stop_grace_period: 3m
entrypoint: /scripts/start-hildr-node.sh
entrypoint: /scripts/start-hildr-node-java.sh
depends_on:
- op-geth
env_file:
Expand All @@ -33,7 +33,7 @@ services:
<<: *logging

op-geth:
image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:v1.101304.1
image: us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:v1.101304.2
container_name: op-geth
profiles:
- op-geth
Expand All @@ -49,7 +49,7 @@ services:
volumes:
- ./:/scripts
- data:/data
- ${OP_GENESIS_JSON_FILEPATH:-.}:/genesis-l2.json
- ${OP_GENESIS_JSON_FILEPATH:-.}:/genesis-l2-attached.json
<<: *logging

op-erigon:
Expand Down
2 changes: 1 addition & 1 deletion docker/start-op-geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ then
if [ ! -d $DATADIR ]
then
mkdir $DATADIR
geth init --datadir=$DATADIR ./genesis-l2.json
geth init --datadir=$DATADIR ./genesis-l2-attached.json
fi
else
echo "Network not recognized. Available options are optimism-goerli and base-goerli"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private OpEthExecutionPayload buildPayload(PayloadAttributes attributes)
OpEthExecutionPayload res;
try (var scope1 = new StructuredTaskScope.ShutdownOnFailure()) {
StructuredTaskScope.Subtask<OpEthExecutionPayload> payloadFuture =
scope1.fork(TracerTaskWrapper.wrap(() -> EngineDriver.this.engine.getPayload(payloadId)));
scope1.fork(TracerTaskWrapper.wrap(() -> EngineDriver.this.engine.getPayloadV2(payloadId)));

scope1.join();
scope1.throwIfFailed();
Expand Down
11 changes: 5 additions & 6 deletions hildr-node/src/main/java/io/optimism/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ OpEthForkChoiceUpdate forkchoiceUpdated(ForkchoiceState forkchoiceState, Payload
* Retrieves a payload by ID, prepared by {forkChoiceUpdated} when called with {@code
* payloadAttributes}.
*
* <p>Specification method: engine_getPayloadV1 params: - [PayloadId]: DATA, 8 Bytes - Identifier
* <p>Specification method: engine_getPayloadV2 params: - [PayloadId]: DATA, 8 Bytes - Identifier
* of the payload build process timeout: 1s returns: - [ExecutionPayload] potential errors: - code
* and message set in case an exception happens while getting the payload. Refer to <a
* href="https://github.com/ethereum-optimism/optimism/blob/develop/specs/exec-engine.md#engine_getPayloadv1">Optimism
* Specs</a>
* href="https://github.com/ethereum-optimism/optimism/blob/develop/specs/exec-engine.md#engine_getpayloadv2">Optimism Specs</a>
*
* @param payloadId the payload id
* @return the payload
* @return the payload v2
* @throws IOException the io exception
* @see <a
* href="https://github.com/ethereum/execution-apis/blob/main/src/engine/paris.md#engine_getpayloadv1">engine_getPayloadV1</a>
* href="https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#engine_getpayloadv2"></a>
*/
OpEthExecutionPayload getPayload(BigInteger payloadId) throws IOException;
OpEthExecutionPayload getPayloadV2(BigInteger payloadId) throws IOException;
}
20 changes: 10 additions & 10 deletions hildr-node/src/main/java/io/optimism/engine/EngineApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ public EngineApi fromEnv() {
if (StringUtils.isBlank(baseUrlParm)) {
throw new RuntimeException(
"""
ENGINE_API_URL environment variable not set.
Please set this to the base url of the engine api
""");
ENGINE_API_URL environment variable not set.
Please set this to the base url of the engine api
""");
}
String secretKey = System.getenv("JWT_SECRET");
if (StringUtils.isBlank(secretKey)) {
throw new RuntimeException(
"""
JWT_SECRET environment variable not set.
Please set this to the 256 bit hex-encoded secret key
used to authenticate with the engine api.
This should be the same as set in the `--auth.secret`
flag when executing go-ethereum.
""");
JWT_SECRET environment variable not set.
Please set this to the 256 bit hex-encoded secret key
used to authenticate with the engine api.
This should be the same as set in the `--auth.secret`
flag when executing go-ethereum.
""");
}
String baseUrlFormat = authUrlFromAddr(baseUrlParm, null);
return new EngineApi(baseUrlFormat, secretKey);
Expand Down Expand Up @@ -157,7 +157,7 @@ public OpEthPayloadStatus newPayload(ExecutionPayload executionPayload) throws I
}

@Override
public OpEthExecutionPayload getPayload(BigInteger payloadId) throws IOException {
public OpEthExecutionPayload getPayloadV2(BigInteger payloadId) throws IOException {
web3jService.addHeader("authorization", String.format("Bearer %1$s", generateJws(key)));
Request<?, OpEthExecutionPayload> r = new Request<>(
ENGINE_GET_PAYLOAD_V2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public static ExecutionPayload from(ExecutionPayloadSSZ payload) {
* @param extraData 0 to 32 byte value for extra data.
* @param baseFeePerGas 256 bits for the base fee per gas.
* @param blockHash The 32 byte block hash.
* @param withdrawals The withdrawals list.
* @param transactions An array of transaction objects where each object is a byte list.
*/
public record ExecutionPayloadReq(
Expand All @@ -213,6 +214,7 @@ public record ExecutionPayloadReq(
String extraData,
String baseFeePerGas,
String blockHash,
List<EthBlock.Withdrawal> withdrawals,
List<String> transactions) {}

/**
Expand All @@ -235,6 +237,7 @@ public ExecutionPayloadReq toReq() {
extraData,
Numeric.toHexStringWithPrefix(baseFeePerGas),
blockHash,
withdrawals,
transactions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@

package io.optimism.engine;

import io.optimism.engine.ExecutionPayload.ExecutionPayloadRes;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.IOException;
import java.util.Objects;
import org.web3j.protocol.ObjectMapperFactory;
import org.web3j.protocol.core.Response;

/**
Expand All @@ -25,7 +33,7 @@
* @author grapebaba
* @since 0.1.0
*/
public class OpEthExecutionPayload extends Response<ExecutionPayloadRes> {
public class OpEthExecutionPayload extends Response<OpEthExecutionPayload.ExecutionPayloadObj> {

/** Instantiates a new Op eth execution payload. */
public OpEthExecutionPayload() {}
Expand All @@ -36,11 +44,89 @@ public OpEthExecutionPayload() {}
* @return the execution payload
*/
public ExecutionPayload getExecutionPayload() {
return getResult().toExecutionPayload();
return getResult().getExecutionPayload().toExecutionPayload();
}

@Override
public void setResult(ExecutionPayloadRes result) {
@JsonDeserialize(using = ResponseDeserializer.class)
public void setResult(ExecutionPayloadObj result) {
super.setResult(result);
}

/**
* The type Execution payload obj.
* @since 0.2.6
*/
public static class ExecutionPayloadObj {

/** The Execution payload result. */
private ExecutionPayload.ExecutionPayloadRes executionPayload;

/** Instantiates a new Execution payload obj. */
public ExecutionPayloadObj() {}

/**
* Instantiates a new Execution payload obj.
*
* @param executionPayload the execution payload result
*/
public ExecutionPayloadObj(ExecutionPayload.ExecutionPayloadRes executionPayload) {
this.executionPayload = executionPayload;
}

/**
* Gets execution payload result.
*
* @return the execution payload result
*/
public ExecutionPayload.ExecutionPayloadRes getExecutionPayload() {
return executionPayload;
}

/**
* Sets execution payload.
*
* @param executionPayload the execution payload result
*/
public void setExecutionPayload(ExecutionPayload.ExecutionPayloadRes executionPayload) {
this.executionPayload = executionPayload;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ExecutionPayloadObj that)) {
return false;
}
return Objects.equals(executionPayload, that.executionPayload);
}

@Override
public int hashCode() {
return Objects.hash(executionPayload);
}
}

/** Json Deserializer of ExecutionPayloadObj. */
public static class ResponseDeserializer extends JsonDeserializer<ExecutionPayloadObj> {

private final ObjectReader objectReader;

/** Instantiates a new Response deserializer. */
public ResponseDeserializer() {
this.objectReader = ObjectMapperFactory.getObjectReader();
}

@Override
public ExecutionPayloadObj deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException {
if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
return objectReader.readValue(jsonParser, ExecutionPayloadObj.class);
} else {
return null; // null is wrapped by Optional in above getter
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ExecutionPayloadRes initExecutionPayload() {
String initExecutionPayloadJson() throws JsonProcessingException {
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
OpEthExecutionPayload opEthExecutionPayload = new OpEthExecutionPayload();
opEthExecutionPayload.setResult(initExecutionPayload());
opEthExecutionPayload.setResult(new OpEthExecutionPayload.ExecutionPayloadObj(initExecutionPayload()));
return ow.writeValueAsString(opEthExecutionPayload);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ void testGetPayload() throws IOException {
assertEquals("http://127.0.0.1:8851", baseUrl);
server.enqueue(new MockResponse().setBody(initExecutionPayloadJson()));
EngineApi engineApi = new EngineApi(baseUrl, SECRET);
OpEthExecutionPayload executionPayload = engineApi.getPayload(new BigInteger("123"));
OpEthExecutionPayload executionPayload = engineApi.getPayloadV2(new BigInteger("123"));
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
assertEquals(initExecutionPayloadJson(), ow.writeValueAsString(executionPayload));
}
Expand Down
Loading