Skip to content

Conversation

@DracoLi
Copy link
Contributor

@DracoLi DracoLi commented Dec 2, 2025

Why this should be merged

Resolves #4628.

This PR defers writing block header/body/receipts from verify/insert to Accept. Instead of persisting blocks immediately upon verification, verified blocks are cached in memory and only written to disk when accepted.

This is needed for coreth to use blockdb before SAE. We should merge this if we want to enable blockdb before SAE is released.

How this works

  • On verify/insert: Instead of writing blocks and receipts to the database, they are stored in in-memory caches. The header number mapping, pre-images, and state trie changes are still written to disk immediately.
  • On Accept: The block header/body and receipts are written to the database before adding the block to the acceptor queue. After writing, block data is removed from the verified caches to free memory.
  • On Reject: Blocks are removed from both verified caches to free memory.
  • Block getters: Updated to check the verified block cache, then fall back to the database. This preserves the ability to query both verified and accepted block headers/bodies/receipts.
  • If the head block is missing on restart (e.g., due to a crash before the head block is accepted), the blockchain falls back to the last accepted block and updates the head accordingly.

This change means verified but not accepted blocks are no longer persisted to disk. If a blockchain crashes before a verified block is accepted, the block will be lost from memory but can be bootstrapped from the network.

How this was tested

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

(coreth) Write block header/body/receipts on Accept instead of Verify

3 participants