clean up the ProcessableBlockHeader (#6117)

* clean up

Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
pull/6135/head
Stefan Pingel 1 year ago committed by GitHub
parent cea3d8a71a
commit 646c5a3bc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java
  2. 12
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeader.java
  3. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/BlockHeaderBuilder.java
  4. 30
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/ProcessableBlockHeader.java
  5. 26
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/SealableBlockHeader.java
  6. 2
      ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestEnv.java
  7. 2
      plugin-api/build.gradle
  8. 81
      plugin-api/src/main/java/org/hyperledger/besu/plugin/data/BlockHeader.java
  9. 108
      plugin-api/src/main/java/org/hyperledger/besu/plugin/data/ProcessableBlockHeader.java

@ -172,10 +172,6 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
timestamp, maybePrevRandao, maybeParentBeaconBlockRoot, newProtocolSpec);
final Address miningBeneficiary =
miningBeneficiaryCalculator.getMiningBeneficiary(processableBlockHeader.getNumber());
Wei blobGasPrice =
newProtocolSpec
.getFeeMarket()
.blobGasPricePerGas(calculateExcessBlobGasForParent(newProtocolSpec, parentHeader));
throwIfStopped();
@ -193,7 +189,6 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
disposableWorldState,
maybeTransactions,
miningBeneficiary,
blobGasPrice,
newProtocolSpec);
transactionResults.logSelectionStats();
@ -321,7 +316,6 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
final MutableWorldState disposableWorldState,
final Optional<List<Transaction>> transactions,
final Address miningBeneficiary,
final Wei blobGasPrice,
final ProtocolSpec protocolSpec)
throws RuntimeException {
final MainnetTransactionProcessor transactionProcessor = protocolSpec.getTransactionProcessor();
@ -329,6 +323,11 @@ public abstract class AbstractBlockCreator implements AsyncBlockCreator {
final AbstractBlockProcessor.TransactionReceiptFactory transactionReceiptFactory =
protocolSpec.getTransactionReceiptFactory();
Wei blobGasPrice =
protocolSpec
.getFeeMarket()
.blobGasPricePerGas(calculateExcessBlobGasForParent(protocolSpec, parentHeader));
final BlockTransactionSelector selector =
new BlockTransactionSelector(
miningParameters,

@ -169,9 +169,9 @@ public class BlockHeader extends SealableBlockHeader
if (withdrawalsRoot != null) {
out.writeBytes(withdrawalsRoot);
}
if (excessBlobGas.isPresent() && blobGasUsed.isPresent()) {
out.writeLongScalar(blobGasUsed.get());
out.writeUInt64Scalar(excessBlobGas.get());
if (excessBlobGas != null && blobGasUsed != null) {
out.writeLongScalar(blobGasUsed);
out.writeUInt64Scalar(excessBlobGas);
}
if (parentBeaconBlockRoot != null) {
out.writeBytes(parentBeaconBlockRoot);
@ -278,8 +278,10 @@ public class BlockHeader extends SealableBlockHeader
if (withdrawalsRoot != null) {
sb.append("withdrawalsRoot=").append(withdrawalsRoot).append(", ");
}
blobGasUsed.ifPresent(aLong -> sb.append("blobGasUsed=").append(aLong).append(", "));
excessBlobGas.ifPresent(blobGas -> sb.append("excessBlobGas=").append(blobGas).append(", "));
if (blobGasUsed != null && excessBlobGas != null) {
sb.append("blobGasUsed=").append(blobGasUsed).append(", ");
sb.append("excessBlobGas=").append(excessBlobGas).append(", ");
}
if (parentBeaconBlockRoot != null) {
sb.append("parentBeaconBlockRoot=").append(parentBeaconBlockRoot).append(", ");
}

@ -194,8 +194,6 @@ public class BlockHeaderBuilder {
timestamp,
baseFee,
mixHashOrPrevRandao,
blobGasUsed,
excessBlobGas,
parentBeaconBlockRoot);
}
@ -261,8 +259,6 @@ public class BlockHeaderBuilder {
timestamp(processableBlockHeader.getTimestamp());
baseFee(processableBlockHeader.getBaseFee().orElse(null));
processableBlockHeader.getPrevRandao().ifPresent(this::prevRandao);
processableBlockHeader.getBlobGasUsed().ifPresent(this::blobGasUsed);
processableBlockHeader.getExcessBlobGas().ifPresent(this::excessBlobGas);
processableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot);
return this;
}

@ -15,7 +15,6 @@
package org.hyperledger.besu.ethereum.core;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.frame.BlockValues;
@ -26,7 +25,8 @@ import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
/** A block header capable of being processed. */
public class ProcessableBlockHeader implements BlockValues {
public class ProcessableBlockHeader
implements BlockValues, org.hyperledger.besu.plugin.data.ProcessableBlockHeader {
protected final Hash parentHash;
@ -44,10 +44,6 @@ public class ProcessableBlockHeader implements BlockValues {
protected final Wei baseFee;
// prevRandao is included for post-merge blocks
protected final Bytes32 mixHashOrPrevRandao;
// blobGasUsed is included for Cancun
protected final Optional<Long> blobGasUsed;
// excessBlogGas is included for Cancun
protected final Optional<BlobGas> excessBlobGas;
// parentBeaconBlockRoot is included for Cancun
protected final Bytes32 parentBeaconBlockRoot;
@ -60,8 +56,6 @@ public class ProcessableBlockHeader implements BlockValues {
final long timestamp,
final Wei baseFee,
final Bytes32 mixHashOrPrevRandao,
final Long blobGasUsed,
final BlobGas excessBlobGas,
final Bytes32 parentBeaconBlockRoot) {
this.parentHash = parentHash;
this.coinbase = coinbase;
@ -71,8 +65,6 @@ public class ProcessableBlockHeader implements BlockValues {
this.timestamp = timestamp;
this.baseFee = baseFee;
this.mixHashOrPrevRandao = mixHashOrPrevRandao;
this.blobGasUsed = Optional.ofNullable(blobGasUsed);
this.excessBlobGas = Optional.ofNullable(excessBlobGas);
this.parentBeaconBlockRoot = parentBeaconBlockRoot;
}
@ -81,6 +73,7 @@ public class ProcessableBlockHeader implements BlockValues {
*
* @return the block parent block hash
*/
@Override
public Hash getParentHash() {
return parentHash;
}
@ -90,6 +83,7 @@ public class ProcessableBlockHeader implements BlockValues {
*
* @return the block coinbase address
*/
@Override
public Address getCoinbase() {
return coinbase;
}
@ -99,6 +93,7 @@ public class ProcessableBlockHeader implements BlockValues {
*
* @return the block difficulty
*/
@Override
public Difficulty getDifficulty() {
return difficulty;
}
@ -168,18 +163,17 @@ public class ProcessableBlockHeader implements BlockValues {
*
* @return the raw bytes of the prevRandao field
*/
@Override
public Optional<Bytes32> getPrevRandao() {
return Optional.ofNullable(mixHashOrPrevRandao);
}
public Optional<BlobGas> getExcessBlobGas() {
return excessBlobGas;
}
public Optional<Long> getBlobGasUsed() {
return blobGasUsed;
}
/**
* Returns the parent beacon block root.
*
* @return the parent beacon block root.
*/
@Override
public Optional<Bytes32> getParentBeaconBlockRoot() {
return Optional.ofNullable(parentBeaconBlockRoot);
}

@ -45,6 +45,10 @@ public class SealableBlockHeader extends ProcessableBlockHeader {
protected final Hash depositsRoot;
protected final Long blobGasUsed;
protected final BlobGas excessBlobGas;
protected SealableBlockHeader(
final Hash parentHash,
final Hash ommersHash,
@ -75,8 +79,6 @@ public class SealableBlockHeader extends ProcessableBlockHeader {
timestamp,
baseFee,
mixHashOrPrevRandao,
blobGasUsed,
excessBlobGas,
parentBeaconBlockRoot);
this.ommersHash = ommersHash;
this.stateRoot = stateRoot;
@ -87,6 +89,8 @@ public class SealableBlockHeader extends ProcessableBlockHeader {
this.logsBloom = logsBloom;
this.gasUsed = gasUsed;
this.extraData = extraData;
this.blobGasUsed = blobGasUsed;
this.excessBlobGas = excessBlobGas;
}
/**
@ -169,4 +173,22 @@ public class SealableBlockHeader extends ProcessableBlockHeader {
public Optional<Hash> getDepositsRoot() {
return Optional.ofNullable(depositsRoot);
}
/**
* Returns the blob gas used if available.
*
* @return the blob gas used if available.
*/
public Optional<Long> getBlobGasUsed() {
return Optional.ofNullable(blobGasUsed);
}
/**
* Returns the excess blob gas used if available.
*
* @return the excess blob gas used if available.
*/
public Optional<BlobGas> getExcessBlobGas() {
return Optional.ofNullable(excessBlobGas);
}
}

@ -227,7 +227,7 @@ public class ReferenceTestEnv extends BlockHeader {
.buildBlockHeader(),
null)));
}
if (excessBlobGas.isEmpty() && parentExcessBlobGas != null && parentBlobGasUsed != null) {
if (parentExcessBlobGas != null && parentBlobGasUsed != null) {
builder.excessBlobGas(
BlobGas.of(
protocolSpec

@ -69,7 +69,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 = 'kyCYfllc1IcisRZIYuLxhC+0+POCzcMQPhE8F8mx1Ns='
knownHash = 'YYrWGQIwp1sgEmwx2DcfjiskFO8euGGKeWh7Lq1F+24='
}
check.dependsOn('checkAPIChanges')

@ -14,7 +14,6 @@
*/
package org.hyperledger.besu.plugin.data;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Quantity;
import org.hyperledger.besu.plugin.Unstable;
@ -22,20 +21,12 @@ import org.hyperledger.besu.plugin.Unstable;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
/**
* The minimum set of data for a BlockHeader, as defined in the <a href=
* "https://ethereum.github.io/yellowpaper/paper.pdf">Ethereum Yellow Paper</a>.
*/
public interface BlockHeader {
/**
* The Keccak 256-bit hash of the parent blocks header, in its entirety.
*
* @return The Keccak 256-bit hash of the parent blocks header, in its entirety.
*/
Hash getParentHash();
public interface BlockHeader extends ProcessableBlockHeader {
/**
* The Keccak 256-bit hash of the ommers list portion of this block.
@ -44,17 +35,6 @@ public interface BlockHeader {
*/
Hash getOmmersHash();
/**
* The 160-bit address to which all fees collected from the successful mining of this block be
* transferred.
*
* <p>The name in the yellow paper is beneficiary.
*
* @return The 160-bit address to which all fees collected from the successful mining of this
* block be transferred.
*/
Address getCoinbase();
/**
* The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed
* and finalizations applied.
@ -91,30 +71,6 @@ public interface BlockHeader {
*/
Bytes getLogsBloom();
/**
* A scalar value corresponding to the difficulty level of this block. This can be calculated from
* the previous blocks difficulty level and the timestamp.
*
* @return A UInt256 value corresponding to the difficulty level of this block. This can be
* calculated from the previous blocks difficulty level and the timestamp.
*/
Quantity getDifficulty();
/**
* A scalar value equal to the number of ancestor blocks. The genesis block has a number of zero.
*
* @return A scalar value equal to the number of ancestor blocks. The genesis block has a number
* of zero.
*/
long getNumber();
/**
* A scalar value equal to the current limit of gas expenditure per block.
*
* @return A scalar value equal to the current limit of gas expenditure per block.
*/
long getGasLimit();
/**
* A scalar value equal to the total gas used in transactions in this block.
*
@ -122,14 +78,6 @@ public interface BlockHeader {
*/
long getGasUsed();
/**
* A scalar value equal to the reasonable output of Unixs time() at this blocks inception.
*
* @return A scalar value equal to the reasonable output of Unixs time() at this blocks
* inception.
*/
long getTimestamp();
/**
* An arbitrary byte array containing data relevant to this block. This must be 32 bytes or fewer.
*
@ -163,25 +111,6 @@ public interface BlockHeader {
*/
Hash getBlockHash();
/**
* The BASEFEE of this header.
*
* @return The BASEFEE of this header.
*/
@Unstable
default Optional<? extends Quantity> getBaseFee() {
return Optional.empty();
}
/**
* Optional 32 bytes of prevRandao data.
*
* @return Optional prevRandao bytes from this header.
*/
default Optional<Bytes32> getPrevRandao() {
return Optional.empty();
}
/**
* The Keccak 256-bit hash of the root node of the trie structure populated with each withdrawal
* in the withdrawals list portion of the block.
@ -216,12 +145,4 @@ public interface BlockHeader {
*/
@Unstable
Optional<? extends Long> getBlobGasUsed();
/**
* The parent beacon block root of this header.
*
* @return The parent_beacon_block_root of this header.
*/
@Unstable
Optional<? extends Bytes32> getParentBeaconBlockRoot();
}

@ -0,0 +1,108 @@
/*
* Copyright ConsenSys AG.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.plugin.data;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Quantity;
import org.hyperledger.besu.plugin.Unstable;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes32;
/**
* The minimum set of data for a BlockHeader, as defined in the <a href=
* "https://ethereum.github.io/yellowpaper/paper.pdf">Ethereum Yellow Paper</a>.
*/
public interface ProcessableBlockHeader {
/**
* The Keccak 256-bit hash of the parent blocks header, in its entirety.
*
* @return The Keccak 256-bit hash of the parent blocks header, in its entirety.
*/
Hash getParentHash();
/**
* The 160-bit address to which all fees collected from the successful mining of this block be
* transferred.
*
* <p>The name in the yellow paper is beneficiary.
*
* @return The 160-bit address to which all fees collected from the successful mining of this
* block be transferred.
*/
Address getCoinbase();
/**
* A scalar value corresponding to the difficulty level of this block. This can be calculated from
* the previous blocks difficulty level and the timestamp.
*
* @return A scalar value corresponding to the difficulty level of this block. This can be
* calculated from the previous blocks difficulty level and the timestamp.
*/
Quantity getDifficulty();
/**
* A scalar value equal to the number of ancestor blocks. The genesis block has a number of zero.
*
* @return A scalar value equal to the number of ancestor blocks. The genesis block has a number
* of zero.
*/
long getNumber();
/**
* A scalar value equal to the current limit of gas expenditure per block.
*
* @return A scalar value equal to the current limit of gas expenditure per block.
*/
long getGasLimit();
/**
* A scalar value equal to the reasonable output of Unixs time() at this blocks inception.
*
* @return A scalar value equal to the reasonable output of Unixs time() at this blocks
* inception.
*/
long getTimestamp();
/**
* Optional 32 bytes of prevRandao data.
*
* @return Optional prevRandao bytes from this header.
*/
default Optional<Bytes32> getPrevRandao() {
return Optional.empty();
}
/**
* The base fee of this block.
*
* @return The base fee of this block.
*/
@Unstable
default Optional<? extends Quantity> getBaseFee() {
return Optional.empty();
}
/**
* The parent beacon block root of this header.
*
* @return The parent_beacon_block_root of this header.
*/
@Unstable
Optional<? extends Bytes32> getParentBeaconBlockRoot();
}
Loading…
Cancel
Save