diff --git a/beacon-chain/state/state-native/BUILD.bazel b/beacon-chain/state/state-native/BUILD.bazel index 3bc169140..db9a9c94b 100644 --- a/beacon-chain/state/state-native/BUILD.bazel +++ b/beacon-chain/state/state-native/BUILD.bazel @@ -90,10 +90,7 @@ go_test( "state_test.go", "state_trie_test.go", "types_test.go", - ] + select({ - "//config:mainnet": ["beacon_state_mainnet_test.go"], - "//config:minimal": ["beacon_state_minimal_test.go"], - }), + ], embed = [":go_default_library"], deps = [ "//beacon-chain/core/transition:go_default_library", diff --git a/beacon-chain/state/state-native/beacon_state_mainnet.go b/beacon-chain/state/state-native/beacon_state_mainnet.go index cd16775de..905147a02 100644 --- a/beacon-chain/state/state-native/beacon_state_mainnet.go +++ b/beacon-chain/state/state-native/beacon_state_mainnet.go @@ -19,36 +19,36 @@ import ( // getters and setters for its respective values and helpful functions such as HashTreeRoot(). type BeaconState struct { version int - genesisTime uint64 `ssz-gen:"true"` - genesisValidatorsRoot [32]byte `ssz-gen:"true" ssz-size:"32"` - slot eth2types.Slot `ssz-gen:"true"` - fork *ethpb.Fork `ssz-gen:"true"` - latestBlockHeader *ethpb.BeaconBlockHeader `ssz-gen:"true"` - blockRoots *customtypes.BlockRoots `ssz-gen:"true" ssz-size:"8192,32"` - stateRoots *customtypes.StateRoots `ssz-gen:"true" ssz-size:"8192,32"` - historicalRoots customtypes.HistoricalRoots `ssz-gen:"true" ssz-size:"?,32" ssz-max:"16777216"` - eth1Data *ethpb.Eth1Data `ssz-gen:"true"` - eth1DataVotes []*ethpb.Eth1Data `ssz-gen:"true" ssz-max:"2048"` - eth1DepositIndex uint64 `ssz-gen:"true"` - validators []*ethpb.Validator `ssz-gen:"true" ssz-max:"1099511627776"` - balances []uint64 `ssz-gen:"true" ssz-max:"1099511627776"` - randaoMixes *customtypes.RandaoMixes `ssz-gen:"true" ssz-size:"65536,32"` - slashings []uint64 `ssz-gen:"true" ssz-size:"8192"` - previousEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"4096"` - currentEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"4096"` - previousEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"` - currentEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"` - justificationBits bitfield.Bitvector4 `ssz-gen:"true" ssz-size:"1"` - previousJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"` - currentJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"` - finalizedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"` - inactivityScores []uint64 `ssz-gen:"true" ssz-max:"1099511627776"` - currentSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"` - nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"` - latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"` - latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"` - nextWithdrawalIndex uint64 `ssz-gen:"true"` - lastWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"` + genesisTime uint64 + genesisValidatorsRoot [32]byte + slot eth2types.Slot + fork *ethpb.Fork + latestBlockHeader *ethpb.BeaconBlockHeader + blockRoots *customtypes.BlockRoots + stateRoots *customtypes.StateRoots + historicalRoots customtypes.HistoricalRoots + eth1Data *ethpb.Eth1Data + eth1DataVotes []*ethpb.Eth1Data + eth1DepositIndex uint64 + validators []*ethpb.Validator + balances []uint64 + randaoMixes *customtypes.RandaoMixes + slashings []uint64 + previousEpochAttestations []*ethpb.PendingAttestation + currentEpochAttestations []*ethpb.PendingAttestation + previousEpochParticipation []byte + currentEpochParticipation []byte + justificationBits bitfield.Bitvector4 + previousJustifiedCheckpoint *ethpb.Checkpoint + currentJustifiedCheckpoint *ethpb.Checkpoint + finalizedCheckpoint *ethpb.Checkpoint + inactivityScores []uint64 + currentSyncCommittee *ethpb.SyncCommittee + nextSyncCommittee *ethpb.SyncCommittee + latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader + latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella + nextWithdrawalIndex uint64 + lastWithdrawalValidatorIndex eth2types.ValidatorIndex lock sync.RWMutex dirtyFields map[nativetypes.FieldIndex]bool diff --git a/beacon-chain/state/state-native/beacon_state_mainnet_test.go b/beacon-chain/state/state-native/beacon_state_mainnet_test.go deleted file mode 100644 index acdb5c4ae..000000000 --- a/beacon-chain/state/state-native/beacon_state_mainnet_test.go +++ /dev/null @@ -1,87 +0,0 @@ -//go:build !minimal - -package state_native - -import ( - "reflect" - "strconv" - "testing" - - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - - "github.com/prysmaticlabs/prysm/v3/testing/assert" - "github.com/prysmaticlabs/prysm/v3/testing/require" -) - -func TestMainnetSszValuesAgainstFieldParams(t *testing.T) { - // Casting needed to avoid lock copy analyzer issue. - bs := (interface{})(BeaconState{}) - bsType := reflect.TypeOf(bs) - - f, ok := bsType.FieldByName("genesisValidatorsRoot") - require.Equal(t, true, ok, "Required field not found") - v := f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("blockRoots") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.BlockRootsLength)+","+strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("stateRoots") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.StateRootsLength)+","+strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("historicalRoots") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, "?,"+strconv.Itoa(fieldparams.RootLength), v) - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.HistoricalRootsLength), v) - - f, ok = bsType.FieldByName("eth1DataVotes") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.Eth1DataVotesLength), v) - - f, ok = bsType.FieldByName("validators") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.ValidatorRegistryLimit), v) - - f, ok = bsType.FieldByName("balances") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.ValidatorRegistryLimit), v) - - f, ok = bsType.FieldByName("randaoMixes") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.RandaoMixesLength)+","+strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("slashings") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.SlashingsLength), v) - - f, ok = bsType.FieldByName("previousEpochAttestations") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.PreviousEpochAttestationsLength), v) - - f, ok = bsType.FieldByName("currentEpochAttestations") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.CurrentEpochAttestationsLength), v) - - f, ok = bsType.FieldByName("justificationBits") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, "1", v) - - f, ok = bsType.FieldByName("inactivityScores") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.ValidatorRegistryLimit), v) -} diff --git a/beacon-chain/state/state-native/beacon_state_minimal.go b/beacon-chain/state/state-native/beacon_state_minimal.go index b2e829a73..133d669c1 100644 --- a/beacon-chain/state/state-native/beacon_state_minimal.go +++ b/beacon-chain/state/state-native/beacon_state_minimal.go @@ -19,36 +19,36 @@ import ( // getters and setters for its respective values and helpful functions such as HashTreeRoot(). type BeaconState struct { version int - genesisTime uint64 `ssz-gen:"true"` - genesisValidatorsRoot [32]byte `ssz-gen:"true" ssz-size:"32"` - slot eth2types.Slot `ssz-gen:"true"` - fork *ethpb.Fork `ssz-gen:"true"` - latestBlockHeader *ethpb.BeaconBlockHeader `ssz-gen:"true"` - blockRoots *customtypes.BlockRoots `ssz-gen:"true" ssz-size:"64,32"` - stateRoots *customtypes.StateRoots `ssz-gen:"true" ssz-size:"64,32"` - historicalRoots customtypes.HistoricalRoots `ssz-gen:"true" ssz-size:"?,32" ssz-max:"16777216"` - eth1Data *ethpb.Eth1Data `ssz-gen:"true"` - eth1DataVotes []*ethpb.Eth1Data `ssz-gen:"true" ssz-max:"32"` - eth1DepositIndex uint64 `ssz-gen:"true"` - validators []*ethpb.Validator `ssz-gen:"true" ssz-max:"1099511627776"` - balances []uint64 `ssz-gen:"true" ssz-max:"1099511627776"` - randaoMixes *customtypes.RandaoMixes `ssz-gen:"true" ssz-size:"64,32"` - slashings []uint64 `ssz-gen:"true" ssz-size:"64"` - previousEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"1024"` - currentEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"1024"` - previousEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"` - currentEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"` - justificationBits bitfield.Bitvector4 `ssz-gen:"true" ssz-size:"1"` - previousJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"` - currentJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"` - finalizedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"` - inactivityScores []uint64 `ssz-gen:"true" ssz-max:"1099511627776"` - currentSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"` - nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"` - latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"` - latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"` - nextWithdrawalIndex uint64 `ssz-gen:"true"` - lastWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"` + genesisTime uint64 + genesisValidatorsRoot [32]byte + slot eth2types.Slot + fork *ethpb.Fork + latestBlockHeader *ethpb.BeaconBlockHeader + blockRoots *customtypes.BlockRoots + stateRoots *customtypes.StateRoots + historicalRoots customtypes.HistoricalRoots + eth1Data *ethpb.Eth1Data + eth1DataVotes []*ethpb.Eth1Data + eth1DepositIndex uint64 + validators []*ethpb.Validator + balances []uint64 + randaoMixes *customtypes.RandaoMixes + slashings []uint64 + previousEpochAttestations []*ethpb.PendingAttestation + currentEpochAttestations []*ethpb.PendingAttestation + previousEpochParticipation []byte + currentEpochParticipation []byte + justificationBits bitfield.Bitvector4 + previousJustifiedCheckpoint *ethpb.Checkpoint + currentJustifiedCheckpoint *ethpb.Checkpoint + finalizedCheckpoint *ethpb.Checkpoint + inactivityScores []uint64 + currentSyncCommittee *ethpb.SyncCommittee + nextSyncCommittee *ethpb.SyncCommittee + latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader + latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella + nextWithdrawalIndex uint64 + lastWithdrawalValidatorIndex eth2types.ValidatorIndex lock sync.RWMutex dirtyFields map[nativetypes.FieldIndex]bool diff --git a/beacon-chain/state/state-native/beacon_state_minimal_test.go b/beacon-chain/state/state-native/beacon_state_minimal_test.go deleted file mode 100644 index 28efcfdaf..000000000 --- a/beacon-chain/state/state-native/beacon_state_minimal_test.go +++ /dev/null @@ -1,86 +0,0 @@ -//go:build minimal - -package state_native - -import ( - "reflect" - "strconv" - "testing" - - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - "github.com/prysmaticlabs/prysm/v3/testing/assert" - "github.com/prysmaticlabs/prysm/v3/testing/require" -) - -func TestMinimalSszValuesAgainstFieldParams(t *testing.T) { - // Casting needed to avoid lock copy analyzer issue. - bs := (interface{})(BeaconState{}) - bsType := reflect.TypeOf(bs) - - f, ok := bsType.FieldByName("genesisValidatorsRoot") - require.Equal(t, true, ok, "Required field not found") - v := f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("blockRoots") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.BlockRootsLength)+","+strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("stateRoots") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.StateRootsLength)+","+strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("historicalRoots") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, "?,"+strconv.Itoa(fieldparams.RootLength), v) - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.HistoricalRootsLength), v) - - f, ok = bsType.FieldByName("eth1DataVotes") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.Eth1DataVotesLength), v) - - f, ok = bsType.FieldByName("validators") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.ValidatorRegistryLimit), v) - - f, ok = bsType.FieldByName("balances") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.ValidatorRegistryLimit), v) - - f, ok = bsType.FieldByName("randaoMixes") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.RandaoMixesLength)+","+strconv.Itoa(fieldparams.RootLength), v) - - f, ok = bsType.FieldByName("slashings") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, strconv.Itoa(fieldparams.SlashingsLength), v) - - f, ok = bsType.FieldByName("previousEpochAttestations") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.PreviousEpochAttestationsLength), v) - - f, ok = bsType.FieldByName("currentEpochAttestations") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.CurrentEpochAttestationsLength), v) - - f, ok = bsType.FieldByName("justificationBits") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-size") - assert.Equal(t, "1", v) - - f, ok = bsType.FieldByName("inactivityScores") - require.Equal(t, true, ok, "Required field not found") - v = f.Tag.Get("ssz-max") - assert.Equal(t, strconv.Itoa(fieldparams.ValidatorRegistryLimit), v) -} diff --git a/hack/update-go-ssz.sh b/hack/update-go-ssz.sh index a611142bb..dcfa6776d 100755 --- a/hack/update-go-ssz.sh +++ b/hack/update-go-ssz.sh @@ -4,7 +4,7 @@ # Script to copy ssz.go files from bazel build folder to appropriate location. # Bazel builds to bazel-bin/... folder, script copies them back to original folder where target is. -bazel query 'kind(ssz_gen_marshal, //proto/...) union kind(ssz_gen_marshal, //beacon-chain/state/...)' | xargs bazel build +bazel query 'kind(ssz_gen_marshal, //proto/...)' | xargs bazel build # Get locations of proto ssz.go files. file_list=()