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.
This commit is contained in:
		| @@ -210,10 +210,12 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Accumulate static rewards; block reward, uncle's and uncle inclusion. | 	// Verify uncles | ||||||
| 	if err = sm.AccumulateRewards(state, block, parent); err != nil { | 	if err = sm.VerifyUncles(state, block, parent); err != nil { | ||||||
| 		return | 		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) | 	// Commit state objects/accounts to a temporary trie (does not save) | ||||||
| 	// used to calculate the state root. | 	// used to calculate the state root. | ||||||
| @@ -291,9 +293,27 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error { | |||||||
| 	return nil | 	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) | 	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() | 	ancestors := set.New() | ||||||
| 	uncles := set.New() | 	uncles := set.New() | ||||||
| 	ancestorHeaders := make(map[common.Hash]*types.Header) | 	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)) | 			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 | 	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.TransitionState(state, parent, block, true) | ||||||
| 	sm.AccumulateRewards(state, block, parent) |  | ||||||
|  |  | ||||||
| 	return state.Logs(), nil | 	return state.Logs(), nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ out: | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	close(self.quitCurrentOp) | 	//close(self.quitCurrentOp) | ||||||
| done: | done: | ||||||
| 	// Empty channel | 	// Empty channel | ||||||
| 	for { | 	for { | ||||||
|   | |||||||
| @@ -270,7 +270,7 @@ gasLimit: | |||||||
|  |  | ||||||
| 	self.current.block.SetUncles(uncles) | 	self.current.block.SetUncles(uncles) | ||||||
|  |  | ||||||
| 	self.current.state.AddBalance(self.coinbase, core.BlockReward) | 	core.AccumulateRewards(self.current.state, self.current.block) | ||||||
|  |  | ||||||
| 	self.current.state.Update(common.Big0) | 	self.current.state.Update(common.Big0) | ||||||
| 	self.push() | 	self.push() | ||||||
| @@ -297,9 +297,6 @@ func (self *worker) commitUncle(uncle *types.Header) error { | |||||||
| 		return core.UncleError(fmt.Sprintf("Uncle already in family (%x)", uncle.Hash())) | 		return core.UncleError(fmt.Sprintf("Uncle already in family (%x)", uncle.Hash())) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	self.current.state.AddBalance(uncle.Coinbase, uncleReward) |  | ||||||
| 	self.current.state.AddBalance(self.coinbase, inclusionReward) |  | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user