Description
DBAccountingPoolDelegationShares
field is represented as Map<(PoolId, DelegationId), Amount>
in the storage.
It's used to retrieve all the delegations for a particular pool. But doing so is not efficient because it fetches all the shares of everyone from db and then filters for a specific pool id.
More effective way would be to represent the data as Map<PoolId, Vec<DelegationId>
.
But it has unexpected space complexity for undo. Undo object for accounting are deltas. UndoDelta for a data field (like a Vec) is just a previous state of the data. So if we add an element to the Vec then undo is the whole Vec without new element. Applying this to delegations means that every block that adds new delegation will have to store a copy of all previous delegations. Making it arithmetic sequence of collections with size i+1. Meaning that for 1000 delegations we have to store 500500 delegation ids in undo storage.
So the question is whether we want to make this tradeoff or try to find another solution.