Source: docs/lotus-v2/research/plans/lotus-v2-chain-index.md
Research — non-normative. This page records an investigation. It defines no rule; a research result enters the specification only through a decision recorded in decision history.

Development chain index implementation review

Status: design review after native 7432a0aa1, monorepo 5abf0198. This is a storage/runtime design, not a consensus change or network-profile adoption. Exact APIs and migration behavior must be reviewed before integration.

Existing boundary

DiskStateTransaction::Commit atomically writes live coins/nodes, current head S, schema/profile V, and immutable undo U || BlockID. Disconnect restores coins/nodes and S in one batch, retaining undo records. Retained-body reads authenticate bytes but do not establish active-chain membership. There is no persistent height index or accumulated-work fork selector. A caller cannot use monetary prev_work as accumulated chainwork: it represents one block's work.

Required next storage packet

Keep the chain index in the same LevelDB database and synchronous batch as S. A second database or a write after chainstate publication would create a crash window where the active index and spendable state disagree.

Proposed record families:

Key Value and purpose
`H BlockID` Canonical 134-byte header, accumulated work, explicit validation stage, and eligibility summary
`A height_u64be` Active BlockID at an exact height
I Index schema/readiness and active tip/height/work, checked against S

Header validity, body availability and successful complete-block connection must remain distinct states. A valid header does not validate its state root. A body present on disk is not necessarily validated. Retain disconnected header/body records without asserting that they are active. Invalidity propagation and best-candidate filtering need explicit rules; storage/resource errors never mark a header consensus-invalid.

Compute work mathematically from canonical positive target. Check accumulation before encoding; do not wrap at 256 bits. A 40-byte unsigned representation can hold cumulative work over the u64 height domain: positive target bounds each block's work by 2^255, with at most 2^64 blocks. Equal accumulated work retains the current valid tip. Clock eligibility remains external and reversible; an ancestor-time summary, if retained, must not become consensus state.

Bounded query and transition requirements

Compatibility and tests

Do not reset existing native/reference/replay/compiler worktrees or data. Prefer an explicit development index schema with new isolated homes and fail-closed old-store detection until a bounded, resumable migration is designed. Generic raw-store fixtures may keep the existing non-indexed mode; the development initializer must explicitly select the mode it requires.

Required tests include exact height/locator results across forks and reopen, work overflow and equal-work behavior, malformed header/index records, profile/genesis mismatch, index/head divergence, bounded fork-planning refusal, and injected failures before/after each atomic write. Separate header-only admission from full signed-body validation. The existing signed compiler pilot must still accept/reject at its intended checks after integration.

This document records requirements and source inspection only. Persistent index, fork selection, reorg recovery and peer synchronization are not yet implemented.