Skip to content

chore: Cache proven chain tip in State#1861

Open
sergerad wants to merge 10 commits intonextfrom
sergerad-tip-cache
Open

chore: Cache proven chain tip in State#1861
sergerad wants to merge 10 commits intonextfrom
sergerad-tip-cache

Conversation

@sergerad
Copy link
Copy Markdown
Collaborator

@sergerad sergerad commented Mar 30, 2026

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 requesting Finality::Proven no longer hit the database on every call.

Changes

  • Introduces a Finality enum (Committed / Proven) in the store's State
  • Replaces State::latest_block_num() with State::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 finality
  • State::load() initializes the proven tip from the DB and returns a watch::Sender that the proof scheduler uses to push updates after mark_proven_and_advance_sequence advances the sequence
  • Simplifies sync_chain_mmr from a match + DB query into a single chain_tip(finality) call
  • Splits up Store::serve() into helper functions spawn_proof_scheduler() and spawn_grpc_servers()

@sergerad sergerad added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Mar 30, 2026
impl From<proto::rpc::Finality> for Finality {
fn from(finality: proto::rpc::Finality) -> Self {
match finality {
proto::rpc::Finality::Unspecified | proto::rpc::Finality::Committed => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about defaulting here for Unspecified, but its probably not a train smash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep chain tip in memory for sync_chain_mmr endpoint

2 participants