Skip to content

Conversation

hawkadrian
Copy link

Enhanced documentation for NodeReader.Node() and StateReader.Storage() methods to clearly communicate memory safety requirements and prevent potential data corruption.

Changes:

  • Added explicit warnings about read-only nature of returned byte slices
  • Clarified that modifications will corrupt database state
  • Explained performance rationale for not deep-copying data
  • Provided guidance on using common.CopyBytes() when modifications are needed

Why these changes are necessary:

The previous documentation was ambiguous about memory safety, potentially leading developers to accidentally modify shared database storage. The returned byte slices are direct references to internal database structures that must remain immutable for data integrity. Any modification would corrupt the database state and cause undefined behavior across the entire Ethereum node. These changes ensure developers understand the critical importance of treating returned data as read-only while maintaining the performance benefits of zero-copy access patterns.

@fjl
Copy link
Contributor

fjl commented Sep 12, 2025

The comment already says the data is not to be modified, this PR just expands the comment with more text.

@fjl fjl closed this Sep 12, 2025
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.

2 participants