Refactor BlockReward.reward() function (#534)

This commit is contained in:
Kirill Fedoseev 2020-10-16 19:13:22 +03:00 committed by GitHub
parent 65fa34f562
commit ac39624d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 5 deletions

View File

@ -75,32 +75,42 @@ contract BlockReward is EternalStorage {
/**
* @dev Special method that is called by the system, in order to get accounts and values for minting new coins in upcoming block.
* Can be called on by a system-reserved address.
* Can be called only by a system-reserved address.
* @param benefactors list of block reward receivers, should be empty.
* @param kind list of reward types for addresses in benefactors list, should be empty.
* @return tuple of addresses list and values list of the same length that describes where and how much new coins should be minted.
*/
function reward(address[] benefactors, uint16[] kind) external onlySystem returns (address[], uint256[]) {
// As these contracts were intended to work on top of the forked Quorum client,
// the arguments of this function will depend on the particular client code.
// For simplicity, and since Quorum does not have any block rewards,
// it was decided to keep argument arrays empty.
// However, in the original OpenEthereum blockReward implementation,
// first argument should contain some reward receiver addresses (i.e. miner of a block, uncle blocks miners, etc.),
// second argument describes the reward types of the benefactors.
require(benefactors.length == 0);
require(kind.length == 0);
uint256 extraLength = extraReceiversLength();
// Lists with extra receivers and their rewards. Extra receivers are generated by the bridge/mediator contracts,
// and they are not passed in the benefactors array.
address[] memory receivers = new address[](extraLength);
uint256[] memory rewards = new uint256[](extraLength);
uint256 i;
uint256 sumOfRewards = 0;
uint256 sumOfBridgeAmounts = 0;
for (i = 0; i < extraLength; i++) {
address extraAddress = extraReceiverByIndex(i);
uint256 extraAmount = extraReceiverAmount(extraAddress);
_setExtraReceiverAmount(0, extraAddress);
receivers[i] = extraAddress;
rewards[i] = extraAmount;
}
for (i = 0; i < extraLength; i++) {
_setMinted(rewards[i], receivers[i]);
_setMinted(extraAmount, extraAddress);
sumOfRewards += extraAmount;
}
for (i = 0; i < bridgesAllowedLength; i++) {
@ -110,9 +120,12 @@ contract BlockReward is EternalStorage {
if (bridgeAmountForBlock > 0) {
_setBridgeAmount(0, bridgeAddress);
_addMintedTotallyByBridge(bridgeAmountForBlock, bridgeAddress);
sumOfBridgeAmounts += bridgeAmountForBlock;
}
}
require(sumOfRewards == sumOfBridgeAmounts);
_clearExtraReceivers();
return (receivers, rewards);