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

EIP-7742 Engine API Changes #7840

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class CodeDelegationTransactionAcceptanceTest extends AcceptanceTestBase
public static final Bytes TRANSACTION_SPONSOR_PRIVATE_KEY =
Bytes.fromHexString("3a4ff6d22d7502ef2452368165422861c01a0f72f851793b372b87888dc3c453");

private final Account otherAccount = accounts.createAccount("otherAccount");
private final Account otherAccount = accounts.getPrimaryBenefactor();

private BesuNode besuNode;
private PragueAcceptanceTestHelper testHelper;
Expand All @@ -85,7 +85,6 @@ void tearDown() {
*/
@Test
public void shouldTransferAllEthOfAuthorizerToSponsor() throws IOException {

// 7702 transaction
final CodeDelegation authorization =
org.hyperledger.besu.ethereum.core.CodeDelegation.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.tests.acceptance.dsl.transaction.eth.EthTransactions;

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -92,11 +93,21 @@ public void buildNewBlock() throws IOException {
assertThat(newBlockHash).isNotEmpty();
}

final String targetBlobCount = "0x3";
final Call newPayloadRequest =
createEngineCall(
createNewPayloadRequest(
executionPayload.toString(), parentBeaconBlockRoot, executionRequests.toString()));
executionPayload.toString(),
parentBeaconBlockRoot,
executionRequests.toString(),
targetBlobCount));
try (final Response newPayloadResponse = newPayloadRequest.execute()) {
final InputStream responseStr = newPayloadResponse.body().byteStream();
JsonNode jsonNode = mapper.readTree(responseStr);
if (jsonNode.has("error")) {
throw new AssertionError(
"Unexpected engine_newPayload error: " + jsonNode.get("error").get("message").asText());
}
assertThat(newPayloadResponse.code()).isEqualTo(200);
}

Expand Down Expand Up @@ -148,7 +159,9 @@ private String createForkChoiceRequest(final String parentBlockHash, final Long
+ " \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\","
+ " \"suggestedFeeRecipient\": \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\","
+ " \"withdrawals\": [],"
+ " \"parentBeaconBlockRoot\": \"0x0000000000000000000000000000000000000000000000000000000000000000\""
+ " \"parentBeaconBlockRoot\": \"0x0000000000000000000000000000000000000000000000000000000000000000\","
+ " \"targetBlobCount\": \"0x3\","
+ " \"maximumBlobCount\": \"0x6\""
+ " }";
}

Expand All @@ -171,7 +184,8 @@ private String createGetPayloadRequest(final String payloadId) {
private String createNewPayloadRequest(
final String executionPayload,
final String parentBeaconBlockRoot,
final String executionRequests) {
final String executionRequests,
final String targetBlobCount) {
return "{"
+ " \"jsonrpc\": \"2.0\","
+ " \"method\": \"engine_newPayloadV4\","
Expand All @@ -183,7 +197,11 @@ private String createNewPayloadRequest(
+ "\""
+ ","
+ executionRequests
+ "],"
+ ","
+ "\""
+ targetBlobCount
+ "\""
+ "]," // end params
+ " \"id\": 67"
+ "}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@
"number":"0x0",
"gasUsed":"0x0",
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas":"0x7"
"baseFeePerGas":"0x7",
"targetBlobCount":"0x1"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,95 @@
{
"request" : {"jsonrpc":"2.0","id":5,"method":"engine_forkchoiceUpdatedV3","params":[{"headBlockHash":"0x33235e7b7a78302cdb54e5ddba66c7ae49b01c1f5498bb00cd0c8ed5206784bf","safeBlockHash":"0x0000000000000000000000000000000000000000000000000000000000000000","finalizedBlockHash":"0x0000000000000000000000000000000000000000000000000000000000000000"},{"timestamp":"0x1236","prevRandao":"0xc13da06dc53836ca0766057413b9683eb9a8773bbb8fcc5691e41c25b56dda1d","suggestedFeeRecipient":"0x0000000000000000000000000000000000000000","withdrawals":[{"index":"0xb","validatorIndex":"0x0","address":"0x0000000000000000000000000000000000000000","amount":"0x64"},{"index":"0xc","validatorIndex":"0x1","address":"0x0100000000000000000000000000000000000000","amount":"0x64"},{"index":"0xd","validatorIndex":"0x2","address":"0x0200000000000000000000000000000000000000","amount":"0x64"},{"index":"0xe","validatorIndex":"0x3","address":"0x0300000000000000000000000000000000000000","amount":"0x64"},{"index":"0xf","validatorIndex":"0x4","address":"0x0400000000000000000000000000000000000000","amount":"0x64"},{"index":"0x10","validatorIndex":"0x5","address":"0x0500000000000000000000000000000000000000","amount":"0x64"},{"index":"0x11","validatorIndex":"0x6","address":"0x0600000000000000000000000000000000000000","amount":"0x64"},{"index":"0x12","validatorIndex":"0x7","address":"0x0700000000000000000000000000000000000000","amount":"0x64"},{"index":"0x13","validatorIndex":"0x8","address":"0x0800000000000000000000000000000000000000","amount":"0x64"},{"index":"0x14","validatorIndex":"0x9","address":"0x0900000000000000000000000000000000000000","amount":"0x64"}],"parentBeaconBlockRoot":"0x062367f0b23e2d49ad5e770d9ad17b83c0c1c625c3f9a290cd9572b3fc6cfc9e"}]},
"response" : {"jsonrpc":"2.0","id":5,"result":{"payloadStatus":{"status":"VALID","latestValidHash":"0x33235e7b7a78302cdb54e5ddba66c7ae49b01c1f5498bb00cd0c8ed5206784bf","validationError":null},"payloadId":"0x29e12df730769ab6"}},
"statusCode" : 200
"request": {
"jsonrpc": "2.0",
"id": 5,
"method": "engine_forkchoiceUpdatedV3",
"params": [
{
"headBlockHash": "0x33235e7b7a78302cdb54e5ddba66c7ae49b01c1f5498bb00cd0c8ed5206784bf",
"safeBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"finalizedBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
{
"timestamp": "0x1236",
"prevRandao": "0xc13da06dc53836ca0766057413b9683eb9a8773bbb8fcc5691e41c25b56dda1d",
"suggestedFeeRecipient": "0x0000000000000000000000000000000000000000",
"withdrawals": [
{
"index": "0xb",
"validatorIndex": "0x0",
"address": "0x0000000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0xc",
"validatorIndex": "0x1",
"address": "0x0100000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0xd",
"validatorIndex": "0x2",
"address": "0x0200000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0xe",
"validatorIndex": "0x3",
"address": "0x0300000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0xf",
"validatorIndex": "0x4",
"address": "0x0400000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0x10",
"validatorIndex": "0x5",
"address": "0x0500000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0x11",
"validatorIndex": "0x6",
"address": "0x0600000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0x12",
"validatorIndex": "0x7",
"address": "0x0700000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0x13",
"validatorIndex": "0x8",
"address": "0x0800000000000000000000000000000000000000",
"amount": "0x64"
},
{
"index": "0x14",
"validatorIndex": "0x9",
"address": "0x0900000000000000000000000000000000000000",
"amount": "0x64"
}
],
"parentBeaconBlockRoot": "0x062367f0b23e2d49ad5e770d9ad17b83c0c1c625c3f9a290cd9572b3fc6cfc9e"
}
]
},
"response": {
"jsonrpc": "2.0",
"id": 5,
"result": {
"payloadStatus": {
"status": "VALID",
"latestValidHash": "0x33235e7b7a78302cdb54e5ddba66c7ae49b01c1f5498bb00cd0c8ed5206784bf",
"validationError": null
},
"payloadId": "0x744ab0889222f836"
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"request" : {"jsonrpc":"2.0","id":2,"method":"engine_getPayloadV3","params":["0x29e12df730769ab6"]},
"request" : {"jsonrpc":"2.0","id":2,"method":"engine_getPayloadV3","params":["0x744ab0889222f836"]},
"response" : {
"jsonrpc" : "2.0",
"id" : 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"latestValidHash": "0xf4a1d287dd3bb7e877c57476912e6a6052bc4eed8ea70d032b55d77f26ee985f",
"validationError": null
},
"payloadId": "0x0065bd2db6663f59"
"payloadId": "0x48b9f464feba7610"
}
},
"statusCode" : 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"latestValidHash": "0xf4a1d287dd3bb7e877c57476912e6a6052bc4eed8ea70d032b55d77f26ee985f",
"validationError": null
},
"payloadId": "0x0065bd2db6663ed9"
"payloadId": "0x48b9f5e4feba7610"
}
},
"statusCode" : 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"jsonrpc": "2.0",
"method": "engine_getPayloadV2",
"params": [
"0x0065bd2db6663ed9"
"0x48b9f5e4feba7610"
],
"id": 67
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;

/** The Merge block creator. */
class MergeBlockCreator extends AbstractBlockCreator {
Expand Down Expand Up @@ -80,6 +81,7 @@ public BlockCreationResult createBlock(
final long timestamp,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount,
final BlockHeader parentHeader) {

return createBlock(
Expand All @@ -88,6 +90,7 @@ public BlockCreationResult createBlock(
withdrawals,
Optional.of(random),
parentBeaconBlockRoot,
targetBlobCount,
timestamp,
false,
parentHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

import com.google.common.annotations.VisibleForTesting;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -257,7 +258,8 @@ public PayloadIdentifier preparePayload(
final Bytes32 prevRandao,
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot) {
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount) {

// we assume that preparePayload is always called sequentially, since the RPC Engine calls
// are sequential, if this assumption changes then more synchronization should be added to
Expand All @@ -270,7 +272,8 @@ public PayloadIdentifier preparePayload(
prevRandao,
feeRecipient,
withdrawals,
parentBeaconBlockRoot);
parentBeaconBlockRoot,
targetBlobCount);

if (blockCreationTasks.containsKey(payloadIdentifier)) {
LOG.debug(
Expand All @@ -295,6 +298,7 @@ public PayloadIdentifier preparePayload(
timestamp,
withdrawals,
parentBeaconBlockRoot,
targetBlobCount,
parentHeader)
.getBlock();

Expand Down Expand Up @@ -326,6 +330,7 @@ public PayloadIdentifier preparePayload(
mergeBlockCreator,
withdrawals,
parentBeaconBlockRoot,
targetBlobCount,
parentHeader);

return payloadIdentifier;
Expand Down Expand Up @@ -368,6 +373,7 @@ private void tryToBuildBetterBlock(
final MergeBlockCreator mergeBlockCreator,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount,
final BlockHeader parentHeader) {

final Supplier<BlockCreationResult> blockCreator =
Expand All @@ -378,6 +384,7 @@ private void tryToBuildBetterBlock(
timestamp,
withdrawals,
parentBeaconBlockRoot,
targetBlobCount,
parentHeader);

LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.CompletableFuture;

import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;

/** The interface Merge mining coordinator. */
public interface MergeMiningCoordinator extends MiningCoordinator {
Expand All @@ -43,6 +44,7 @@ public interface MergeMiningCoordinator extends MiningCoordinator {
* @param feeRecipient the fee recipient
* @param withdrawals the optional list of withdrawals
* @param parentBeaconBlockRoot optional root hash of the parent beacon block
* @param targetBlobCount optional target blob count
* @return the payload identifier
*/
PayloadIdentifier preparePayload(
Expand All @@ -51,7 +53,8 @@ PayloadIdentifier preparePayload(
final Bytes32 prevRandao,
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot);
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount);

@Override
default boolean isCompatibleWithEngineApi() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public PayloadIdentifier(final Long payloadId) {
* @param feeRecipient the fee recipient
* @param withdrawals the withdrawals
* @param parentBeaconBlockRoot the parent beacon block root
* @param targetBlobCount the target blob count
* @return the payload identifier
*/
public static PayloadIdentifier forPayloadParams(
Expand All @@ -71,23 +72,26 @@ public static PayloadIdentifier forPayloadParams(
final Bytes32 prevRandao,
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot) {
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount) {

return new PayloadIdentifier(
timestamp
^ ((long) parentHash.toHexString().hashCode()) << 8
^ ((long) prevRandao.toHexString().hashCode()) << 16
^ ((long) feeRecipient.toHexString().hashCode()) << 24
^ (long)
withdrawals
.map(
ws ->
ws.stream()
.sorted(Comparator.comparing(Withdrawal::getIndex))
.map(Withdrawal::hashCode)
.reduce(1, (a, b) -> a ^ (b * 31)))
.orElse(0)
^ ((long) parentBeaconBlockRoot.hashCode()) << 40);
withdrawals
.map(
ws ->
ws.stream()
.sorted(Comparator.comparing(Withdrawal::getIndex))
.map(Withdrawal::hashCode)
.reduce(1, (a, b) -> a ^ (b * 31)))
.orElse(0)
<< 32
Copy link
Contributor Author

@siladu siladu Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, added a (<< 32) left shift for withdrawals to keep the hashcodes evenly distributed by using the same pattern as the other fields.

This change impacts the shanghai and cancun ATs

^ ((long) parentBeaconBlockRoot.hashCode()) << 40
^ ((long) targetBlobCount.hashCode()) << 48);
}

@Override
Expand Down
Loading
Loading