Skip to content

Commit

Permalink
NOD-525: Optimize PoolRewards with cached hashing (#1321)
Browse files Browse the repository at this point in the history
* NOD-525: Optimize PoolRewards with cached hashing

Replace BufferedRef with HashedBufferedRef in PoolRewards'
bakerPoolRewardDetails  LFMBTree to cache computed hashes. This
optimization eliminates redundant hash  calculations previously
performed for each block.

Technical details:
- Switched from BufferedRef to HashedBufferedRef
- Affects bakerPoolRewardDetails tree in PoolRewards data
  • Loading branch information
drsk0 authored Feb 13, 2025
1 parent 19de805 commit 20283ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased changes
- Replace `BufferedRef` with `HashedBufferedRef` in `PoolRewards`
`bakerPoolRewardDetails::LFMBTree` field to cache computed hashes.

## 8.0.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ data PoolRewards (bhv :: BlockHashVersion) (av :: AccountVersion) = PoolRewards
currentCapital :: !(CapitalDistributionRef bhv),
-- | The details of rewards accruing to baker pools.
-- These are indexed by the index of the baker in the capital distribution (_not_ the BakerId).
bakerPoolRewardDetails :: !(LFMBT.LFMBTree Word64 BufferedRef (BakerPoolRewardDetails av)),
bakerPoolRewardDetails :: !(LFMBT.LFMBTree Word64 HashedBufferedRef (BakerPoolRewardDetails av)),
-- | The transaction reward amount accruing to the passive delegators.
passiveDelegationTransactionRewards :: !Amount,
-- | The transaction reward fraction accruing to the foundation.
Expand Down Expand Up @@ -140,7 +140,7 @@ migratePoolRewardsP1 curBakers nextBakers blockCounts npEpoch npMintRate = do
passiveDelegatorsCapital = Vec.empty
}
makeBakerCapital (bid, amt) = BakerCapital bid amt Vec.empty
makePRD :: (BakerId, a) -> m (BufferedRef (BakerPoolRewardDetails av))
makePRD :: (BakerId, a) -> m (HashedBufferedRef (BakerPoolRewardDetails av))
makePRD (bid, _) = do
let bprd =
BakerPoolRewardDetails
Expand Down

0 comments on commit 20283ad

Please sign in to comment.