github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/distribution/spec/01_concepts.md (about) 1 <!-- 2 order: 1 3 --> 4 5 # Concepts 6 7 ## Reference Counting in F1 Fee Distribution 8 9 In F1 fee distribution, in order to calculate the rewards a delegator ought to receive when they 10 withdraw their delegation, we must read the terms of the summation of rewards divided by tokens from 11 the period which they ended when they delegated, and the final period (created when they withdraw). 12 13 Additionally, as slashes change the amount of tokens a delegation will have (but we calculate this lazily, 14 only when a delegator un-delegates), we must calculate rewards in separate periods before / after any slashes 15 which occurred in between when a delegator delegated and when they withdrew their rewards. Thus slashes, like 16 delegations, reference the period which was ended by the slash event. 17 18 All stored historical rewards records for periods which are no longer referenced by any delegations 19 or any slashes can thus be safely removed, as they will never be read (future delegations and future 20 slashes will always reference future periods). This is implemented by tracking a `ReferenceCount` 21 along with each historical reward storage entry. Each time a new object (delegation or slash) 22 is created which might need to reference the historical record, the reference count is incremented. 23 Each time one object which previously needed to reference the historical record is deleted, the reference 24 count is decremented. If the reference count hits zero, the historical record is deleted.