use of org.hyperledger.besu.ethereum.mainnet.MiningBeneficiaryCalculator in project besu by hyperledger.
the class RewardTraceGenerator method generateFromBlock.
/**
* Generates a stream of reward {@link Trace} from the passed {@link Block} data.
*
* @param protocolSchedule the {@link ProtocolSchedule} to use
* @param block the current {@link Block} to use
* @return a stream of generated reward traces {@link Trace}
*/
public static Stream<Trace> generateFromBlock(final ProtocolSchedule protocolSchedule, final Block block) {
final List<Trace> flatTraces = new ArrayList<>();
final BlockHeader blockHeader = block.getHeader();
final List<BlockHeader> ommers = block.getBody().getOmmers();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final Wei blockReward = protocolSpec.getBlockReward();
final MiningBeneficiaryCalculator miningBeneficiaryCalculator = protocolSpec.getMiningBeneficiaryCalculator();
final Wei coinbaseReward = protocolSpec.getBlockProcessor().getCoinbaseReward(blockReward, blockHeader.getNumber(), ommers.size());
// add uncle reward traces
ommers.forEach(ommerBlockHeader -> {
final Wei ommerReward = protocolSpec.getBlockProcessor().getOmmerReward(blockReward, blockHeader.getNumber(), ommerBlockHeader.getNumber());
final Action.Builder uncleActionBuilder = Action.builder().author(miningBeneficiaryCalculator.calculateBeneficiary(ommerBlockHeader).toHexString()).rewardType(UNCLE_LABEL).value(ommerReward.toShortHexString());
flatTraces.add(RewardTrace.builder().actionBuilder(uncleActionBuilder).blockHash(block.getHash().toHexString()).blockNumber(blockHeader.getNumber()).type(REWARD_LABEL).build());
});
// add block reward trace
final Action.Builder blockActionBuilder = Action.builder().author(miningBeneficiaryCalculator.calculateBeneficiary(blockHeader).toHexString()).rewardType(BLOCK_LABEL).value(coinbaseReward.toShortHexString());
flatTraces.add(0, RewardTrace.builder().actionBuilder(blockActionBuilder).blockHash(block.getHash().toHexString()).blockNumber(blockHeader.getNumber()).type(REWARD_LABEL).build());
return flatTraces.stream();
}
use of org.hyperledger.besu.ethereum.mainnet.MiningBeneficiaryCalculator in project besu by hyperledger.
the class PrivateStorageMigrationTest method setUp.
@Before
public void setUp() {
final KeyValueStorage kvStorage = new InMemoryKeyValueStorage();
privateStateStorage = new PrivateStateKeyValueStorage(kvStorage);
privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
lenient().when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
lenient().when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor);
lenient().when(protocolSpec.getTransactionReceiptFactory()).thenReturn(transactionReceiptFactory);
lenient().when(protocolSpec.getBlockReward()).thenReturn(Wei.ZERO);
lenient().when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(miningBeneficiaryCalculator);
lenient().when(protocolSpec.isSkipZeroBlockRewards()).thenReturn(false);
migration = new PrivateStorageMigration(blockchain, PRIVACY_ADDRESS, protocolSchedule, publicWorldStateArchive, privateStateStorage, privateStateRootResolver, legacyPrivateStateStorage, (protocolSpec) -> privateMigrationBlockProcessor);
}
Aggregations