chore: Cache proven chain tip in State#1861
Conversation
| impl From<proto::rpc::Finality> for Finality { | ||
| fn from(finality: proto::rpc::Finality) -> Self { | ||
| match finality { | ||
| proto::rpc::Finality::Unspecified | proto::rpc::Finality::Committed => { |
There was a problem hiding this comment.
I'm not sure how I feel about defaulting here for Unspecified, but its probably not a train smash.
SantiagoPittella
left a comment
There was a problem hiding this comment.
Could we benefit of using AtomicU32 inside State instead of the channel? Considering that we are only borrowing to get the latest value
Possibly yeah. Though I would insist we new type wrap it so it has a |
Happy to do this in a followup if we think its worth while. Seems a bit more boilerplate for potentially low/no benefit. EDIT: Updating this in #1857 as it does help with the logic (potentially even necessary) |
Closes #1841.
Cache proven-in-sequence tip to avoid repeated DB queries
Adds a
watch::channel-based cache for the proven-in-sequence block number, so RPC endpoints requestingFinality::Provenno longer hit the database on every call.Changes
Finalityenum (Committed/Proven) in the store'sStateState::latest_block_num()withState::chain_tip(finality)which returns the committed tip (from the in-memory MMR) or the proven tip (from the cached watch channel) depending on the requested finalityState::load()initializes the proven tip from the DB and returns awatch::Senderthat the proof scheduler uses to push updates aftermark_proven_and_advance_sequenceadvances the sequencesync_chain_mmrfrom a match + DB query into a singlechain_tip(finality)callStore::serve()into helper functionsspawn_proof_scheduler()andspawn_grpc_servers()