zebra icon indicating copy to clipboard operation
zebra copied to clipboard

Store cumulative work in the finalized state for each height

Open teor2345 opened this issue 1 year ago • 0 comments

Motivation

We need to store block work in the finalized state database to:

  1. efficiently calculate getnetworksolps & getnetworkhashps responses, and
  2. show the full cumulative chain work in chain fork progress bars (and other logging and metrics)

Otherwise, we have to load:

  1. block headers for the RPC height range to calculate solutions per second
  2. block headers for the entire chain to calculate cumulative work

Specifications

See the upgrade design docs for more details.

Implementation Steps

  • [ ] update the database format in the Zebra docs
  • [ ] increment the state minor version
  • [ ] write the new format in the block write task
  • [ ] update older formats in the format upgrade task
  • [ ] test that the new format works when creating a new state, and updating an older state

Complex Code or Requirements

This will need an in-place format update. There's no need to wait for this update to complete, or do it in any particular order. The RPCs can fall back to loading block headers, and the chain forks can use the partial cumulative work.

If we store the cumulative work, we can calculate the block work for height using: cumulative_work(height) - cumulative_work(height - 1)

Testing

Compare the work bits and RPC outputs with zcashd.

Optional Cleanups

  • [ ] Use the full work in Chain
  • [ ] Replace PartialCumulativeWork with Work in Chain
  • [ ] Delete the PartialCumulativeWork type

teor2345 avatar Jun 29 '23 22:06 teor2345