diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go index 2e880d113..ba3857281 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go @@ -185,14 +185,9 @@ func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount return 0, 0, 0, ierrors.Wrapf(err, "failed to multiply profitMarginComplement and poolReward for unDecayedEpochRewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } - result, err = safemath.SafeDiv(result>>profitMarginExponent, uint64(rewardsForAccountInEpoch.PoolStake)) + undecayedEpochRewards, err := safemath.Safe64MulDiv(result>>profitMarginExponent, uint64(delegatedAmount), uint64(rewardsForAccountInEpoch.PoolStake)) if err != nil { - return 0, 0, 0, ierrors.Wrapf(err, "failed to divide by PoolStake for unDecayedEpochRewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) - } - - undecayedEpochRewards, err := safemath.SafeMul(result, uint64(delegatedAmount)) - if err != nil { - return 0, 0, 0, ierrors.Wrapf(err, "failed to multiply by delegatedAmmount for unDecayedEpochRewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) + return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate unDecayedEpochRewards due to overflow for epoch %d and validator accountID %s", epoch, validatorID) } decayProvider := t.apiProvider.APIForEpoch(epoch).ManaDecayProvider() diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go index 99c3d9b08..8e9ea3dea 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/testsuite_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/require" + "github.com/iotaledger/hive.go/core/safemath" + "github.com/iotaledger/hive.go/kvstore" "github.com/iotaledger/hive.go/kvstore/mapdb" "github.com/iotaledger/hive.go/lo" @@ -272,7 +274,10 @@ func (t *TestSuite) delegatorReward(epoch iotago.EpochIndex, profitMargin, poolR if poolRewardWithFixedCost >= fixedCost { poolRewards = poolRewardWithFixedCost - fixedCost } - unDecayedEpochRewards := (((profitMarginComplement * poolRewards) >> profitMarginExponent) / poolStake) * delegatedAmount + + result := (profitMarginComplement * poolRewards) >> profitMarginExponent + unDecayedEpochRewards, err := safemath.Safe64MulDiv(result, delegatedAmount, poolStake) + require.NoError(t.T, err) decayProvider := t.api.ManaDecayProvider() decayedEpochRewards, err := decayProvider.DecayManaByEpochs(iotago.Mana(unDecayedEpochRewards), epoch, epoch)