fix(leasing): floor per-contributor dividend share so beneficiary gets the leftover#2610
Open
boskodev790 wants to merge 26 commits intoopentensor:mainfrom
Open
fix(leasing): floor per-contributor dividend share so beneficiary gets the leftover#2610boskodev790 wants to merge 26 commits intoopentensor:mainfrom
boskodev790 wants to merge 26 commits intoopentensor:mainfrom
Conversation
boskodev790
commented
Apr 22, 2026
…al-e2e fix staking approval e2e test
…bnet Introduce netuid generation for storage cleaning
…s the leftover distribute_leased_network_dividends in pallets/subtensor/src/subnets/leasing.rs rounded each contributor's share UP with `.ceil()` before accumulating into `alpha_distributed`. Summed across contributors, the ceilings can accumulate to MORE than `total_contributors_cut_alpha`, at which point `total_contributors_cut_alpha.saturating_sub(alpha_distributed)` on line ~327 clamps to zero — the beneficiary receives nothing, even when they were legitimately entitled to the leftover dust between the contributors' cut and the beneficiary's implicit share (`raised - deposit`). Concrete example: deposit = 1 TAO, raised = 1_000 TAO (999 TAO from many small contributors). Beneficiary's intended share per dividend event is ~`deposit / raised = 0.1 %` of `total_contributors_cut_alpha`. With enough contributors each rounding UP by ~1 rao, the cumulative rounding can exceed the beneficiary's intended slice, zeroing their payout. In the degenerate case where `alpha_distributed` exceeds the lease coldkey's actual stake on the subnet (the sum of previously-accumulated dividends plus the current owner cut), `transfer_stake_within_subnet` will fail mid-loop and the whole `with_storage_layer` block rolls back — those dividends then re-accumulate silently and the pattern repeats on the next distribution, breaking the invariant that dividends are actually distributed at each `LeaseDividendsDistributionInterval` boundary. Switch the per-contributor rounding to `.floor()` so the sum is always `<= total_contributors_cut_alpha`, letting the beneficiary's `saturating_sub` on line ~327 always produce the true leftover. The top-level `lease.emissions_share.mul_ceil(owner_cut_alpha.to_u64())` higher up (line ~273) still rounds UP in favour of the contributors, which is the deliberate intent called out by the comment there. Update the matching `.ceil()` calls in `tests/leasing.rs::test_distribute_lease_network_dividends_multiple_contributors_works` so the expected per-contributor alpha is computed with the same rounding as production; the `distributed_alpha == bene + c1 + c2` assertion now holds unconditionally rather than only for fractional shares that happen to round cleanly in U64F64.
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.