-
Notifications
You must be signed in to change notification settings - Fork 764
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
Initial implementation of EngineGetPayloadV2 #4833
Merged
Gabriel-Trintinalia
merged 8 commits into
hyperledger:main
from
Gabriel-Trintinalia:engine-get-payload-v2-method
Dec 21, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5a3ed04
Initial implementation of EngineGetPayloadV2
Gabriel-Trintinalia 41392c4
Classes reorganization
Gabriel-Trintinalia a475252
Classes reorganization
Gabriel-Trintinalia 7f8104c
Rename class to conform with Java conventions
Gabriel-Trintinalia a37892d
Merge branch 'main' into engine-get-payload-v2-method
Gabriel-Trintinalia adcf9a6
Remove abstract class and rename methods to match Spec (V2)
Gabriel-Trintinalia a6487df
Merge branch 'main' into engine-get-payload-v2-method
Gabriel-Trintinalia 8778720
Merge branch 'main' into engine-get-payload-v2-method
Gabriel-Trintinalia 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 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
This file contains 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
49 changes: 49 additions & 0 deletions
49
...org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV1.java
This file contains 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,49 @@ | ||
/* | ||
* 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.Block; | ||
|
||
import io.vertx.core.Vertx; | ||
|
||
public class EngineGetPayloadV1 extends AbstractEngineGetPayload { | ||
|
||
public EngineGetPayloadV1( | ||
final Vertx vertx, | ||
final ProtocolContext protocolContext, | ||
final MergeMiningCoordinator mergeMiningCoordinator, | ||
final BlockResultFactory blockResultFactory, | ||
final EngineCallListener engineCallListener) { | ||
super(vertx, protocolContext, mergeMiningCoordinator, blockResultFactory, engineCallListener); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RpcMethod.ENGINE_GET_PAYLOAD.getMethodName(); | ||
} | ||
|
||
@Override | ||
protected JsonRpcResponse createResponse(final JsonRpcRequestContext request, final Block block) { | ||
return new JsonRpcSuccessResponse( | ||
request.getRequest().getId(), blockResultFactory.payloadTransactionCompleteV1(block)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java
This file contains 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,49 @@ | ||
/* | ||
* 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.Block; | ||
|
||
import io.vertx.core.Vertx; | ||
|
||
public class EngineGetPayloadV2 extends AbstractEngineGetPayload { | ||
|
||
public EngineGetPayloadV2( | ||
final Vertx vertx, | ||
final ProtocolContext protocolContext, | ||
final MergeMiningCoordinator mergeMiningCoordinator, | ||
final BlockResultFactory blockResultFactory, | ||
final EngineCallListener engineCallListener) { | ||
super(vertx, protocolContext, mergeMiningCoordinator, blockResultFactory, engineCallListener); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RpcMethod.ENGINE_GET_PAYLOAD_V2.getMethodName(); | ||
} | ||
|
||
@Override | ||
protected JsonRpcResponse createResponse(final JsonRpcRequestContext request, final Block block) { | ||
return new JsonRpcSuccessResponse( | ||
request.getRequest().getId(), blockResultFactory.payloadTransactionCompleteV2(block)); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -85,14 +85,29 @@ public BlockResult transactionComplete(final Block block) { | |
block.getHeader(), txs, ommers, block.getHeader().getDifficulty(), block.calculateSize()); | ||
} | ||
|
||
public EngineGetPayloadResult enginePayloadTransactionComplete(final Block block) { | ||
public EngineGetPayloadResultV1 payloadTransactionCompleteV1(final Block block) { | ||
final List<String> txs = | ||
block.getBody().getTransactions().stream() | ||
.map(TransactionEncoder::encodeOpaqueBytes) | ||
.map(Bytes::toHexString) | ||
.collect(Collectors.toList()); | ||
|
||
return new EngineGetPayloadResult(block.getHeader(), txs); | ||
return new EngineGetPayloadResultV1(block.getHeader(), txs); | ||
} | ||
|
||
public EngineGetPayloadResultV2 payloadTransactionCompleteV2(final Block block) { | ||
final List<String> txs = | ||
block.getBody().getTransactions().stream() | ||
.map(TransactionEncoder::encodeOpaqueBytes) | ||
.map(Bytes::toHexString) | ||
.collect(Collectors.toList()); | ||
|
||
final long blockValue = calculateBlockValue(txs); | ||
return new EngineGetPayloadResultV2(block.getHeader(), txs, Quantity.create(blockValue)); | ||
} | ||
|
||
private long calculateBlockValue(final List<String> ignored) { | ||
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. Good idea to separate out for later implementation 👍 Check notice Code scanning / CodeQL Useless parameter
The parameter 'ignored' is never used.
|
||
return 0L; | ||
} | ||
|
||
public BlockResult transactionHash(final BlockWithMetadata<Hash, Hash> blockWithMetadata) { | ||
|
This file contains 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
155 changes: 155 additions & 0 deletions
155
.../org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadResultV2.java
This file contains 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,155 @@ | ||
/* | ||
* 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.core.BlockHeader; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
|
||
@JsonPropertyOrder({ | ||
"executionPayload", | ||
"blockValue", | ||
}) | ||
public class EngineGetPayloadResultV2 { | ||
protected final PayloadResult executionPayload; | ||
private final String blockValue; | ||
|
||
public EngineGetPayloadResultV2( | ||
final BlockHeader header, final List<String> transactions, final String blockValue) { | ||
this.executionPayload = new PayloadResult(header, transactions); | ||
this.blockValue = blockValue; | ||
} | ||
|
||
@JsonGetter(value = "executionPayload") | ||
public PayloadResult getExecutionPayload() { | ||
return executionPayload; | ||
} | ||
|
||
@JsonGetter(value = "blockValue") | ||
public String getBlockValue() { | ||
return blockValue; | ||
} | ||
|
||
public static class PayloadResult { | ||
|
||
protected final String blockHash; | ||
private final String parentHash; | ||
private final String feeRecipient; | ||
private final String stateRoot; | ||
private final String receiptsRoot; | ||
private final String logsBloom; | ||
private final String prevRandao; | ||
private final String blockNumber; | ||
private final String gasLimit; | ||
private final String gasUsed; | ||
private final String timestamp; | ||
private final String extraData; | ||
private final String baseFeePerGas; | ||
protected final List<String> transactions; | ||
|
||
public PayloadResult(final BlockHeader header, final List<String> transactions) { | ||
this.blockNumber = Quantity.create(header.getNumber()); | ||
this.blockHash = header.getHash().toString(); | ||
this.parentHash = header.getParentHash().toString(); | ||
this.logsBloom = header.getLogsBloom().toString(); | ||
this.stateRoot = header.getStateRoot().toString(); | ||
this.receiptsRoot = header.getReceiptsRoot().toString(); | ||
this.extraData = header.getExtraData().toString(); | ||
this.baseFeePerGas = header.getBaseFee().map(Quantity::create).orElse(null); | ||
this.gasLimit = Quantity.create(header.getGasLimit()); | ||
this.gasUsed = Quantity.create(header.getGasUsed()); | ||
this.timestamp = Quantity.create(header.getTimestamp()); | ||
this.transactions = transactions; | ||
this.feeRecipient = header.getCoinbase().toString(); | ||
this.prevRandao = header.getPrevRandao().map(Bytes32::toHexString).orElse(null); | ||
} | ||
|
||
@JsonGetter(value = "blockNumber") | ||
public String getNumber() { | ||
return blockNumber; | ||
} | ||
|
||
@JsonGetter(value = "blockHash") | ||
public String getHash() { | ||
return blockHash; | ||
} | ||
|
||
@JsonGetter(value = "parentHash") | ||
public String getParentHash() { | ||
return parentHash; | ||
} | ||
|
||
@JsonGetter(value = "logsBloom") | ||
public String getLogsBloom() { | ||
return logsBloom; | ||
} | ||
|
||
@JsonGetter(value = "prevRandao") | ||
public String getPrevRandao() { | ||
return prevRandao; | ||
} | ||
|
||
@JsonGetter(value = "stateRoot") | ||
public String getStateRoot() { | ||
return stateRoot; | ||
} | ||
|
||
@JsonGetter(value = "receiptsRoot") | ||
public String getReceiptRoot() { | ||
return receiptsRoot; | ||
} | ||
|
||
@JsonGetter(value = "extraData") | ||
public String getExtraData() { | ||
return extraData; | ||
} | ||
|
||
@JsonGetter(value = "baseFeePerGas") | ||
public String getBaseFeePerGas() { | ||
return baseFeePerGas; | ||
} | ||
|
||
@JsonGetter(value = "gasLimit") | ||
public String getGasLimit() { | ||
return gasLimit; | ||
} | ||
|
||
@JsonGetter(value = "gasUsed") | ||
public String getGasUsed() { | ||
return gasUsed; | ||
} | ||
|
||
@JsonGetter(value = "timestamp") | ||
public String getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
@JsonGetter(value = "transactions") | ||
public List<String> getTransactions() { | ||
return transactions; | ||
} | ||
|
||
@JsonGetter(value = "feeRecipient") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public String getFeeRecipient() { | ||
return feeRecipient; | ||
} | ||
} | ||
} |
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.
This is better than extending EngineGetPayload 👍