Skip to content

fix: Reduce view scope in batch_builder.get_batch_inputs - #2747

Merged
Mirko-von-Leipzig merged 2 commits into
nextfrom
sergerad-get-batch-inputs-view
Oct 8, 2026
Merged

Mirko-von-Leipzig merged 2 commits into
nextfrom
sergerad-get-batch-inputs-view

Conversation

@sergerad

@sergerad sergerad commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

We have noticed that the sequencer reports 2 live state snapshots (snapshots.live on the store's write_block span) far more often than full nodes do, even though full nodes serve more read traffic.

The likely cause is BatchJob::get_batch_inputs. It bound a StateView for the whole function, so the snapshot stayed pinned while the fee collection transaction was proven locally and validated by the validator. Neither step reads the state. When that work overlaps a block commit, the previous snapshot generation is still pinned at publish time.

This PR releases the view as soon as the last state read is done.

Changes

  • Scope the view with State::with_view so it only covers the store reads and the fee collection transaction execution.
  • Split get_batch_inputs into three helpers:
    • read_batch_inputs: reads the note inclusion proofs, partial blockchain and reference block header.
    • execute_fee_collection: reads the protocol config and genesis commitment, then executes the fee collection transaction.
    • prove_fee_collection: proves the transaction and validates it with the validator. Runs after the view is released.
  • Add a private BatchInputs struct to carry the store reads between the helpers.

No behavior change is intended beyond the shorter snapshot lifetime.

Testing

Existing batch_builder tests pass. They do not cover the fee collection path.

Changelog

changelog = "none"
reason    = "Internal change only."

@sergerad
sergerad requested review from Mirko-von-Leipzig and kkovaacs and removed request for Mirko-von-Leipzig October 7, 2026 19:07
@sergerad sergerad changed the title fix: Reduce view scope in batch builder fix: Reduce view scope in batch_builder.get_batch_inputs Oct 7, 2026

@kkovaacs kkovaacs left a comment

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.

Nice!

@Mirko-von-Leipzig
Mirko-von-Leipzig merged commit 18aec67 into next Oct 8, 2026
28 checks passed
@Mirko-von-Leipzig
Mirko-von-Leipzig deleted the sergerad-get-batch-inputs-view branch October 8, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants