Skip to content

Commit

Permalink
Merge branch 'main' into multi-version-flat-db-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew1001 authored Jan 15, 2025
2 parents ece75e0 + 5cc309a commit d1f77b0
Show file tree
Hide file tree
Showing 36 changed files with 944 additions and 252 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Allow gasPrice (legacy) and 1559 gasPrice params to be specified simultaneously for `eth_call`, `eth_createAccessList`, and `eth_estimateGas` [#8059](https://github.com/hyperledger/besu/pull/8059)
- Improve debug_traceBlock calls performance and reduce output size [#8076](https://github.com/hyperledger/besu/pull/8076)
- Add support for EIP-7702 transaction in the txpool [#8018](https://github.com/hyperledger/besu/pull/8018) [#7984](https://github.com/hyperledger/besu/pull/7984)
- Add support for `movePrecompileToAddress` in `StateOverrides` (`eth_call`)[8115](https://github.com/hyperledger/besu/pull/8115)

### Bug fixes
- Fix serialization of state overrides when `movePrecompileToAddress` is present [#8204](https://github.com/hyperledger/besu/pull/8024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void shouldTransferAllEthOfAuthorizerToSponsor() throws IOException {
*/
@Test
public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
final long GAS_LIMIT = 1000000L;
cluster.verify(authorizer.balanceEquals(Amount.ether(90000)));
final long GAS_LIMIT = 1_000_000L;
cluster.verify(authorizer.balanceEquals(Amount.ether(90_000)));

final CodeDelegation authorization =
org.hyperledger.besu.ethereum.core.CodeDelegation.builder()
Expand All @@ -159,7 +159,7 @@ public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
.type(TransactionType.DELEGATE_CODE)
.chainId(BigInteger.valueOf(20211))
.nonce(0)
.maxPriorityFeePerGas(Wei.of(1000000000))
.maxPriorityFeePerGas(Wei.of(1_000_000_000))
.maxFeePerGas(Wei.fromHexString("0x02540BE400"))
.gasLimit(GAS_LIMIT)
.to(Address.fromHexStringStrict(authorizer.getAddress()))
Expand Down Expand Up @@ -209,7 +209,7 @@ public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
.nonce(2)
.maxPriorityFeePerGas(Wei.of(10))
.maxFeePerGas(Wei.of(100))
.gasLimit(21000)
.gasLimit(21_000)
.to(Address.fromHexStringStrict(otherAccount.getAddress()))
.value(Wei.ONE)
.payload(Bytes.EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void buildNewBlock() throws IOException {
executionPayload.toString(), parentBeaconBlockRoot, executionRequests.toString()));
try (final Response newPayloadResponse = newPayloadRequest.execute()) {
assertThat(newPayloadResponse.code()).isEqualTo(200);

final String responseStatus =
mapper.readTree(newPayloadResponse.body().string()).get("result").get("status").asText();
assertThat(responseStatus).isEqualTo("VALID");
}

final Call moveChainAheadRequest = createEngineCall(createForkChoiceRequest(newBlockHash));
Expand Down
10 changes: 2 additions & 8 deletions datatypes/src/main/java/org/hyperledger/besu/datatypes/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ public class Hash extends DelegatingBytes32 {
public static final Hash EMPTY = hash(Bytes.EMPTY);

/**
* Hash of empty requests or "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"
* Hash of empty requests or "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
*/
public static final Hash EMPTY_REQUESTS_HASH =
Hash.wrap(
sha256(
Bytes.concatenate(
sha256(Bytes.of(RequestType.DEPOSIT.getSerializedType())),
sha256(Bytes.of(RequestType.WITHDRAWAL.getSerializedType())),
sha256(Bytes.of(RequestType.CONSOLIDATION.getSerializedType())))));
public static final Hash EMPTY_REQUESTS_HASH = Hash.wrap(sha256(Bytes.EMPTY));

/**
* Instantiates a new Hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ public class StateOverride {
private final Optional<Long> nonce;
private final Optional<String> code;
private final Optional<Map<String, String>> stateDiff;
private final Optional<Address> movePrecompileToAddress;

private StateOverride(
final Optional<Wei> balance,
final Optional<Long> nonce,
final Optional<String> code,
final Optional<Map<String, String>> stateDiff) {
final Optional<Map<String, String>> stateDiff,
final Optional<Address> movePrecompileToAddress) {
this.balance = balance;
this.nonce = nonce;
this.code = code;
this.stateDiff = stateDiff;
this.movePrecompileToAddress = movePrecompileToAddress;
}

/**
Expand Down Expand Up @@ -84,13 +87,23 @@ public Optional<Map<String, String>> getStateDiff() {
return stateDiff;
}

/**
* Gets the new address for the pre-compiled contract
*
* @return the new address for the pre-compiled contract if present
*/
public Optional<Address> getMovePrecompileToAddress() {
return movePrecompileToAddress;
}

/** Builder class for Account overrides */
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Builder {
private Optional<Wei> balance = Optional.empty();
private Optional<Long> nonce = Optional.empty();
private Optional<String> code = Optional.empty();
private Optional<Map<String, String>> stateDiff = Optional.empty();
private Optional<Address> movePrecompileToAddress = Optional.empty();

/** Default constructor. */
public Builder() {}
Expand Down Expand Up @@ -139,13 +152,24 @@ public Builder withStateDiff(final Map<String, String> stateDiff) {
return this;
}

/**
* Sets the new address for the pre-compiled contract
*
* @param newPrecompileAddress the new address for the pre-compile contract
* @return the builder
*/
public Builder withMovePrecompileToAddress(final Address newPrecompileAddress) {
this.movePrecompileToAddress = Optional.ofNullable(newPrecompileAddress);
return this;
}

/**
* build the account override from the builder
*
* @return account override
*/
public StateOverride build() {
return new StateOverride(balance, nonce, code, stateDiff);
return new StateOverride(balance, nonce, code, stateDiff, movePrecompileToAddress);
}
}

Expand Down Expand Up @@ -195,6 +219,8 @@ public String toString() {
+ code
+ ", stateDiff="
+ stateDiff
+ ", movePrecompileToAddress="
+ movePrecompileToAddress
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void shouldGetExpectedValueForEmptyHash() {
public void shouldGetExpectedValueForEmptyRequestsHash() {
assertThat(Hash.EMPTY_REQUESTS_HASH)
.isEqualTo(
Hash.fromHexString(
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
Hash.fromHexString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import io.vertx.core.Vertx;
import io.vertx.core.json.Json;
Expand Down Expand Up @@ -596,8 +595,12 @@ private Optional<List<Request>> extractRequests(final Optional<List<String>> may

return maybeRequestsParam.map(
requests ->
IntStream.range(0, requests.size())
.mapToObj(i -> new Request(RequestType.of(i), Bytes.fromHexString(requests.get(i))))
requests.stream()
.map(
s -> {
final Bytes request = Bytes.fromHexString(s);
return new Request(RequestType.of(request.get(0)), request.slice(1));
})
.collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public EngineGetPayloadResultV4 payloadTransactionCompleteV4(final PayloadWrappe
rqs ->
rqs.stream()
.sorted(Comparator.comparing(Request::getType))
.map(r -> r.getData().toHexString())
.filter(r -> !r.getData().isEmpty())
.map(Request::getEncodedRequest)
.map(Bytes::toHexString)
.toList());

final BlobsBundleV1 blobsBundleV1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.hyperledger.besu.ethereum.transaction.TransactionSimulator;
import org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult;

import java.util.Map;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
Expand Down Expand Up @@ -123,6 +124,33 @@ public void someStateOverrides() {
assertThat(overrideMap).containsValue(override);
}

@Test
public void fullStateOverrides() {
StateOverrideMap suppliedOverrides = new StateOverrideMap();
StateOverride override =
new StateOverride.Builder()
.withNonce(new UnsignedLongParameter("0x9e"))
.withBalance(Wei.of(100))
.withCode("0x1234")
.withStateDiff(Map.of("0x1234", "0x5678"))
.withMovePrecompileToAddress(Address.fromHexString("0x1234"))
.build();
final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3");
suppliedOverrides.put(address, override);

final JsonRpcRequestContext request =
ethCallRequestWithStateOverrides(callParameter(), "latest", suppliedOverrides);

Optional<StateOverrideMap> maybeOverrideMap = method.getAddressStateOverrideMap(request);
assertThat(maybeOverrideMap.isPresent()).isTrue();
StateOverrideMap actualOverrideMap = maybeOverrideMap.get();
assertThat(actualOverrideMap.keySet()).hasSize(1);
assertThat(actualOverrideMap.values()).hasSize(1);

assertThat(actualOverrideMap).containsKey(address);
assertThat(actualOverrideMap).containsValue(override);
}

@Test
public void shouldReturnInternalErrorWhenProcessorReturnsEmpty() {
final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))),
final List<String> requestsWithoutRequestId =
requests.stream()
.sorted(Comparator.comparing(Request::getType))
.map(r -> r.getData().toHexString())
.map(Request::getEncodedRequest)
.map(Bytes::toHexString)
.toList();
Optional.of(resp)
.map(JsonRpcSuccessResponse.class::cast)
Expand All @@ -172,6 +173,53 @@ header, new BlockBody(List.of(blobTx), emptyList(), Optional.of(emptyList()))),
verify(engineCallListener, times(1)).executionEngineCalled();
}

@Test
public void shouldExcludeEmptyRequestsInRequestsList() {

BlockHeader header =
new BlockHeaderTestFixture().timestamp(pragueHardfork.milestone() + 1).buildHeader();
PayloadIdentifier payloadIdentifier =
PayloadIdentifier.forPayloadParams(
Hash.ZERO,
pragueHardfork.milestone(),
Bytes32.random(),
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());

BlockWithReceipts block =
new BlockWithReceipts(
new Block(header, new BlockBody(emptyList(), emptyList(), Optional.of(emptyList()))),
emptyList());
final List<Request> unorderedRequests =
List.of(
new Request(RequestType.CONSOLIDATION, Bytes.of(1)),
new Request(RequestType.DEPOSIT, Bytes.of(1)),
new Request(RequestType.WITHDRAWAL, Bytes.EMPTY));
PayloadWrapper payload =
new PayloadWrapper(payloadIdentifier, block, Optional.of(unorderedRequests));

when(mergeContext.retrievePayloadById(payloadIdentifier)).thenReturn(Optional.of(payload));

final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), payloadIdentifier);
assertThat(resp).isInstanceOf(JsonRpcSuccessResponse.class);

final List<String> expectedRequests =
List.of(
Bytes.concatenate(Bytes.of(RequestType.DEPOSIT.getSerializedType()), Bytes.of(1))
.toHexString(),
Bytes.concatenate(Bytes.of(RequestType.CONSOLIDATION.getSerializedType()), Bytes.of(1))
.toHexString());
Optional.of(resp)
.map(JsonRpcSuccessResponse.class::cast)
.ifPresent(
r -> {
assertThat(r.getResult()).isInstanceOf(EngineGetPayloadResultV4.class);
final EngineGetPayloadResultV4 res = (EngineGetPayloadResultV4) r.getResult();
assertThat(res.getExecutionRequests()).isEqualTo(expectedRequests);
});
}

@Test
public void shouldReturnUnsupportedFork() {
final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), mockPid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ protected JsonRpcResponse resp(final EnginePayloadParameter payload) {
final List<String> requestsWithoutRequestId =
VALID_REQUESTS.stream()
.sorted(Comparator.comparing(Request::getType))
.map(r -> r.getData().toHexString())
.map(
r ->
Bytes.concatenate(Bytes.of(r.getType().getSerializedType()), r.getData())
.toHexString())
.toList();
Object[] params =
maybeParentBeaconBlockRoot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@
"method": "eth_call",
"params": [
{
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"data": "0x12a7b914"
"comment": "Call to ECREC Precompiled on a different address, expect the original behaviour of ECREC precompile",
"from": "0xc100000000000000000000000000000000000000",
"to": "0x0000000000000000000000000000000000123456",
"input": "0x82f3df49d3645876de6313df2bbe9fbce593f21341a7b03acdb9423bc171fcc9000000000000000000000000000000000000000000000000000000000000001cba13918f50da910f2d55a7ea64cf716ba31dad91856f45908dde900530377d8a112d60f36900d18eb8f9d3b4f85a697b545085614509e3520e4b762e35d0d6bd"
},
"latest",
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"0xc100000000000000000000000000000000000000": {
"balance": "0xde0b6b3a7640000",
"nonce": 88
},
"0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": {
"stateDiff": {
"0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7"
},
"movePrecompileToAddress":null
"0x0000000000000000000000000000000000000001": {
"comment": "Move ECREC Precompiled to address",
"code": "0x60003560010160005260206000f3",
"movePrecompileToAddress": "0x0000000000000000000000000000000000123456"
}
}
]
},
"response": {
"jsonrpc": "2.0",
"id": 3,
"result": "0x0000000000000000000000000000000000000000000000000000000000000001"
"comment": "The original ECREC precompile behaviour is expected, not the overridden one",
"result": "0x000000000000000000000000c6e93f4c1920eaeaa1e699f76a7a8c18e3056074"
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"request": {
"id": 3,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f",
"from": "a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"data": "0x12a7b914"
},
"latest",
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0xde0b6b3a7640000",
"nonce": 88
},
"0xb9741079a300Cb3B8f324CdDB847c0d1d273a05E": {
"stateDiff": {
"0x1cf7945003fc5b59d2f6736f0704557aa805c4f2844084ccd1173b8d56946962": "0x000000000000000000000000000000000000000000000000000000110ed03bf7"
},
"movePrecompileToAddress":null
}
}
]
},
"response": {
"jsonrpc": "2.0",
"id": 3,
"result": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"statusCode": 200
}
Loading

0 comments on commit d1f77b0

Please sign in to comment.