Gas limit for bounty and slashing distribution
After every bounty payment (should be once per month) to a validator, the bounty is distributed to all delegators. In order to do that, there is a `for` loop that iterates over all active delegators and sends their bounty to `SkaleBalances` contract:\\n```\\nfor (uint i = 0; i < shares.length; ++i) {\\n    skaleToken.send(address(skaleBalances), shares[i].amount, abi.encode(shares[i].holder));\\n\\n    uint created = delegationController.getDelegation(shares[i].delegationId).created;\\n    uint delegationStarted = timeHelpers.getNextMonthStartFromDate(created);\\n    skaleBalances.lockBounty(shares[i].holder, timeHelpers.addMonths(delegationStarted, 3));\\n}\\n```\\n\\nThere are also few more loops over all the active delegators. This leads to a huge gas cost of distribution mechanism. A number of active delegators that can be processed before hitting the gas limit is limited and not big enough.\\nThe same issue is with slashing:\\n```\\nfunction slash(uint validatorId, uint amount) external allow("SkaleDKG") {\\n    ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService"));\\n    require(validatorService.validatorExists(validatorId), "Validator does not exist");\\n\\n    Distributor distributor = Distributor(contractManager.getContract("Distributor"));\\n    TokenState tokenState = TokenState(contractManager.getContract("TokenState"));\\n\\n    Distributor.Share[] memory shares = distributor.distributePenalties(validatorId, amount);\\n    for (uint i = 0; i < shares.length; ++i) {\\n        tokenState.slash(shares[i].delegationId, shares[i].amount);\\n    }\\n}\\n```\\n
The best solution would require major changes to the codebase, but would eventually make it simpler and safer. Instead of distributing and centrally calculating bounty for each delegator during one call it's better to just store all the necessary values, so delegator would be able to calculate the bounty on withdrawal. Amongst the necessary values, there should be history of total delegated amounts per validator during each bounty payment and history of all delegations with durations of their active state.
```\\nfor (uint i = 0; i < shares.length; ++i) {\\n    skaleToken.send(address(skaleBalances), shares[i].amount, abi.encode(shares[i].holder));\\n\\n    uint created = delegationController.getDelegation(shares[i].delegationId).created;\\n    uint delegationStarted = timeHelpers.getNextMonthStartFromDate(created);\\n    skaleBalances.lockBounty(shares[i].holder, timeHelpers.addMonths(delegationStarted, 3));\\n}\\n```\\n