Skip to content

rawdb: recover witness size from filesystem metadata miss#2200

Open
AaronAjose wants to merge 1 commit into0xPolygon:developfrom
AaronAjose:witness-size-fs-metadata-fallback
Open

rawdb: recover witness size from filesystem metadata miss#2200
AaronAjose wants to merge 1 commit into0xPolygon:developfrom
AaronAjose:witness-size-fs-metadata-fallback

Conversation

@AaronAjose
Copy link
Copy Markdown
Contributor

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

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Changes only for a subset of nodes

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

  • I have added at least 2 reviewer or the whole pos-v1 team
  • I have added sufficient documentation in code
  • I will be resolving comments - if any - by pushing each fix in a separate commit and linking the commit hash in the comment reply
  • Created a task in Jira and informed the team for implementation in Erigon client (if applicable)
  • Includes RPC methods changes, and the Notion documentation has been updated

Cross repository changes

  • This PR requires changes to heimdall
    Heimdall PR link: N/A
  • This PR requires changes to matic-cli
    matic-cli PR link: N/A

Testing

  • I have added unit tests
  • I have added tests to CI
  • I have tested this code manually on local environment
  • I have tested this code manually on remote devnet using express-cli
  • I have tested this code manually on amoy
  • I have created new e2e tests into express-cli

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:

  • core/rawdb/database_witness_test.go
  • TestOpen_FSWitnessStore_ReadWitnessSizeFallbackToFile

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@sonarqubecloud
Copy link
Copy Markdown

@adamdossa adamdossa requested a review from pratikspatil024 May 5, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant