Skip to content

The way delegations per pool are stored and fetched is not optimal #1248

Open
@azarovh

Description

@azarovh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    chainstateChainstate-related issuesstorageEverything related to storage, whether it's blockchain, wallet or otherwise

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions