Skip to content

Commit

Permalink
distribute addtional reward for collecting more votes than needed
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC committed Apr 4, 2023
1 parent d173cbf commit 02029d2
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

collectAddtionalVotesRewardRatio = float64(1) // ratio of addtional 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) * collectAddtionalVotesRewardRatio)
}
}

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

0 comments on commit 02029d2

Please sign in to comment.