I'm building a staking pool as a way to learn smart contract using solidity. The staking reward will be calculated based on how much is the user's balance and for how long he/she has been staking. The problem is during the course of staking the balance can change. So how can I achieve a fair reward distribution? Can one calculate reward distribution every block?