Skip to content

Commit

Permalink
Merge remote-tracking branch 'jason/7685_flat_encoding' into pectra-d…
Browse files Browse the repository at this point in the history
…evnet4-7702
  • Loading branch information
daniellehrner committed Oct 17, 2024
2 parents bdb0cb3 + 21b7aae commit 6457be5
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public enum RpcErrorType implements RpcMethodError {
INVALID_REMOTE_CAPABILITIES_PARAMS(
INVALID_PARAMS_ERROR_CODE, "Invalid remote capabilities params"),
INVALID_REWARD_PERCENTILES_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid reward percentiles params"),
INVALID_REQUESTS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid versioned hash params"),
INVALID_REQUESTS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid requests params"),
INVALID_SEALER_ID_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid sealer ID params"),
INVALID_STORAGE_KEYS_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid storage keys params"),
INVALID_SUBSCRIPTION_PARAMS(INVALID_PARAMS_ERROR_CODE, "Invalid subscription params"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.hyperledger.besu.ethereum.blockcreation;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.mainnet.requests.DepositRequestProcessor.DEFAULT_DEPOSIT_CONTRACT_ADDRESS;
import static org.hyperledger.besu.ethereum.mainnet.requests.RequestContractAddresses.DEFAULT_DEPOSIT_CONTRACT_ADDRESS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.RequestType;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Request;
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.mainnet.BodyValidation;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
Expand Down Expand Up @@ -217,10 +220,19 @@ private static BlockHeader buildHeader(
.excessBlobGas(isCancunAtGenesis(genesis) ? parseExcessBlobGas(genesis) : null)
.parentBeaconBlockRoot(
(isCancunAtGenesis(genesis) ? parseParentBeaconBlockRoot(genesis) : null))
.requestsHash(isPragueAtGenesis(genesis) ? Hash.EMPTY_TRIE_HASH : null)
.requestsHash(isPragueAtGenesis(genesis) ? calcEmptyRequestsHash() : null)
.buildBlockHeader();
}

private static Hash calcEmptyRequestsHash() {
final List<Request> emptyRequests =
List.of(
new Request(RequestType.DEPOSIT, Bytes.EMPTY),
new Request(RequestType.WITHDRAWAL, Bytes.EMPTY),
new Request(RequestType.CONSOLIDATION, Bytes.EMPTY));
return BodyValidation.requestsHash(emptyRequests);
}

private static Address parseCoinbase(final GenesisConfigFile genesis) {
return genesis
.getCoinbase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,17 @@

import org.hyperledger.besu.datatypes.RequestType;

import java.util.Objects;

import org.apache.tuweni.bytes.Bytes;

public class Request implements org.hyperledger.besu.plugin.data.Request {
private final RequestType type;
private final Bytes data;

public Request(final RequestType type, final Bytes data) {
this.type = type;
this.data = data;
}

public record Request(RequestType type, Bytes data)
implements org.hyperledger.besu.plugin.data.Request {
@Override
public RequestType getType() {
return type;
return type();
}

@Override
public Bytes getData() {
return data;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof Request request)) return false;
return type == request.type && Objects.equals(data, request.data);
}

@Override
public int hashCode() {
return Objects.hash(type, data);
}

@Override
public String toString() {
return "Request{" + "type=" + type + ", data=" + data + '}';
return data();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

public class DepositRequestProcessor implements RequestProcessor {

public static final Address DEFAULT_DEPOSIT_CONTRACT_ADDRESS =
Address.fromHexString("0x00000000219ab540356cbb839cbe05303d7705fa");

private final Optional<Address> depositContractAddress;

public DepositRequestProcessor(final Address depositContractAddress) {
Expand All @@ -40,7 +37,7 @@ public DepositRequestProcessor(final Address depositContractAddress) {
@Override
public Request process(final ProcessRequestContext context) {
if (depositContractAddress.isEmpty()) {
throw new IllegalStateException("Deposit contract address is not set.");
return new Request(RequestType.DEPOSIT, Bytes.EMPTY);
}
Optional<Bytes> depositRequests = getDepositRequestData(context.transactionReceipts());
return new Request(RequestType.DEPOSIT, depositRequests.orElse(Bytes.EMPTY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public static RequestProcessorCoordinator pragueRequestsProcessors(
return new RequestProcessorCoordinator.Builder()
.addProcessor(
RequestType.WITHDRAWAL,
new WithdrawalRequestProcessor(
requestContractAddresses.getWithdrawalRequestContractAddress()))
new SystemCallRequestProcessor(
requestContractAddresses.getWithdrawalRequestContractAddress(),
RequestType.WITHDRAWAL))
.addProcessor(
RequestType.CONSOLIDATION,
new ConsolidationRequestProcessor(
requestContractAddresses.getConsolidationRequestContractAddress()))
new SystemCallRequestProcessor(
requestContractAddresses.getConsolidationRequestContractAddress(),
RequestType.CONSOLIDATION))
.addProcessor(
RequestType.DEPOSIT,
new DepositRequestProcessor(requestContractAddresses.getDepositContractAddress()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean validate(

if (hasRequestsHash) {
LOG.warn(
"Block {} header contains requests_root but requests are prohibited", block.getHash());
"Block {} header contains requests_hash but requests are prohibited", block.getHash());
}

return !hasRequestsHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
*/
package org.hyperledger.besu.ethereum.mainnet.requests;

import static org.hyperledger.besu.ethereum.mainnet.requests.ConsolidationRequestProcessor.CONSOLIDATION_REQUEST_CONTRACT_ADDRESS;
import static org.hyperledger.besu.ethereum.mainnet.requests.DepositRequestProcessor.DEFAULT_DEPOSIT_CONTRACT_ADDRESS;
import static org.hyperledger.besu.ethereum.mainnet.requests.WithdrawalRequestProcessor.DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Address;

Expand All @@ -26,6 +22,13 @@ public class RequestContractAddresses {
private final Address depositContractAddress;
private final Address consolidationRequestContractAddress;

public static final Address DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS =
Address.fromHexString("0x09FC772D0857550724B07B850A4323F39112AAAA");
public static final Address DEFAULT_CONSOLIDATION_REQUEST_CONTRACT_ADDRESS =
Address.fromHexString("0x01ABEA29659E5E97C95107F20BB753CD3E09BBBB");
public static final Address DEFAULT_DEPOSIT_CONTRACT_ADDRESS =
Address.fromHexString("0x00000000219ab540356cbb839cbe05303d7705fa");

public RequestContractAddresses(
final Address withdrawalRequestContractAddress,
final Address depositContractAddress,
Expand All @@ -44,7 +47,7 @@ public static RequestContractAddresses fromGenesis(
genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS),
genesisConfigOptions
.getConsolidationRequestContractAddress()
.orElse(CONSOLIDATION_REQUEST_CONTRACT_ADDRESS));
.orElse(DEFAULT_CONSOLIDATION_REQUEST_CONTRACT_ADDRESS));
}

public Address getWithdrawalRequestContractAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Request;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.mainnet.BodyValidation;

import java.util.List;
Expand All @@ -40,15 +39,11 @@ public class RequestsValidator {
* Validates a block's requests by ensuring they are correctly ordered, have a valid root, and
* pass their respective type-specific validations.
*
* @param block The block containing the requests to be validated.
* @param maybeRequests The list of requests contained within the block.
* @param receipts The list of transaction receipts corresponding to the requests.
* @param block The block containing the requestHash to be validated.
* @param maybeRequests The list of requests to be validated.
* @return true if all validations pass; false otherwise.
*/
public boolean validate(
final Block block,
final Optional<List<Request>> maybeRequests,
final List<TransactionReceipt> receipts) {
public boolean validate(final Block block, final Optional<List<Request>> maybeRequests) {

if (!isRequestsHashValid(block, maybeRequests)) {
return false;
Expand All @@ -67,7 +62,7 @@ private boolean isRequestsHashValid(final Block block, final Optional<List<Reque
final Optional<Hash> maybeRequestsHash = block.getHeader().getRequestsHash();

if (maybeRequestsHash.isEmpty()) {
LOG.warn("Block {} must contain requests root", blockHash);
LOG.warn("Block {} must contain requests hash", blockHash);
return false;
}

Expand All @@ -78,9 +73,7 @@ private boolean isRequestsHashValid(final Block block, final Optional<List<Reque

final Hash expectedRequestsHash = BodyValidation.requestsHash(requests.get());
if (!expectedRequestsHash.equals(maybeRequestsHash.get())) {
LOG.warn(
"Block {} requests root does not match expected hash root for requests in block",
blockHash);
LOG.warn("Block {} requests hash does not match expected request hash", blockHash);
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@
package org.hyperledger.besu.ethereum.mainnet.requests;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.RequestType;
import org.hyperledger.besu.ethereum.core.Request;
import org.hyperledger.besu.ethereum.mainnet.SystemCallProcessor;

import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;

/**
* Abstract base class for processing system call requests.
*
* @param <T> The type of request to be processed.
*/
public abstract class AbstractSystemCallRequestProcessor<T extends Request>
implements RequestProcessor {
/** Processes system call requests. */
public class SystemCallRequestProcessor implements RequestProcessor {

private final Address callAddress;
private final RequestType requestType;

public SystemCallRequestProcessor(final Address callAddress, final RequestType requestType) {
this.callAddress = callAddress;
this.requestType = requestType;
}

/**
* Processes a system call and converts the result into requests of type T.
* Processes a system call and converts the result as a Request.
*
* @param context The request context being processed.
* @return An {@link Optional} containing a list of {@link T} objects if any are found
* @return A {@link Request} request
*/
@Override
public Request process(final ProcessRequestContext context) {
Expand All @@ -44,27 +46,13 @@ public Request process(final ProcessRequestContext context) {

Bytes systemCallOutput =
systemCallProcessor.process(
getCallAddress(),
callAddress,
context.mutableWorldState().updater(),
context.blockHeader(),
context.operationTracer(),
context.blockHashLookup());

return parseRequest(systemCallOutput == null ? Bytes.EMPTY : systemCallOutput);
Bytes requestData = systemCallOutput == null ? Bytes.EMPTY : systemCallOutput;
return new Request(requestType, requestData);
}

/**
* Parses a single request from the provided bytes.
*
* @param requestBytes The bytes representing a single request.
* @return A parsed {@link T} object.
*/
protected abstract T parseRequest(final Bytes requestBytes);

/**
* Gets the call address for the specific request type.
*
* @return The call address.
*/
protected abstract Address getCallAddress();
}
Loading

0 comments on commit 6457be5

Please sign in to comment.