Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-rocksdb-version-from-8-0-0_to-8-3-2
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarla authored Sep 7, 2023
2 parents 730289e + b74d392 commit f7fb396
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you have any questions, queries or comments, [Besu channel on Hyperledger Dis

## Besu Users

To install the Besu binary, follow [these instructions](https://besu.hyperledger.org/HowTo/Get-Started/Install-Binaries/).
To install the Besu binary, follow [these instructions](https://besu.hyperledger.org/public-networks/get-started/install/binary-distribution).

## Besu Developers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ public PayloadIdentifier preparePayload(

final PayloadIdentifier payloadIdentifier =
PayloadIdentifier.forPayloadParams(
parentHeader.getBlockHash(), timestamp, prevRandao, feeRecipient, withdrawals);
parentHeader.getBlockHash(),
timestamp,
prevRandao,
feeRecipient,
withdrawals,
parentBeaconBlockRoot);

if (blockCreationTasks.containsKey(payloadIdentifier)) {
LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ public PayloadIdentifier(final Long payloadId) {
* @param prevRandao the prev randao
* @param feeRecipient the fee recipient
* @param withdrawals the withdrawals
* @param parentBeaconBlockRoot the parent beacon block root
* @return the payload identifier
*/
public static PayloadIdentifier forPayloadParams(
final Hash parentHash,
final Long timestamp,
final Bytes32 prevRandao,
final Address feeRecipient,
final Optional<List<Withdrawal>> withdrawals) {
final Optional<List<Withdrawal>> withdrawals,
final Optional<Bytes32> parentBeaconBlockRoot) {

return new PayloadIdentifier(
timestamp
Expand All @@ -84,7 +86,8 @@ public static PayloadIdentifier forPayloadParams(
.sorted(Comparator.comparing(Withdrawal::getIndex))
.map(Withdrawal::hashCode)
.reduce(1, (a, b) -> a ^ (b * 31)))
.orElse(0));
.orElse(0)
^ ((long) parentBeaconBlockRoot.hashCode()) << 40);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public void serializesToEvenHexRepresentation() {
public void conversionCoverage() {
var idTest =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, Bytes32.random(), Address.fromHexString("0x42"), Optional.empty());
Hash.ZERO,
1337L,
Bytes32.random(),
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());
assertThat(new PayloadIdentifier(idTest.getAsBigInteger().longValue())).isEqualTo(idTest);
assertThat(new PayloadIdentifier(idTest.getAsBigInteger().longValue())).isEqualTo(idTest);
}
Expand Down Expand Up @@ -82,10 +87,20 @@ public void differentWithdrawalAmountsYieldDifferentHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForWithdrawals1 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals1));
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.of(withdrawals1),
Optional.empty());
var idForWithdrawals2 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals2));
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.of(withdrawals2),
Optional.empty());
assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2);
}

Expand Down Expand Up @@ -118,10 +133,20 @@ public void differentOrderedWithdrawalsYieldSameHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForWithdrawals1 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals1));
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.of(withdrawals1),
Optional.empty());
var idForWithdrawals2 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals2));
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.of(withdrawals2),
Optional.empty());
assertThat(idForWithdrawals1).isEqualTo(idForWithdrawals2);
}

Expand All @@ -130,10 +155,64 @@ public void emptyOptionalAndEmptyListWithdrawalsYieldDifferentHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForWithdrawals1 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.empty());
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());
var idForWithdrawals2 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(emptyList()));
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.of(emptyList()),
Optional.empty());
assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2);
}

@Test
public void emptyOptionalAndNonEmptyParentBeaconBlockRootYieldDifferentHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForWithdrawals1 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());
var idForWithdrawals2 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.empty(),
Optional.of(Bytes32.ZERO));
assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2);
}

@Test
public void differentParentBeaconBlockRootYieldDifferentHash() {
final Bytes32 prevRandao = Bytes32.random();
var idForWithdrawals1 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.empty(),
Optional.of(Bytes32.fromHexStringLenient("0x1")));
var idForWithdrawals2 =
PayloadIdentifier.forPayloadParams(
Hash.ZERO,
1337L,
prevRandao,
Address.fromHexString("0x42"),
Optional.empty(),
Optional.of(Bytes32.ZERO));
assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,24 @@ public class Address extends DelegatingBytes {
public static final Address BLAKE2B_F_COMPRESSION = Address.precompiled(0x09);
/** The constant KZG_POINT_EVAL aka POINT_EVALUATION_PRECOMPILE_ADDRESS. */
public static final Address KZG_POINT_EVAL = Address.precompiled(0xA);
/** The constant PARENT_BEACON_BLOCK_ROOT_REGISTRY aka HISTORY_STORAGE_ADDRESS. */
public static final Address PARENT_BEACON_BLOCK_ROOT_REGISTRY = Address.precompiled(0xB);
// TODO: this is not a precompile anymore. The address is correct for testnet 8. Fix after testnet
// 8 when we know what the real address is
/** The constant BLS12_G1ADD. */
public static final Address BLS12_G1ADD = Address.precompiled(0xC);
public static final Address BLS12_G1ADD = Address.precompiled(0xB);
/** The constant BLS12_G1MUL. */
public static final Address BLS12_G1MUL = Address.precompiled(0xD);
public static final Address BLS12_G1MUL = Address.precompiled(0xC);
/** The constant BLS12_G1MULTIEXP. */
public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xE);
public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xD);
/** The constant BLS12_G2ADD. */
public static final Address BLS12_G2ADD = Address.precompiled(0xF);
public static final Address BLS12_G2ADD = Address.precompiled(0xE);
/** The constant BLS12_G2MUL. */
public static final Address BLS12_G2MUL = Address.precompiled(0x10);
public static final Address BLS12_G2MUL = Address.precompiled(0xF);
/** The constant BLS12_G2MULTIEXP. */
public static final Address BLS12_G2MULTIEXP = Address.precompiled(0x11);
public static final Address BLS12_G2MULTIEXP = Address.precompiled(0x10);
/** The constant BLS12_PAIRING. */
public static final Address BLS12_PAIRING = Address.precompiled(0x12);
public static final Address BLS12_PAIRING = Address.precompiled(0x11);
/** The constant BLS12_MAP_FP_TO_G1. */
public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x13);
public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x12);
/** The constant BLS12_MAP_FP2_TO_G2. */
public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x14);
public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x13);
/** The constant ZERO. */
public static final Address ZERO = Address.fromHexString("0x0");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public void shouldReturnValidWithoutFinalizedWithPayload() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
payloadParams.getSuggestedFeeRecipient(),
Optional.empty(),
Optional.empty());

