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