# README
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 inbeacon_state_mainnet.go
andbeacon_state_minimal.go
. Update the marshaling code 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()
andToProto()
functions and add a newProtobufBeaconState[Version]
function, all ingetters_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. - Add an
experimentalState[Version]SharedFieldCountRef
constant that represents the number of non multi-value slice fields whose references are shared between states. - 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).
- Add a
- If the field is a slice, add it to the field map in
types.go
. - 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.)
# Functions
ComputeFieldRootsWithHasher hashes the provided state and returns its respective field roots.
FinalizedRootGeneralizedIndex for the beacon state.
InitializeFromProtoAltair the beacon state from a protobuf representation.
InitializeFromProtoBellatrix the beacon state from a protobuf representation.
InitializeFromProtoCapella the beacon state from a protobuf representation.
InitializeFromProtoDeneb the beacon state from a protobuf representation.
InitializeFromProtoPhase0 the beacon state from a protobuf representation.
InitializeFromProtoUnsafeAltair directly uses the beacon state protobuf fields and sets them as fields of the BeaconState type.
InitializeFromProtoUnsafeBellatrix directly uses the beacon state protobuf fields and sets them as fields of the BeaconState type.
InitializeFromProtoUnsafeCapella directly uses the beacon state protobuf fields and sets them as fields of the BeaconState type.
InitializeFromProtoUnsafeDeneb directly uses the beacon state protobuf fields and sets them as fields of the BeaconState type.
InitializeFromProtoUnsafeElectra directly uses the beacon state protobuf fields and sets them as fields of the BeaconState type.
InitializeFromProtoUnsafePhase0 directly uses the beacon state protobuf fields and sets them as fields of the BeaconState type.
NewMultiValueBalances creates a new slice whose shared items will be populated with copies of input values.
NewMultiValueBlockRoots creates a new slice whose shared items will be populated with copies of input values.
NewMultiValueInactivityScores creates a new slice whose shared items will be populated with copies of input values.
NewMultiValueRandaoMixes creates a new slice whose shared items will be populated with copies of input values.
NewMultiValueStateRoots creates a new slice whose shared items will be populated with copies of input values.
NewMultiValueValidators creates a new slice whose shared items will be populated with input values.
NewValidator initializes the read only wrapper for validator.
ProtobufBeaconStateAltair transforms an input into beacon state Altair in the form of protobuf.
ProtobufBeaconStateBellatrix transforms an input into beacon state Bellatrix in the form of protobuf.
ProtobufBeaconStateCapella transforms an input into beacon state Capella in the form of protobuf.
ProtobufBeaconStateDeneb transforms an input into beacon state Deneb in the form of protobuf.
ProtobufBeaconStateElectra transforms an input into beacon state Electra in the form of protobuf.
ProtobufBeaconStatePhase0 transforms an input into beacon state in the form of protobuf.
# Variables
ErrNilWrappedValidator returns when caller attempts to wrap a nil pointer validator.
# Structs
BeaconState defines a struct containing utilities for the Ethereum Beacon Chain state, defining getters and setters for its respective values and helpful functions such as HashTreeRoot().