Skip to content

feat: Deferred block proving#1725

Open
sergerad wants to merge 82 commits intonextfrom
sergerad-deferred-block-proving
Open

feat: Deferred block proving#1725
sergerad wants to merge 82 commits intonextfrom
sergerad-deferred-block-proving

Conversation

@sergerad
Copy link
Collaborator

@sergerad sergerad commented Mar 2, 2026

Context

We are adding deferred (asynchronous) block proving for the node, as described #1592. Currently, block proving happens synchronously during apply_block, which means block commitment is blocked until the proof is generated.

Blocks will now exhibit committed (not yet proven) and proven states. A committed block is already part of the canonical chain and fully usable. Clients that require proof-level finality can opt into it via the new finality parameter on SyncChainMmr.

Changes

  • Schema: Added proving_inputs BLOB and is_proven BOOLEAN columns to the block_headers table, with partial index for querying proven (is_proven = 1) blocks.
  • Block proof file storage: Block proofs are stored as files via BlockStore (following the existing block file pattern) rather than as BLOBs in SQLite.
  • DB queries: Added mark_block_proven, select_block_proving_inputs (returns deserialized BlockProofRequest), and select_latest_proven_block_num.
  • Decoupled proving from apply_block: The BlockProofRequest is now serialized and persisted alongside the block during apply_block.
  • Proof scheduler: Added a background task (proof_scheduler.rs) that drives deferred proving. It queries unproven blocks on startup (restart recovery), listens for new block commits via Notify, and proves blocks concurrently using FuturesOrdered for FIFO completion ordering. Proofs are saved to files, then the block is marked proven in the DB.
  • Finality on SyncChainMmr: Added a Finality enum (COMMITTED, PROVEN) to the protobuf and a finality field on SyncChainMmrRequest.
  • Refactored apply_block query: Introduced ApplyBlockData struct to replace the 7-parameter function signature.

@sergerad sergerad changed the title Sergerad deferred block proving feat: Deferred block proving Mar 2, 2026
@sergerad sergerad marked this pull request as ready for review March 2, 2026 23:42
@sergerad sergerad requested review from Mirko-von-Leipzig, bobbinth and drahnr and removed request for Mirko-von-Leipzig March 2, 2026 23:43
Comment on lines +625 to +628
/// Returns the highest block number that has been proven, or `None` if no blocks have been
/// proven yet.
#[instrument(level = "debug", target = COMPONENT, skip_all, ret(level = "debug"), err)]
pub async fn select_latest_proven_block_num(&self) -> Result<Option<BlockNumber>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do we treat the genesis block? Should it not always be considered proven?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the comments to reflect - we treat the genesis block as proven


/// Errors that can occur during block proving.
#[derive(Debug, Error)]
enum ProveBlockError {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is something we want to use more, we should take a look at https://crates.io/crates/fatality


// Mark completed proofs as proven sequentially.
// Find the lowest in-flight block.
let lowest_in_flight = inflight.first().copied().unwrap_or(next_to_schedule);
Copy link
Contributor

Choose a reason for hiding this comment

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

This implies that we set anything that is not inflight to be proven. What if these fail? We'd currently error out above in line 153. I'd prefer to have the individual proven blocks set deliberately to retain a 1:1 relationship.
How important is the continuity property in this context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Mirko-von-Leipzig @bobbinth it turned out to be much simpler to allow out-of-order proof saves. We have gone through quite a few iterations now and latest one is by far the simplest IMO.

Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

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

I think the logic is sound, I don't particularly like the logic inversion when it comes marking blocks as proven, since it's error rather error prone.

block_header BLOB NOT NULL,
signature BLOB NOT NULL,
commitment BLOB NOT NULL,
proving_inputs BLOB, -- Serialized BlockProofRequest needed for deferred proving. NULL if it has been proven or never proven (genesis block).
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: leave a TODO that the size might become a problem in the future

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.

5 participants