Search in sources :

Example 1 with MainnetBlockProcessor

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());
}
Also used : MainnetBlockProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor) MainnetBlockProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor) BlockProcessor(org.hyperledger.besu.ethereum.mainnet.BlockProcessor) MainnetBlockImporter(org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) MainnetBlockValidator(org.hyperledger.besu.ethereum.MainnetBlockValidator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) MainnetBlockImporter(org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) MainnetBlockValidator(org.hyperledger.besu.ethereum.MainnetBlockValidator)

Example 2 with MainnetBlockProcessor

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);
}
Also used : Trace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.Trace) MainnetBlockProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor) AbstractBlockProcessor(org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

MainnetBlockProcessor (org.hyperledger.besu.ethereum.mainnet.MainnetBlockProcessor)2 BlockValidator (org.hyperledger.besu.ethereum.BlockValidator)1 MainnetBlockValidator (org.hyperledger.besu.ethereum.MainnetBlockValidator)1 Trace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.Trace)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)1 AbstractBlockProcessor (org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor)1 BlockProcessor (org.hyperledger.besu.ethereum.mainnet.BlockProcessor)1 MainnetBlockImporter (org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 Test (org.junit.Test)1