Rename field random to prevRandao (#3495)

* rename field random to prevRandao

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
pull/3502/head
Daniel Lehrner 3 years ago committed by GitHub
parent db232418c2
commit d2a413b61b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdated.java
  2. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayload.java
  3. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java
  4. 16
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadParameter.java
  5. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/EngineGetPayloadResult.java
  6. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedTest.java
  7. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadTest.java
  8. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadTest.java
  9. 18
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java
  10. 26
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java
  11. 35
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java
  12. 18
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java
  13. 14
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java
  14. 10
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockHeaderTestFixture.java
  15. 12
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/operations/PrevRanDaoOperationTest.java
  16. 8
      evm/src/main/java/org/hyperledger/besu/evm/frame/BlockValues.java
  17. 2
      evm/src/main/java/org/hyperledger/besu/evm/operation/PrevRanDaoOperation.java
  18. 2
      plugin-api/build.gradle
  19. 6
      plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java

@ -102,7 +102,7 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
mergeCoordinator.preparePayload(
currentHead.get(),
payloadAttributes.getTimestamp(),
payloadAttributes.getRandom(),
payloadAttributes.getPrevRandao(),
payloadAttributes.getSuggestedFeeRecipient()));
payloadId.ifPresent(

@ -120,7 +120,7 @@ public class EngineNewPayload extends ExecutionEngineJsonRpcMethod {
blockParam.getTimestamp(),
Bytes.fromHexString(blockParam.getExtraData()),
blockParam.getBaseFeePerGas(),
blockParam.getRandom(),
blockParam.getPrevRandao(),
0,
headerFunctions);

@ -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();
}

@ -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<String> 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<String> getTransactions() {

@ -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")

@ -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 =

@ -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(""));
});
}

@ -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);
}

@ -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<List<Transaction>> maybeTransactions,
final Optional<List<BlockHeader>> maybeOmmers,
final Optional<Bytes32> maybeRandom,
final Optional<Bytes32> 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<Bytes32> maybeRandom) {
final long timestamp, final Optional<Bytes32> 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();
}

@ -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<LogsBloomFilter> 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);
}

@ -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;
}

@ -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<Bytes32> getRandom() {
return Optional.ofNullable(mixHashOrRandom);
public Optional<Bytes32> getPrevRandao() {
return Optional.ofNullable(mixHashOrPrevRandao);
}
}

@ -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;

@ -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<Wei> baseFee = Optional.empty();
private Optional<Bytes32> random = Optional.empty();
private Optional<Bytes32> 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;
}

@ -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);

@ -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;
}

@ -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());
}

@ -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')

@ -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<Bytes32> getRandom() {
default Optional<Bytes32> getPrevRandao() {
return Optional.empty();
}
}

Loading…
Cancel
Save