moonbeam-foundation / crowdloan-rewards

Substrate pallet that enables parachains to issue rewards to crowdloan contributors in parachain-native tokens.
12 stars 16 forks source link

`payable_per_block` suffers from integer division truncation #9

Closed notlesh closed 3 years ago

notlesh commented 3 years ago

The calculation for paying out a reward currently "rounds down" as a result of integer division. This result is then amplified by the number of blocks used to calculate how much should be paid over time, effectively dampening the payout rate.

The relevant code starts here.

As an extreme example, if payable_per_block were calculated as 2/3 (e.g. info.total_reward - first_paid == 2 and T::VestingPeriod::get() == 3), the result would be 0 (because floor(2/3) == 0). In this extreme case, no rewards would ever be paid out (as a result of lines 439/440).

The above is the case when (info.total_reward - first_paid) < T::VestingPeriod::get().

In less extreme examples (such as 11/10) the results would be that the payout rate is reduced, although the user would eventually be able to claim the entire balance (e.g. line 444).

girazoki commented 3 years ago

Thanks, will work on a solution for this

girazoki commented 3 years ago

https://github.com/PureStake/crowdloan-rewards/pull/10 should solve it