From d2a413b61b7effa609cb093bfb537682dd18904b Mon Sep 17 00:00:00 2001 From: Daniel Lehrner Date: Fri, 25 Feb 2022 11:41:07 +0100 Subject: [PATCH] Rename field random to prevRandao (#3495) * rename field random to prevRandao Signed-off-by: Daniel Lehrner --- .../engine/EngineForkchoiceUpdated.java | 2 +- .../methods/engine/EngineNewPayload.java | 2 +- .../EnginePayloadAttributesParameter.java | 12 +++---- .../parameters/EnginePayloadParameter.java | 16 ++++----- .../results/EngineGetPayloadResult.java | 12 +++---- .../engine/EngineForkchoiceUpdatedTest.java | 2 +- .../methods/engine/EngineGetPayloadTest.java | 6 ++-- .../methods/engine/EngineNewPayloadTest.java | 2 +- .../blockcreation/AbstractBlockCreator.java | 18 +++++----- .../besu/ethereum/core/BlockHeader.java | 26 +++++++------- .../ethereum/core/BlockHeaderBuilder.java | 35 +++++++++++-------- .../ethereum/core/ProcessableBlockHeader.java | 18 +++++----- .../ethereum/core/SealableBlockHeader.java | 14 ++++++-- .../ethereum/core/BlockHeaderTestFixture.java | 10 +++--- .../operations/PrevRanDaoOperationTest.java | 12 +++---- .../besu/evm/frame/BlockValues.java | 8 ++--- .../evm/operation/PrevRanDaoOperation.java | 2 +- plugin-api/build.gradle | 2 +- .../besu/plugin/data/BlockHeader.java | 6 ++-- 19 files changed, 110 insertions(+), 95 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java index 844c39ddc8..31b727dce5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java @@ -102,7 +102,7 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod { mergeCoordinator.preparePayload( currentHead.get(), payloadAttributes.getTimestamp(), - payloadAttributes.getRandom(), + payloadAttributes.getPrevRandao(), payloadAttributes.getSuggestedFeeRecipient())); payloadId.ifPresent( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java index 485c19a232..2831b74e15 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java @@ -120,7 +120,7 @@ public class EngineNewPayload extends ExecutionEngineJsonRpcMethod { blockParam.getTimestamp(), Bytes.fromHexString(blockParam.getExtraData()), blockParam.getBaseFeePerGas(), - blockParam.getRandom(), + blockParam.getPrevRandao(), 0, headerFunctions); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java index 17acceda14..e9c2379c04 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java @@ -24,16 +24,16 @@ import org.apache.tuweni.bytes.Bytes32; public class EnginePayloadAttributesParameter { final Long timestamp; - final Bytes32 random; + final Bytes32 prevRandao; final Address suggestedFeeRecipient; @JsonCreator public EnginePayloadAttributesParameter( @JsonProperty("timestamp") final String timestamp, - @JsonProperty("random") final String random, + @JsonProperty("prevRandao") final String prevRandao, @JsonProperty("suggestedFeeRecipient") final String suggestedFeeRecipient) { this.timestamp = Long.decode(timestamp); - this.random = Bytes32.fromHexString(random); + this.prevRandao = Bytes32.fromHexString(prevRandao); this.suggestedFeeRecipient = Address.fromHexString(suggestedFeeRecipient); } @@ -41,8 +41,8 @@ public class EnginePayloadAttributesParameter { return timestamp; } - public Bytes32 getRandom() { - return random; + public Bytes32 getPrevRandao() { + return prevRandao; } public Address getSuggestedFeeRecipient() { @@ -52,7 +52,7 @@ public class EnginePayloadAttributesParameter { public String serialize() { return new JsonObject() .put("timestamp", timestamp) - .put("random", random.toHexString()) + .put("prevRandao", prevRandao.toHexString()) .put("suggestedFeeRecipient", suggestedFeeRecipient.toHexString()) .encode(); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadParameter.java index 1cebeb001f..15f9b5d074 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadParameter.java @@ -27,9 +27,9 @@ import org.apache.tuweni.bytes.Bytes32; /** * parentHash: DATA, 32 Bytes feeRecipient: DATA, 20 Bytes stateRoot: DATA, 32 Bytes receiptsRoot: - * DATA, 32 Bytes logsBloom: DATA, 256 Bytes random: DATA, 32 Bytes blockNumber: QUANTITY gasLimit: - * QUANTITY gasUsed: QUANTITY timestamp: QUANTITY baseFeePerGas: QUANTITY blockHash: DATA, 32 Bytes - * transactions: Array of TypedTransaction + * DATA, 32 Bytes logsBloom: DATA, 256 Bytes prevRandao: DATA, 32 Bytes blockNumber: QUANTITY + * gasLimit: QUANTITY gasUsed: QUANTITY timestamp: QUANTITY baseFeePerGas: QUANTITY blockHash: DATA, + * 32 Bytes transactions: Array of TypedTransaction */ public class EnginePayloadParameter { private final Hash blockHash; @@ -37,7 +37,7 @@ public class EnginePayloadParameter { private final Address feeRecipient; private final Hash stateRoot; private final long blockNumber; - private final Bytes32 random; + private final Bytes32 prevRandao; private final Wei baseFeePerGas; private final long gasLimit; private final long gasUsed; @@ -61,7 +61,7 @@ public class EnginePayloadParameter { @JsonProperty("extraData") final String extraData, @JsonProperty("receiptRoot") final Hash receiptsRoot, @JsonProperty("logsBloom") final LogsBloomFilter logsBloom, - @JsonProperty("random") final String random, + @JsonProperty("prevRandao") final String prevRandao, @JsonProperty("transactions") final List transactions) { this.blockHash = blockHash; this.parentHash = parentHash; @@ -75,7 +75,7 @@ public class EnginePayloadParameter { this.extraData = extraData; this.receiptsRoot = receiptsRoot; this.logsBloom = logsBloom; - this.random = Bytes32.fromHexString(random); + this.prevRandao = Bytes32.fromHexString(prevRandao); this.transactions = transactions; } @@ -127,8 +127,8 @@ public class EnginePayloadParameter { return logsBloom; } - public Bytes32 getRandom() { - return random; + public Bytes32 getPrevRandao() { + return prevRandao; } public List getTransactions() { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadResult.java index 99088cc897..384c4875cb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadResult.java @@ -30,7 +30,7 @@ import org.apache.tuweni.bytes.Bytes32; "stateRoot", "receiptsRoot", "logsBloom", - "random", + "prevRandao", "blockNumber", "gasLimit", "gasUsed", @@ -46,7 +46,7 @@ public class EngineGetPayloadResult { private final String stateRoot; private final String receiptsRoot; private final String logsBloom; - private final String random; + private final String prevRandao; private final String blockNumber; private final String gasLimit; private final String gasUsed; @@ -69,7 +69,7 @@ public class EngineGetPayloadResult { this.timestamp = Quantity.create(header.getTimestamp()); this.transactions = transactions; this.feeRecipient = header.getCoinbase().toString(); - this.random = header.getRandom().map(Bytes32::toHexString).orElse(null); + this.prevRandao = header.getPrevRandao().map(Bytes32::toHexString).orElse(null); } @JsonGetter(value = "blockNumber") @@ -92,9 +92,9 @@ public class EngineGetPayloadResult { return logsBloom; } - @JsonGetter(value = "random") - public String getRandom() { - return random; + @JsonGetter(value = "prevRandao") + public String getPrevRandao() { + return prevRandao; } @JsonGetter(value = "stateRoot") diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java index e4cf6547da..909244399c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java @@ -155,7 +155,7 @@ public class EngineForkchoiceUpdatedTest { PayloadIdentifier.forPayloadParams(mockHeader.getHash(), payloadParams.getTimestamp()); when(mergeCoordinator.preparePayload( - mockHeader, payloadParams.getTimestamp(), payloadParams.getRandom(), Address.ECREC)) + mockHeader, payloadParams.getTimestamp(), payloadParams.getPrevRandao(), Address.ECREC)) .thenReturn(mockPayloadId); var res = diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadTest.java index c6b4ff5026..3c1ee216f4 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadTest.java @@ -55,7 +55,7 @@ public class EngineGetPayloadTest { private static final PayloadIdentifier mockPid = PayloadIdentifier.forPayloadParams(Hash.ZERO, 1337L); private static final BlockHeader mockHeader = - new BlockHeaderTestFixture().random(Bytes32.random()).buildHeader(); + new BlockHeaderTestFixture().prevRandao(Bytes32.random()).buildHeader(); private static final Block mockBlock = new Block(mockHeader, new BlockBody(Collections.emptyList(), Collections.emptyList())); @@ -87,8 +87,8 @@ public class EngineGetPayloadTest { assertThat(r.getResult()).isInstanceOf(EngineGetPayloadResult.class); EngineGetPayloadResult res = (EngineGetPayloadResult) r.getResult(); assertThat(res.getHash()).isEqualTo(mockHeader.getHash().toString()); - assertThat(res.getRandom()) - .isEqualTo(mockHeader.getRandom().map(Bytes32::toString).orElse("")); + assertThat(res.getPrevRandao()) + .isEqualTo(mockHeader.getPrevRandao().map(Bytes32::toString).orElse("")); }); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java index 623ecd0518..ad2c5f184e 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java @@ -284,7 +284,7 @@ public class EngineNewPayloadTest { header.getExtraData() == null ? null : header.getExtraData().toHexString(), header.getReceiptsRoot(), header.getLogsBloom(), - header.getRandom().map(Bytes32::toHexString).orElse("0x0"), + header.getPrevRandao().map(Bytes32::toHexString).orElse("0x0"), txs); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java index 07e58b3a1f..71efee2a63 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -146,12 +146,12 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { protected Block createBlock( final Optional> maybeTransactions, final Optional> maybeOmmers, - final Optional maybeRandom, + final Optional maybePrevRandao, final long timestamp, boolean rewardCoinbase) { try { final ProcessableBlockHeader processableBlockHeader = - createPendingBlockHeader(timestamp, maybeRandom); + createPendingBlockHeader(timestamp, maybePrevRandao); throwIfStopped(); @@ -168,7 +168,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { throwIfStopped(); - final ProtocolSpec protocolSpec = + final ProtocolSpec newProtocolSpec = protocolSchedule.getByBlockNumber(processableBlockHeader.getNumber()); if (rewardCoinbase @@ -176,8 +176,8 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { disposableWorldState, processableBlockHeader, ommers, - protocolSpec.getBlockReward(), - protocolSpec.isSkipZeroBlockRewards())) { + newProtocolSpec.getBlockReward(), + newProtocolSpec.isSkipZeroBlockRewards())) { LOG.trace("Failed to apply mining reward, exiting."); throw new RuntimeException("Failed to apply mining reward."); } @@ -268,7 +268,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { } private ProcessableBlockHeader createPendingBlockHeader( - final long timestamp, final Optional maybeRandom) { + final long timestamp, final Optional maybePrevRandao) { final long newBlockNumber = parentHeader.getNumber() + 1; long gasLimit = protocolSpec @@ -295,7 +295,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { feeMarket.targetGasUsed(parentHeader))) .orElse(null); - final Bytes32 random = maybeRandom.orElse(null); + final Bytes32 prevRandao = maybePrevRandao.orElse(null); return BlockHeaderBuilder.create() .parentHash(parentHeader.getHash()) .coinbase(coinbase) @@ -304,7 +304,7 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator { .gasLimit(gasLimit) .timestamp(timestamp) .baseFee(baseFee) - .random(random) + .prevRandao(prevRandao) .buildProcessableBlockHeader(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java index 4f2798aa43..5fed4dfb2e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -60,7 +60,7 @@ public class BlockHeader extends SealableBlockHeader final long timestamp, final Bytes extraData, final Wei baseFee, - final Bytes32 mixHashOrRandom, + final Bytes32 mixHashOrPrevRandao, final long nonce, final BlockHeaderFunctions blockHeaderFunctions, final Optional privateLogsBloom) { @@ -79,7 +79,7 @@ public class BlockHeader extends SealableBlockHeader timestamp, extraData, baseFee, - mixHashOrRandom); + mixHashOrPrevRandao); this.nonce = nonce; this.hash = Suppliers.memoize(() -> blockHeaderFunctions.hash(this)); this.parsedExtraData = Suppliers.memoize(() -> blockHeaderFunctions.parseExtraData(this)); @@ -101,7 +101,7 @@ public class BlockHeader extends SealableBlockHeader final long timestamp, final Bytes extraData, final Wei baseFee, - final Bytes32 mixHashOrRandom, + final Bytes32 mixHashOrPrevRandao, final long nonce, final BlockHeaderFunctions blockHeaderFunctions) { super( @@ -119,7 +119,7 @@ public class BlockHeader extends SealableBlockHeader timestamp, extraData, baseFee, - mixHashOrRandom); + mixHashOrPrevRandao); this.nonce = nonce; this.hash = Suppliers.memoize(() -> blockHeaderFunctions.hash(this)); this.parsedExtraData = Suppliers.memoize(() -> blockHeaderFunctions.parseExtraData(this)); @@ -133,12 +133,12 @@ public class BlockHeader extends SealableBlockHeader */ @Override public Hash getMixHash() { - return Hash.wrap(mixHashOrRandom); + return Hash.wrap(mixHashOrPrevRandao); } @Override - public Bytes32 getMixHashOrRandom() { - return mixHashOrRandom; + public Bytes32 getMixHashOrPrevRandao() { + return mixHashOrPrevRandao; } /** @@ -220,7 +220,7 @@ public class BlockHeader extends SealableBlockHeader out.writeLongScalar(gasUsed); out.writeLongScalar(timestamp); out.writeBytes(extraData); - out.writeBytes(mixHashOrRandom); + out.writeBytes(mixHashOrPrevRandao); out.writeLong(nonce); if (baseFee != null) { out.writeUInt256Scalar(baseFee); @@ -244,7 +244,7 @@ public class BlockHeader extends SealableBlockHeader final long gasUsed = input.readLongScalar(); final long timestamp = input.readLongScalar(); final Bytes extraData = input.readBytes(); - final Bytes32 mixHashOrRandom = input.readBytes32(); + final Bytes32 mixHashOrPrevRandao = input.readBytes32(); final long nonce = input.readLong(); final Wei baseFee = !input.isEndOfCurrentList() ? Wei.of(input.readUInt256Scalar()) : null; input.leaveList(); @@ -263,7 +263,7 @@ public class BlockHeader extends SealableBlockHeader timestamp, extraData, baseFee, - mixHashOrRandom, + mixHashOrPrevRandao, nonce, blockHeaderFunctions); } @@ -304,7 +304,7 @@ public class BlockHeader extends SealableBlockHeader sb.append("timestamp=").append(timestamp).append(", "); sb.append("extraData=").append(extraData).append(", "); sb.append("baseFee=").append(baseFee).append(", "); - sb.append("mixHashOrRandom=").append(mixHashOrRandom).append(", "); + sb.append("mixHashOrPrevRandao=").append(mixHashOrPrevRandao).append(", "); sb.append("nonce=").append(nonce); return sb.append("}").toString(); } @@ -327,7 +327,7 @@ public class BlockHeader extends SealableBlockHeader pluginBlockHeader.getTimestamp(), pluginBlockHeader.getExtraData(), pluginBlockHeader.getBaseFee().map(Wei::fromQuantity).orElse(null), - pluginBlockHeader.getRandom().orElse(null), + pluginBlockHeader.getPrevRandao().orElse(null), pluginBlockHeader.getNonce(), blockHeaderFunctions); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java index 24b946aacd..d285b77884 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -60,7 +60,7 @@ public class BlockHeaderBuilder { private Wei baseFee = null; - private Bytes32 mixHashOrRandom = null; + private Bytes32 mixHashOrPrevRandao = null; private BlockHeaderFunctions blockHeaderFunctions; @@ -90,7 +90,7 @@ public class BlockHeaderBuilder { .baseFee(header.getBaseFee().orElse(null)) .mixHash(header.getMixHash()) .nonce(header.getNonce()) - .random(header.getRandom().orElse(null)); + .prevRandao(header.getPrevRandao().orElse(null)); } public static BlockHeaderBuilder fromBuilder(final BlockHeaderBuilder fromBuilder) { @@ -110,7 +110,7 @@ public class BlockHeaderBuilder { .timestamp(fromBuilder.timestamp) .extraData(fromBuilder.extraData) .baseFee(fromBuilder.baseFee) - .random(fromBuilder.mixHashOrRandom) + .prevRandao(fromBuilder.mixHashOrPrevRandao) .blockHeaderFunctions(fromBuilder.blockHeaderFunctions); toBuilder.nonce = fromBuilder.nonce; return toBuilder; @@ -134,7 +134,7 @@ public class BlockHeaderBuilder { timestamp < 0 ? Instant.now().getEpochSecond() : timestamp, extraData, baseFee, - mixHashOrRandom, + mixHashOrPrevRandao, nonce.getAsLong(), blockHeaderFunctions); } @@ -143,7 +143,14 @@ public class BlockHeaderBuilder { validateProcessableBlockHeader(); return new ProcessableBlockHeader( - parentHash, coinbase, difficulty, number, gasLimit, timestamp, baseFee, mixHashOrRandom); + parentHash, + coinbase, + difficulty, + number, + gasLimit, + timestamp, + baseFee, + mixHashOrPrevRandao); } public SealableBlockHeader buildSealableBlockHeader() { @@ -164,12 +171,12 @@ public class BlockHeaderBuilder { timestamp, extraData, baseFee, - mixHashOrRandom); + mixHashOrPrevRandao); } private void validateBlockHeader() { validateSealableBlockHeader(); - checkState(this.mixHashOrRandom != null, "Missing mixHash or random"); + checkState(this.mixHashOrPrevRandao != null, "Missing mixHash or prevRandao"); checkState(this.nonce.isPresent(), "Missing nonce"); checkState(this.blockHeaderFunctions != null, "Missing blockHeaderFunctions"); } @@ -203,7 +210,7 @@ public class BlockHeaderBuilder { gasLimit(processableBlockHeader.getGasLimit()); timestamp(processableBlockHeader.getTimestamp()); baseFee(processableBlockHeader.getBaseFee().orElse(null)); - processableBlockHeader.getRandom().ifPresent(this::random); + processableBlockHeader.getPrevRandao().ifPresent(this::prevRandao); return this; } @@ -223,7 +230,7 @@ public class BlockHeaderBuilder { timestamp(sealableBlockHeader.getTimestamp()); extraData(sealableBlockHeader.getExtraData()); baseFee(sealableBlockHeader.getBaseFee().orElse(null)); - sealableBlockHeader.getRandom().ifPresent(this::random); + sealableBlockHeader.getPrevRandao().ifPresent(this::prevRandao); return this; } @@ -308,7 +315,7 @@ public class BlockHeaderBuilder { public BlockHeaderBuilder mixHash(final Hash mixHash) { checkNotNull(mixHash); - this.mixHashOrRandom = mixHash; + this.mixHashOrPrevRandao = mixHash; return this; } @@ -327,9 +334,9 @@ public class BlockHeaderBuilder { return this; } - public BlockHeaderBuilder random(final Bytes32 random) { - if (random != null) { - this.mixHashOrRandom = random; + public BlockHeaderBuilder prevRandao(final Bytes32 prevRandao) { + if (prevRandao != null) { + this.mixHashOrPrevRandao = prevRandao; } return this; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java index 0ee9016478..de85ab52c0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -41,8 +41,8 @@ public class ProcessableBlockHeader implements BlockValues { protected final long timestamp; // base fee is included for post EIP-1559 blocks protected final Wei baseFee; - // random is included for post-merge blocks - protected final Bytes32 mixHashOrRandom; + // prevRandao is included for post-merge blocks + protected final Bytes32 mixHashOrPrevRandao; protected ProcessableBlockHeader( final Hash parentHash, @@ -52,7 +52,7 @@ public class ProcessableBlockHeader implements BlockValues { final long gasLimit, final long timestamp, final Wei baseFee, - final Bytes32 mixHashOrRandom) { + final Bytes32 mixHashOrPrevRandao) { this.parentHash = parentHash; this.coinbase = coinbase; this.difficulty = difficulty; @@ -60,7 +60,7 @@ public class ProcessableBlockHeader implements BlockValues { this.gasLimit = gasLimit; this.timestamp = timestamp; this.baseFee = baseFee; - this.mixHashOrRandom = mixHashOrRandom; + this.mixHashOrPrevRandao = mixHashOrPrevRandao; } /** @@ -141,11 +141,11 @@ public class ProcessableBlockHeader implements BlockValues { } /** - * Returns the random of the block. + * Returns the prevRandao of the block. * - * @return the raw bytes of the random field + * @return the raw bytes of the prevRandao field */ - public Optional getRandom() { - return Optional.ofNullable(mixHashOrRandom); + public Optional getPrevRandao() { + return Optional.ofNullable(mixHashOrPrevRandao); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java index 3440a9b24c..07a9e8ba0d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -53,8 +53,16 @@ public class SealableBlockHeader extends ProcessableBlockHeader { final long timestamp, final Bytes extraData, final Wei baseFee, - final Bytes32 mixHashOrRandom) { - super(parentHash, coinbase, difficulty, number, gasLimit, timestamp, baseFee, mixHashOrRandom); + final Bytes32 mixHashOrPrevRandao) { + super( + parentHash, + coinbase, + difficulty, + number, + gasLimit, + timestamp, + baseFee, + mixHashOrPrevRandao); this.ommersHash = ommersHash; this.stateRoot = stateRoot; this.transactionsRoot = transactionsRoot; diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java index ae66dde0b7..2e70c8bae6 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -41,7 +41,7 @@ public class BlockHeaderTestFixture { private long gasLimit = 0; private Optional baseFee = Optional.empty(); - private Optional random = Optional.empty(); + private Optional prevRandao = Optional.empty(); private long gasUsed = 0; private long timestamp = 0; private Bytes extraData = Bytes.EMPTY; @@ -64,7 +64,7 @@ public class BlockHeaderTestFixture { builder.gasLimit(gasLimit); builder.gasUsed(gasUsed); baseFee.ifPresent(builder::baseFee); - random.ifPresent((builder::random)); + prevRandao.ifPresent((builder::prevRandao)); builder.timestamp(timestamp); builder.extraData(extraData); builder.mixHash(mixHash); @@ -134,8 +134,8 @@ public class BlockHeaderTestFixture { return this; } - public BlockHeaderTestFixture random(final Bytes32 random) { - this.random = Optional.ofNullable(random); + public BlockHeaderTestFixture prevRandao(final Bytes32 prevRandao) { + this.prevRandao = Optional.ofNullable(prevRandao); return this; } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/operations/PrevRanDaoOperationTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/operations/PrevRanDaoOperationTest.java index 8633adc004..b4d5558637 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/operations/PrevRanDaoOperationTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/operations/PrevRanDaoOperationTest.java @@ -34,18 +34,18 @@ import org.junit.Test; public class PrevRanDaoOperationTest { @Test - public void pushesRandWhenDifficultyZero() { + public void pushesPrevRandaoWhenDifficultyZero() { PrevRanDaoOperation op = new PrevRanDaoOperation(new LondonGasCalculator()); MessageFrame messageFrame = mock(MessageFrame.class); BlockValues blockHeader = mock(BlockValues.class); - Bytes32 rand = Bytes32.fromHexString("0xb0b0face"); + Bytes32 prevRandao = Bytes32.fromHexString("0xb0b0face"); when(blockHeader.getDifficultyBytes()).thenReturn(UInt256.ZERO); - when(blockHeader.getMixHashOrRandom()).thenReturn(rand); + when(blockHeader.getMixHashOrPrevRandao()).thenReturn(prevRandao); when(messageFrame.getBlockValues()).thenReturn(blockHeader); EVM evm = mock(EVM.class); Operation.OperationResult r = op.executeFixedCostOperation(messageFrame, evm); assertThat(r.getHaltReason()).isNotPresent(); - verify(messageFrame).pushStackItem(rand); + verify(messageFrame).pushStackItem(prevRandao); } @Test @@ -53,10 +53,10 @@ public class PrevRanDaoOperationTest { PrevRanDaoOperation op = new PrevRanDaoOperation(new LondonGasCalculator()); MessageFrame messageFrame = mock(MessageFrame.class); BlockValues blockHeader = mock(BlockValues.class); - Bytes32 rand = Bytes32.fromHexString("0xb0b0face"); + Bytes32 prevRandao = Bytes32.fromHexString("0xb0b0face"); Bytes difficulty = Bytes.random(32); when(blockHeader.getDifficultyBytes()).thenReturn(difficulty); - when(blockHeader.getMixHashOrRandom()).thenReturn(rand); + when(blockHeader.getMixHashOrPrevRandao()).thenReturn(prevRandao); when(messageFrame.getBlockValues()).thenReturn(blockHeader); EVM evm = mock(EVM.class); Operation.OperationResult r = op.executeFixedCostOperation(messageFrame, evm); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/frame/BlockValues.java b/evm/src/main/java/org/hyperledger/besu/evm/frame/BlockValues.java index 1e093081e7..74db00274a 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/frame/BlockValues.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/frame/BlockValues.java @@ -1,5 +1,5 @@ /* - * Copyright contributors to Hyperledger Besu + * Copyright Hyperledger Besu Contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -37,11 +37,11 @@ public interface BlockValues { } /** - * Returns the mixHash before merge, and the randao value after + * Returns the mixHash before merge, and the prevRandao value after * - * @return the mixHash before merge, and the randao value after + * @return the mixHash before merge, and the prevRandao value after */ - default Bytes32 getMixHashOrRandom() { + default Bytes32 getMixHashOrPrevRandao() { return null; } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/PrevRanDaoOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/PrevRanDaoOperation.java index 638946fddd..4227c646f3 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/PrevRanDaoOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/PrevRanDaoOperation.java @@ -30,7 +30,7 @@ public class PrevRanDaoOperation extends AbstractFixedCostOperation { public OperationResult executeFixedCostOperation(final MessageFrame frame, final EVM evm) { if (frame.getBlockValues().getDifficultyBytes() == null || frame.getBlockValues().getDifficultyBytes().equals(UInt256.ZERO)) { - frame.pushStackItem(frame.getBlockValues().getMixHashOrRandom()); + frame.pushStackItem(frame.getBlockValues().getMixHashOrPrevRandao()); } else { frame.pushStackItem(frame.getBlockValues().getDifficultyBytes()); } diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 83a3bfc907..d4588ad028 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -64,7 +64,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'pDLQUs2Gl9hFV1ecKSacbbfwovrjMf/IBPiY1zkOZlI=' + knownHash = 'hRHEr0UjfMKObN5VFIHk9GgcYlcEsEXEYfj0qVl5XQk=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java index d4dd4c0d69..6e7e39aabf 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java @@ -171,11 +171,11 @@ public interface BlockHeader { } /** - * Optional 32 bytes of random data. + * Optional 32 bytes of prevRandao data. * - * @return Optional random bytes from this header. + * @return Optional prevRandao bytes from this header. */ - default Optional getRandom() { + default Optional getPrevRandao() { return Optional.empty(); } }