fix uncle rewards

This commit is contained in:
Luke Williams 2019-09-12 23:05:53 +02:00
parent c02ffc0dec
commit 5ac0cff06f

View file

@ -666,7 +666,7 @@ func (ubqhash *Ubqhash) Prepare(chain consensus.ChainReader, header *types.Heade
// setting the final state and assembling the block.
func (ubqhash *Ubqhash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(state, header, uncles)
accumulateRewards(chain.Config(), state, header, uncles)
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
// Header seems complete, assemble into a block and return
@ -706,7 +706,7 @@ func (ubqhash *Ubqhash) SealHash(header *types.Header) (hash common.Hash) {
// AccumulateRewards credits the coinbase of the given block with the mining
// reward. The total reward consists of the static block reward and rewards for
// included uncles. The coinbase of each uncle block is also rewarded.
func accumulateRewards(state *state.StateDB, header *types.Header, uncles []*types.Header) {
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header) {
reward := new(big.Int).Set(blockReward)
if header.Number.Cmp(big.NewInt(358363)) > 0 {
@ -731,16 +731,22 @@ func accumulateRewards(state *state.StateDB, header *types.Header, uncles []*typ
reward = big.NewInt(1e+18)
}
// Uncle reward step down fix.
ufixReward := new(big.Int).Set(blockReward)
if config.IsByzantium(header.Number) {
ufixReward = reward
}
r := new(big.Int)
for _, uncle := range uncles {
r.Add(uncle.Number, big2)
r.Sub(r, header.Number)
r.Mul(r, blockReward)
r.Mul(r, ufixReward)
r.Div(r, big2)
if header.Number.Cmp(big.NewInt(10)) < 0 {
state.AddBalance(uncle.Coinbase, r)
r.Div(blockReward, big32)
r.Div(ufixReward, big32)
if r.Cmp(big.NewInt(0)) < 0 {
r = big.NewInt(0)
}
@ -749,7 +755,7 @@ func accumulateRewards(state *state.StateDB, header *types.Header, uncles []*typ
r = big.NewInt(0)
}
state.AddBalance(uncle.Coinbase, r)
r.Div(blockReward, big32)
r.Div(ufixReward, big32)
}
reward.Add(reward, r)