Search in sources :

Example 1 with DifficultyCalculator

use of org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator in project besu by hyperledger.

the class AbstractBlockCreator method createPendingBlockHeader.

private ProcessableBlockHeader createPendingBlockHeader(final long timestamp, final Optional<Bytes32> maybePrevRandao) {
    final long newBlockNumber = parentHeader.getNumber() + 1;
    long gasLimit = protocolSpec.getGasLimitCalculator().nextGasLimit(parentHeader.getGasLimit(), targetGasLimitSupplier.get().orElse(parentHeader.getGasLimit()), newBlockNumber);
    final DifficultyCalculator difficultyCalculator = protocolSpec.getDifficultyCalculator();
    final BigInteger difficulty = difficultyCalculator.nextDifficulty(timestamp, parentHeader, protocolContext);
    final Wei baseFee = Optional.of(protocolSpec.getFeeMarket()).filter(FeeMarket::implementsBaseFee).map(BaseFeeMarket.class::cast).map(feeMarket -> feeMarket.computeBaseFee(newBlockNumber, parentHeader.getBaseFee().orElse(Wei.ZERO), parentHeader.getGasUsed(), feeMarket.targetGasUsed(parentHeader))).orElse(null);
    final Bytes32 prevRandao = maybePrevRandao.orElse(null);
    return BlockHeaderBuilder.create().parentHash(parentHeader.getHash()).coinbase(coinbase).difficulty(Difficulty.of(difficulty)).number(newBlockNumber).gasLimit(gasLimit).timestamp(timestamp).baseFee(baseFee).prevRandao(prevRandao).buildProcessableBlockHeader();
}
Also used : BaseFeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket) AbstractPendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.AbstractPendingTransactionsSorter) EvmAccount(org.hyperledger.besu.evm.account.EvmAccount) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) SealableBlockHeader(org.hyperledger.besu.ethereum.core.SealableBlockHeader) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Supplier(java.util.function.Supplier) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Lists(com.google.common.collect.Lists) BaseFeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket) Wei(org.hyperledger.besu.datatypes.Wei) ScheduleBasedBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions) BigInteger(java.math.BigInteger) MergeConfigOptions(org.hyperledger.besu.config.MergeConfigOptions) Block(org.hyperledger.besu.ethereum.core.Block) BodyValidation(org.hyperledger.besu.ethereum.mainnet.BodyValidation) Bytes32(org.apache.tuweni.bytes.Bytes32) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) Difficulty(org.hyperledger.besu.ethereum.core.Difficulty) AbstractBlockProcessor(org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor) Logger(org.slf4j.Logger) CancellationException(java.util.concurrent.CancellationException) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) BlockHeaderBuilder(org.hyperledger.besu.ethereum.core.BlockHeaderBuilder) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) DifficultyCalculator(org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator) MainnetTransactionProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor) List(java.util.List) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) Optional(java.util.Optional) BlockHeaderFunctions(org.hyperledger.besu.ethereum.core.BlockHeaderFunctions) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Collections(java.util.Collections) Hash(org.hyperledger.besu.datatypes.Hash) DifficultyCalculator(org.hyperledger.besu.ethereum.mainnet.DifficultyCalculator) BigInteger(java.math.BigInteger) Wei(org.hyperledger.besu.datatypes.Wei) Bytes32(org.apache.tuweni.bytes.Bytes32)

Aggregations

Lists (com.google.common.collect.Lists)1 BigInteger (java.math.BigInteger)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 CancellationException (java.util.concurrent.CancellationException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Supplier (java.util.function.Supplier)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 MergeConfigOptions (org.hyperledger.besu.config.MergeConfigOptions)1 Address (org.hyperledger.besu.datatypes.Address)1 Hash (org.hyperledger.besu.datatypes.Hash)1 Wei (org.hyperledger.besu.datatypes.Wei)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 BlockHeaderBuilder (org.hyperledger.besu.ethereum.core.BlockHeaderBuilder)1 BlockHeaderFunctions (org.hyperledger.besu.ethereum.core.BlockHeaderFunctions)1