frequency-chain / frequency

Frequency: A Polkadot Parachain
https://www.frequency.xyz
Apache License 2.0
48 stars 18 forks source link

Feat/reward pool refactor #1976 #2005

Closed shannonwells closed 1 month ago

shannonwells commented 1 month ago

Goal

The goal of this PR is to implement a "chunk" version of the overall reward pool history to reduce read/write load and hence weight for transactions and on_initialize when a new RewardEra needs to start.

Part of #1976

Discussion

This is is just one part of optimizing storage access. There will be more work later.

The current era Reward Pool and a ProviderBoostHistories record are updated on every provider_boost and unstake (for a boost account) call.

Instead of storing all overall Reward Pool history in a single CountedStorageMap, store the current total stake for the current era separately, and divide the actual past era history up into BoundedBTrees. The BTrees are of size RewardPoolChunkLength. These are in a StorageMap indexed by a u32 which is just the chunk index from 0 to history-size/chunk-length - 1.

This is unsurprisingly more complicated than the original solution, however it does have some advantages.

Checklist