feat(x/distribution): auto-stake bond denom rewards and commission#94
Draft
giunatale wants to merge 19 commits into
Draft
feat(x/distribution): auto-stake bond denom rewards and commission#94giunatale wants to merge 19 commits into
giunatale wants to merge 19 commits into
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.
df912a6 to
af5ec28
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.
af5ec28 to
4790a44
Compare
there was no actual need to force-claim the commission at migration, therefore this part of the migration code is here removed.
Implements commission auto-stake routed through the standard staking.Delegate path at two trigger points: 1. MsgWithdrawValidatorCommission — operator-initiated. Auto-stakes bond denom commission, then pays out non-bond as before. 2. AfterEpochEnd, gated on a new commission_auto_stake_epoch_identifier param — protocol-driven. Iterates bonded validators and auto-stakes each one's bond denom commission. Operators can still withdraw more often if they prefer; the epoch is a floor on cadence, not a ceiling. The standard Delegate path keeps shares-based F1 accounting consistent because share changes go through the BeforeDelegationSharesModified / AfterDelegationModified hook flow, exactly as F1 expects. A different mechanism to do this at BeginBlock was explored but resulted in a much more cumbersome and invasive implementation. Validators that are unbonding, unbonded, or jailed are not in GetBondedValidatorsByPower and are therefore skipped by the epoch trigger; they no longer accrue new commission either, so commission already accumulated waits in accumulatedCommission until validator removal. The existing AfterValidatorRemoved force-payout handles any residual at that point. The escape route is bounded by epoch length (~one epoch's commission per validator lifetime) and is not a viable incentive.
4790a44 to
03eaa96
Compare
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a variant of #93 that also adds auto-staking of validator's commission.
Commission auto-stake is not done at allocation time and is instead routed through the standard
staking.Delegatepath at two trigger points:MsgWithdrawValidatorCommission— operator-initiated. Auto-stakes bonddenom commission, then pays out non-bond as before.
AfterEpochEnd, gated on a newcommission_auto_stake_epoch_identifierparam — protocol-driven. Iterates bonded validators and auto-stakes
each one's bond denom commission. Operators can still withdraw more
often if they prefer; the epoch is a floor on cadence, not a ceiling.
The standard
Delegatepath keeps shares-based F1 accounting consistent because share changes go through theBeforeDelegationSharesModified/AfterDelegationModifiedhook flow, exactly as F1 expects. A different mechanism to do this at BeginBlock was explored but resulted in a much more cumbersome and invasive implementation, hence more prone to errors and bugs (because it had to circumvent the invariant by which new shares issuance had to go through the aforementioned hooks).