feat(x/distribution): auto-stake bond denom rewards#93
Conversation
Adds a new keeper method in x/staking that increases a bonded validator's token balance without issuing new delegator shares, raising the per-share exchange rate for all existing delegators proportionally. Modifies the allocation logic in x/distribution to route the bond denom (minus validator commission) through the auto-staking path while commission and other coins go through F1.
67f756f to
5660536
Compare
The tokens-based F1 algorithm computes rewards-per-token using val.GetTokens() and applies slash events to scale stake by (1-fraction). This works when sum(startingStakes) == val.Tokens, but auto-staking breaks that invariant: AddValidatorTokens raises val.Tokens without issuing new shares, so per-token ratio dilutes existing delegators. A sole self-delegator who should receive 100% of non-bond rewards instead got rewards × old_tokens / new_tokens, with the residual accumulating as unclaimable F1 dust on the validator. Switching the ratio to rewards-per-share (val.GetDelegatorShares()) and storing the delegator's share count in startingInfo.Stake makes the calculation invariant to per-share exchange-rate changes from both auto-staking and slashing. Slash event handling in calculateDelegationRewardsBetween becomes unnecessary - slashes naturally reduce future rewards via reduced voting power, and the shares-based ratio distributes whatever was earned proportionally.
|
A failing integration test raised an issue I initially missed (copying from commit comment):
Had to also update the migration code (which is now more invasive since it has to perform the token-based -> share-based migration) and the migration test is now importing |
there was no actual need to force-claim the commission at migration, therefore this part of the migration code is here removed.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This PR adds auto-staking of bond denom rewards.
The feature is implemented editing the allocation logic to divert bond denom rewards directly to the bonded pool, essentially resulting in an increase of shares' exchange rate. This is achieved by adding a
AddValidatorTokenstox/staking/keeper/validator.go.Performance impact should be acceptable as it adds a handful of KV operations but overall reward distribution complexity remains unchanged wrt to pure F1 (O(validators))