From 9d2a25dffbeb61cf72882fa77deb0b4a2af2ba5a Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Tue, 24 Jan 2023 10:54:16 -0500 Subject: [PATCH] 4844 engine api (#4991) * json container for getting blob bundles * spdx headers, formatting, npe fix Signed-off-by: Justin Florentine Co-authored-by: Jason Frame Co-authored-by: garyschulte (cherry picked from commit 5fa943380176a18c9b5c394756fca6d3aabfe66f) (cherry picked from commit af8466f1561b4d5995bfa85782acee0644c3f879) --- .../merge/TransitionProtocolSchedule.java | 9 +++ .../org/hyperledger/besu/datatypes/Blob.java | 18 +++++ .../besu/datatypes/KZGCommitment.java | 18 +++++ .../engine/AbstractEngineGetPayload.java | 6 +- .../engine/AbstractEngineNewPayload.java | 3 +- .../engine/EngineGetBlobsBundleV1.java | 19 +++--- .../methods/engine/EngineGetPayloadV1.java | 4 +- .../methods/engine/EngineGetPayloadV2.java | 4 +- .../methods/engine/EngineGetPayloadV3.java | 67 ++++++------------- .../methods/engine/EngineNewPayloadV3.java | 4 +- .../internal/results/BlobsBundleV1.java | 17 ++--- .../ExecutionEngineJsonRpcMethods.java | 12 ++-- .../engine/AbstractEngineGetPayloadTest.java | 11 +-- .../engine/EngineGetPayloadV3Test.java | 21 ++++-- .../besu/ethereum/core/Transaction.java | 18 +++++ 15 files changed, 140 insertions(+), 91 deletions(-) create mode 100644 datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java create mode 100644 datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java index 9a7795e4306..92ff0bacd8a 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java @@ -253,4 +253,13 @@ public void setPublicWorldStateArchiveForPrivacyBlockProcessor( public void setProtocolContext(final ProtocolContext protocolContext) { this.protocolContext = protocolContext; } + + /** + * Exposes timestamp based schedules for reference. + * + * @return timestampSchedule the timestamp schedule + */ + public TimestampSchedule getTimestampSchedule() { + return timestampSchedule; + } } diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java new file mode 100644 index 00000000000..70b22d58691 --- /dev/null +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java @@ -0,0 +1,18 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.hyperledger.besu.datatypes; + +public class Blob {} diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java new file mode 100644 index 00000000000..3ccffa485e2 --- /dev/null +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/KZGCommitment.java @@ -0,0 +1,18 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.hyperledger.besu.datatypes; + +public class KZGCommitment {} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java index 7fed880caa7..287d0e9ac34 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import java.util.Optional; @@ -40,7 +40,7 @@ public abstract class AbstractEngineGetPayload extends ExecutionEngineJsonRpcMet protected final BlockResultFactory blockResultFactory; private static final Logger LOG = LoggerFactory.getLogger(AbstractEngineGetPayload.class); - protected final Optional schedule; + protected final Optional schedule; public AbstractEngineGetPayload( final Vertx vertx, @@ -48,7 +48,7 @@ public AbstractEngineGetPayload( final MergeMiningCoordinator mergeMiningCoordinator, final BlockResultFactory blockResultFactory, final EngineCallListener engineCallListener, - final ProtocolSchedule schedule) { + final TimestampSchedule schedule) { super(vertx, protocolContext, engineCallListener); this.mergeMiningCoordinator = mergeMiningCoordinator; this.blockResultFactory = blockResultFactory; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java index f14bd43e45f..9c303329dbb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java @@ -164,8 +164,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext) blockParam.getExcessDataGas() == null ? null : DataGas.fromHexString(blockParam.getExcessDataGas()), - null, - headerFunctions); + null, headerFunctions); // ensure the block hash matches the blockParam hash // this must be done before any other check diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetBlobsBundleV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetBlobsBundleV1.java index 8933a35e9c9..5a46450990e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetBlobsBundleV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetBlobsBundleV1.java @@ -26,7 +26,7 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import java.util.List; import java.util.Optional; @@ -43,7 +43,7 @@ public EngineGetBlobsBundleV1( final MergeMiningCoordinator mergeMiningCoordinator, final BlockResultFactory blockResultFactory, final EngineCallListener engineCallListener, - final ProtocolSchedule schedule) { + final TimestampSchedule schedule) { super( vertx, protocolContext, @@ -63,23 +63,20 @@ protected JsonRpcResponse createResponse( private BlobsBundleV1 createResponse(final Block block) { - final List blobsWithCommitments = + List kzgs = block.getBody().getTransactions().stream() .map(Transaction::getBlobsWithCommitments) .filter(Optional::isPresent) .map(Optional::get) - .collect(Collectors.toList()); - - final List kzgs = - blobsWithCommitments.stream() .flatMap(b -> b.getKzgCommitments().stream()) - .map(Bytes::toString) .collect(Collectors.toList()); - final List blobs = - blobsWithCommitments.stream() + List blobs = + block.getBody().getTransactions().stream() + .map(Transaction::getBlobsWithCommitments) + .filter(Optional::isPresent) + .map(Optional::get) .flatMap(b -> b.getBlobs().stream()) - .map(Bytes::toString) .collect(Collectors.toList()); return new BlobsBundleV1(block.getHash(), kzgs, blobs); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV1.java index 5efe17ca3f3..3f0d0b29470 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV1.java @@ -23,7 +23,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import java.util.Optional; @@ -37,7 +37,7 @@ public EngineGetPayloadV1( final MergeMiningCoordinator mergeMiningCoordinator, final BlockResultFactory blockResultFactory, final EngineCallListener engineCallListener, - final ProtocolSchedule schedule) { + final TimestampSchedule schedule) { super( vertx, protocolContext, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java index 35684fd64ee..5fc2ec0b5c7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java @@ -24,7 +24,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import java.util.Optional; @@ -38,7 +38,7 @@ public EngineGetPayloadV2( final MergeMiningCoordinator mergeMiningCoordinator, final BlockResultFactory blockResultFactory, final EngineCallListener engineCallListener, - final ProtocolSchedule schedule) { + final TimestampSchedule schedule) { super( vertx, protocolContext, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java index 48c0fe1e318..d3ca9e9b048 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java @@ -18,34 +18,24 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec; - -import java.util.Optional; +import org.hyperledger.besu.ethereum.mainnet.DefaultTimestampSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import io.vertx.core.Vertx; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class EngineGetPayloadV3 extends AbstractEngineGetPayload { - private static final Logger LOG = LoggerFactory.getLogger(EngineGetPayloadV3.class); - private final Optional shanghai; - private final Optional cancun; - public EngineGetPayloadV3( final Vertx vertx, final ProtocolContext protocolContext, final MergeMiningCoordinator mergeMiningCoordinator, final BlockResultFactory blockResultFactory, final EngineCallListener engineCallListener, - final ProtocolSchedule schedule) { + final TimestampSchedule schedule) { super( vertx, protocolContext, @@ -53,8 +43,6 @@ public EngineGetPayloadV3( blockResultFactory, engineCallListener, schedule); - this.shanghai = schedule.hardforkFor(s -> s.fork().name().equalsIgnoreCase("Shanghai")); - this.cancun = schedule.hardforkFor(s -> s.fork().name().equalsIgnoreCase("Cancun")); } @Override @@ -66,37 +54,26 @@ public String getName() { protected JsonRpcResponse createResponse( final JsonRpcRequestContext request, final BlockWithReceipts blockWithReceipts) { - try { - long builtAt = blockWithReceipts.getHeader().getTimestamp(); - - if (beforeShanghai(builtAt)) { - return new JsonRpcSuccessResponse( - request.getRequest().getId(), - blockResultFactory.payloadTransactionCompleteV1(blockWithReceipts.getBlock())); - } else if (duringShanghai(builtAt)) { - return new JsonRpcSuccessResponse( - request.getRequest().getId(), - blockResultFactory.payloadTransactionCompleteV2(blockWithReceipts)); - } else { - return new JsonRpcSuccessResponse( - request.getRequest().getId(), - blockResultFactory.payloadTransactionCompleteV3(blockWithReceipts)); - } - - } catch (ClassCastException e) { - LOG.error("configuration error, can't call V3 endpoint with non-default protocol schedule"); - return new JsonRpcErrorResponse(request.getRequest().getId(), JsonRpcError.INTERNAL_ERROR); + DefaultTimestampSchedule tsched = (DefaultTimestampSchedule) this.schedule.get(); + long shanghaiTimestamp = tsched.scheduledAt("Shanghai"); + long cancunTimestamp = tsched.scheduledAt("Cancun"); + long builtAt = blockWithReceipts.getHeader().getTimestamp(); + if (builtAt < shanghaiTimestamp) { + return new JsonRpcSuccessResponse( + request.getRequest().getId(), + blockResultFactory.payloadTransactionCompleteV1(blockWithReceipts.getBlock())); + } else if (builtAt >= shanghaiTimestamp && builtAt < cancunTimestamp) { + return new JsonRpcSuccessResponse( + request.getRequest().getId(), + blockResultFactory.payloadTransactionCompleteV2(blockWithReceipts)); + } else if (builtAt >= cancunTimestamp) { + return new JsonRpcSuccessResponse( + request.getRequest().getId(), + blockResultFactory.payloadTransactionCompleteV3(blockWithReceipts)); } - } - - private boolean duringShanghai(final long builtAt) { - return (this.shanghai.isPresent() && builtAt >= this.shanghai.get().milestone()) - && // - (this.cancun.isEmpty() - || (this.cancun.isPresent() && builtAt < this.cancun.get().milestone())); - } - private boolean beforeShanghai(final long builtAt) { - return this.shanghai.isEmpty() || builtAt < this.shanghai.get().milestone(); + return new JsonRpcSuccessResponse( + request.getRequest().getId(), + blockResultFactory.payloadTransactionCompleteV3(blockWithReceipts)); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java index 0457640a028..68b388a3b01 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java @@ -18,7 +18,7 @@ import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import io.vertx.core.Vertx; @@ -26,7 +26,7 @@ public class EngineNewPayloadV3 extends AbstractEngineNewPayload { public EngineNewPayloadV3( final Vertx vertx, - final ProtocolSchedule timestampSchedule, + final TimestampSchedule timestampSchedule, final ProtocolContext protocolContext, final MergeMiningCoordinator mergeCoordinator, final EthPeers ethPeers, diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlobsBundleV1.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlobsBundleV1.java index 2d188204843..71ca6172271 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlobsBundleV1.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/BlobsBundleV1.java @@ -21,34 +21,35 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.tuweni.bytes.Bytes; @JsonPropertyOrder({"blockHash", "kzgs", "blobs"}) public class BlobsBundleV1 { - private final String blockHash; + private final Hash blockHash; - private final List kzgs; + private final List kzgs; - private final List blobs; + private final List blobs; - public BlobsBundleV1(final Hash blockHash, final List kzgs, final List blobs) { - this.blockHash = blockHash.toString(); + public BlobsBundleV1(final Hash blockHash, final List kzgs, final List blobs) { + this.blockHash = blockHash; this.kzgs = kzgs; this.blobs = blobs; } @JsonGetter("blockHash") - public String getBlockHash() { + public Hash getBlockHash() { return blockHash; } @JsonGetter("kzgs") - public List getKzgs() { + public List getKzgs() { return kzgs; } @JsonGetter("blobs") - public List getBlobs() { + public List getBlobs() { return blobs; } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ExecutionEngineJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ExecutionEngineJsonRpcMethods.java index 962ae992a2b..b03ae742191 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ExecutionEngineJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/ExecutionEngineJsonRpcMethods.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetBlobsBundleV1; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadBodiesByHashV1; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadBodiesByRangeV1; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetBlobsBundleV1; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV1; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV2; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineGetPayloadV3; @@ -32,6 +33,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV2; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV3; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EnginePreparePayloadDebug; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineNewPayloadV3; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.EngineQosTimer; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; @@ -86,21 +88,21 @@ protected Map create() { mergeCoordinator.get(), blockResultFactory, engineQosTimer, - protocolSchedule), + timestampSchedule), new EngineGetPayloadV2( consensusEngineServer, protocolContext, mergeCoordinator.get(), blockResultFactory, engineQosTimer, - protocolSchedule), + timestampSchedule), new EngineGetPayloadV3( consensusEngineServer, protocolContext, mergeCoordinator.get(), blockResultFactory, engineQosTimer, - protocolSchedule), + timestampSchedule), new EngineNewPayloadV1( consensusEngineServer, protocolSchedule, @@ -117,7 +119,7 @@ protected Map create() { engineQosTimer), new EngineNewPayloadV3( consensusEngineServer, - protocolSchedule, + timestampSchedule, protocolContext, mergeCoordinator.get(), ethPeers, @@ -140,7 +142,7 @@ protected Map create() { mergeCoordinator.get(), new BlockResultFactory(), engineQosTimer, - protocolSchedule), + timestampSchedule), new EngineExchangeTransitionConfiguration( consensusEngineServer, protocolContext, engineQosTimer), new EngineGetPayloadBodiesByHashV1( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java index 26e39e436ad..7735bf3d930 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java @@ -36,8 +36,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import java.util.Collections; import java.util.Optional; @@ -62,7 +61,7 @@ AbstractEngineGetPayload create( final MergeMiningCoordinator mergeCoordinator, final BlockResultFactory ethPeers, final EngineCallListener engineCallListener, - final ProtocolSchedule schedule); + final TimestampSchedule schedule); } private final MethodFactory methodFactory; @@ -118,7 +117,11 @@ public void before() { mergeMiningCoordinator, factory, engineCallListener, - protocolSchedule); + getTimestampSchedule()); + } + + protected TimestampSchedule getTimestampSchedule() { + return null; } @Test diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java index 1866fe17802..6db6c1c51b4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -32,6 +33,8 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; +import org.hyperledger.besu.ethereum.mainnet.DefaultTimestampSchedule; +import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule; import java.util.Collections; import java.util.Optional; @@ -47,12 +50,21 @@ .class) // mocks in parent class may not be used, throwing unnecessary stubbing public class EngineGetPayloadV3Test extends AbstractEngineGetPayloadTest { + private static final long SHANGHAI_AT = 1337L; private static final long CANCUN_AT = 31337L; public EngineGetPayloadV3Test() { super(EngineGetPayloadV3::new); } + @Override + public TimestampSchedule getTimestampSchedule() { + DefaultTimestampSchedule mockSchedule = mock(DefaultTimestampSchedule.class); + when(mockSchedule.scheduledAt("Cancun")).thenReturn(CANCUN_AT); + when(mockSchedule.scheduledAt("Shanghai")).thenReturn(SHANGHAI_AT); + return mockSchedule; + } + @Override @Test public void shouldReturnExpectedMethodName() { @@ -72,11 +84,7 @@ public void shouldReturnBlockForKnownPayloadId() { // should return withdrawals and excessGas for a post-cancun block PayloadIdentifier postCancunPid = PayloadIdentifier.forPayloadParams( - Hash.ZERO, - CANCUN_AT, - Bytes32.random(), - Address.fromHexString("0x42"), - Optional.empty()); + Hash.ZERO, CANCUN_AT, Bytes32.random(), Address.fromHexString("0x42")); BlockWithReceipts postCancunBlock = new BlockWithReceipts( @@ -85,8 +93,7 @@ public void shouldReturnBlockForKnownPayloadId() { new BlockBody( Collections.emptyList(), Collections.emptyList(), - Optional.of(Collections.emptyList()), - Optional.empty())), + Optional.of(Collections.emptyList()))), Collections.emptyList()); when(mergeContext.retrieveBlockById(postCancunPid)).thenReturn(Optional.of(postCancunBlock)); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java index 6012a96cec3..0d104cb8461 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java @@ -1375,5 +1375,23 @@ public BlobsWithCommitments( this.blobs = blobs; this.kzgProof = kzgProof; } + + public List getBlobs() { + return blobs.getElements().stream() + .map( + blob -> { + return blob.getElements().stream() + .map(sszuInt256Wrapper -> (Bytes) sszuInt256Wrapper.getData().toBytes()) + .reduce(Bytes::concatenate) + .orElseThrow(); + }) + .collect(Collectors.toList()); + } + + public List getKzgCommitments() { + return kzgCommitments.getElements().stream() + .map(c -> c.getData()) + .collect(Collectors.toList()); + } } }