refactor: split headers from blocks in storage#96
Conversation
🤖 Kimi Code ReviewSecurity & Consensus-Critical Issues
Performance & Resource Issues
Code Quality & Maintainability
Minor Issues
Recommendations
Automated review by Kimi (Moonshot AI) · custom prompt |
🤖 Claude Code ReviewPerfect. Now let me analyze the overall change for any potential issues. Let me compile the review: Code Review: PR #96 - Split Headers from Blocks in StorageSummaryThis PR refactors block storage to separate block headers from bodies, preparing for checkpoint sync (issue #93). The changes are well-structured and largely correct, but there are a few potential issues to address. Critical Issues1. Release vs Debug Behavior Mismatch -
|
🤖 Codex Code ReviewFound a few issues worth addressing; rest looks reasonable. Findings (ordered by severity)
Notes
If you want, I can propose concrete fixes for the Automated review by OpenAI Codex · custom prompt |
Greptile OverviewGreptile SummaryThis PR refactors block storage by splitting block headers from block bodies into separate database tables. This architectural change simplifies handling of the anchor state, where block headers are readily available but bodies may not be. Key Changes
Architecture BenefitsThe split storage provides several advantages:
Implementation QualityThe refactoring is systematic and thorough across all layers (storage, blockchain, network, tests). The API surface has been appropriately updated with consistent naming conventions. Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| crates/storage/src/api/tables.rs | split Blocks table into BlockHeaders and BlockBodies tables, updated ALL_TABLES count |
| crates/common/types/src/block.rs | added PartialEq, Eq to BlockHeader, added header() and from_header_and_body() methods; body root validation only in debug mode |
| crates/storage/src/store.rs | major refactoring: split block storage into headers/bodies, renamed from_genesis to from_anchor_state, refactored initialization logic, removed unused functions, updated all block access to use headers |
| crates/blockchain/src/store.rs | replaced all get_block calls with get_block_header, replaced contains_block with has_state |
Sequence Diagram
sequenceDiagram
participant Client
participant Store
participant Backend
participant BlockHeadersTable
participant BlockBodiesTable
participant StatesTable
Note over Client,StatesTable: Block Storage Flow (New Architecture)
Client->>Store: insert_signed_block(root, signed_block)
Store->>Store: extract header via block.header()
Store->>Store: extract body from block.body
Store->>Backend: begin_write()
Backend-->>Store: WriteBatch
Store->>Backend: put_batch(BlockHeaders, header)
Store->>Backend: put_batch(BlockBodies, body)
Store->>Backend: put_batch(BlockSignatures, signatures)
Store->>Backend: commit()
Note over Client,StatesTable: Block Retrieval Flow
Client->>Store: get_signed_block(root)
Store->>Backend: begin_read()
Backend-->>Store: ReadView
Store->>BlockHeadersTable: get(root)
BlockHeadersTable-->>Store: header_bytes
Store->>BlockBodiesTable: get(root)
BlockBodiesTable-->>Store: body_bytes
Store->>Store: Block::from_header_and_body(header, body)
Store-->>Client: SignedBlockWithAttestation
Note over Client,StatesTable: Header-Only Access (Optimized)
Client->>Store: get_block_header(root)
Store->>Backend: begin_read()
Backend-->>Store: ReadView
Store->>BlockHeadersTable: get(root)
BlockHeadersTable-->>Store: header_bytes
Store-->>Client: BlockHeader
Note over Client,StatesTable: Initialization from Anchor State
Client->>Store: from_anchor_state(backend, state)
Store->>Store: extract header from state.latest_block_header
Store->>Backend: put_batch(BlockHeaders, header)
Note over Store,Backend: Body NOT stored (not available)
Store->>Backend: put_batch(States, state)
Required for #93
This PR streamlines block storage by splitting block headers from bodies. This simplifies the handling of the anchor state, since the block header is readily available from it, but the body is not, even if it's unnecessary for child block processing.