-
Notifications
You must be signed in to change notification settings - Fork 977
Add getPayloadBodiesByRangeV1 and getPayloadBodiesByHash engine methods #4980
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
Changes from 17 commits
b1f2abd
4c3568e
bb5c6ed
70ee2a5
0b120cb
49a3df2
32bf2f2
1b4a2da
7edc4d0
1debe06
fdf1c4d
fb86166
9bdacea
bfc98a0
e43b88e
423b66a
fa72ac5
c8aa200
367d601
61bce3d
bccde29
650e70c
663e11e
2139828
558d325
cfb88cc
f5b1d3c
d726acb
840a59d
e9d138b
4cf2f51
b3b7c58
334c700
a5a2610
35719c9
e8e5a02
db5447f
77da267
dbb6231
b7ae081
2385ad7
08b90a9
00a8b1b
48a8732
f838d57
b3b62fd
9018c4b
7b10e9f
7554285
6b8927e
3e903dc
f1f49bf
d4e5120
5700e9b
24a174d
9dd4185
afed502
e7b5f7c
ab05f35
740c895
3a644ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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 static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda; | ||
|
|
||
| import org.hyperledger.besu.datatypes.Hash; | ||
| 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.methods.ExecutionEngineJsonRpcMethod; | ||
| 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.chain.Blockchain; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import io.vertx.core.Vertx; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class EngineGetPayloadBodiesByHashV1 extends ExecutionEngineJsonRpcMethod { | ||
| private static final Logger LOG = LoggerFactory.getLogger(EngineGetPayloadBodiesByHashV1.class); | ||
| private final BlockResultFactory blockResultFactory; | ||
|
|
||
| public EngineGetPayloadBodiesByHashV1( | ||
| final Vertx vertx, | ||
| final ProtocolContext protocolContext, | ||
| final BlockResultFactory blockResultFactory, | ||
| final EngineCallListener engineCallListener) { | ||
| super(vertx, protocolContext, engineCallListener); | ||
| this.blockResultFactory = blockResultFactory; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return RpcMethod.ENGINE_GET_PAYLOAD_BODIES_BY_HASH_V1.getMethodName(); | ||
| } | ||
|
|
||
| @Override | ||
| public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { | ||
| engineCallListener.executionEngineCalled(); | ||
|
|
||
| final Hash[] blockHashes = request.getRequiredParameter(0, Hash[].class); | ||
|
|
||
| traceLambda(LOG, "{} parameters: blockHashes {}", () -> getName(), () -> blockHashes); | ||
|
|
||
| final Blockchain blockchain = protocolContext.getBlockchain(); | ||
| return new JsonRpcSuccessResponse( | ||
| request.getRequest().getId(), | ||
| blockResultFactory.payloadBodiesCompleteV1( | ||
| Arrays.stream(blockHashes).map(blockchain::getBlockBody).collect(Collectors.toList()))); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * 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 static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda; | ||
|
|
||
| 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.methods.ExecutionEngineJsonRpcMethod; | ||
| 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.chain.Blockchain; | ||
|
|
||
| import java.util.stream.Collectors; | ||
| import java.util.stream.LongStream; | ||
|
|
||
| import io.vertx.core.Vertx; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class EngineGetPayloadBodiesByRangeV1 extends ExecutionEngineJsonRpcMethod { | ||
| private static final Logger LOG = LoggerFactory.getLogger(EngineGetPayloadBodiesByRangeV1.class); | ||
| private final BlockResultFactory blockResultFactory; | ||
|
|
||
| public EngineGetPayloadBodiesByRangeV1( | ||
| final Vertx vertx, | ||
| final ProtocolContext protocolContext, | ||
| final BlockResultFactory blockResultFactory, | ||
| final EngineCallListener engineCallListener) { | ||
| super(vertx, protocolContext, engineCallListener); | ||
| this.blockResultFactory = blockResultFactory; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return RpcMethod.ENGINE_GET_PAYLOAD_BODIES_BY_RANGE_V1.getMethodName(); | ||
| } | ||
|
|
||
| @Override | ||
| public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) { | ||
| engineCallListener.executionEngineCalled(); | ||
|
|
||
| final long startBlockNumber = request.getRequiredParameter(0, Long.class); | ||
| final long count = request.getRequiredParameter(1, Long.class); | ||
|
|
||
| traceLambda( | ||
| LOG, | ||
| "{} parameters: start block number {} count {}", | ||
| () -> getName(), | ||
| () -> startBlockNumber, | ||
| () -> count); | ||
|
|
||
| final Blockchain blockchain = protocolContext.getBlockchain(); | ||
|
|
||
| final long latestKnownBlockNumber = blockchain.getChainHeadBlockNumber(); | ||
| final long upperBound = startBlockNumber + count; | ||
| final long finalBlockNumber = | ||
| latestKnownBlockNumber < upperBound ? latestKnownBlockNumber + 1 : upperBound; | ||
|
|
||
| return new JsonRpcSuccessResponse( | ||
| request.getRequest().getId(), | ||
| blockResultFactory.payloadBodiesCompleteV1( | ||
| LongStream.range(startBlockNumber, finalBlockNumber) | ||
| .mapToObj( | ||
| blockNumber -> | ||
| blockchain | ||
| .getBlockHashByNumber(blockNumber) | ||
| .flatMap(blockchain::getBlockBody)) | ||
siladu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .collect(Collectors.toList()))); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * 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.results; | ||
|
|
||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter; | ||
| import org.hyperledger.besu.ethereum.core.BlockBody; | ||
| import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonGetter; | ||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
|
|
||
| @JsonPropertyOrder({"payloadBodies"}) | ||
| public class EngineGetPayloadBodiesResultV1 { | ||
|
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. nit: Not sure it makes sense for this outer result type to be V1...the type in the spec that is versioned is ExecutionPayloadBodyV1 which you have below as PayloadBody...if anything then that should be versioned, but I'm thinking avoid versioning unless we have to. The only engine api result class that's versioned is EngineGetPayloadResultV1/V2 are versioned because they are different data shapes and we need to distinguish. I am having second thoughts about those names now though. |
||
| private final List<PayloadBody> payloadBodies; | ||
|
|
||
| public EngineGetPayloadBodiesResultV1(final List<PayloadBody> payloadBody) { | ||
| this.payloadBodies = payloadBody; | ||
| } | ||
|
|
||
| @JsonValue | ||
| public List<PayloadBody> getPayloadBodies() { | ||
| return payloadBodies; | ||
| } | ||
|
|
||
| public static class PayloadBody { | ||
| private final List<String> transactions; | ||
| private final List<WithdrawalParameter> withdrawals; | ||
|
|
||
| public PayloadBody(final BlockBody blockBody) { | ||
| this.transactions = | ||
| blockBody.getTransactions().stream() | ||
| .map(TransactionEncoder::encodeOpaqueBytes) | ||
| .map(Bytes::toHexString) | ||
| .collect(Collectors.toList()); | ||
| this.withdrawals = | ||
| blockBody | ||
| .getWithdrawals() | ||
| .map( | ||
| ws -> | ||
| ws.stream() | ||
| .map(WithdrawalParameter::fromWithdrawal) | ||
| .collect(Collectors.toList())) | ||
| .orElse(null); | ||
| } | ||
|
|
||
| @JsonGetter(value = "transactions") | ||
| public List<String> getTransactions() { | ||
| return transactions; | ||
| } | ||
|
|
||
| @JsonGetter(value = "withdrawals") | ||
| public List<WithdrawalParameter> getWithdrawals() { | ||
| return withdrawals; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.