@@ -143,10 +143,18 @@ func (w *DiskWAL) ReplayOnForest(forest *mtrie.Forest) error {
143143//
144144// When no numbered V7 checkpoint is available it falls back to a V7 root
145145// checkpoint (converted from the V6 root.checkpoint during bootstrap), mirroring
146- // the V6 root-checkpoint fallback in [DiskWAL.replay]. With no V7 checkpoint of
147- // either kind it replays all segments onto the (presumably empty) `forest`.
146+ // the V6 root-checkpoint fallback in [DiskWAL.replay].
148147//
149- // No error returns are expected during normal operation.
148+ // A V7 checkpoint of one kind or the other is required: a payloadless forest
149+ // retains only leaf-hash commitments, which cannot be reconstructed by WAL
150+ // replay alone (the WAL records full payload updates, but replaying every update
151+ // from genesis to rebuild the commitment is not feasible at runtime). When
152+ // neither a numbered V7 checkpoint nor a V7 root checkpoint is present, this
153+ // refuses to seed rather than silently booting an empty, uncommitted forest.
154+ //
155+ // Expected error returns during normal operation:
156+ // - error containing "no V7 checkpoint found": when the WAL directory contains
157+ // no V7 checkpoint of either kind, so the forest cannot be seeded.
150158func (w * DiskWAL ) ReplayOnPayloadlessForest (forest * payloadless.Forest ) error {
151159 checkpointer , err := w .NewCheckpointer ()
152160 if err != nil {
@@ -158,6 +166,16 @@ func (w *DiskWAL) ReplayOnPayloadlessForest(forest *payloadless.Forest) error {
158166 return fmt .Errorf ("cannot load latest V7 checkpoint: %w" , err )
159167 }
160168
169+ // LoadLatestCheckpointV7 returns no tries and loadedCheckpoint == -1 only when
170+ // neither a numbered V7 checkpoint nor a V7 root checkpoint was found. In that
171+ // case there is no seed for the leaf-hash commitment, so refuse to start.
172+ if loadedCheckpoint < 0 && len (tries ) == 0 {
173+ return fmt .Errorf (
174+ "no V7 checkpoint found in %s; a V7 checkpoint is required to start a payloadless ledger" ,
175+ w .wal .Dir (),
176+ )
177+ }
178+
161179 if err := forest .AddTries (tries ); err != nil {
162180 return fmt .Errorf ("failed to seed payloadless forest from V7 checkpoint: %w" , err )
163181 }
0 commit comments