onflow/flow-core-contracts

Refactor rewards calculation and payment to be done in batches

joshuahannan opened this issue · 1 comments

Issue To Be Solved

The rewards payment transaction currently is a very long and costly transaction and should be made more efficient.

Suggest A Solution

And ideal solution would dynamically split up the rewards payments into batches that are a reasonable size based on number of delegators, expected gas usage, etc.

The FlowEpoch.EpochMetadata.rewardAmounts still needs to be stored in the current epoch's metadata every time in the same format as usual.

In FlowEpoch.heartbeat(), pay these batches over the course of successive blocks.

Open questions

Specifics about how and where to split these up most efficiently.

How do we determine the ideal size for a batch of rewards payments?

Can we make the batch size dynamically determined so we don't have to update it as the network grows and shrinks?

In this PR, , I moved the rewards calculation to the beginning of the epoch commit phase so that it freed up some computation at the end of the epoch, but haven't done it in batches yet