Skip to content

Commit

Permalink
4844 engine api (hyperledger#4991)
Browse files Browse the repository at this point in the history
* json container for getting blob bundles
* spdx headers, formatting, npe fix

Signed-off-by: Justin Florentine <justin+github@florentine.us>
Co-authored-by: Jason Frame <jason.frame@consensys.net>
Co-authored-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
3 people authored Jan 24, 2023
1 parent 8e3a912 commit 5fa9433
Show file tree
Hide file tree
Showing 24 changed files with 787 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,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;
}
}
18 changes: 18 additions & 0 deletions datatypes/src/main/java/org/hyperledger/besu/datatypes/Blob.java
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public enum RpcMethod {

ENGINE_GET_PAYLOAD_V1("engine_getPayloadV1"),
ENGINE_GET_PAYLOAD_V2("engine_getPayloadV2"),
ENGINE_GET_PAYLOAD_V3("engine_getPayloadV3"),
ENGINE_EXECUTE_PAYLOAD("engine_executePayloadV1"),
ENGINE_NEW_PAYLOAD_V1("engine_newPayloadV1"),
ENGINE_NEW_PAYLOAD_V2("engine_newPayloadV2"),
ENGINE_NEW_PAYLOAD_V3("engine_newPayloadV3"),
ENGINE_FORKCHOICE_UPDATED_V1("engine_forkchoiceUpdatedV1"),
ENGINE_FORKCHOICE_UPDATED_V2("engine_forkchoiceUpdatedV2"),
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION("engine_exchangeTransitionConfigurationV1"),

ENGINE_GET_BLOBS_BUNDLE_V1("engine_getBlobsBundleV1"),
GOQUORUM_ETH_GET_QUORUM_PAYLOAD("eth_getQuorumPayload"),
GOQUORUM_STORE_RAW("goquorum_storeRaw"),
PRIV_CALL("priv_call"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
import org.hyperledger.besu.ethereum.core.BlockWithReceipts;
import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule;

import java.util.Optional;

Expand All @@ -40,15 +41,19 @@ public abstract class AbstractEngineGetPayload extends ExecutionEngineJsonRpcMet
protected final BlockResultFactory blockResultFactory;
private static final Logger LOG = LoggerFactory.getLogger(AbstractEngineGetPayload.class);

protected final Optional<TimestampSchedule> schedule;

public AbstractEngineGetPayload(
final Vertx vertx,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener) {
final EngineCallListener engineCallListener,
final TimestampSchedule schedule) {
super(vertx, protocolContext, engineCallListener);
this.mergeMiningCoordinator = mergeMiningCoordinator;
this.blockResultFactory = blockResultFactory;
this.schedule = Optional.ofNullable(schedule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.datatypes.DataGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
Expand Down Expand Up @@ -156,7 +157,9 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
blockParam.getPrevRandao(),
0,
maybeWithdrawals.map(BodyValidation::withdrawalsRoot).orElse(null),
null,
blockParam.getExcessDataGas() == null
? null
: DataGas.fromHexString(blockParam.getExcessDataGas()),
headerFunctions);

// ensure the block hash matches the blockParam hash
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.ethereum.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
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.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlobsBundleV1;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.BlockResultFactory;
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.TimestampSchedule;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import io.vertx.core.Vertx;
import org.apache.tuweni.bytes.Bytes;

public class EngineGetBlobsBundleV1 extends AbstractEngineGetPayload {

public EngineGetBlobsBundleV1(
final Vertx vertx,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener,
final TimestampSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
protected JsonRpcResponse createResponse(
final JsonRpcRequestContext request, final BlockWithReceipts blockWithReceipts) {

return new JsonRpcSuccessResponse(
request.getRequest().getId(), createResponse(blockWithReceipts.getBlock()));
}

private BlobsBundleV1 createResponse(final Block block) {

List<Bytes> kzgs =
block.getBody().getTransactions().stream()
.map(Transaction::getBlobsWithCommitments)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(b -> b.getKzgCommitments().stream())
.collect(Collectors.toList());

List<Bytes> blobs =
block.getBody().getTransactions().stream()
.map(Transaction::getBlobsWithCommitments)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(b -> b.getBlobs().stream())
.collect(Collectors.toList());

return new BlobsBundleV1(block.getHash(), kzgs, blobs);
}

@Override
public String getName() {
return RpcMethod.ENGINE_GET_BLOBS_BUNDLE_V1.getMethodName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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.TimestampSchedule;

import io.vertx.core.Vertx;

Expand All @@ -32,8 +33,15 @@ public EngineGetPayloadV1(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener) {
super(vertx, protocolContext, mergeMiningCoordinator, blockResultFactory, engineCallListener);
final EngineCallListener engineCallListener,
final TimestampSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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.TimestampSchedule;

import io.vertx.core.Vertx;

Expand All @@ -32,8 +33,15 @@ public EngineGetPayloadV2(
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener) {
super(vertx, protocolContext, mergeMiningCoordinator, blockResultFactory, engineCallListener);
final EngineCallListener engineCallListener,
final TimestampSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.ethereum.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
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.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.DefaultTimestampSchedule;
import org.hyperledger.besu.ethereum.mainnet.TimestampSchedule;

import io.vertx.core.Vertx;

public class EngineGetPayloadV3 extends AbstractEngineGetPayload {

public EngineGetPayloadV3(
final Vertx vertx,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeMiningCoordinator,
final BlockResultFactory blockResultFactory,
final EngineCallListener engineCallListener,
final TimestampSchedule schedule) {
super(
vertx,
protocolContext,
mergeMiningCoordinator,
blockResultFactory,
engineCallListener,
schedule);
}

@Override
public String getName() {
return RpcMethod.ENGINE_GET_PAYLOAD_V3.getMethodName();
}

@Override
protected JsonRpcResponse createResponse(
final JsonRpcRequestContext request, final BlockWithReceipts blockWithReceipts) {

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));
}

return new JsonRpcSuccessResponse(
request.getRequest().getId(),
blockResultFactory.payloadTransactionCompleteV3(blockWithReceipts));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.ethereum.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
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.TimestampSchedule;

import io.vertx.core.Vertx;

public class EngineNewPayloadV3 extends AbstractEngineNewPayload {

public EngineNewPayloadV3(
final Vertx vertx,
final TimestampSchedule timestampSchedule,
final ProtocolContext protocolContext,
final MergeMiningCoordinator mergeCoordinator,
final EthPeers ethPeers,
final EngineCallListener engineCallListener) {
super(
vertx, timestampSchedule, protocolContext, mergeCoordinator, ethPeers, engineCallListener);
}

@Override
public String getName() {
return RpcMethod.ENGINE_NEW_PAYLOAD_V3.getMethodName();
}
}
Loading

0 comments on commit 5fa9433

Please sign in to comment.