rawdb: recover witness size from filesystem metadata miss#2200
Conversation
|
@claude - review once |
|
Claude finished @pratikspatil024's task in 1m 48s —— View job Code Review: rawdb: recover witness size from filesystem metadata miss
Overall: This is a well-scoped bugfix that addresses a real crash-residue scenario (file write succeeds → DB put fails → Suggestion: Consider repairing the DB metadata on recovery
Since func (s *fsWitnessStore) readWitnessSizeFromFile(hash common.Hash) *uint64 {
info, err := os.Stat(witnessFilePath(s.dir, hash))
if err != nil || !info.Mode().IsRegular() {
return nil
}
size := uint64(info.Size())
// Repair missing DB metadata so future reads hit the fast path.
var buf [8]byte
binary.BigEndian.PutUint64(buf[:], size)
if err := s.db.Put(witnessSizeKey(hash), buf[:]); err != nil {
log.Warn("Failed to repair witness size metadata", "hash", hash, "err", err)
}
return &size
}This is a self-healing pattern — the first recovery call fixes the inconsistency, and all subsequent calls use the DB. Not a blocker, but recommended. Fix this → Minor: Concrete type assertion couples accessor to implementation
type witnessSizeRecoverer interface {
readWitnessSizeFromFile(hash common.Hash) *uint64
}Not a blocker — the current approach is pragmatic and correct. Test review
One minor gap: the test does not verify that the original (non-fallback) path also works — i.e., that // Verify normal path works first.
size := ReadWitnessSize(db, hash)
if size == nil || *size != uint64(len(payload)) {
t.Fatal("expected witness size from DB metadata")
}Security notes
VerdictApprove with suggestion — the fix is correct and well-tested. The self-repair suggestion (writing recovered size back to DB) would make it more robust in production by avoiding repeated |
|
@AaronAjose - is it possible for you to sign this commit? You can rebase locally to rewrite history with signed commits and force-push. |
c827015 to
628eec1
Compare
628eec1 to
2c39eb5
Compare
|
|
@pratikspatil024 Done, pls re-check. |
|
Thanks @AaronAjose! |



Description
This PR fixes a data-consistency bug in filesystem-backed witness storage.
fsWitnessStore.WriteWitness writes witness blobs to disk first (tmp + rename) and writes witnessSizeKey to DB afterward. If the file write succeeds but DB Put fails, the process exits via log.Crit. After restart, the file may exist while DB size metadata is missing.
Before this change, ReadWitnessSize only read DB metadata and returned nil when missing. In WIT pagination/metadata paths, that becomes 0/unavailable, which can silently fail witness page serving for data that is actually present on disk.
This PR adds a fallback in ReadWitnessSize: when DB size metadata is missing and witness storage is filesystem-backed, size is recovered from os.Stat on the witness file. A unit test was added to validate this crash-residue scenario (file exists + size key missing).
Changes
Breaking changes
None.
Nodes audience
This primarily affects nodes using filesystem witness storage (--witness.filestore) and only on recovery paths where DB size metadata is missing while witness files exist on disk.
No new flags or config behavior changes were introduced.
Checklist
Cross repository changes
Heimdall PR link: N/A
matic-cli PR link: N/A
Testing
Manual tests
Not executed in this cycle.
Note: full Go test/build validation is currently blocked unless Go >=1.26.2 toolchain is available (project go.mod requirement).
Additional comments
Added unit test: