fn stake_weighted_credits_observed(
stake: &Stake,
absorbed_lamports: u64,
absorbed_credits_observed: u64
) -> Option<u64>
Expand description
Calculate the effective credits observed for two stakes when merging
When merging two ActivationEpoch
or FullyActive
stakes, the credits
observed of the merged stake is the weighted average of the two stakes’
credits observed.
This is because we can derive the effective credits_observed by reversing the staking rewards equation, while keeping the rewards unchanged after merge (i.e. strong requirement), like below:
a(N) => account, r => rewards, s => stake, c => credits: assume: a3 = merge(a1, a2) then: a3.s = a1.s + a2.s
Next, given: aN.r = aN.c * aN.s (for every N) finally: a3.r = a1.r + a2.r a3.c * a3.s = a1.c * a1.s + a2.c * a2.s a3.c = (a1.c * a1.s + a2.c * a2.s) / (a1.s + a2.s) // QED
(For this discussion, we omitted irrelevant variables, including distance calculation against vote_account and point indirection.)