mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
Fixed div by zero for calculate reward.
This commit is contained in:
parent
9a6c1c5382
commit
73b55f9815
1 changed files with 21 additions and 14 deletions
|
|
@ -128,14 +128,16 @@ func GetRewardForCheckpoint(chain consensus.ChainReader, blockSignerAddr common.
|
||||||
func CalculateRewardForSigner(chainReward *big.Int, signers map[common.Address]*rewardLog, totalSigner uint64) (map[common.Address]*big.Int, error) {
|
func CalculateRewardForSigner(chainReward *big.Int, signers map[common.Address]*rewardLog, totalSigner uint64) (map[common.Address]*big.Int, error) {
|
||||||
resultSigners := make(map[common.Address]*big.Int)
|
resultSigners := make(map[common.Address]*big.Int)
|
||||||
// Add reward for signers.
|
// Add reward for signers.
|
||||||
for signer, rLog := range signers {
|
if totalSigner > 0 {
|
||||||
// Add reward for signer.
|
for signer, rLog := range signers {
|
||||||
calcReward := new(big.Int)
|
// Add reward for signer.
|
||||||
calcReward.Div(chainReward, new(big.Int).SetUint64(totalSigner))
|
calcReward := new(big.Int)
|
||||||
calcReward.Mul(calcReward, new(big.Int).SetUint64(rLog.Sign))
|
calcReward.Div(chainReward, new(big.Int).SetUint64(totalSigner))
|
||||||
rLog.Reward = calcReward
|
calcReward.Mul(calcReward, new(big.Int).SetUint64(rLog.Sign))
|
||||||
|
rLog.Reward = calcReward
|
||||||
|
|
||||||
resultSigners[signer] = calcReward
|
resultSigners[signer] = calcReward
|
||||||
|
}
|
||||||
}
|
}
|
||||||
jsonSigners, err := json.Marshal(signers)
|
jsonSigners, err := json.Marshal(signers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -205,13 +207,18 @@ func GetRewardBalancesRate(masterAddr common.Address, totalReward *big.Int, vali
|
||||||
totalCap.Add(totalCap, voterCap)
|
totalCap.Add(totalCap, voterCap)
|
||||||
voterCaps[voteAddr] = voterCap
|
voterCaps[voteAddr] = voterCap
|
||||||
}
|
}
|
||||||
for addr, voteCap := range voterCaps {
|
if totalCap.Cmp(new(big.Int).SetInt64(0)) > 0 {
|
||||||
rcap := new(big.Int).Mul(totalVoterReward, voteCap)
|
for addr, voteCap := range voterCaps {
|
||||||
rcap = new(big.Int).Div(rcap, totalCap)
|
// Only valid voter has cap > 0.
|
||||||
if balances[addr] != nil {
|
if voteCap.Cmp(new(big.Int).SetInt64(0)) > 0 {
|
||||||
balances[addr].Add(balances[addr], rcap)
|
rcap := new(big.Int).Mul(totalVoterReward, voteCap)
|
||||||
} else {
|
rcap = new(big.Int).Div(rcap, totalCap)
|
||||||
balances[addr] = rcap
|
if balances[addr] != nil {
|
||||||
|
balances[addr].Add(balances[addr], rcap)
|
||||||
|
} else {
|
||||||
|
balances[addr] = rcap
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue