@@ -600,17 +600,22 @@ func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.H
600
600
601
601
// Finalize implements consensus.Engine, accumulating the block and uncle rewards,
602
602
// setting the final state on the header
603
- func (ethash * Ethash ) Finalize (chain consensus.ChainHeaderReader , header * types.Header , state * state.StateDB , txs []* types.Transaction , uncles []* types.Header ) {
603
+ func (ethash * Ethash ) Finalize (chain consensus.ChainHeaderReader , header * types.Header , state * state.StateDB , txs []* types.Transaction , uncles []* types.Header ) error {
604
604
// Accumulate any block and uncle rewards and commit the final state root
605
- accumulateRewards (chain .Config (), state , header , uncles )
605
+ if err := accumulateRewards (chain .Config (), state , header , uncles ); err != nil {
606
+ return err
607
+ }
606
608
header .Root = state .IntermediateRoot (chain .Config ().IsEIP158 (header .Number ))
609
+ return nil
607
610
}
608
611
609
612
// FinalizeAndAssemble implements consensus.Engine, accumulating the block and
610
613
// uncle rewards, setting the final state and assembling the block.
611
614
func (ethash * Ethash ) FinalizeAndAssemble (chain consensus.ChainHeaderReader , header * types.Header , state * state.StateDB , txs []* types.Transaction , uncles []* types.Header , receipts []* types.Receipt ) (* types.Block , error ) {
612
615
// Finalize block
613
- ethash .Finalize (chain , header , state , txs , uncles )
616
+ if err := ethash .Finalize (chain , header , state , txs , uncles ); err != nil {
617
+ return nil , err
618
+ }
614
619
615
620
// sign header.Root with node's private key
616
621
if ! metaminer .IsPoW () {
@@ -663,7 +668,7 @@ var (
663
668
// AccumulateRewards credits the coinbase of the given block with the mining
664
669
// reward. The total reward consists of the static block reward and rewards for
665
670
// included uncles. The coinbase of each uncle block is also rewarded.
666
- func accumulateRewards (config * params.ChainConfig , state * state.StateDB , header * types.Header , uncles []* types.Header ) {
671
+ func accumulateRewards (config * params.ChainConfig , state * state.StateDB , header * types.Header , uncles []* types.Header ) error {
667
672
// Select the correct block reward based on chain progression
668
673
blockReward := FrontierBlockReward
669
674
if config .IsByzantium (header .Number ) {
@@ -695,18 +700,13 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
695
700
func (addr common.Address , amt * big.Int ) {
696
701
state .AddBalance (addr , amt )
697
702
})
698
- if err == nil {
699
- header .Rewards = rewards
700
- if coinbase != nil {
701
- header .Coinbase = * coinbase
702
- }
703
- } else {
704
- // upon error, rewards go to the coinbase
705
- reward := new (big.Int )
706
- if header .Fees != nil {
707
- reward .Add (blockReward , header .Fees )
708
- }
709
- state .AddBalance (header .Coinbase , reward )
703
+ if err != nil {
704
+ return err
705
+ }
706
+ header .Rewards = rewards
707
+ if coinbase != nil {
708
+ header .Coinbase = * coinbase
710
709
}
711
710
}
711
+ return nil
712
712
}
0 commit comments