Search in sources :

Example 1 with SealableBlockHeader

use of org.hyperledger.besu.ethereum.core.SealableBlockHeader in project besu by hyperledger.

the class AbstractBlockCreator method createBlock.

protected Block createBlock(final Optional<List<Transaction>> maybeTransactions, final Optional<List<BlockHeader>> maybeOmmers, final Optional<Bytes32> maybePrevRandao, final long timestamp, boolean rewardCoinbase) {
    try {
        final ProcessableBlockHeader processableBlockHeader = createPendingBlockHeader(timestamp, maybePrevRandao);
        final Address miningBeneficiary = miningBeneficiaryCalculator.getMiningBeneficiary(processableBlockHeader.getNumber());
        throwIfStopped();
        final MutableWorldState disposableWorldState = duplicateWorldStateAtParent();
        throwIfStopped();
        final List<BlockHeader> ommers = maybeOmmers.orElse(selectOmmers());
        throwIfStopped();
        final BlockTransactionSelector.TransactionSelectionResults transactionResults = selectTransactions(processableBlockHeader, disposableWorldState, maybeTransactions, miningBeneficiary);
        throwIfStopped();
        final ProtocolSpec newProtocolSpec = protocolSchedule.getByBlockNumber(processableBlockHeader.getNumber());
        if (rewardCoinbase && !rewardBeneficiary(disposableWorldState, processableBlockHeader, ommers, miningBeneficiary, newProtocolSpec.getBlockReward(), newProtocolSpec.isSkipZeroBlockRewards())) {
            LOG.trace("Failed to apply mining reward, exiting.");
            throw new RuntimeException("Failed to apply mining reward.");
        }
        throwIfStopped();
        final SealableBlockHeader sealableBlockHeader = BlockHeaderBuilder.create().populateFrom(processableBlockHeader).ommersHash(BodyValidation.ommersHash(MergeConfigOptions.isMergeEnabled() ? Collections.emptyList() : ommers)).stateRoot(disposableWorldState.rootHash()).transactionsRoot(BodyValidation.transactionsRoot(transactionResults.getTransactions())).receiptsRoot(BodyValidation.receiptsRoot(transactionResults.getReceipts())).logsBloom(BodyValidation.logsBloom(transactionResults.getReceipts())).gasUsed(transactionResults.getCumulativeGasUsed()).extraData(extraDataCalculator.get(parentHeader)).buildSealableBlockHeader();
        final BlockHeader blockHeader = createFinalBlockHeader(sealableBlockHeader);
        return new Block(blockHeader, new BlockBody(transactionResults.getTransactions(), ommers));
    } catch (final SecurityModuleException ex) {
        throw new IllegalStateException("Failed to create block signature", ex);
    } catch (final CancellationException ex) {
        throw ex;
    } catch (final Exception ex) {
        // TODO(tmm): How are we going to know this has exploded, and thus restart it?
        throw new IllegalStateException("Block creation failed unexpectedly. Will restart on next block added to chain.", ex);
    }
}
Also used : SealableBlockHeader(org.hyperledger.besu.ethereum.core.SealableBlockHeader) Address(org.hyperledger.besu.datatypes.Address) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) CancellationException(java.util.concurrent.CancellationException) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) CancellationException(java.util.concurrent.CancellationException) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) Block(org.hyperledger.besu.ethereum.core.Block) SealableBlockHeader(org.hyperledger.besu.ethereum.core.SealableBlockHeader) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Aggregations

CancellationException (java.util.concurrent.CancellationException)1 Address (org.hyperledger.besu.datatypes.Address)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 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)1 SealableBlockHeader (org.hyperledger.besu.ethereum.core.SealableBlockHeader)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)1