Local storage and retention
Local storage keeps the headers and block data that a node needs to follow the chain, serve data, and run availability checks. The system combines durable stores with short-term caches, then removes data outside a shared time window without removing the header history or verification state needed for correct node behavior. See Blockstore design, Data pruning, Header synchronization, and Share retrieval for related flows.
Storage model
Headers and extended data squares (EDSs) have different storage roles. A header is the durable identity and commitment for a block. An EDS is the data that the header commits to and that the node may need to serve or verify.
Header storage
The header store keeps the retained chain view used by synchronization, data access, and data availability sampling (DAS). It exposes a local head, a network head, and a tail. The tail is the lowest retained header, so it defines the lower bound for normal historical header work. Header synchronization describes how headers enter and leave this store.
References: nodebuilder/…/constructors.go• L121-146 nodebuilder/…/service.go• L56-166 nodebuilder/…/service.go• L169-223
Block-data storage
The EDS store keeps block data by its data root and links each height to that data. It can keep the original data square (ODS) and the fourth quadrant (Q4) of the EDS in separate durable files. The ODS file also keeps the square metadata and axis roots. Q4 extends read access for parts of the square that are expensive to derive from the ODS, but it is optional after retention removes parity-backed data. Empty blocks use a shared empty representation while still keeping a height link, so an empty block remains a valid stored data result.
The store reads data through an accessor. A caller can request samples, rows, namespace data, or a full EDS without needing to manage the file layout. An ODS-only accessor serves the stored half of an axis and can derive some other reads from the ODS. It does not provide the second half as stored data when Q4 is absent. This gives local reads a clear boundary when retention has removed Q4.
References: store/store.go• L33-47 store/store.go• L102-172 store/store.go• L306-399 store/getter.go• L27-140 store/…/ods.go• L22-29 store/…/ods.go• L203-224 store/…/ods.go• L265-283 store/…/ods_q4.go• L22-35 store/…/ods_q4.go• L149-163
Memory caches
Caches reduce repeated reads from durable storage. The base EDS store can cache recent accessors. A bridge can add a separate blockstore cache for data requests, while cache layers can read through the base cache and load from the durable store on a miss. Cache eviction does not change retention: it closes the in-memory accessor, but the durable data remains until a retention action removes it.
The file accessor can also keep the ODS in memory after a full read. This is a read-performance cache inside one opened accessor, not a second durable copy of the block data. The Q4 accessor opens its separate file only when a read needs data from the second half. If that file is gone, reads fall back to ODS behavior instead of restoring Q4.
The EDS accessor can cache axis shares and their proofs for repeated sample and namespace requests. Separate row and column caches use a fixed memory budget, and a miss reads from the underlying accessor or rebuilds the proof data on demand. This cache improves read speed without changing which block data is durable or how long it is retained.
References: store/store_options.go• L7-23 store/store_cache.go• L11-65 store/…/accessor_cache.go• L20-79 store/…/accessor_cache.go• L193-217 store/…/ods.go• L33-45 store/…/ods.go• L392-419 store/…/ods_q4.go• L86-110 store/…/ods_q4.go• L188-203 share/…/proofs_cache.go• L28-39 share/…/proofs_cache.go• L41-82 share/…/proofs_cache.go• L154-212 share/…/proofs_cache.go• L363-375
Network data cache
Light nodes use a datastore-backed Bitswap blockstore for retrieved sample data. This cache supports later sampling work, but the light node does not use it as a complete local EDS store. The light availability service records which samples succeeded and removes both those sample blocks and their result record when pruning reaches the header.
References: nodebuilder/…/module.go• L63-92 share/…/availability.go• L26-73 share/…/availability.go• L186-243
Retention boundary
Retention uses block time rather than a fixed number of blocks. The same availability window guides sampling, request routing, header retention, and block-data retention, so a node does not keep a header-dependent task after it has removed the data or header needed to complete it.
Peer selection state
Remote data recovery keeps short-lived peer pools for recent data hashes. A header validates the matching pool and supplies the trusted height used for cleanup, while the manager drops pools below the recent-header boundary and ignores announcements that are too old. Per-peer limits on unvalidated pools and a bounded invalid-hash cache keep this recovery state from growing without limit.
References: share/…/manager.go• L44-57 share/…/manager.go• L64-98 share/…/manager.go• L351-375 share/…/manager.go• L406-445 share/…/manager.go• L467-510 share/…/manager.go• L546-642
Availability windows
The default sampling and request window is seven days. The storage window adds one hour so block data remains available for work near the sampling boundary. A zero window disables the age check. CELESTIA_OVERRIDE_AVAILABILITY_WINDOW changes the resolved window for all consumers that use this policy.
| Window | System role |
|---|---|
| Sampling window | Limits normal availability checks and light-node sampling. |
| Request window | Selects normal versus archival data sources for requests. |
| Storage window | Keeps the block data needed by full availability and DAS. |
References: share/…/window.go• L12-20 share/…/window.go• L28-53 nodebuilder/…/module.go• L54-78
Header and data alignment
Header retention must cover the storage window. Header configuration rejects a pruning window that is shorter than the storage window, because a retained EDS without its header cannot support normal verification and a retained header without the data can break local availability work. DAS also starts from the current header tail and discards saved work below that tail after restart.
References: nodebuilder/…/config.go• L84-104 das/daser.go• L97-152 das/state.go• L65-75
Local and remote recovery
When local block data is retained, the local getter is the lowest-cost source. After pruning, a bridge can use Share Exchange or Bitswap to recover data from peers, while the header can still come from the retained header path. The Share Exchange EDS path transfers the ODS shares, rebuilds the EDS, and checks its data root against the header before it returns the data. This separation lets the node reclaim old block bytes without losing block identity or the ability to request data when a caller still needs it. Share retrieval explains the source order and verification path.
References: store/getter.go• L27-140 nodebuilder/…/constructors.go• L17-64 share/…/cascade.go• L30-43 share/…/cascade.go• L148-218 share/…/read.go• L15-39 share/…/read_fuzz_test.go• L19-46 share/…/server_fuzz_test.go• L121-228 share/…/eds_response.go• L15-50 share/…/shrex.go• L205-249
Retention policies
Node roles apply different retention policies to match their data duties. A bridge normally stores full EDS data for recent blocks and serves it to peers. A light node stores sampling results and selected sample blocks instead of retaining every EDS.
Bridge policy
For a non-archival bridge, full availability skips blocks outside the storage window. For a recent block it stores both ODS and Q4. The pruner later removes both parts and the height link when the block becomes old. A bridge can still request the old data from the network after this local removal.
References: share/…/availability.go• L57-108 share/…/availability.go• L111-119 nodebuilder/…/module.go• L221-233
Archival policy
An archival bridge keeps the ODS for old blocks but does not keep Q4 outside the storage window. It therefore preserves the original block data while limiting the larger parity-backed data used for recent access. Archival mode also disables header and block-data pruning and starts header sync from genesis.
References: share/…/availability.go• L98-119 nodebuilder/…/constructors.go• L83-97 nodebuilder/…/module.go• L66-79 store/…/ods_q4.go• L125-163
Light policy
A light node checks availability by sampling selected shares. It stores sample blocks and sampling results so incomplete work can continue after a restart. Pruning removes those per-header results when the related header leaves the retained range; it does not require a full EDS to be present locally.
References: share/…/availability.go• L76-183 share/…/availability.go• L186-243 nodebuilder/…/module.go• L54-65
Mode transitions
The node records whether full availability has run in pruned or archival mode. A node can move from archival to pruned mode. The startup path resets the pruning checkpoint for that change so the pruner can remove all old block data, including data that archival mode kept. A node that has run with pruning enabled cannot later become archival without re-initialization.
References: share/…/utils.go• L12-45 nodebuilder/…/module.go• L96-132 share/…/availability.go• L19-23
Pruning lifecycle
The pruning service reclaims data in height order as headers become older than the retention boundary. It delegates the actual removal to the node role's availability service and persists progress so a restart can continue without treating completed work as new work.
When the service processes a pruning round, it follows this sequence:
- Load the last completed height and previously failed heights.
- Use the current header time and retention window to find an old, bounded header range.
- Retry previously failed heights before processing the next range.
- Ask the role-specific pruner to remove or trim the block data for each header.
- Persist the last completed height and any failures for the next round.
The diagram shows how header age selects the work and how the role policy determines the data action.
flowchart LR
A[Retained header store] --> B[Header tail and head]
B --> C[Age cutoff from retention window]
C --> D[Bounded old-header range]
D --> E{Node role}
E -->|Light| F[Remove sample blocks and results]
E -->|Pruned bridge| G[Remove ODS and Q4]
E -->|Archival bridge| H[Remove Q4 only]
F --> I[Persist checkpoint]
G --> I
H --> I
I --> J[Retry failures next cycle]
References: pruner/service.go• L74-89 pruner/service.go• L129-229 pruner/find.go• L15-97
Progress checkpoints
The pruner checkpoint stores the last pruned height and a set of failed heights. The service retries failures in later rounds, so one bad delete does not stop progress for all later blocks. If the header tail moves past a failed height, the service drops that failure because the header is no longer available for a safe retry.
References: pruner/checkpoint.go• L20-31 pruner/checkpoint.go• L34-60 pruner/checkpoint.go• L109-128 pruner/service.go• L232-251
Header-delete coordination
Header pruning and block-data pruning share a delete callback. If the header syncer removes a header first, the callback removes its block data. If the block-data pruner removes data first, the callback sees the completed checkpoint and does not repeat the work. Header-delete callbacks can arrive out of order, so each callback prunes its own height rather than relying only on the last sequential checkpoint. This coordination keeps the header tail and block-data tail aligned across both deletion orders.
References: pruner/service.go• L69-71 pruner/service.go• L254-285 nodebuilder/…/module.go• L52-85
Pruning cadence
The service runs pruning rounds on a timer and limits each header fetch to a bounded batch. A round can continue through more than one batch when a node has a large backlog. If every header in a full batch fails, the round stops instead of fetching the same batch again. The checkpoint makes catch-up safe after a stop or a conversion from archival to pruned mode.
References: pruner/params.go• L10-35 pruner/service.go• L129-149 pruner/service.go• L183-229 pruner/find.go• L10-13 pruner/find.go• L100-122
Correctness boundary
Retention can remove local data, but it must not weaken the link between a header and the data it names. Headers retain the data root. Any data recovered from a cache or peer is still checked against that commitment before a caller uses it.
Verification after storage
The durable store records the data hash and axis roots with the ODS. The accessor uses those values to serve data, while higher-level availability and retrieval paths compare results with the header's data-availability header. A cache hit changes where bytes come from, not which commitment they must satisfy. ODS and Q4 files are also checked for the expected shape when they are created or validated. When a full EDS arrives from Share Exchange, the reader accepts only share-aligned input, fills an incomplete final square with tail padding, reconstructs the square, and rejects a data-root mismatch. The network stream can close before this CPU-bound verification completes.
The same boundary applies to network requests and notices. IDs and data responses must be well formed, stay within the requested square, and verify against the committed roots. A Share Exchange notice must carry a valid height and non-empty data hash before it can guide peer selection.
References: store/…/ods.go• L48-75 store/…/ods.go• L143-164 store/…/ods_q4.go• L37-75 store/getter.go• L52-71 share/…/read.go• L42-73 share/…/read_fuzz_test.go• L40-46 share/…/ids_fuzz_test.go• L138-225 share/…/namespace_fuzz_test.go• L132-217 share/…/server_fuzz_test.go• L121-228 share/…/pubsub_fuzz_test.go• L17-65 share/…/eds_response.go• L15-50 share/…/shrex.go• L230-249
Intake ordering
On a bridge, the Core listener stores the EDS before it publishes the matching header to local header consumers. This ordering prevents DAS from seeing a new header before its local data source is ready. It matters most when the header is fresh and the local store is the preferred source.
References: core/listener.go• L289-351 nodebuilder/…/module.go• L25-48 nodebuilder/…/module.go• L75-99
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the sampling, request, and storage windows aligned across availability checks, header pruning, peer choice, and block-data pruning. The environment override must affect every consumer that resolves the window.
- Keep header pruning at or above the storage window. A smaller header range can remove the proof context that retained block data needs.
- Keep the full-availability storage action and its prune action as a pair. Recent blocks use ODS plus Q4, archival old blocks use ODS only, and each mode must remove exactly the data it stores.
- Keep light sampling result keys, sample-block identifiers, and light pruning aligned. A change in one can leave cached sample blocks that no later operation can identify.
- Preserve the header-delete callback and pruner checkpoint rules when changing either header sync or data pruning. Both deletion orders must remain safe.
- Preserve bridge intake ordering when changing header publication or EDS writes. Header-driven DAS must not run before the local EDS is ready.
- Keep archival mode transitions aligned across persisted mode state, full availability, header sync, and the pruning checkpoint reset.
- Keep EDS stream parsing, reconstruction, and data-root verification as one correctness contract. A change that permits partial-share input or returns an unverified square can expose data that does not match the header.
- Keep ODS and Q4 file shape checks aligned with the data square and tail-padding rules. A file that is short or contains extra bytes must not become a valid accessor.
- Keep request ID bounds, namespace and range inclusion checks, and Share Exchange notice validation aligned with peer selection and response verification. A valid wire encoding is not enough if it names data outside the committed square.
- Keep proof-cache bounds and cache-miss fallback aligned with accessor reads. The cache must improve repeated proof work without becoming an unbounded copy of EDS data or changing durable retention.
- Keep peer-pool cleanup tied to the trusted header height and recent-header boundary. Bound unvalidated pools and invalid-hash state so remote announcements cannot turn recovery state into an unbounded memory store.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Header retention is shorter than the storage window | DAS or data requests can lose the header needed to use retained block data | Validate the header pruning window against the storage window |
| A pruned bridge receives an old block outside its storage window | Full availability can request and store data that policy says is no longer local | Return the outside-window result and use peer retrieval for old data |
| A pruning delete fails | The block remains on disk and later rounds can skip it if progress is not recorded correctly | Record failed heights and retry them before new work |
| Every header in a full pruning batch fails | The service can repeatedly fetch and retry the same batch in one round | Stop the round when a full batch makes no progress and retry it later |
| Header sync deletes a header while its data is still stored | Local storage can retain unreachable block data | Run the header-delete callback and prune the matching block data |
| A bridge publishes a header before its EDS is stored | DAS can request data before the local getter can serve it | Store the EDS before publishing the header and use fanout-only bridge subscription |
| A node changes from archival to pruned without resetting progress | Old archival data can remain because the pruner believes it already passed those heights | Detect the mode change and reset the pruning checkpoint |
| A node tries to change from pruned to archival | The node cannot claim archival history after old data was removed | Reject the transition and require re-initialization |
| An ODS or Q4 file has the wrong size | The accessor can read incomplete or extra data as a valid block square | Validate each file against the expected square and padding layout |
| Q4 is removed while an ODS-only read needs the second half of an axis | The read returns missing data, and full reconstruction may not be possible locally | Treat Q4 as optional and use remote recovery when the ODS cannot satisfy the request |
| A cache accessor is evicted while a reader still uses it | The reader can lose a file handle or observe a closed accessor | Use reference-counted accessors and close only after readers release them |
| Proof or axis requests fill the cache with distinct axes | Remote requests can retain unbounded memory and reduce node stability | Use bounded row and column caches and rebuild evicted entries from the accessor |
| An EDS response ends in the middle of a share or fails its data-root check | The node can use incomplete or unrelated block data as the response for a header | Reject partial shares and verify the reconstructed EDS against the header root before returning it |
| A malformed request ID, namespace response, or Share Exchange notice passes the wire checks | The node can ask for data outside the square or build peer state from an invalid commitment | Decode exact wire sizes, check bounds and inclusion, and validate the height and data hash |
| A peer announces many unvalidated data hashes or invalid hashes | Peer pools or blacklist state can consume memory without bound | Limit unvalidated pools per peer and use bounded invalid-hash state |
| A peer pool keeps an announced height instead of the matching header height | The pool can survive past the retention boundary and serve stale recovery choices | Replace announced height with the trusted header height before cleanup |
| A manager without Share Exchange pools one pool per request | Requests can accumulate state that no cleanup loop services | Use discovered peers directly when Share Exchange pools are disabled |
Key files
| File | Why to read it |
|---|---|
| store/store.go | Defines the durable EDS store, height-to-data links, access paths, and removal operations. |
| store/…/ods.go | Shows the durable ODS representation, stored roots, lazy reads, and the in-memory ODS cache. |
| store/…/ods_q4.go | Shows how optional Q4 data extends ODS reads and how the accessor behaves after Q4 is trimmed. |
| store/…/square.go | Shows the in-memory square shape used when the ODS is cached. |
| store/getter.go | Defines the local getter used for samples, rows, namespaces, and complete EDS reads. |
| store/store_cache.go | Shows how an additional blockstore cache sits above the durable EDS store. |
| store/…/accessor_cache.go | Explains cache eviction and reader-safe accessor lifetime. |
| share/…/proofs_cache.go | Shows the bounded in-memory cache for EDS axes and proof data used by repeated reads. |
| share/…/window.go | Defines the shared retention and request boundaries. |
| share/…/availability.go | Shows bridge storage choices and the difference between pruning and archival removal. |
| share/…/availability.go | Shows light-node sample persistence and cleanup. |
| share/…/read.go | Defines the common EDS stream reader and the integrity check used before a reconstructed square is accepted. |
| share/…/eds_response.go | Shows how a network EDS response separates stream reading from square reconstruction and verification. |
| share/…/shrex.go | Connects remote EDS recovery, peer choice, retry behavior, and header-root verification. |
| share/…/manager.go | Shows how recent header state bounds remote peer pools and invalid-announcement state used for data recovery. |
| pruner/service.go | Connects periodic pruning, retries, checkpoints, bounded catch-up, and header-delete coordination. |
| pruner/find.go | Defines how header time and the retention window select pruneable ranges. |
| pruner/checkpoint.go | Defines durable pruning progress and failed-height recovery. |
| nodebuilder/…/module.go | Wires node roles, archival behavior, availability policies, and mode conversion. |
| nodebuilder/…/config.go | Enforces the header-retention contract needed by block-data and sampling work. |
| nodebuilder/…/module.go | Shows which roles receive a durable EDS store and which use cached or network data paths. |