Skip to content

Subsume ssDelegations into ssActiveStake #5577

@lehins

Description

@lehins

Blocked on #5576

We need to introduce a new type that will contain not only the stake for a staking credential, but also the associated delegation:

data StakeWithDelegation = StakeWithDelegation
  { swdStake :: {-# UNPACK #-} !(NonZero (CompactForm Coin))
  , swdDelegation :: !(KeyHash StakePool)
  }
newtype ActiveStake = ActiveStake
  { unActiveStake :: VMap VB VB (Credential Staking) StakeWithDelegation
  }

This will properly describe the invariant of the active stake in the snapshots: we only care about non-zero stake that is "active", i.e. has an active delegation to a registered stake pool.

This approach will let us remove ssDelegations field and will later reduce the number of tables needed for LedgerHD, since ssActiveStake and ssDelegations can be combined into a single field:

 data SnapShot = SnapShot
-  { ssActiveStake :: !Stake
+  { ssActiveStake :: !ActiveStake
-  , ssDelegations :: !(VMap VB VB (Credential Staking) (KeyHash StakePool)) 

This will also result in some nice computational optimizations:
As part of the resolveInstantStake we already lookup the actual delegation, but ignore the result. We just need to retain the result and this will let us avoid:

This work has already been partially started in this branch and can be picked up where it was left off: https://github.com/IntersectMBO/cardano-ledger/tree/lehins/subsume-delegs-to-active-stake

Metadata

Metadata

Assignees

Labels

💾 LedgerHDTasks needed for making LedgerHD possible

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions