Skip to content

Commit

Permalink
EIP-7742 Fix AT and update TODOs
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu committed Dec 10, 2024
1 parent 15c5cdd commit ffc85c8
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 74 deletions.
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 targetBlobsPerBlock = "0x3";
final Call newPayloadRequest =
createEngineCall(
createNewPayloadRequest(
executionPayload.toString(), parentBeaconBlockRoot, executionRequests.toString()));
executionPayload.toString(),
parentBeaconBlockRoot,
executionRequests.toString(),
targetBlobsPerBlock));
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\","
+ " \"targetBlobsPerBlock\": \"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 targetBlobsPerBlock) {
return "{"
+ " \"jsonrpc\": \"2.0\","
+ " \"method\": \"engine_newPayloadV4\","
Expand All @@ -183,7 +197,11 @@ private String createNewPayloadRequest(
+ "\""
+ ","
+ executionRequests
+ "],"
+ ","
+ "\""
+ targetBlobsPerBlock
+ "\""
+ "]," // 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",
"targetBlobsPerBlock":"0x1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public BlockCreationResult createBlock(
final long timestamp,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount,
final Optional<UInt64> targetBlobsPerBlock,
final BlockHeader parentHeader) {

return createBlock(
Expand All @@ -90,7 +90,7 @@ public BlockCreationResult createBlock(
withdrawals,
Optional.of(random),
parentBeaconBlockRoot,
targetBlobCount,
targetBlobsPerBlock,
timestamp,
false,
parentHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public PayloadIdentifier preparePayload(
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount) {
final Optional<UInt64> targetBlobsPerBlock) {

// 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 @@ -273,7 +273,7 @@ public PayloadIdentifier preparePayload(
feeRecipient,
withdrawals,
parentBeaconBlockRoot,
targetBlobCount);
targetBlobsPerBlock);

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

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

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

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

LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +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
* @param targetBlobsPerBlock optional target blobs per block
* @return the payload identifier
*/
PayloadIdentifier preparePayload(
Expand All @@ -54,7 +54,7 @@ PayloadIdentifier preparePayload(
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount);
final Optional<UInt64> targetBlobsPerBlock);

@Override
default boolean isCompatibleWithEngineApi() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +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
* @param targetBlobsPerBlock the target blobs per block
* @return the payload identifier
*/
public static PayloadIdentifier forPayloadParams(
Expand All @@ -73,7 +73,7 @@ public static PayloadIdentifier forPayloadParams(
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount) {
final Optional<UInt64> targetBlobsPerBlock) {

return new PayloadIdentifier(
timestamp
Expand All @@ -91,7 +91,7 @@ public static PayloadIdentifier forPayloadParams(
.orElse(0)
<< 32
^ ((long) parentBeaconBlockRoot.hashCode()) << 40
^ ((long) targetBlobCount.hashCode()) << 48);
^ ((long) targetBlobsPerBlock.hashCode()) << 48);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ public PayloadIdentifier preparePayload(
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot,
final Optional<UInt64> targetBlobCount) {
final Optional<UInt64> targetBlobsPerBlock) {
return mergeCoordinator.preparePayload(
parentHeader,
timestamp,
prevRandao,
feeRecipient,
withdrawals,
parentBeaconBlockRoot,
targetBlobCount);
targetBlobsPerBlock);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void differentParentBeaconBlockRootYieldDifferentHash() {
}

@Test
public void emptyOptionalAndNonEmptyTargetBlobCountYieldDifferentHash() {
public void emptyOptionalAndNonEmptyTargetBlobsPerBlockYieldDifferentHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForTbc1 =
PayloadIdentifier.forPayloadParams(
Expand All @@ -252,7 +252,7 @@ public void emptyOptionalAndNonEmptyTargetBlobCountYieldDifferentHash() {
}

@Test
public void differentTargetBlobCountYieldDifferentHash() {
public void differentTargetBlobsPerBlockYieldDifferentHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForTbc1 =
PayloadIdentifier.forPayloadParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
payloadAttributes.getSuggestedFeeRecipient(),
finalWithdrawals,
Optional.ofNullable(payloadAttributes.getParentBeaconBlockRoot()),
Optional.ofNullable(payloadAttributes.getTargetBlobCount())));
Optional.ofNullable(payloadAttributes.getTargetBlobsPerBlock())));

payloadId.ifPresent(
pid ->
Expand Down Expand Up @@ -319,9 +319,9 @@ private void logPayload(final EnginePayloadAttributesParameter payloadAttributes
.setMessage(message)
.addArgument(() -> payloadAttributes.getParentBeaconBlockRoot().toHexString());
}
if (payloadAttributes.getTargetBlobCount() != null) {
message += ", targetBlobCount: {}";
builder = builder.setMessage(message).addArgument(payloadAttributes::getTargetBlobCount);
if (payloadAttributes.getTargetBlobsPerBlock() != null) {
message += ", targetBlobsPerBlock: {}";
builder = builder.setMessage(message).addArgument(payloadAttributes::getTargetBlobsPerBlock);
}
builder.log();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
e);
}

final Optional<String> maybeTargetBlobCountParam;
final Optional<String> maybeTargetBlobsPerBlockParam;
try {
maybeTargetBlobCountParam = requestContext.getOptionalParameter(4, String.class);
maybeTargetBlobsPerBlockParam = requestContext.getOptionalParameter(4, String.class);
} catch (JsonRpcParameterException e) {
throw new InvalidJsonRpcRequestException(
"Invalid target blob count parameter (index 4)",
"Invalid target blobs per block parameter (index 4)",
RpcErrorType.INVALID_TARGET_BLOB_COUNT_PARAM,
e);
}
Expand All @@ -164,7 +164,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
maybeVersionedHashParam,
maybeParentBeaconBlockRootParam,
maybeRequestsParam,
maybeTargetBlobCountParam);
maybeTargetBlobsPerBlockParam);
if (!parameterValidationResult.isValid()) {
return new JsonRpcErrorResponse(reqId, parameterValidationResult);
}
Expand Down Expand Up @@ -223,16 +223,16 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
return new JsonRpcErrorResponse(reqId, RpcErrorType.INVALID_EXECUTION_REQUESTS_PARAMS);
}

final Optional<UInt64> maybeTargetBlobCount;
final Optional<UInt64> maybeTargetBlobsPerBlock;
try {
maybeTargetBlobCount = maybeTargetBlobCountParam.map(UInt64::fromHexString);
maybeTargetBlobsPerBlock = maybeTargetBlobsPerBlockParam.map(UInt64::fromHexString);
} catch (RuntimeException ex) {
return respondWithInvalid(
reqId,
blockParam,
mergeCoordinator.getLatestValidAncestor(blockParam.getParentHash()).orElse(null),
INVALID,
"Invalid targetBlobCount");
"Invalid targetBlobsPerBlock");
}

if (mergeContext.get().isSyncing()) {
Expand Down Expand Up @@ -303,7 +303,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
: BlobGas.fromHexString(blockParam.getExcessBlobGas()),
maybeParentBeaconBlockRoot.orElse(null),
maybeRequests.map(BodyValidation::requestsHash).orElse(null),
maybeTargetBlobCount.orElse(null),
maybeTargetBlobsPerBlock.orElse(null),
headerFunctions);

// ensure the block hash matches the blockParam hash
Expand Down Expand Up @@ -482,7 +482,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
final Optional<List<String>> maybeVersionedHashParam,
final Optional<String> maybeBeaconBlockRootParam,
final Optional<List<String>> maybeRequestsParam,
final Optional<String> maybeTargetBlobCountParam) {
final Optional<String> maybeTargetBlobsPerBlockParam) {
return ValidationResult.valid();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected ValidationResult<RpcErrorType> validateParameter(
return ValidationResult.invalid(
getInvalidPayloadAttributesError(), "Missing parent beacon block root hash");
}
if (maybePayloadAttributes.get().getTargetBlobCount() == null) {
if (maybePayloadAttributes.get().getTargetBlobsPerBlock() == null) {
return ValidationResult.invalid(
getInvalidPayloadAttributesError(), "Missing target blob count");
getInvalidPayloadAttributesError(), "Missing target blobs per block");
}
if (maybePayloadAttributes.get().getMaximumBlobCount() == null) {
return ValidationResult.invalid(
Expand All @@ -96,8 +96,8 @@ protected Optional<JsonRpcErrorResponse> isPayloadAttributesValid(
"Parent beacon block root hash not present in payload attributes after cancun hardfork");
return Optional.of(new JsonRpcErrorResponse(requestId, getInvalidPayloadAttributesError()));
}
if (payloadAttributes.getTargetBlobCount() == null) {
LOG.error("targetBlobCount not present in payload attributes after prague hardfork");
if (payloadAttributes.getTargetBlobsPerBlock() == null) {
LOG.error("targetBlobsPerBlock not present in payload attributes after prague hardfork");
return Optional.of(new JsonRpcErrorResponse(requestId, getInvalidPayloadAttributesError()));
}
if (payloadAttributes.getMaximumBlobCount() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
final Optional<List<String>> maybeVersionedHashParam,
final Optional<String> maybeBeaconBlockRootParam,
final Optional<List<String>> maybeRequestsParam,
final Optional<String> maybeTargetBlobCountParam) {
final Optional<String> maybeTargetBlobsPerBlockParam) {
if (payloadParameter.getBlobGasUsed() != null) {
return ValidationResult.invalid(
RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Unexpected blob gas used field present");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
final Optional<List<String>> maybeVersionedHashParam,
final Optional<String> maybeBeaconBlockRootParam,
final Optional<List<String>> maybeRequestsParam,
final Optional<String> maybeTargetBlobCountParam) {
final Optional<String> maybeTargetBlobsPerBlockParam) {
if (payloadParameter.getBlobGasUsed() == null) {
return ValidationResult.invalid(
RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
final Optional<List<String>> maybeVersionedHashParam,
final Optional<String> maybeBeaconBlockRootParam,
final Optional<List<String>> maybeRequestsParam,
final Optional<String> maybeTargetBlobCountParam) {
final Optional<String> maybeTargetBlobsPerBlockParam) {
if (payloadParameter.getBlobGasUsed() == null) {
return ValidationResult.invalid(
RpcErrorType.INVALID_BLOB_GAS_USED_PARAMS, "Missing blob gas used field");
Expand All @@ -74,9 +74,9 @@ protected ValidationResult<RpcErrorType> validateParameters(
} else if (maybeRequestsParam.isEmpty()) {
return ValidationResult.invalid(
RpcErrorType.INVALID_EXECUTION_REQUESTS_PARAMS, "Missing execution requests field");
} else if (maybeTargetBlobCountParam.isEmpty()) {
} else if (maybeTargetBlobsPerBlockParam.isEmpty()) {
return ValidationResult.invalid(
RpcErrorType.INVALID_TARGET_BLOB_COUNT_PARAM, "Missing targetBlobCount field");
RpcErrorType.INVALID_TARGET_BLOB_COUNT_PARAM, "Missing targetBlobsPerBlock field");
} else {
return ValidationResult.valid();
}
Expand Down
Loading

0 comments on commit ffc85c8

Please sign in to comment.