In a naive implementation, the staking contract would push fractional payments to all the participants each time a reward gets distributed. However, in such an implementation the distribute function would take O(N) time to compute, where N is the number of participants.
Is there a better solution?
I've been working on the fractional approach pegged on block number instead of time
Distribution of rewards among stakeholders iterating over an array of stakeholders is inefficient in terms of gas spending. Therefore to calculate the reward since the last reward calculation requires keeping the sum of rewards at block #X and total staked at block #X. Hence, on each reward addition, we need to keep an array of the sum of stakes at a specific block number. And the second array is for the sum of rewards at a specific block number. It's becoming quite complicated. To keep it non-reentrant along with an ever-growing 2 array of sums.
Need some input on how to implement this on-chain