Skip to content

Commit 40f05b2

Browse files
committed
reward supply fix
1 parent 9f70de1 commit 40f05b2

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

consensus/cuckoo/consensus.go

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
380380
}
381381

382382
if parent.Difficulty.Cmp(params.MeanDifficultyBoundDivisor) >= 0 && parent.Difficulty.Cmp(params.HighDifficultyBoundDivisor) < 0 {
383-
y.Div(parent.Difficulty, params.MeanDifficultyBoundDivisor)
384-
} else if parent.Difficulty.Cmp(params.HighDifficultyBoundDivisor) >= 0 {
385-
y.Div(parent.Difficulty, params.HighDifficultyBoundDivisor)
386-
} else {
387-
y.Div(parent.Difficulty, params.DifficultyBoundDivisor)
388-
}
383+
y.Div(parent.Difficulty, params.MeanDifficultyBoundDivisor)
384+
} else if parent.Difficulty.Cmp(params.HighDifficultyBoundDivisor) >= 0 {
385+
y.Div(parent.Difficulty, params.HighDifficultyBoundDivisor)
386+
} else {
387+
y.Div(parent.Difficulty, params.DifficultyBoundDivisor)
388+
}
389389

390390
// parent_diff + (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))
391391
y.Div(parent.Difficulty, params.DifficultyBoundDivisor)
@@ -658,11 +658,11 @@ func (cuckoo *Cuckoo) SealHash(header *types.Header) (hash common.Hash) {
658658
var (
659659
big0 = big.NewInt(0)
660660
//big2 = big.NewInt(2)
661-
big4 = big.NewInt(4)
662-
big8 = big.NewInt(8)
663-
big32 = big.NewInt(32)
664-
big64 = big.NewInt(64)
665-
big128 = big.NewInt(128)
661+
big4 = big.NewInt(4)
662+
big8 = big.NewInt(8)
663+
big32 = big.NewInt(32)
664+
big64 = big.NewInt(64)
665+
big128 = big.NewInt(128)
666666
big4096 = big.NewInt(4096)
667667
)
668668

@@ -684,13 +684,21 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
684684
/*if config.IsConstantinople(header.Number) {
685685
blockReward = ConstantinopleBlockReward
686686
}*/
687-
header.Supply.Add(header.Supply, blockReward)
688-
if header.Supply.Cmp(params.CTXC_TOP) > 0 {
687+
688+
if header.Supply.Cmp(params.CTXC_TOP) >= 0 {
689689
blockReward = big0
690690
header.Supply = params.CTXC_TOP
691691
}
692-
// Accumulate the rewards for the miner and any included uncles
692+
693693
if blockReward.Cmp(big0) > 0 {
694+
surplus := new(big.Int).Sub(params.CTXC_TOP, header.Supply)
695+
header.Supply.Add(header.Supply, blockReward)
696+
if header.Supply.Cmp(params.CTXC_TOP) >= 0 {
697+
blockReward = surplus
698+
header.Supply = params.CTXC_TOP
699+
}
700+
// Accumulate the rewards for the miner and any included uncles
701+
//if blockReward.Cmp(big0) > 0 {
694702
reward := new(big.Int).Set(blockReward)
695703
r := new(big.Int)
696704
for _, uncle := range uncles {
@@ -701,15 +709,25 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
701709

702710
header.Supply.Add(header.Supply, r)
703711
if header.Supply.Cmp(params.CTXC_TOP) > 0 {
712+
//header.Supply = params.CTXC_TOP
713+
header.Supply.Sub(header.Supply, r)
704714
r = big0
705-
header.Supply = params.CTXC_TOP
715+
break
706716
}
707717
state.AddBalance(uncle.Coinbase, r)
708718
//todo
709-
/*r.Div(blockReward, big8)
710-
state.AddBalance(uncle.Coinbase, r)
719+
//r.Div(blockReward, big8)
720+
//state.AddBalance(uncle.Coinbase, r)
721+
711722
r.Div(blockReward, big32)
712-
reward.Add(reward, r)*/
723+
header.Supply.Add(header.Supply, r)
724+
if header.Supply.Cmp(params.CTXC_TOP) > 0 {
725+
header.Supply.Sub(header.Supply, r)
726+
r = big0
727+
//header.Supply = params.CTXC_TOP
728+
break
729+
}
730+
reward.Add(reward, r)
713731
}
714732

715733
state.AddBalance(header.Coinbase, reward)

0 commit comments

Comments
 (0)