Files
prysm/beacon-chain/state/state-native
Preston Van Loon 2fd6bd8150 Add golang.org/x/tools modernize static analyzer and fix violations (#15946)
* Ran gopls modernize to fix everything

go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...

* Override rules_go provided dependency for golang.org/x/tools to v0.38.0.

To update this, checked out rules_go, then ran `bazel run //go/tools/releaser -- upgrade-dep -mirror=false org_golang_x_tools` and copied the patches.

* Fix buildtag violations and ignore buildtag violations in external

* Introduce modernize analyzer package.

* Add modernize "any" analyzer.

* Fix violations of any analyzer

* Add modernize "appendclipped" analyzer.

* Fix violations of appendclipped

* Add modernize "bloop" analyzer.

* Add modernize "fmtappendf" analyzer.

* Add modernize "forvar" analyzer.

* Add modernize "mapsloop" analyzer.

* Add modernize "minmax" analyzer.

* Fix violations of minmax analyzer

* Add modernize "omitzero" analyzer.

* Add modernize "rangeint" analyzer.

* Fix violations of rangeint.

* Add modernize "reflecttypefor" analyzer.

* Fix violations of reflecttypefor analyzer.

* Add modernize "slicescontains" analyzer.

* Add modernize "slicessort" analyzer.

* Add modernize "slicesdelete" analyzer. This is disabled by default for now. See https://go.dev/issue/73686.

* Add modernize "stringscutprefix" analyzer.

* Add modernize "stringsbuilder" analyzer.

* Fix violations of stringsbuilder analyzer.

* Add modernize "stringsseq" analyzer.

* Add modernize "testingcontext" analyzer.

* Add modernize "waitgroup" analyzer.

* Changelog fragment

* gofmt

* gazelle

* Add modernize "newexpr" analyzer.

* Disable newexpr until go1.26

* Add more details in WORKSPACE on how to update the override

* @nalepae feedback on min()

* gofmt

* Fix violations of forvar
2025-11-14 01:27:22 +00:00
..
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2022-11-18 19:12:19 +00:00
2022-06-21 15:26:56 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +00:00
2025-11-06 16:16:23 +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.