zebra
zebra copied to clipboard
Store cumulative work in the finalized state for each height
Motivation
We need to store block work in the finalized state database to:
- efficiently calculate
getnetworksolps
&getnetworkhashps
responses, and - show the full cumulative chain work in chain fork progress bars (and other logging and metrics)
Otherwise, we have to load:
- block headers for the RPC height range to calculate solutions per second
- 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
withWork
inChain
- [ ] Delete the
PartialCumulativeWork
type