mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30: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,6 +128,7 @@ 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.
|
||||||
|
if totalSigner > 0 {
|
||||||
for signer, rLog := range signers {
|
for signer, rLog := range signers {
|
||||||
// Add reward for signer.
|
// Add reward for signer.
|
||||||
calcReward := new(big.Int)
|
calcReward := new(big.Int)
|
||||||
|
|
@ -137,6 +138,7 @@ func CalculateRewardForSigner(chainReward *big.Int, signers map[common.Address]*
|
||||||
|
|
||||||
resultSigners[signer] = calcReward
|
resultSigners[signer] = calcReward
|
||||||
}
|
}
|
||||||
|
}
|
||||||
jsonSigners, err := json.Marshal(signers)
|
jsonSigners, err := json.Marshal(signers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Fail to parse json signers", "error", err)
|
log.Error("Fail to parse json signers", "error", err)
|
||||||
|
|
@ -205,7 +207,10 @@ func GetRewardBalancesRate(masterAddr common.Address, totalReward *big.Int, vali
|
||||||
totalCap.Add(totalCap, voterCap)
|
totalCap.Add(totalCap, voterCap)
|
||||||
voterCaps[voteAddr] = voterCap
|
voterCaps[voteAddr] = voterCap
|
||||||
}
|
}
|
||||||
|
if totalCap.Cmp(new(big.Int).SetInt64(0)) > 0 {
|
||||||
for addr, voteCap := range voterCaps {
|
for addr, voteCap := range voterCaps {
|
||||||
|
// Only valid voter has cap > 0.
|
||||||
|
if voteCap.Cmp(new(big.Int).SetInt64(0)) > 0 {
|
||||||
rcap := new(big.Int).Mul(totalVoterReward, voteCap)
|
rcap := new(big.Int).Mul(totalVoterReward, voteCap)
|
||||||
rcap = new(big.Int).Div(rcap, totalCap)
|
rcap = new(big.Int).Div(rcap, totalCap)
|
||||||
if balances[addr] != nil {
|
if balances[addr] != nil {
|
||||||
|
|
@ -215,6 +220,8 @@ func GetRewardBalancesRate(masterAddr common.Address, totalReward *big.Int, vali
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foudationReward := new(big.Int).Mul(totalReward, new(big.Int).SetInt64(RewardFoundationPercent))
|
foudationReward := new(big.Int).Mul(totalReward, new(big.Int).SetInt64(RewardFoundationPercent))
|
||||||
foudationReward = new(big.Int).Div(foudationReward, new(big.Int).SetInt64(100))
|
foudationReward = new(big.Int).Div(foudationReward, new(big.Int).SetInt64(100))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue