Skip to content

Commit

Permalink
Merge pull request #434 from iotaledger/fix_rewards_calculations
Browse files Browse the repository at this point in the history
Fix rewards calculations
  • Loading branch information
karimodm authored Oct 19, 2023
2 parents 73ba689 + ad9b2b8 commit 4947202
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 168 deletions.
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ require (
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/app v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/constraints v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/crypto v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/ds v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/lo v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/logger v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/runtime v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/stringify v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/ads v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/app v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/constraints v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019113503-7986872a7a38
github.com/iotaledger/hive.go/crypto v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/ds v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/lo v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/logger v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/runtime v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019113503-7986872a7a38
github.com/iotaledger/hive.go/stringify v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231011161248-cf0bd6e08811
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231011154428-257141868dad
github.com/iotaledger/iota.go/v4 v4.0.0-20231019083312-e415fefc417c
Expand Down Expand Up @@ -88,7 +88,7 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/ipfs/boxo v0.10.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
56 changes: 28 additions & 28 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,34 +277,34 @@ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJ
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PTNgli6EbS4tV9qu3QAm/kBU3XaYZV2xdzys=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7/go.mod h1:ZRdPu684P0fQ1z8sXz4dj9H5LWHhz4a9oCtvjunkSrw=
github.com/iotaledger/hive.go/ads v0.0.0-20231019082730-54e1c06ab9c2 h1:asyE+LxMChmcSix5rsms0L23jrlzJt616UoDijPpWTY=
github.com/iotaledger/hive.go/ads v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231019082730-54e1c06ab9c2 h1:ZjcC0WoYVs64iMFHzodM8qsdncA9O2ItWA3A98JhHMo=
github.com/iotaledger/hive.go/app v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231019082730-54e1c06ab9c2 h1:QPDVoivTVVJIYfXuWW2GpEZLFaJQutkevr2Wm/VKdu4=
github.com/iotaledger/hive.go/constraints v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019082730-54e1c06ab9c2 h1:oVnQnvYgLEzlFxEu4DcHYfGqT5v+8fVQfAGyPMmZL6c=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019082730-54e1c06ab9c2/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231019082730-54e1c06ab9c2 h1:CTbrWBYM98pfpfdYNGfx/a8ub4SXrltjmeGjpB7Jkx4=
github.com/iotaledger/hive.go/crypto v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231019082730-54e1c06ab9c2 h1:8i4bvVO+paY/ZxWKr0OHw1xx8Kz9CUIg3+B5gVl7fjk=
github.com/iotaledger/hive.go/ds v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019082730-54e1c06ab9c2 h1:rpBz3vmvDd2rab6kZE4b4NXkaNSKsJ7v74DLOsbBUlA=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019082730-54e1c06ab9c2 h1:fgKzJkRaLIGUZpQaB6koK3tYagN2nSaGo1qXmNaKRaA=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231019082730-54e1c06ab9c2 h1:BUsL7XFucscD/7jtEpS/EbgFI08PhP4Af3gHNMRqkKA=
github.com/iotaledger/hive.go/lo v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231019082730-54e1c06ab9c2 h1:Pm1UzKTgobqi1SSX7VG3wMYtahq4vagtOLI/xUypoto=
github.com/iotaledger/hive.go/log v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231019082730-54e1c06ab9c2 h1:+LqfdkgC1ahuAhTbXPIyydmni8IsvxNgZziM1cZKfmc=
github.com/iotaledger/hive.go/logger v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231019082730-54e1c06ab9c2 h1:7keivgxNXi2yqt6yx3TWMmZf9vBEaGM4UNpFuaRxg8E=
github.com/iotaledger/hive.go/runtime v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019082730-54e1c06ab9c2 h1:as3d3f7gH2/fR1997OWmRPpKwjY0E1X7Twc4LWBTEuE=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019082730-54e1c06ab9c2/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231019082730-54e1c06ab9c2 h1:virnPQxZvZ00VqcZBzTvPo5DLUZgIvH06YEhktwW224=
github.com/iotaledger/hive.go/stringify v0.0.0-20231019082730-54e1c06ab9c2/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/hive.go/ads v0.0.0-20231019113503-7986872a7a38 h1:/Td52GNRrMzh0lVKwQu/BbVciwrKn5LwtkWAzd41X4Q=
github.com/iotaledger/hive.go/ads v0.0.0-20231019113503-7986872a7a38/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231019113503-7986872a7a38 h1:t60nsq/lI168gM0WqIP44FDHk784uXy35P6uKt9WbMU=
github.com/iotaledger/hive.go/app v0.0.0-20231019113503-7986872a7a38/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231019113503-7986872a7a38 h1:xYh6+dUl+iocWofo0Z/0/OJGSdxYaPV1oYo1HlFj8+s=
github.com/iotaledger/hive.go/constraints v0.0.0-20231019113503-7986872a7a38/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019113503-7986872a7a38 h1:3OUYK9wgyH4U6xfGnLdU1QdYQ5dpS/6WRju+eXP051E=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019113503-7986872a7a38/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231019113503-7986872a7a38 h1:iXqM0/Y4poiiuNf+0tu3nUj9Dzp4slrWHJ8GXKgt2Zk=
github.com/iotaledger/hive.go/crypto v0.0.0-20231019113503-7986872a7a38/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231019113503-7986872a7a38 h1:xyaKXgNt8CQ4t14Raqu/4+aBRZQunGOlK+T+99egkSA=
github.com/iotaledger/hive.go/ds v0.0.0-20231019113503-7986872a7a38/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019113503-7986872a7a38 h1:6I6PEdLuwiIpmiXFVEW5lPaNe+xFdaBR6NSHsNZ3o6c=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019113503-7986872a7a38/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019113503-7986872a7a38 h1:SCBXTAhrLFs0o9EJxO9ZBGPyfq1VhOdb5pP7+vFhdtk=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019113503-7986872a7a38/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231019113503-7986872a7a38 h1:qks472rk/MjwwFvDrlpckxWTf4c1yd+k7ve/IkeuPYk=
github.com/iotaledger/hive.go/lo v0.0.0-20231019113503-7986872a7a38/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231019113503-7986872a7a38 h1:6HIBNKOWLXY5Gk1s+q93D6IsTcqwANigfMO3ePtV3HQ=
github.com/iotaledger/hive.go/log v0.0.0-20231019113503-7986872a7a38/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231019113503-7986872a7a38 h1:lTp8+8GgFH63IMY0G9B90v2vmOlgo+c3XiZg4f0Te+I=
github.com/iotaledger/hive.go/logger v0.0.0-20231019113503-7986872a7a38/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231019113503-7986872a7a38 h1:lPiKbh8o/SN2FGCN9RF7iN1zE+KXCidp815GSOieU8s=
github.com/iotaledger/hive.go/runtime v0.0.0-20231019113503-7986872a7a38/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019113503-7986872a7a38 h1:njGr4TrKdpa66XyioxhDU3slV9gZOZeEg7/M8bjXw7M=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019113503-7986872a7a38/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231019113503-7986872a7a38 h1:jh0LHzzLqVO+SW9NkvNIgYo1g3CyTBnR8Qv3+PNH+dY=
github.com/iotaledger/hive.go/stringify v0.0.0-20231019113503-7986872a7a38/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231011161248-cf0bd6e08811 h1:nR8uTm1Htn2RQOT53RV2zdCIflpuF8N00Tv2FWYimY0=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231011161248-cf0bd6e08811/go.mod h1:rmclNpXw5sKJDHU0e51Ar/9zL00P7Uu9hkfaM7vAAiE=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231011154428-257141868dad h1:TRM9EkAole9fYY1vHEVQ6zCEOGuvCWq/bczZ98Al5Ec=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota
return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate profit margin factor due to overflow for epoch %d and validator accountID %s", epoch, validatorID)
}

result, err = safemath.SafeMul(result>>profitMarginExponent, uint64(stakeAmount))
if err != nil {
return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate profit margin factor due to overflow for epoch %d and validator accountID %s", epoch, validatorID)
}

residualValidatorFactor, err := safemath.SafeDiv(result, uint64(rewardsForAccountInEpoch.PoolStake))
residualValidatorFactor, err := safemath.Safe64MulDiv(result>>profitMarginExponent, uint64(stakeAmount), uint64(rewardsForAccountInEpoch.PoolStake))
if err != nil {
return 0, 0, 0, ierrors.Wrapf(err, "failed to calculate residual validator factor due to overflow for epoch %d and validator accountID %s", epoch, validatorID)
}
Expand Down Expand Up @@ -210,6 +205,7 @@ func (t *Tracker) rewardsForAccount(accountID iotago.AccountID, epoch iotago.Epo

return m.Get(accountID)
}

func (t *Tracker) poolReward(slot iotago.SlotIndex, totalValidatorsStake, totalStake, poolStake, validatorStake iotago.BaseToken, performanceFactor uint64) (iotago.Mana, error) {
apiForSlot := t.apiProvider.APIForSlot(slot)
epoch := apiForSlot.TimeProvider().EpochFromSlot(slot)
Expand Down
28 changes: 14 additions & 14 deletions tools/evil-spammer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ replace github.com/iotaledger/iota-core/tools/genesis-snapshot => ../genesis-sna
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/ethereum/go-ethereum v1.13.4
github.com/iotaledger/hive.go/app v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/ds v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/lo v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/logger v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/runtime v0.0.0-20231019082730-54e1c06ab9c2
github.com/iotaledger/hive.go/app v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231019113503-7986872a7a38
github.com/iotaledger/hive.go/ds v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/ierrors v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/lo v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/logger v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/hive.go/runtime v0.0.0-20231019113503-7986872a7a38
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota-core/tools/genesis-snapshot v0.0.0-00010101000000-000000000000
github.com/iotaledger/iota.go/v4 v4.0.0-20231019083312-e415fefc417c
Expand All @@ -37,13 +37,13 @@ require (
github.com/holiman/uint256 v1.2.3 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/iotaledger/hive.go/ads v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/crypto v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231019082730-54e1c06ab9c2 // indirect
github.com/iotaledger/hive.go/ads v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/iotaledger/hive.go/crypto v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/iotaledger/hive.go/kvstore v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231019113503-7986872a7a38 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231019113503-7986872a7a38 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
Expand Down
Loading

0 comments on commit 4947202

Please sign in to comment.