use of org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor in project besu by hyperledger.
the class NoRewardProtocolScheduleWrapper method getByBlockNumber.
@Override
public ProtocolSpec getByBlockNumber(final long number) {
final ProtocolSpec original = delegate.getByBlockNumber(number);
final BlockProcessor noRewardBlockProcessor = new MainnetBlockProcessor(original.getTransactionProcessor(), original.getTransactionReceiptFactory(), Wei.ZERO, original.getMiningBeneficiaryCalculator(), original.isSkipZeroBlockRewards(), Optional.empty());
final BlockValidator noRewardBlockValidator = new MainnetBlockValidator(original.getBlockHeaderValidator(), original.getBlockBodyValidator(), noRewardBlockProcessor, original.getBadBlocksManager());
final BlockImporter noRewardBlockImporter = new MainnetBlockImporter(noRewardBlockValidator);
return new ProtocolSpec(original.getName(), original.getEvm(), original.getTransactionValidator(), original.getTransactionProcessor(), original.getPrivateTransactionProcessor(), original.getBlockHeaderValidator(), original.getOmmerHeaderValidator(), original.getBlockBodyValidator(), noRewardBlockProcessor, noRewardBlockImporter, noRewardBlockValidator, original.getBlockHeaderFunctions(), original.getTransactionReceiptFactory(), original.getDifficultyCalculator(), // block reward
Wei.ZERO, original.getMiningBeneficiaryCalculator(), original.getPrecompileContractRegistry(), original.isSkipZeroBlockRewards(), original.getGasCalculator(), original.getGasLimitCalculator(), original.getFeeMarket(), original.getBadBlocksManager(), Optional.empty());
}
use of org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor in project besu by hyperledger.
the class RewardTraceGeneratorTest method assertThatTraceGeneratorReturnValidRewardsForMainnetBlockProcessor.
@Test
public void assertThatTraceGeneratorReturnValidRewardsForMainnetBlockProcessor() {
final AbstractBlockProcessor.TransactionReceiptFactory transactionReceiptFactory = mock(AbstractBlockProcessor.TransactionReceiptFactory.class);
final MainnetBlockProcessor blockProcessor = new MainnetBlockProcessor(transactionProcessor, transactionReceiptFactory, blockReward, BlockHeader::getCoinbase, true, Optional.empty());
when(protocolSpec.getBlockProcessor()).thenReturn(blockProcessor);
final Stream<Trace> traceStream = RewardTraceGenerator.generateFromBlock(protocolSchedule, block);
final Action.Builder actionBlockReward = Action.builder().rewardType("block").author(blockBeneficiary.toHexString()).value(blockProcessor.getCoinbaseReward(blockReward, block.getHeader().getNumber(), 1).toShortHexString());
final Trace blocReward = new RewardTrace.Builder().blockHash(block.getHash().toHexString()).blockNumber(block.getHeader().getNumber()).actionBuilder(actionBlockReward).type("reward").build();
// calculate reward with MainnetBlockProcessor
final Action.Builder actionOmmerReward = Action.builder().rewardType("uncle").author(ommerBeneficiary.toHexString()).value(blockProcessor.getOmmerReward(blockReward, block.getHeader().getNumber(), ommerHeader.getNumber()).toShortHexString());
final Trace ommerReward = new RewardTrace.Builder().blockHash(block.getHash().toHexString()).blockNumber(block.getHeader().getNumber()).actionBuilder(actionOmmerReward).type("reward").build();
final List<Trace> traces = traceStream.collect(Collectors.toList());
// check block reward
assertThat(traces.get(0)).usingRecursiveComparison().isEqualTo(blocReward);
// check ommer reward
assertThat(traces.get(1)).usingRecursiveComparison().isEqualTo(ommerReward);
}
Aggregations