Skip to content

Commit

Permalink
Fix #199
Browse files Browse the repository at this point in the history
- skip reward calculation if there are no eletected PReps
  • Loading branch information
eunsoo-icon committed Jan 23, 2024
1 parent 7263acb commit 1887305
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 9 additions & 5 deletions icon/iiss/calculator/iiss4.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ func (r *iiss4Reward) Calculate() error {
return err
}

if err = r.processPrepReward(); err != nil {
return err
}
if r.g.GetElectedPRepCount() == 0 {
r.Logger().Debugf("there is no elected PRep. skip reward calculation")
} else {
if err = r.processPrepReward(); err != nil {
return err
}

if err = r.processVoterReward(); err != nil {
return err
if err = r.processVoterReward(); err != nil {
return err
}
}

if err = processBTP(r); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions icon/iiss/calculator/prep.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ func fundToPeriodIScore(reward *big.Int, period int64) *big.Int {
// CalculateReward calculates commission, wage and voter reward of the PRep.
func (p *PRepInfo) CalculateReward(totalReward, totalMinWage, minBond *big.Int) error {
p.log.Debugf("CalculateReward()")
if p.electedPRepCount == 0 {
p.log.Debugf("skip PRepInfo.CalculateReward()")
return nil
}
tReward := fundToPeriodIScore(totalReward, p.GetTermPeriod())
minWage := fundToPeriodIScore(totalMinWage, p.GetTermPeriod())
p.log.Debugf("RewardFund: PRep: %d, wage: %d", tReward, minWage)
Expand Down
8 changes: 8 additions & 0 deletions icon/iiss/calculator/prep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,11 @@ func prepReward(prep *PRep, totalReward, totalPower int64, offsetLimit int) (rew
commission = prep.commissionRate.MulInt64(reward)
return
}

func TestPRepInfo_CalculateReward_without_elected_prep(t *testing.T) {
pInfo := newTestPRepInfo(nil, icmodule.ToRate(5), 100, 0)
assert.NotPanics(t, func() {
err := pInfo.CalculateReward(big.NewInt(1_000), big.NewInt(1_000), big.NewInt(300))
assert.NoError(t, err)
})
}

0 comments on commit 1887305

Please sign in to comment.