Files
prysm/beacon-chain/state/state-native
Potuz 426fbcc3b0 Add state diff serialization (#15250)
* Add serialization code for state diffs

Adds serialization code for state diffs.
Adds code to create and apply state diffs
Adds fuzz tests and benchmarks for serialization/deserialization

Co-authored-by: Claude <noreply@anthropic.com>

* Add Fulu support

* Review #1

* gazelle

* Fix some fuzzers

* Failing cases from the fuzzers in consensus-types/hdiff

* Fix more fuzz tests

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* add comparison tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Use ConvertToElectra in UpgradeToElectra

* Add comments on constants

* Fix readEth1Data

* remove colons from error messages

* Add design doc

* Apply suggestions from code review

Bast

Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Preston Van Loon <preston@pvl.dev>
Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com>
2025-10-20 21:52:32 +00:00
..
2025-06-12 20:40:34 +00:00
2022-11-18 19:12:19 +00:00
2022-06-21 15:26:56 +00:00
2025-06-12 20:40:34 +00:00

Adding a new field to the state

Note: Whenever only the name of a file is provided, it's assumed to be in the /beacon-chain/state/state-native package.

  • Add a BeaconState[Version]FieldCount configuration item to /config/params/config.go and set it in /config/params/mainnet_config.go.
  • Add the field to the BeaconState struct in beacon_state.go. Update the marshaling structs in the same file too.
  • Add the field's metadata to /beacon-chain/state/state-native/types/types.go.
  • Add a getter and a setter for the field, either to existing getter_XXX.go/setter_XXX.go files or create new ones if the field doesn't fit anywhere. Add the new getter and setter to /beacon-chain/state/interfaces.go.
  • Update state hashing in hasher.go.
  • Update ToProtoUnsafe() and ToProto() functions and add a new ProtobufBeaconState[Version] function, all in getters_state.go.
  • If the field is a multi-value slice, update multi_value_slices.go.
  • Update spec_parameters.go.
  • Update state_trie.go:
    • Add a [version]Fields variable that contains all fields of the new state version.
    • Add a [version]SharedFieldRefCount constant that represents the number of fields whose references are shared between states. Multi-value slice references are not shared in this way so don't include them.
    • Add the following functions: InitializeFromProto[Version](), InitializeFromProtoUnsafe[Version]().
    • Update the following functions: Copy(), initializeMerkleLayers(), RecordStateMetrics() (applies only to multi-value slice fields), rootSelector(), finalizerCleanup() (applies only to multi-value slice fields).
  • If the field is a slice, add it to the field map in types.go. This only applies to large slices that need to be rehashed only in part. In particular, this mostly applies for arrays of objects, and not for arrays of basic SSZ types as these are not hashed by taking the root of each element.
  • If the field is a slice, update the fieldConverters() function in /beacon-chain/state/fieldtrie/field_trie_helpers.go. The exact implementation will vary depending on a few factors (is the field similar to an existing one, is it a multi-value slice etc). This applies only for the slices as mentioned in the previous comment.