mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
fix uncle rewards
This commit is contained in:
parent
c02ffc0dec
commit
5ac0cff06f
1 changed files with 15 additions and 9 deletions
|
|
@ -666,7 +666,7 @@ func (ubqhash *Ubqhash) Prepare(chain consensus.ChainReader, header *types.Heade
|
||||||
// setting the final state and assembling the block.
|
// 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) {
|
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
|
// 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.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
|
|
||||||
// Header seems complete, assemble into a block and return
|
// 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
|
// AccumulateRewards credits the coinbase of the given block with the mining
|
||||||
// reward. The total reward consists of the static block reward and rewards for
|
// reward. The total reward consists of the static block reward and rewards for
|
||||||
// included uncles. The coinbase of each uncle block is also rewarded.
|
// 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)
|
reward := new(big.Int).Set(blockReward)
|
||||||
|
|
||||||
if header.Number.Cmp(big.NewInt(358363)) > 0 {
|
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)
|
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)
|
r := new(big.Int)
|
||||||
for _, uncle := range uncles {
|
for _, uncle := range uncles {
|
||||||
r.Add(uncle.Number, big2)
|
r.Add(uncle.Number, big2)
|
||||||
r.Sub(r, header.Number)
|
r.Sub(r, header.Number)
|
||||||
r.Mul(r, blockReward)
|
r.Mul(r, ufixReward)
|
||||||
r.Div(r, big2)
|
r.Div(r, big2)
|
||||||
|
|
||||||
if header.Number.Cmp(big.NewInt(10)) < 0 {
|
if header.Number.Cmp(big.NewInt(10)) < 0 {
|
||||||
state.AddBalance(uncle.Coinbase, r)
|
state.AddBalance(uncle.Coinbase, r)
|
||||||
r.Div(blockReward, big32)
|
r.Div(ufixReward, big32)
|
||||||
if r.Cmp(big.NewInt(0)) < 0 {
|
if r.Cmp(big.NewInt(0)) < 0 {
|
||||||
r = big.NewInt(0)
|
r = big.NewInt(0)
|
||||||
}
|
}
|
||||||
|
|
@ -749,7 +755,7 @@ func accumulateRewards(state *state.StateDB, header *types.Header, uncles []*typ
|
||||||
r = big.NewInt(0)
|
r = big.NewInt(0)
|
||||||
}
|
}
|
||||||
state.AddBalance(uncle.Coinbase, r)
|
state.AddBalance(uncle.Coinbase, r)
|
||||||
r.Div(blockReward, big32)
|
r.Div(ufixReward, big32)
|
||||||
}
|
}
|
||||||
|
|
||||||
reward.Add(reward, r)
|
reward.Add(reward, r)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue