Fix voted reward calculation
Segment the reward period only by unregister TX of elected P-Reps
@@ -429,7 +429,7 @@ func (c *Calculator) calculateVotedReward() error {
switch type_ {
case icstage.TypeEventEnable:
obj := icstage.ToEventEnable(o)
- if obj.Status().IsEnabled() == false {
+ if obj.Status().IsEnabled() == false && vInfo.IsElectedPRep(obj.Target()) {
vInfo.CalculateReward(multiplier, divider, keyOffset-from)
from = keyOffset
vInfo.SetEnable(obj.Target(), obj.Status())
@@ -1225,6 +1225,19 @@ func (vi *votedInfo) GetPRepByAddress(addr module.Address) *votedData {
return vi.preps[key]
}
+func (vi *votedInfo) IsElectedPRep(addr module.Address) bool {
+ key := icutils.ToKey(addr)
+ for i, addrKey := range vi.rank {
+ if i == vi.maxRankForReward {
+ return false
+ }
+ if key == addrKey {
+ return true
+ }
+ }
+ return false
+}
+
func (vi *votedInfo) AddVotedData(addr module.Address, data *votedData) {
vi.preps[icutils.ToKey(addr)] = data
if data.Enable() {
