@@ -7,7 +7,7 @@ import io.iohk.ethereum.domain._
7
7
import io .iohk .ethereum .ledger .BlockExecutionError .{StateBeforeFailure , TxsExecutionError }
8
8
import io .iohk .ethereum .ledger .Ledger ._
9
9
import io .iohk .ethereum .ledger .BlockPreparator ._
10
- import io .iohk .ethereum .utils .{BlockchainConfig , Logger }
10
+ import io .iohk .ethereum .utils .{BlockchainConfig , Config , Logger }
11
11
import io .iohk .ethereum .vm .{PC => _ , _ }
12
12
13
13
import scala .annotation .tailrec
@@ -60,50 +60,52 @@ class BlockPreparator(
60
60
block : Block ,
61
61
worldStateProxy : InMemoryWorldStateProxy
62
62
): InMemoryWorldStateProxy = {
63
- val blockNumber = block.header.number
64
-
65
- val minerRewardForBlock = blockRewardCalculator.calculateMiningRewardForBlock(blockNumber)
66
- val minerRewardForOmmers =
67
- blockRewardCalculator.calculateMiningRewardForOmmers(blockNumber, block.body.uncleNodesList.size)
68
-
69
- val minerAddress = Address (block.header.beneficiary)
70
- val treasuryAddress = blockchainConfig.treasuryAddress
71
- val existsTreasuryContract = worldStateProxy.getAccount( treasuryAddress).isDefined
72
-
73
- val worldAfterPayingBlockReward =
74
- if (block.header.treasuryOptOut.isEmpty || ! existsTreasuryContract) {
75
- val minerReward = minerRewardForOmmers + minerRewardForBlock
76
- val worldAfterMinerReward = increaseAccountBalance(minerAddress, UInt256 (minerReward))(worldStateProxy)
77
- log.debug( s " Paying block $blockNumber reward of $minerReward to miner with address $ minerAddress" )
78
- worldAfterMinerReward
79
- } else if (block.header.treasuryOptOut.get) {
80
- val minerReward = minerRewardForOmmers + minerRewardForBlock * MinerRewardPercentageAfterECIP1098 / 100
81
- val worldAfterMinerReward = increaseAccountBalance(minerAddress, UInt256 (minerReward))(worldStateProxy)
82
- log.debug(
83
- s " Paying block $blockNumber reward of $minerReward to miner with address $minerAddress , miner opted-out of treasury "
84
- )
85
- worldAfterMinerReward
86
- } else {
87
- val minerReward = minerRewardForOmmers + minerRewardForBlock * MinerRewardPercentageAfterECIP1098 / 100
88
- val worldAfterMinerReward = increaseAccountBalance(minerAddress, UInt256 (minerReward))(worldStateProxy)
89
- val treasuryReward = minerRewardForBlock * TreasuryRewardPercentageAfterECIP1098 / 100
90
- val worldAfterTreasuryReward =
91
- increaseAccountBalance(treasuryAddress, UInt256 (treasuryReward))(worldAfterMinerReward)
92
-
93
- log.debug(
94
- s " Paying block $blockNumber reward of $minerReward to miner with address $minerAddress " +
95
- s " paying treasury reward of $treasuryReward to treasury with address $treasuryAddress "
96
- )
97
- worldAfterTreasuryReward
98
- }
99
-
100
- block.body.uncleNodesList.foldLeft(worldAfterPayingBlockReward) { (ws, ommer) =>
101
- val ommerAddress = Address (ommer.beneficiary)
102
- val ommerReward = blockRewardCalculator.calculateOmmerRewardForInclusion(blockNumber, ommer.number)
63
+ if ( ! Config .testmode) {
64
+ val blockNumber = block.header.number
65
+
66
+ val minerRewardForBlock = blockRewardCalculator.calculateMiningRewardForBlock(blockNumber)
67
+ val minerRewardForOmmers =
68
+ blockRewardCalculator.calculateMiningRewardForOmmers(blockNumber, block.body.uncleNodesList.size)
69
+
70
+ val minerAddress = Address (block.header.beneficiary)
71
+ val treasuryAddress = blockchainConfig. treasuryAddress
72
+ val existsTreasuryContract = worldStateProxy.getAccount(treasuryAddress).isDefined
73
+
74
+ val worldAfterPayingBlockReward =
75
+ if (block.header.treasuryOptOut.isEmpty || ! existsTreasuryContract) {
76
+ val minerReward = minerRewardForOmmers + minerRewardForBlock
77
+ val worldAfterMinerReward = increaseAccountBalance( minerAddress, UInt256 (minerReward))(worldStateProxy )
78
+ log.debug( s " Paying block $blockNumber reward of $minerReward to miner with address $minerAddress " )
79
+ worldAfterMinerReward
80
+ } else if (block.header.treasuryOptOut.get) {
81
+ val minerReward = minerRewardForOmmers + minerRewardForBlock * MinerRewardPercentageAfterECIP1098 / 100
82
+ val worldAfterMinerReward = increaseAccountBalance(minerAddress, UInt256 (minerReward))(worldStateProxy)
83
+ log.debug(
84
+ s " Paying block $blockNumber reward of $minerReward to miner with address $minerAddress , miner opted-out of treasury "
85
+ )
86
+ worldAfterMinerReward
87
+ } else {
88
+ val minerReward = minerRewardForOmmers + minerRewardForBlock * MinerRewardPercentageAfterECIP1098 / 100
89
+ val worldAfterMinerReward = increaseAccountBalance(minerAddress, UInt256 (minerReward))(worldStateProxy)
90
+ val treasuryReward = minerRewardForBlock * TreasuryRewardPercentageAfterECIP1098 / 100
91
+ val worldAfterTreasuryReward =
92
+ increaseAccountBalance(treasuryAddress, UInt256 (treasuryReward))(worldAfterMinerReward)
93
+
94
+ log.debug(
95
+ s " Paying block $blockNumber reward of $minerReward to miner with address $minerAddress " +
96
+ s " paying treasury reward of $treasuryReward to treasury with address $treasuryAddress "
97
+ )
98
+ worldAfterTreasuryReward
99
+ }
100
+ block.body.uncleNodesList.foldLeft(worldAfterPayingBlockReward) { (ws, ommer) =>
101
+ val ommerAddress = Address (ommer.beneficiary)
102
+ val ommerReward = blockRewardCalculator.calculateOmmerRewardForInclusion(blockNumber, ommer.number)
103
103
104
- log.debug(s " Paying block $blockNumber reward of $ommerReward to ommer with account address $ommerAddress" )
105
- increaseAccountBalance(ommerAddress, UInt256 (ommerReward))(ws)
106
- }
104
+ log.debug(s " Paying block $blockNumber reward of $ommerReward to ommer with account address $ommerAddress" )
105
+ increaseAccountBalance(ommerAddress, UInt256 (ommerReward))(ws)
106
+ }
107
+ } else
108
+ worldStateProxy
107
109
}
108
110
109
111
/**
0 commit comments