Skip to content

Commit

Permalink
Merge pull request #79 from node-real/addtional-reward-for-collecting…
Browse files Browse the repository at this point in the history
…-more-votes-than-needed

distribute additional reward for collecting redundant votes
  • Loading branch information
NathanBSC authored Apr 4, 2023
2 parents d173cbf + fba030c commit 6f79937
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const (
processBackOffTime = uint64(1) // second

systemRewardPercent = 4 // it means 1/2^4 = 1/16 percentage of gas fee incoming will be distributed to system

collectAdditionalVotesRewardRatio = float64(1) // ratio of additional reward for collecting more votes than needed
)

var (
Expand Down Expand Up @@ -999,11 +1001,17 @@ func (p *Parlia) distributeFinalityReward(chain consensus.ChainHeaderReader, sta
log.Error("invalid attestation, vote number larger than validators number")
continue
}
validVoteCount := 0
for index, val := range validators {
if validatorsBitSet.Test(uint(index)) {
accumulatedWeights[val] += 1
validVoteCount += 1
}
}
quorum := cmath.CeilDiv(len(snap.Validators)*2, 3)
if validVoteCount > quorum {
accumulatedWeights[head.Coinbase] += uint64(float64(validVoteCount-quorum) * collectAdditionalVotesRewardRatio)
}
}

validators := make([]common.Address, 0, len(accumulatedWeights))
Expand Down

0 comments on commit 6f79937

Please sign in to comment.