diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-02 03:18:41 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-02 03:18:41 +0800 |
commit | 344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a (patch) | |
tree | 2216ff16ed60340f904b889b532ef513e21bb451 /core | |
parent | 516ec28544e0f9c76e18d82742d3ae58cfb59cc1 (diff) | |
download | dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.tar dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.tar.gz dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.tar.bz2 dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.tar.lz dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.tar.xz dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.tar.zst dexon-344b3556ebd8c96f96d78ad2d9d386e6ed66ce0a.zip |
Fixed uncle rewards in miner
The uncle rewards were changed in the block processor. This change will
reflect those changes in the miner as well.
Diffstat (limited to 'core')
-rw-r--r-- | core/block_processor.go | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/core/block_processor.go b/core/block_processor.go index f7f0cd188..ec68dc6c9 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -210,10 +210,12 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big return } - // Accumulate static rewards; block reward, uncle's and uncle inclusion. - if err = sm.AccumulateRewards(state, block, parent); err != nil { + // Verify uncles + if err = sm.VerifyUncles(state, block, parent); err != nil { return } + // Accumulate static rewards; block reward, uncle's and uncle inclusion. + AccumulateRewards(state, block) // Commit state objects/accounts to a temporary trie (does not save) // used to calculate the state root. @@ -291,9 +293,27 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error { return nil } -func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, parent *types.Block) error { +func AccumulateRewards(statedb *state.StateDB, block *types.Block) { reward := new(big.Int).Set(BlockReward) + for _, uncle := range block.Uncles() { + num := new(big.Int).Add(big.NewInt(8), uncle.Number) + num.Sub(num, block.Number()) + + r := new(big.Int) + r.Mul(BlockReward, num) + r.Div(r, big.NewInt(8)) + + statedb.AddBalance(uncle.Coinbase, r) + + reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32))) + } + + // Get the account associated with the coinbase + statedb.AddBalance(block.Header().Coinbase, reward) +} + +func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *types.Block) error { ancestors := set.New() uncles := set.New() ancestorHeaders := make(map[common.Hash]*types.Header) @@ -327,21 +347,8 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren return ValidationError(fmt.Sprintf("%v", err)) } - num := new(big.Int).Add(big.NewInt(8), uncle.Number) - num.Sub(num, block.Number()) - - r := new(big.Int) - r.Mul(BlockReward, num) - r.Div(r, big.NewInt(8)) - - statedb.AddBalance(uncle.Coinbase, r) - - reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32))) } - // Get the account associated with the coinbase - statedb.AddBalance(block.Header().Coinbase, reward) - return nil } @@ -358,7 +365,6 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro ) sm.TransitionState(state, parent, block, true) - sm.AccumulateRewards(state, block, parent) return state.Logs(), nil } |