when(mergeCoordinator.preparePayload(
Expand Down Expand Up @@ -518,6 +519,7 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
payloadParams.getSuggestedFeeRecipient(),
Optional.empty(),
Optional.empty());

when(mergeCoordinator.preparePayload(
Expand Down Expand Up @@ -603,7 +605,8 @@ public void shouldReturnValidIfWithdrawalsIsNotNull_WhenWithdrawalsAllowed() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
payloadParams.getSuggestedFeeRecipient(),
withdrawals);
withdrawals,
Optional.empty());

when(mergeCoordinator.preparePayload(
mockHeader,
Expand Down Expand Up @@ -645,6 +648,7 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() {
payloadParams.getTimestamp(),
payloadParams.getPrevRandao(),
payloadParams.getSuggestedFeeRecipient(),
Optional.empty(),
Optional.empty());

when(mergeCoordinator.preparePayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public AbstractEngineGetPayloadTest() {
protected static final BlockResultFactory factory = new BlockResultFactory();
protected static final PayloadIdentifier mockPid =
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 1337L, Bytes32.random(), Address.fromHexString("0x42"), Optional.empty());
Hash.ZERO,
1337L,
Bytes32.random(),
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());
protected static final BlockHeader mockHeader =
new BlockHeaderTestFixture().prevRandao(Bytes32.random()).buildHeader();
private static final Block mockBlock =
Expand Down Expand Up @@ -147,7 +152,12 @@ public void shouldFailForUnknownPayloadId() {
resp(
getMethodName(),
PayloadIdentifier.forPayloadParams(
Hash.ZERO, 0L, Bytes32.random(), Address.fromHexString("0x42"), Optional.empty()));
Hash.ZERO,
0L,
Bytes32.random(),
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty()));
assertThat(resp).isInstanceOf(JsonRpcErrorResponse.class);
verify(engineCallListener, times(1)).executionEngineCalled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void shouldReturnBlockForKnownPayloadId() {
cancunHardfork.milestone(),
Bytes32.random(),
Address.fromHexString("0x42"),
Optional.empty(),
Optional.empty());

BlobTestFixture blobTestFixture = new BlobTestFixture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,21 @@ public class ParentBeaconBlockRootHelper {

// Modulus use to for the timestamp to store the root
public static final long HISTORICAL_ROOTS_MODULUS = 98304;

// Address of the system user, that is used to call the contract for storing the root
// public static final Address SYSTEM_ADDRESS =
// Address.fromHexString("0xfffffffffffffffffffffffffffffffffffffffe");

// The address of the contract that stores the roots
// public static final Address BEACON_ROOTS_ADDRESS =
// Address.fromHexString("0x89e64Be8700cC37EB34f9209c96466DEEDc0d8a6");
public static final Address BEACON_ROOTS_ADDRESS =
Address.fromHexString("0xbEac00dDB15f3B6d645C48263dC93862413A222D");

public static void storeParentBeaconBlockRoot(
final WorldUpdater worldUpdater, final long timestamp, final Bytes32 root) {
/*
pseudo code from EIP 4788:
timestamp_as_uint256 = to_uint256_be(block_header.timestamp)
parent_beacon_block_root = block_header.parent_beacon_block_root
sstore(HISTORY_STORAGE_ADDRESS, timestamp_index, timestamp_as_uint256)
sstore(HISTORY_STORAGE_ADDRESS, root_index, parent_beacon_block_root)
see EIP-4788: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4788.md
*/
final long timestampReduced = timestamp % HISTORICAL_ROOTS_MODULUS;
final long timestampExtended = timestampReduced + HISTORICAL_ROOTS_MODULUS;

final UInt256 timestampIndex = UInt256.valueOf(timestampReduced);
final UInt256 rootIndex = UInt256.valueOf(timestampExtended);

final MutableAccount account =
worldUpdater.getOrCreate(Address.PARENT_BEACON_BLOCK_ROOT_REGISTRY).getMutable();
final MutableAccount account = worldUpdater.getOrCreate(BEACON_ROOTS_ADDRESS).getMutable();
account.setStorageValue(timestampIndex, UInt256.valueOf(timestamp));
account.setStorageValue(rootIndex, UInt256.fromBytes(root));
worldUpdater.commit();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=23.7.2-SNAPSHOT
version=23.7.3-SNAPSHOT

org.gradle.welcome=never
# Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396)
Expand Down

0 comments on commit f7fb396

Please sign in to comment.