Skip to content

Finalize delegation clean up from db #909

@azarovh

Description

@azarovh

All delegation information must be cleaned up from the database if:

  • the pool is decommissioned
  • the delegation balance is 0

Cleaning up means deleting Delegationid -> DelegationData entries and corresponding delegation balances.

There are 2 scenarios that lead to this:

  1. The pool is decommissioned and then delegation is spent;
  2. Delegation is spent and then the pool is decommissioned.

In #894 only the first case was covered.

The second one is more complicated to handle because of the way the db is structured right now. The only way to iterate through all delegations of a particular pool is to use PoSAccountingView::get_pool_delegations_shares, but if the balance is 0 the shares are no longer present and we cannot easily get all DelegationId of a pool.

There are 2 possible solutions:

  1. Keep zero values for delegation balances. This way get_pool_delegations_shares would return all delegations even with empty balances. The downside of this approach is that it requires storing useless data and changing low-level logic of the accounting crate where values are merged.
  2. Change the schema of the db. Instead of having following maps:
  • DelegationId -> DelegationData
  • DelegationId -> Amount
  • (PoolId, DelegationId) -> Amount
    we could use something like:
  • DelegationId -> DelegationData
  • DelegationId -> Amount
  • PoolId -> Vec[DelegationId]
    which will make manipulations and access more complex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConsensusConsensus related issuesaccountingAccounting-related issues (specifically the accounting crate and things related to it)storageEverything 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