Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/rewards distribution 2 #97

Merged
merged 8 commits into from
Dec 16, 2024
Merged

F/rewards distribution 2 #97

merged 8 commits into from
Dec 16, 2024

Conversation

maurolacy
Copy link
Collaborator

@maurolacy maurolacy commented Dec 11, 2024

Follow-up / Alternative to #95, in which the rewards are distributed over the (latest) active finality provider set.

This may incur a number of (small) errors in the distribution, namely:

  1. It rewards members of the active set wether they voted for a block or not. This is good for simplicity, as tracking the votes would require delaying rewards distribution until all the votes for a block are gathered. This is also what is being done on the Babylon side AFAIK.
  2. It rewards members of the latest active set, even when some previous blocks might have been finalised over / with a different active set. In this impl we distribute pending rewards as soon as we have an active set available. Since the active set changes infrequently and (typically) slightly, this is good for simplicity, as in this way we don't need to track which rewards belong to which active set / height. This design decision is also supported by the fact that block rewards are small, and so reward errors per block, if any, will be accordingly small as well.
  3. We consider the entire balance of the finality contract to be rewards, and we distribute it entirely, to the first available active finality provider set. Again, this is for simplicity, as in this way we don't need to track balance amounts at each block.
  4. The remainder of the distribution across a given active fp set is left in the balance for further distribution. On the bright side, since in this impl we're taking the total balance instead of specific balance amounts, we're preventing in this way a secular accumulation of remainders in the balance, which is great.

In summary: These small potential errors are considered acceptable, and are all in the name of simplicity.

Please notice that this also fixes a bug in the impl, in which we were considering the rewards were being sent to the staking contract for distribution. They clearly have to be sent to the finality contract instead, since a) it has the info for distribution, b) it has to send the rewards to Babylon, and so it requires ownership of them.
Will fix this in the SDK and docs next as well.

@maurolacy maurolacy changed the base branch from main to f/rewards-distribution December 11, 2024 10:02
@maurolacy maurolacy force-pushed the f/rewards-distribution-2 branch from 0caebc0 to ff51423 Compare December 11, 2024 10:03
@maurolacy maurolacy changed the base branch from f/rewards-distribution to main December 11, 2024 10:03
@maurolacy maurolacy mentioned this pull request Dec 11, 2024
@SebastianElvis
Copy link
Member

Probably this design is good for now as 1) this serves as a PoC/baseline on the user stories that we can improve upon, and 2) we haven't received a concrete tokenomics design from the product team.

However, I think problem 1/2/3 needs to be resolved if we really decides on the pro rata distribution over FPs. This is because the protocol needs to ensure the reward distribution is fair, i.e., the reward of an FP has to be proportional to its contribution. Using the last voting power table to do the distribution might cause non-negligible bias. For example, if a FP is slashed and then suddenly the chain has 100 new finalised blocks, then this FP won't get any reward for its previous contribution. This looks like an edge case in terms of engineering, but this bias might not be negligible from the product's pov.

It would be good if we create a github issue to track this

Comment on lines +626 to +632
// Try to use the finality provider set at the previous height
let active_fps = FP_SET.may_load(deps.storage, env.block.height - 1)?;
// Short-circuit if there are no active finality providers
let active_fps = match active_fps {
Some(active_fps) => active_fps,
None => return Ok(()),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a TODO here that we will have to use the voting power table of the height that is being finalised, rather than the latest height, for fair distribution.

Btw, Babylon side has implemented the exact design for reward distribution at the FP level -- https://github.com/babylonlabs-io/babylon/blob/main/x/incentive/keeper/btc_staking_gauge.go

@maurolacy
Copy link
Collaborator Author

maurolacy commented Dec 12, 2024

For example, if a FP is slashed and then suddenly the chain has 100 new finalised blocks, then this FP won't get any reward for its previous contribution. This looks like an edge case in terms of engineering, but this bias might not be negligible from the product's pov.

If a FP falls off the active set it will lose their contribution from previous blocks, true. It is assumed the delta of finalised blocks is typically / usually small (<10?).
On the other hand, if a FP is in the active set and doesn't vote, currently it gets rewards anyway (as long as blocks are being finalised by other FPs, that is). So, this serves as a kind of compensation.

It would be good if we create a github issue to track this

Will do.

Update: #99.

@maurolacy maurolacy force-pushed the f/rewards-distribution-2 branch from 934aabc to 5a3698e Compare December 15, 2024 16:07
@maurolacy maurolacy merged commit 84130eb into main Dec 16, 2024
3 checks passed
@maurolacy maurolacy deleted the f/rewards-distribution-2 branch December 16, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants