penumbra icon indicating copy to clipboard operation
penumbra copied to clipboard

uptime tracking optimization

Open dynst opened this issue 8 months ago • 0 comments

Describe the bug

Currently, per validator, an entire 10,000-bit BitVec is read from storage, updated, and then written to storage again every block.

https://github.com/penumbra-zone/penumbra/blob/2034d4fb7597061a0303a2257dd279f2b40417d2/crates/core/component/stake/src/uptime.rs#L68C9-L69C63

This seems like it could be potentially optimized for less storage read-write overhead by

  • holding a VecDeque<BitVec> in memory, with each BitVec a smaller, 200-bit vector
  • only writing the latest, 200-bit vector back to nonverifiable storage every block: about 25 bytes per block per validator, instead of 1250 bytes per block per validator.
  • deleting the oldest BitVec from storage once it falls outside the 10,000 block window

Additional context

Optimizing this to be O(1) instead of the current O(n) seems like a necessary prerequisite for any potential increase of signed_blocks_window_len to a value larger than 10,000 like suggested in #4631.

dynst avatar Jun 24 '24 21:06 dynst