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 based on pectra-devnet-4 #7805

Draft
wants to merge 12 commits into
base: pectra-devnet-4
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static BlockHeader createBlockHeader(
null,
null,
null,
null,
blockHeaderFunctions);
}
}
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 @@ -20,8 +20,11 @@

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.provider.Arguments;

// TODO SLD
@Disabled("TODO SLD - Enable when Prague spec is finalized")
public class ExecutionEnginePragueAcceptanceTest extends AbstractJsonRpcTest {
private static final String GENESIS_FILE = "/jsonrpc/engine/prague/genesis.json";
private static final String TEST_CASE_PATH = "/jsonrpc/engine/prague/test-cases/";
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 @@ -193,6 +193,7 @@ public void miningParametersBlockPeriodSecondsIsUpdatedOnTransition() {
null,
null,
null,
null,
getBlockHeaderFunctions());
final Block block1 = new Block(header1, BlockBody.empty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public void miningParametersBlockPeriodSecondsIsUpdatedOnTransition() {
null,
null,
null,
null,
new CliqueBlockHeaderFunctions());
final Block block1 = new Block(header1, BlockBody.empty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private void setSyncTarget() {
mock(EthPeer.class),
new org.hyperledger.besu.ethereum.core.BlockHeader(
null, null, null, null, null, null, null, null, 1, 1, 1, 1, null, null, null, 1, null,
null, null, null, null, null));
null, null, null, null, null, null));
}

private void clearSyncTarget() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ public String getParentBeaconBlockRoot() {
"0x0000000000000000000000000000000000000000000000000000000000000000");
}

/**
* Gets target blob count.
*
* @return the target blob count
*/
public Optional<String> getTargetBlobCount() {
// TODO SLD EIP-7742 not sure if we should use a default value here or enforce any
// "pragueAtGenesis" genesis file (used in devnets) to have this value
return JsonUtil.getValueAsString(genesisRoot, "targetblobcount");
}

/**
* Gets coinbase.
*
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
Loading
Loading