From 73443208a1cd28fa17242e830fa84ad89ff42b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kapka?= Date: Sat, 17 Sep 2022 00:17:46 +0200 Subject: [PATCH] Remove proto state (#11445) * Remove native state flag and use native state in spectests * remove feature from tests * use e2e config in slasher simulator * use params.BeaconConfig in testutil * use correct function * use minimal config in go_test * fix TestListValidators * parameterize sync committee bits and aggregation bits * Fix TestServer_ListIndexedAttestations_GenesisEpoch (cherry picked from commit 254ab623dde08ae8886b152facdbbd8889ed79db) * fix more tests * fix even more * moreeee * aaaand more * one more fix * one more * simplify TestGetAltairDuties_UnknownPubkey * comment out problematic test * one more fix * one more * aaaand one more * another * use fieldparams in HydrateBlindedBeaconBlockBodyBellatrix * create new package for mainnet tests * TestServer_GetBellatrixBeaconBlock * change slashed validator index * clear cache in reward_test.go * deprecate flag * create bazel mainnet target * move attester mainnet test to mainnet target * "fix" proposer tests * use minimal config in TestServer_circuitBreakBuilder * fix TestProposer_ProposeBlock_OK * more fixes in validator package * more fixes * more fixes * test code * move TestProposer_GetBeaconBlock_BellatrixEpoch to minimal * finally * remove proposer_bellatrix_mainnet_test.go * fix TestServer_GetBellatrixBeaconBlock_HappyCase * fix TestServer_GetBellatrixBeaconBlock_BuilderCase * Preston needs to fix this! * Revert "Preston needs to fix this!" This reverts commit b03d97a16e3080e254c7b19d7f193d3c600ca869. * remove proto state tests * fix migration tests * static analysis fix * review * remove proto state * swap state in tests * fix BUILD file in /proto/testing * remove metrics test with nil state --- beacon-chain/blockchain/BUILD.bazel | 3 +- beacon-chain/blockchain/chain_info_test.go | 17 +- beacon-chain/blockchain/process_block_test.go | 15 - beacon-chain/blockchain/service_test.go | 8 +- .../blockchain/state_balance_cache_test.go | 4 +- beacon-chain/cache/BUILD.bazel | 4 +- beacon-chain/cache/active_balance_test.go | 6 +- beacon-chain/cache/checkpoint_state_test.go | 12 +- beacon-chain/cache/skip_slot_cache_test.go | 4 +- .../cache/sync_committee_head_state_test.go | 10 +- beacon-chain/core/altair/BUILD.bazel | 5 +- beacon-chain/core/altair/attestation_test.go | 4 +- beacon-chain/core/altair/deposit_fuzz_test.go | 6 +- beacon-chain/core/altair/deposit_test.go | 14 +- .../core/altair/epoch_precompute_test.go | 15 +- beacon-chain/core/altair/epoch_spec_test.go | 8 +- .../core/altair/sync_committee_test.go | 27 +- beacon-chain/core/altair/upgrade.go | 4 +- beacon-chain/core/blocks/BUILD.bazel | 2 +- .../blocks/attestation_regression_test.go | 4 +- beacon-chain/core/blocks/attestation_test.go | 8 +- .../core/blocks/attester_slashing_test.go | 6 +- .../core/blocks/block_operations_fuzz_test.go | 44 +- beacon-chain/core/blocks/deposit_test.go | 18 +- beacon-chain/core/blocks/eth1_data_test.go | 6 +- beacon-chain/core/blocks/exit_test.go | 8 +- .../proposer_slashing_regression_test.go | 4 +- .../core/blocks/proposer_slashing_test.go | 4 +- beacon-chain/core/blocks/withdrawals_test.go | 10 +- beacon-chain/core/epoch/BUILD.bazel | 2 +- .../core/epoch/epoch_processing_fuzz_test.go | 4 +- .../core/epoch/epoch_processing_test.go | 24 +- .../core/epoch/precompute/BUILD.bazel | 3 +- .../justification_finalization_test.go | 13 +- .../core/epoch/precompute/new_test.go | 4 +- .../epoch/precompute/reward_penalty_test.go | 18 +- .../core/epoch/precompute/slashing_test.go | 8 +- beacon-chain/core/execution/BUILD.bazel | 2 +- beacon-chain/core/execution/upgrade.go | 4 +- beacon-chain/core/helpers/BUILD.bazel | 3 +- beacon-chain/core/helpers/attestation_test.go | 4 +- .../core/helpers/beacon_committee_test.go | 32 +- beacon-chain/core/helpers/block_test.go | 6 +- beacon-chain/core/helpers/randao_test.go | 8 +- .../core/helpers/rewards_penalties_test.go | 24 +- .../core/helpers/sync_committee_test.go | 35 +- beacon-chain/core/helpers/validators_test.go | 22 +- beacon-chain/core/time/BUILD.bazel | 2 +- beacon-chain/core/time/slot_epoch_test.go | 10 +- beacon-chain/core/transition/BUILD.bazel | 4 +- .../core/transition/benchmarks_test.go | 6 +- .../core/transition/skip_slot_cache_test.go | 10 +- beacon-chain/core/transition/state.go | 6 +- .../core/transition/state_fuzz_test.go | 4 +- beacon-chain/core/transition/state_test.go | 6 +- .../core/transition/stateutils/BUILD.bazel | 2 +- .../stateutils/validator_index_map_test.go | 4 +- .../core/transition/transition_fuzz_test.go | 20 +- .../core/transition/transition_test.go | 20 +- beacon-chain/core/validators/BUILD.bazel | 2 +- .../core/validators/validator_test.go | 18 +- beacon-chain/db/kv/BUILD.bazel | 6 +- beacon-chain/db/kv/genesis.go | 4 +- .../db/kv/migration_state_validators_test.go | 9 +- beacon-chain/db/kv/state.go | 9 +- .../deterministic-genesis/BUILD.bazel | 2 +- beacon-chain/deterministic-genesis/service.go | 8 +- beacon-chain/execution/BUILD.bazel | 1 - beacon-chain/execution/service.go | 3 +- beacon-chain/execution/testing/BUILD.bazel | 2 +- .../execution/testing/mock_faulty_powchain.go | 4 +- .../forkchoice/doubly-linked-tree/BUILD.bazel | 2 +- .../doubly-linked-tree/forkchoice_test.go | 4 +- .../forkchoice/protoarray/BUILD.bazel | 2 +- .../forkchoice/protoarray/ffg_update_test.go | 4 +- .../operations/voluntaryexits/BUILD.bazel | 2 +- .../operations/voluntaryexits/service_test.go | 6 +- beacon-chain/rpc/eth/beacon/BUILD.bazel | 3 +- beacon-chain/rpc/eth/beacon/validator.go | 9 +- beacon-chain/rpc/eth/beacon/validator_test.go | 12 +- beacon-chain/rpc/eth/helpers/BUILD.bazel | 2 +- .../rpc/eth/helpers/validator_status_test.go | 6 +- beacon-chain/rpc/eth/validator/BUILD.bazel | 2 +- beacon-chain/rpc/eth/validator/validator.go | 4 +- .../rpc/prysm/v1alpha1/beacon/BUILD.bazel | 2 +- .../v1alpha1/beacon/attestations_test.go | 6 +- .../rpc/prysm/v1alpha1/beacon/blocks_test.go | 6 +- .../prysm/v1alpha1/beacon/validators_test.go | 6 +- .../rpc/prysm/v1alpha1/validator/BUILD.bazel | 3 +- .../v1alpha1/validator/aggregator_test.go | 8 +- .../prysm/v1alpha1/validator/attester_test.go | 4 +- .../validator/proposer_bellatrix_test.go | 4 +- .../prysm/v1alpha1/validator/proposer_test.go | 46 +- .../v1alpha1/validator/server_mainnet_test.go | 4 +- .../prysm/v1alpha1/validator/server_test.go | 6 +- .../v1alpha1/validator/status_mainnet_test.go | 4 +- .../prysm/v1alpha1/validator/status_test.go | 22 +- beacon-chain/state/genesis/BUILD.bazel | 2 +- beacon-chain/state/genesis/genesis.go | 4 +- beacon-chain/state/state-native/BUILD.bazel | 16 +- beacon-chain/state/stategen/BUILD.bazel | 2 +- .../state/stategen/hot_state_cache_test.go | 4 +- beacon-chain/state/v1/BUILD.bazel | 56 --- beacon-chain/state/v1/doc.go | 40 -- beacon-chain/state/v1/field_roots.go | 14 - beacon-chain/state/v1/getters_attestation.go | 55 --- beacon-chain/state/v1/getters_block.go | 99 ----- beacon-chain/state/v1/getters_checkpoint.go | 160 ------- beacon-chain/state/v1/getters_eth1.go | 91 ---- beacon-chain/state/v1/getters_misc.go | 163 ------- beacon-chain/state/v1/getters_randao.go | 85 ---- beacon-chain/state/v1/getters_state.go | 123 ------ beacon-chain/state/v1/getters_validator.go | 293 ------------- beacon-chain/state/v1/proofs.go | 54 --- beacon-chain/state/v1/readonly_validator.go | 89 ---- beacon-chain/state/v1/setters_attestation.go | 98 ----- beacon-chain/state/v1/setters_block.go | 68 --- beacon-chain/state/v1/setters_checkpoint.go | 58 --- beacon-chain/state/v1/setters_eth1.go | 74 ---- beacon-chain/state/v1/setters_misc.go | 182 -------- beacon-chain/state/v1/setters_randao.go | 53 --- beacon-chain/state/v1/setters_state.go | 59 --- beacon-chain/state/v1/setters_validator.go | 228 ---------- beacon-chain/state/v1/spec_parameters.go | 11 - beacon-chain/state/v1/state_trie.go | 410 ------------------ beacon-chain/state/v1/types.go | 78 ---- beacon-chain/state/v1/unsupported_getters.go | 42 -- beacon-chain/state/v1/unsupported_setters.go | 62 --- beacon-chain/state/v2/BUILD.bazel | 59 --- beacon-chain/state/v2/deprecated_getters.go | 22 - beacon-chain/state/v2/deprecated_setters.go | 27 -- beacon-chain/state/v2/error.go | 5 - beacon-chain/state/v2/field_roots.go | 14 - beacon-chain/state/v2/getters_block.go | 99 ----- beacon-chain/state/v2/getters_checkpoint.go | 160 ------- beacon-chain/state/v2/getters_eth1.go | 91 ---- beacon-chain/state/v2/getters_misc.go | 164 ------- .../state/v2/getters_participation.go | 78 ---- beacon-chain/state/v2/getters_randao.go | 85 ---- beacon-chain/state/v2/getters_state.go | 126 ------ .../state/v2/getters_sync_committee.go | 69 --- beacon-chain/state/v2/getters_validator.go | 324 -------------- beacon-chain/state/v2/proofs.go | 83 ---- beacon-chain/state/v2/setters_block.go | 68 --- beacon-chain/state/v2/setters_checkpoint.go | 58 --- beacon-chain/state/v2/setters_eth1.go | 74 ---- beacon-chain/state/v2/setters_misc.go | 181 -------- .../state/v2/setters_participation.go | 155 ------- beacon-chain/state/v2/setters_randao.go | 53 --- beacon-chain/state/v2/setters_state.go | 59 --- .../state/v2/setters_sync_committee.go | 31 -- beacon-chain/state/v2/setters_validator.go | 265 ----------- beacon-chain/state/v2/spec_parameters.go | 11 - beacon-chain/state/v2/state_trie.go | 397 ----------------- ...f3330d00508d015fe3c204b6bc6607296f64ec221c | 3 - beacon-chain/state/v2/types.go | 78 ---- beacon-chain/state/v3/BUILD.bazel | 61 --- beacon-chain/state/v3/deprecated_getters.go | 16 - beacon-chain/state/v3/deprecated_setters.go | 21 - beacon-chain/state/v3/error.go | 5 - beacon-chain/state/v3/field_roots.go | 14 - beacon-chain/state/v3/getters_block.go | 99 ----- beacon-chain/state/v3/getters_checkpoint.go | 160 ------- beacon-chain/state/v3/getters_eth1.go | 91 ---- beacon-chain/state/v3/getters_misc.go | 163 ------- .../state/v3/getters_participation.go | 78 ---- .../state/v3/getters_payload_header.go | 31 -- beacon-chain/state/v3/getters_randao.go | 85 ---- beacon-chain/state/v3/getters_state.go | 127 ------ .../state/v3/getters_sync_committee.go | 69 --- beacon-chain/state/v3/getters_validator.go | 324 -------------- beacon-chain/state/v3/proofs.go | 83 ---- beacon-chain/state/v3/setters_block.go | 68 --- beacon-chain/state/v3/setters_checkpoint.go | 58 --- beacon-chain/state/v3/setters_eth1.go | 74 ---- beacon-chain/state/v3/setters_misc.go | 181 -------- .../state/v3/setters_participation.go | 146 ------- .../state/v3/setters_payload_header.go | 24 - beacon-chain/state/v3/setters_randao.go | 53 --- beacon-chain/state/v3/setters_state.go | 59 --- .../state/v3/setters_sync_committee.go | 31 -- beacon-chain/state/v3/setters_validator.go | 265 ----------- beacon-chain/state/v3/spec_parameters.go | 11 - beacon-chain/state/v3/state_trie.go | 395 ----------------- beacon-chain/state/v3/types.go | 77 ---- beacon-chain/sync/BUILD.bazel | 2 +- beacon-chain/sync/initial-sync/BUILD.bazel | 1 - beacon-chain/sync/rpc_status_test.go | 4 +- beacon-chain/sync/service_test.go | 4 +- .../sync/validate_proposer_slashing_test.go | 4 +- .../sync/validate_voluntary_exit_test.go | 4 +- encoding/ssz/detect/BUILD.bazel | 4 +- encoding/ssz/detect/configfork.go | 10 +- proto/testing/BUILD.bazel | 9 +- testing/benchmark/BUILD.bazel | 2 +- testing/benchmark/pregen.go | 6 +- testing/util/BUILD.bazel | 4 +- testing/util/altair.go | 6 +- testing/util/attestation.go | 16 +- testing/util/bellatrix_state.go | 6 +- testing/util/state.go | 10 +- tools/benchmark-files-gen/BUILD.bazel | 2 +- tools/benchmark-files-gen/main.go | 4 +- tools/pcli/BUILD.bazel | 2 +- tools/pcli/main.go | 4 +- 205 files changed, 443 insertions(+), 8979 deletions(-) delete mode 100644 beacon-chain/state/v1/BUILD.bazel delete mode 100644 beacon-chain/state/v1/doc.go delete mode 100644 beacon-chain/state/v1/field_roots.go delete mode 100644 beacon-chain/state/v1/getters_attestation.go delete mode 100644 beacon-chain/state/v1/getters_block.go delete mode 100644 beacon-chain/state/v1/getters_checkpoint.go delete mode 100644 beacon-chain/state/v1/getters_eth1.go delete mode 100644 beacon-chain/state/v1/getters_misc.go delete mode 100644 beacon-chain/state/v1/getters_randao.go delete mode 100644 beacon-chain/state/v1/getters_state.go delete mode 100644 beacon-chain/state/v1/getters_validator.go delete mode 100644 beacon-chain/state/v1/proofs.go delete mode 100644 beacon-chain/state/v1/readonly_validator.go delete mode 100644 beacon-chain/state/v1/setters_attestation.go delete mode 100644 beacon-chain/state/v1/setters_block.go delete mode 100644 beacon-chain/state/v1/setters_checkpoint.go delete mode 100644 beacon-chain/state/v1/setters_eth1.go delete mode 100644 beacon-chain/state/v1/setters_misc.go delete mode 100644 beacon-chain/state/v1/setters_randao.go delete mode 100644 beacon-chain/state/v1/setters_state.go delete mode 100644 beacon-chain/state/v1/setters_validator.go delete mode 100644 beacon-chain/state/v1/spec_parameters.go delete mode 100644 beacon-chain/state/v1/state_trie.go delete mode 100644 beacon-chain/state/v1/types.go delete mode 100644 beacon-chain/state/v1/unsupported_getters.go delete mode 100644 beacon-chain/state/v1/unsupported_setters.go delete mode 100644 beacon-chain/state/v2/BUILD.bazel delete mode 100644 beacon-chain/state/v2/deprecated_getters.go delete mode 100644 beacon-chain/state/v2/deprecated_setters.go delete mode 100644 beacon-chain/state/v2/error.go delete mode 100644 beacon-chain/state/v2/field_roots.go delete mode 100644 beacon-chain/state/v2/getters_block.go delete mode 100644 beacon-chain/state/v2/getters_checkpoint.go delete mode 100644 beacon-chain/state/v2/getters_eth1.go delete mode 100644 beacon-chain/state/v2/getters_misc.go delete mode 100644 beacon-chain/state/v2/getters_participation.go delete mode 100644 beacon-chain/state/v2/getters_randao.go delete mode 100644 beacon-chain/state/v2/getters_state.go delete mode 100644 beacon-chain/state/v2/getters_sync_committee.go delete mode 100644 beacon-chain/state/v2/getters_validator.go delete mode 100644 beacon-chain/state/v2/proofs.go delete mode 100644 beacon-chain/state/v2/setters_block.go delete mode 100644 beacon-chain/state/v2/setters_checkpoint.go delete mode 100644 beacon-chain/state/v2/setters_eth1.go delete mode 100644 beacon-chain/state/v2/setters_misc.go delete mode 100644 beacon-chain/state/v2/setters_participation.go delete mode 100644 beacon-chain/state/v2/setters_randao.go delete mode 100644 beacon-chain/state/v2/setters_state.go delete mode 100644 beacon-chain/state/v2/setters_sync_committee.go delete mode 100644 beacon-chain/state/v2/setters_validator.go delete mode 100644 beacon-chain/state/v2/spec_parameters.go delete mode 100644 beacon-chain/state/v2/state_trie.go delete mode 100644 beacon-chain/state/v2/testdata/fuzz/FuzzV2StateHashTreeRoot/52875ab39ad0eeec927085f3330d00508d015fe3c204b6bc6607296f64ec221c delete mode 100644 beacon-chain/state/v2/types.go delete mode 100644 beacon-chain/state/v3/BUILD.bazel delete mode 100644 beacon-chain/state/v3/deprecated_getters.go delete mode 100644 beacon-chain/state/v3/deprecated_setters.go delete mode 100644 beacon-chain/state/v3/error.go delete mode 100644 beacon-chain/state/v3/field_roots.go delete mode 100644 beacon-chain/state/v3/getters_block.go delete mode 100644 beacon-chain/state/v3/getters_checkpoint.go delete mode 100644 beacon-chain/state/v3/getters_eth1.go delete mode 100644 beacon-chain/state/v3/getters_misc.go delete mode 100644 beacon-chain/state/v3/getters_participation.go delete mode 100644 beacon-chain/state/v3/getters_payload_header.go delete mode 100644 beacon-chain/state/v3/getters_randao.go delete mode 100644 beacon-chain/state/v3/getters_state.go delete mode 100644 beacon-chain/state/v3/getters_sync_committee.go delete mode 100644 beacon-chain/state/v3/getters_validator.go delete mode 100644 beacon-chain/state/v3/proofs.go delete mode 100644 beacon-chain/state/v3/setters_block.go delete mode 100644 beacon-chain/state/v3/setters_checkpoint.go delete mode 100644 beacon-chain/state/v3/setters_eth1.go delete mode 100644 beacon-chain/state/v3/setters_misc.go delete mode 100644 beacon-chain/state/v3/setters_participation.go delete mode 100644 beacon-chain/state/v3/setters_payload_header.go delete mode 100644 beacon-chain/state/v3/setters_randao.go delete mode 100644 beacon-chain/state/v3/setters_state.go delete mode 100644 beacon-chain/state/v3/setters_sync_committee.go delete mode 100644 beacon-chain/state/v3/setters_validator.go delete mode 100644 beacon-chain/state/v3/spec_parameters.go delete mode 100644 beacon-chain/state/v3/state_trie.go delete mode 100644 beacon-chain/state/v3/types.go diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 95c1761e80..7ba7872225 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -132,9 +132,8 @@ go_test( "//beacon-chain/execution/testing:go_default_library", "//beacon-chain/forkchoice/types:go_default_library", "//beacon-chain/p2p:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v3:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/blockchain/chain_info_test.go b/beacon-chain/blockchain/chain_info_test.go index dc5749aae9..454e706852 100644 --- a/beacon-chain/blockchain/chain_info_test.go +++ b/beacon-chain/blockchain/chain_info_test.go @@ -10,9 +10,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray" forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -61,7 +60,7 @@ func prepareForkchoiceState( } base.BlockRoots[0] = append(base.BlockRoots[0], blockRoot[:]...) - st, err := v3.InitializeFromProto(base) + st, err := state_native.InitializeFromProtoBellatrix(base) return st, blockRoot, err } @@ -125,7 +124,7 @@ func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) { func TestHeadSlot_CanRetrieve(t *testing.T) { c := &Service{} - s, err := v1.InitializeFromProto(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{}) require.NoError(t, err) c.head = &head{slot: 100, state: s} assert.Equal(t, types.Slot(100), c.HeadSlot()) @@ -179,7 +178,7 @@ func TestHeadRoot_UseDB(t *testing.T) { func TestHeadBlock_CanRetrieve(t *testing.T) { b := util.NewBeaconBlock() b.Block.Slot = 1 - s, err := v1.InitializeFromProto(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{}) require.NoError(t, err) wsb, err := blocks.NewSignedBeaconBlock(b) require.NoError(t, err) @@ -194,7 +193,7 @@ func TestHeadBlock_CanRetrieve(t *testing.T) { } func TestHeadState_CanRetrieve(t *testing.T) { - s, err := v1.InitializeFromProto(ðpb.BeaconState{Slot: 2, GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:]}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: 2, GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:]}) require.NoError(t, err) c := &Service{} c.head = &head{state: s} @@ -211,7 +210,7 @@ func TestGenesisTime_CanRetrieve(t *testing.T) { func TestCurrentFork_CanRetrieve(t *testing.T) { f := ðpb.Fork{Epoch: 999} - s, err := v1.InitializeFromProto(ðpb.BeaconState{Fork: f}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Fork: f}) require.NoError(t, err) c := &Service{} c.head = &head{state: s} @@ -236,7 +235,7 @@ func TestGenesisValidatorsRoot_CanRetrieve(t *testing.T) { c := &Service{} assert.Equal(t, [32]byte{}, c.GenesisValidatorsRoot(), "Did not get correct genesis validators root") - s, err := v1.InitializeFromProto(ðpb.BeaconState{GenesisValidatorsRoot: []byte{'a'}}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{GenesisValidatorsRoot: []byte{'a'}}) require.NoError(t, err) c.head = &head{state: s} assert.Equal(t, [32]byte{'a'}, c.GenesisValidatorsRoot(), "Did not get correct genesis validators root") @@ -250,7 +249,7 @@ func TestHeadETH1Data_Nil(t *testing.T) { func TestHeadETH1Data_CanRetrieve(t *testing.T) { d := ðpb.Eth1Data{DepositCount: 999} - s, err := v1.InitializeFromProto(ðpb.BeaconState{Eth1Data: d}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Eth1Data: d}) require.NoError(t, err) c := &Service{} c.head = &head{state: s} diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index 94f81d1c6f..250b3cb6c0 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -29,7 +29,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -1125,20 +1124,6 @@ func TestVerifyBlkDescendant(t *testing.T) { } } -func TestHandleEpochBoundary_BadMetrics(t *testing.T) { - ctx := context.Background() - opts := testServiceOptsNoDB() - service, err := NewService(ctx, opts...) - require.NoError(t, err) - - s, err := util.NewBeaconState() - require.NoError(t, err) - require.NoError(t, s.SetSlot(1)) - service.head = &head{state: (*v1.BeaconState)(nil)} - - require.ErrorContains(t, "failed to initialize precompute: nil inner state", service.handleEpochBoundary(ctx, s)) -} - func TestHandleEpochBoundary_UpdateFirstSlot(t *testing.T) { ctx := context.Background() opts := testServiceOptsNoDB() diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 220bc1eb5e..a2c595a31e 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -24,8 +24,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/v3/config/features" "github.com/prysmaticlabs/prysm/v3/config/params" consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -84,7 +84,7 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service { srv.Stop() }) bState, _ := util.DeterministicGenesisState(t, 10) - pbState, err := v1.ProtobufBeaconState(bState.InnerStateUnsafe()) + pbState, err := state_native.ProtobufBeaconStatePhase0(bState.InnerStateUnsafe()) require.NoError(t, err) mockTrie, err := trie.NewTrie(0) require.NoError(t, err) @@ -509,7 +509,7 @@ func BenchmarkHasBlockForkChoiceStore_ProtoArray(b *testing.B) { r, err := blk.Block.HashTreeRoot() require.NoError(b, err) bs := ðpb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}} - beaconState, err := v1.InitializeFromProto(bs) + beaconState, err := state_native.InitializeFromProtoPhase0(bs) require.NoError(b, err) wsb, err := consensusblocks.NewSignedBeaconBlock(blk) require.NoError(b, err) @@ -530,7 +530,7 @@ func BenchmarkHasBlockForkChoiceStore_DoublyLinkedTree(b *testing.B) { r, err := blk.Block.HashTreeRoot() require.NoError(b, err) bs := ðpb.BeaconState{FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, 32)}} - beaconState, err := v1.InitializeFromProto(bs) + beaconState, err := state_native.InitializeFromProtoPhase0(bs) require.NoError(b, err) wsb, err := consensusblocks.NewSignedBeaconBlock(blk) require.NoError(b, err) diff --git a/beacon-chain/blockchain/state_balance_cache_test.go b/beacon-chain/blockchain/state_balance_cache_test.go index 8cc48d6aef..c4e2a2448b 100644 --- a/beacon-chain/blockchain/state_balance_cache_test.go +++ b/beacon-chain/blockchain/state_balance_cache_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -34,7 +34,7 @@ func testStateFixture(opts ...testStateOpt) state.BeaconState { for _, o := range opts { o(a) } - s, _ := v2.InitializeFromProtoUnsafe(a) + s, _ := state_native.InitializeFromProtoUnsafeAltair(a) return s } diff --git a/beacon-chain/cache/BUILD.bazel b/beacon-chain/cache/BUILD.bazel index cb66d975d3..f39ae7256a 100644 --- a/beacon-chain/cache/BUILD.bazel +++ b/beacon-chain/cache/BUILD.bazel @@ -73,9 +73,7 @@ go_test( embed = [":go_default_library"], deps = [ "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", - "//beacon-chain/state/v3:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", diff --git a/beacon-chain/cache/active_balance_test.go b/beacon-chain/cache/active_balance_test.go index ccea0c3bd8..83ec176aa4 100644 --- a/beacon-chain/cache/active_balance_test.go +++ b/beacon-chain/cache/active_balance_test.go @@ -7,7 +7,7 @@ import ( "math" "testing" - state "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -24,7 +24,7 @@ func TestBalanceCache_AddGetBalance(t *testing.T) { raw := ðpb.BeaconState{ BlockRoots: blockRoots, } - st, err := state.InitializeFromProto(raw) + st, err := state_native.InitializeFromProtoPhase0(raw) require.NoError(t, err) cache := NewEffectiveBalanceCache() @@ -68,7 +68,7 @@ func TestBalanceCache_BalanceKey(t *testing.T) { raw := ðpb.BeaconState{ BlockRoots: blockRoots, } - st, err := state.InitializeFromProto(raw) + st, err := state_native.InitializeFromProtoPhase0(raw) require.NoError(t, err) require.NoError(t, st.SetSlot(types.Slot(math.MaxUint64))) diff --git a/beacon-chain/cache/checkpoint_state_test.go b/beacon-chain/cache/checkpoint_state_test.go index fa62362131..dbdf920a5c 100644 --- a/beacon-chain/cache/checkpoint_state_test.go +++ b/beacon-chain/cache/checkpoint_state_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -18,7 +18,7 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) { cache := NewCheckpointStateCache() cp1 := ðpb.Checkpoint{Epoch: 1, Root: bytesutil.PadTo([]byte{'A'}, 32)} - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ GenesisValidatorsRoot: params.BeaconConfig().ZeroHash[:], Slot: 64, }) @@ -33,16 +33,16 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) { s, err = cache.StateByCheckpoint(cp1) require.NoError(t, err) - pbState1, err := v1.ProtobufBeaconState(s.InnerStateUnsafe()) + pbState1, err := state_native.ProtobufBeaconStatePhase0(s.InnerStateUnsafe()) require.NoError(t, err) - pbstate, err := v1.ProtobufBeaconState(st.InnerStateUnsafe()) + pbstate, err := state_native.ProtobufBeaconStatePhase0(st.InnerStateUnsafe()) require.NoError(t, err) if !proto.Equal(pbState1, pbstate) { t.Error("incorrectly cached state") } cp2 := ðpb.Checkpoint{Epoch: 2, Root: bytesutil.PadTo([]byte{'B'}, 32)} - st2, err := v1.InitializeFromProto(ðpb.BeaconState{ + st2, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 128, }) require.NoError(t, err) @@ -59,7 +59,7 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) { func TestCheckpointStateCache_MaxSize(t *testing.T) { c := NewCheckpointStateCache() - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, }) require.NoError(t, err) diff --git a/beacon-chain/cache/skip_slot_cache_test.go b/beacon-chain/cache/skip_slot_cache_test.go index 1e26593443..3d7bacfd3d 100644 --- a/beacon-chain/cache/skip_slot_cache_test.go +++ b/beacon-chain/cache/skip_slot_cache_test.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/cache" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/assert" "github.com/prysmaticlabs/prysm/v3/testing/require" @@ -23,7 +23,7 @@ func TestSkipSlotCache_RoundTrip(t *testing.T) { require.NoError(t, c.MarkInProgress(r)) - s, err = v1.InitializeFromProto(ðpb.BeaconState{ + s, err = state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 10, }) require.NoError(t, err) diff --git a/beacon-chain/cache/sync_committee_head_state_test.go b/beacon-chain/cache/sync_committee_head_state_test.go index 5aff1471e0..4f1e7a69ba 100644 --- a/beacon-chain/cache/sync_committee_head_state_test.go +++ b/beacon-chain/cache/sync_committee_head_state_test.go @@ -4,9 +4,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -14,21 +12,21 @@ import ( ) func TestSyncCommitteeHeadState(t *testing.T) { - beaconState, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Fork: ðpb.Fork{ PreviousVersion: params.BeaconConfig().GenesisForkVersion, CurrentVersion: params.BeaconConfig().GenesisForkVersion, }, }) require.NoError(t, err) - phase0State, err := v1.InitializeFromProto(ðpb.BeaconState{ + phase0State, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Fork: ðpb.Fork{ PreviousVersion: params.BeaconConfig().GenesisForkVersion, CurrentVersion: params.BeaconConfig().GenesisForkVersion, }, }) require.NoError(t, err) - bellatrixState, err := v3.InitializeFromProto(ðpb.BeaconStateBellatrix{ + bellatrixState, err := state_native.InitializeFromProtoBellatrix(ðpb.BeaconStateBellatrix{ Fork: ðpb.Fork{ PreviousVersion: params.BeaconConfig().GenesisForkVersion, CurrentVersion: params.BeaconConfig().GenesisForkVersion, diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 32882b7b7e..6d0e14bab2 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -30,7 +30,7 @@ go_library( "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v2:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", @@ -72,8 +72,7 @@ go_test( "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v2:go_default_library", - "//beacon-chain/state/v3:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/core/altair/attestation_test.go b/beacon-chain/core/altair/attestation_test.go index 1c62697b64..600908fa10 100644 --- a/beacon-chain/core/altair/attestation_test.go +++ b/beacon-chain/core/altair/attestation_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -419,7 +419,7 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) { if b.Block == nil { b.Block = ðpb.BeaconBlockAltair{} } - s, err := stateAltair.InitializeFromProtoUnsafe(st) + s, err := state_native.InitializeFromProtoUnsafeAltair(st) require.NoError(t, err) if b.Block == nil || b.Block.Body == nil { continue diff --git a/beacon-chain/core/altair/deposit_fuzz_test.go b/beacon-chain/core/altair/deposit_fuzz_test.go index cf10f6bf65..bd504fd6ad 100644 --- a/beacon-chain/core/altair/deposit_fuzz_test.go +++ b/beacon-chain/core/altair/deposit_fuzz_test.go @@ -6,7 +6,7 @@ import ( fuzz "github.com/google/gofuzz" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/require" ) @@ -21,7 +21,7 @@ func TestFuzzProcessDeposits_10000(t *testing.T) { for i := range deposits { fuzzer.Fuzz(deposits[i]) } - s, err := stateAltair.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafeAltair(state) require.NoError(t, err) r, err := altair.ProcessDeposits(ctx, s, deposits) if err != nil && r != nil { @@ -38,7 +38,7 @@ func TestFuzzProcessDeposit_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) - s, err := stateAltair.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafeAltair(state) require.NoError(t, err) r, err := altair.ProcessDeposit(s, deposit, true) if err != nil && r != nil { diff --git a/beacon-chain/core/altair/deposit_test.go b/beacon-chain/core/altair/deposit_test.go index 4be685afde..bd6b55a7be 100644 --- a/beacon-chain/core/altair/deposit_test.go +++ b/beacon-chain/core/altair/deposit_test.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/container/trie" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -29,7 +29,7 @@ func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -62,7 +62,7 @@ func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) { require.NoError(t, err, "Could not generate proof") deposit.Proof = proof - beaconState, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Eth1Data: ðpb.Eth1Data{ DepositRoot: []byte{0}, BlockHash: []byte{1}, @@ -87,7 +87,7 @@ func TestProcessDeposits_AddsNewValidatorDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -145,7 +145,7 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T) balances := []uint64{0, 50} root, err := depositTrie.HashTreeRoot() require.NoError(t, err) - beaconState, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: registry, Balances: balances, Eth1Data: ðpb.Eth1Data{ @@ -173,7 +173,7 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -216,7 +216,7 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + beaconState, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: registry, Balances: balances, Eth1Data: eth1Data, diff --git a/beacon-chain/core/altair/epoch_precompute_test.go b/beacon-chain/core/altair/epoch_precompute_test.go index 4e7e07ca7f..fd72cbec64 100644 --- a/beacon-chain/core/altair/epoch_precompute_test.go +++ b/beacon-chain/core/altair/epoch_precompute_test.go @@ -7,8 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -18,7 +17,7 @@ import ( func TestInitializeEpochValidators_Ok(t *testing.T) { ffe := params.BeaconConfig().FarFutureEpoch - s, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + s, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Slot: params.BeaconConfig().SlotsPerEpoch, // Validator 0 is slashed // Validator 1 is withdrawable @@ -66,7 +65,7 @@ func TestInitializeEpochValidators_Ok(t *testing.T) { func TestInitializeEpochValidators_Overflow(t *testing.T) { ffe := params.BeaconConfig().FarFutureEpoch - s, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + s, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Slot: params.BeaconConfig().SlotsPerEpoch, Validators: []*ethpb.Validator{ {WithdrawableEpoch: ffe, ExitEpoch: ffe, EffectiveBalance: math.MaxUint64}, @@ -80,7 +79,7 @@ func TestInitializeEpochValidators_Overflow(t *testing.T) { } func TestInitializeEpochValidators_BadState(t *testing.T) { - s, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + s, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: []*ethpb.Validator{{}}, InactivityScores: []uint64{}, }) @@ -150,7 +149,7 @@ func TestProcessEpochParticipation_InactiveValidator(t *testing.T) { } return b } - st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + st, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Slot: 2 * params.BeaconConfig().SlotsPerEpoch, Validators: []*ethpb.Validator{ {EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance}, // Inactive @@ -468,7 +467,7 @@ func testState() (state.BeaconState, error) { } return b } - return stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + return state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Slot: 2 * params.BeaconConfig().SlotsPerEpoch, Validators: []*ethpb.Validator{ {EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: params.BeaconConfig().FarFutureEpoch}, @@ -505,7 +504,7 @@ func testStateBellatrix() (state.BeaconState, error) { } return b } - return v3.InitializeFromProto(ðpb.BeaconStateBellatrix{ + return state_native.InitializeFromProtoBellatrix(ðpb.BeaconStateBellatrix{ Slot: 2 * params.BeaconConfig().SlotsPerEpoch, Validators: []*ethpb.Validator{ {EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: params.BeaconConfig().FarFutureEpoch}, diff --git a/beacon-chain/core/altair/epoch_spec_test.go b/beacon-chain/core/altair/epoch_spec_test.go index 2045751ef0..dbf93168cb 100644 --- a/beacon-chain/core/altair/epoch_spec_test.go +++ b/beacon-chain/core/altair/epoch_spec_test.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/epoch" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -103,7 +103,7 @@ func TestProcessSlashings_NotSlashed(t *testing.T) { Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance}, Slashings: []uint64{0, 1e9}, } - s, err := stateAltair.InitializeFromProto(base) + s, err := state_native.InitializeFromProtoAltair(base) require.NoError(t, err) newState, err := epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplierAltair) require.NoError(t, err) @@ -174,7 +174,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) { t.Run(fmt.Sprint(i), func(t *testing.T) { helpers.ClearCache() original := proto.Clone(tt.state) - s, err := stateAltair.InitializeFromProto(tt.state) + s, err := state_native.InitializeFromProtoAltair(tt.state) require.NoError(t, err) newState, err := epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplierAltair) require.NoError(t, err) @@ -190,7 +190,7 @@ func TestProcessSlashings_BadValue(t *testing.T) { Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance}, Slashings: []uint64{math.MaxUint64, 1e9}, } - s, err := stateAltair.InitializeFromProto(base) + s, err := state_native.InitializeFromProtoAltair(base) require.NoError(t, err) _, err = epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplierAltair) require.ErrorContains(t, "addition overflows", err) diff --git a/beacon-chain/core/altair/sync_committee_test.go b/beacon-chain/core/altair/sync_committee_test.go index 55ad2682cb..47371ea1ca 100644 --- a/beacon-chain/core/altair/sync_committee_test.go +++ b/beacon-chain/core/altair/sync_committee_test.go @@ -8,8 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -28,7 +27,7 @@ func TestSyncCommitteeIndices_CanGet(t *testing.T) { EffectiveBalance: params.BeaconConfig().MinDepositAmount, } } - st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + st, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -46,14 +45,6 @@ func TestSyncCommitteeIndices_CanGet(t *testing.T) { wantErr bool errString string }{ - { - name: "nil inner state", - args: args{ - state: &v2.BeaconState{}, - }, - wantErr: true, - errString: "nil inner state", - }, { name: "genesis validator count, epoch 0", args: args{ @@ -103,7 +94,7 @@ func TestSyncCommitteeIndices_DifferentPeriods(t *testing.T) { EffectiveBalance: params.BeaconConfig().MinDepositAmount, } } - st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + st, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -140,7 +131,7 @@ func TestSyncCommittee_CanGet(t *testing.T) { PublicKey: blsKey.PublicKey().Marshal(), } } - st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + st, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -158,14 +149,6 @@ func TestSyncCommittee_CanGet(t *testing.T) { wantErr bool errString string }{ - { - name: "nil inner state", - args: args{ - state: &v2.BeaconState{}, - }, - wantErr: true, - errString: "nil inner state", - }, { name: "genesis validator count, epoch 0", args: args{ @@ -395,7 +378,7 @@ func getState(t *testing.T, count uint64) state.BeaconState { PublicKey: blsKey.PublicKey().Marshal(), } } - st, err := stateAltair.InitializeFromProto(ðpb.BeaconStateAltair{ + st, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) diff --git a/beacon-chain/core/altair/upgrade.go b/beacon-chain/core/altair/upgrade.go index ab89a4dd81..399cdfc113 100644 --- a/beacon-chain/core/altair/upgrade.go +++ b/beacon-chain/core/altair/upgrade.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - statealtair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/attestation" @@ -95,7 +95,7 @@ func UpgradeToAltair(ctx context.Context, state state.BeaconState) (state.Beacon InactivityScores: make([]uint64, numValidators), } - newState, err := statealtair.InitializeFromProtoUnsafe(s) + newState, err := state_native.InitializeFromProtoUnsafeAltair(s) if err != nil { return nil, err } diff --git a/beacon-chain/core/blocks/BUILD.bazel b/beacon-chain/core/blocks/BUILD.bazel index b0735c4750..52d38c8c1e 100644 --- a/beacon-chain/core/blocks/BUILD.bazel +++ b/beacon-chain/core/blocks/BUILD.bazel @@ -89,7 +89,7 @@ go_test( "//beacon-chain/core/validators:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/core/blocks/attestation_regression_test.go b/beacon-chain/core/blocks/attestation_regression_test.go index b986fe9fc1..1353f772e1 100644 --- a/beacon-chain/core/blocks/attestation_regression_test.go +++ b/beacon-chain/core/blocks/attestation_regression_test.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/assert" @@ -36,7 +36,7 @@ func TestProcessAttestationNoVerifySignature_BeaconFuzzIssue78(t *testing.T) { if err := spb.UnmarshalSSZ(stateData); err != nil { t.Fatal(err) } - st, err := v1.InitializeFromProtoUnsafe(spb) + st, err := state_native.InitializeFromProtoUnsafePhase0(spb) if err != nil { t.Fatal(err) } diff --git a/beacon-chain/core/blocks/attestation_test.go b/beacon-chain/core/blocks/attestation_test.go index 21085d480d..6ba4934f58 100644 --- a/beacon-chain/core/blocks/attestation_test.go +++ b/beacon-chain/core/blocks/attestation_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -192,7 +192,7 @@ func TestConvertToIndexed_OK(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 5, Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -250,7 +250,7 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 5, Validators: validators, Fork: ðpb.Fork{ @@ -337,7 +337,7 @@ func TestValidateIndexedAttestation_AboveMaxLength(t *testing.T) { } want := "validator indices count exceeds MAX_VALIDATORS_PER_COMMITTEE" - st, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + st, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) err = blocks.VerifyIndexedAttestation(context.Background(), st, indexedAtt1) assert.ErrorContains(t, want, err) diff --git a/beacon-chain/core/blocks/attester_slashing_test.go b/beacon-chain/core/blocks/attester_slashing_test.go index 35c5ca65ce..cc39977f36 100644 --- a/beacon-chain/core/blocks/attester_slashing_test.go +++ b/beacon-chain/core/blocks/attester_slashing_test.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" v "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/validators" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -46,7 +46,7 @@ func TestProcessAttesterSlashings_DataNotSlashable(t *testing.T) { var registry []*ethpb.Validator currentSlot := types.Slot(0) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Slot: currentSlot, }) @@ -65,7 +65,7 @@ func TestProcessAttesterSlashings_IndexedAttestationFailedToVerify(t *testing.T) var registry []*ethpb.Validator currentSlot := types.Slot(0) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Slot: currentSlot, }) diff --git a/beacon-chain/core/blocks/block_operations_fuzz_test.go b/beacon-chain/core/blocks/block_operations_fuzz_test.go index cb2ecd1e96..0385a81ede 100644 --- a/beacon-chain/core/blocks/block_operations_fuzz_test.go +++ b/beacon-chain/core/blocks/block_operations_fuzz_test.go @@ -6,7 +6,7 @@ import ( fuzz "github.com/google/gofuzz" v "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/validators" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -24,7 +24,7 @@ func TestFuzzProcessAttestationNoVerify_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(att) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) _, err = ProcessAttestationNoVerifySignature(ctx, s, att) _ = err @@ -40,7 +40,7 @@ func TestFuzzProcessBlockHeader_10000(t *testing.T) { fuzzer.Fuzz(state) fuzzer.Fuzz(block) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) if block.Block == nil || block.Block.Body == nil || block.Block.Body.Eth1Data == nil { continue @@ -79,7 +79,7 @@ func TestFuzzverifyDepositDataSigningRoot_10000(_ *testing.T) { func TestFuzzProcessEth1DataInBlock_10000(t *testing.T) { fuzzer := fuzz.NewWithSeed(0) e := ðpb.Eth1Data{} - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) @@ -111,7 +111,7 @@ func TestFuzzEth1DataHasEnoughSupport_10000(t *testing.T) { for i := 0; i < 100000; i++ { fuzzer.Fuzz(eth1data) fuzzer.Fuzz(&stateVotes) - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1DataVotes: stateVotes, }) require.NoError(t, err) @@ -129,7 +129,7 @@ func TestFuzzProcessBlockHeaderNoVerify_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(block) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) _, err = ProcessBlockHeaderNoVerify(context.Background(), s, block.Slot, block.ProposerIndex, block.ParentRoot, []byte{}) _ = err @@ -144,7 +144,7 @@ func TestFuzzProcessRandao_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(b) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) if b.Block == nil || b.Block.Body == nil { continue @@ -166,7 +166,7 @@ func TestFuzzProcessRandaoNoVerify_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(blockBody) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessRandaoNoVerify(s, blockBody.RandaoReveal) if err != nil && r != nil { @@ -183,7 +183,7 @@ func TestFuzzProcessProposerSlashings_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(p) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessProposerSlashings(ctx, s, []*ethpb.ProposerSlashing{p}, v.SlashValidator) if err != nil && r != nil { @@ -199,7 +199,7 @@ func TestFuzzVerifyProposerSlashing_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(proposerSlashing) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) err = VerifyProposerSlashing(s, proposerSlashing) _ = err @@ -214,7 +214,7 @@ func TestFuzzProcessAttesterSlashings_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(a) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessAttesterSlashings(ctx, s, []*ethpb.AttesterSlashing{a}, v.SlashValidator) if err != nil && r != nil { @@ -231,7 +231,7 @@ func TestFuzzVerifyAttesterSlashing_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(attesterSlashing) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) err = VerifyAttesterSlashing(ctx, s, attesterSlashing) _ = err @@ -268,7 +268,7 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(b) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) if b.Block == nil || b.Block.Body == nil { continue @@ -290,7 +290,7 @@ func TestFuzzVerifyIndexedAttestationn_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(idxAttestation) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) err = VerifyIndexedAttestation(ctx, s, idxAttestation) _ = err @@ -305,7 +305,7 @@ func TestFuzzVerifyAttestation_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(attestation) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) err = VerifyAttestationSignature(ctx, s, attestation) _ = err @@ -322,7 +322,7 @@ func TestFuzzProcessDeposits_10000(t *testing.T) { for i := range deposits { fuzzer.Fuzz(deposits[i]) } - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessDeposits(ctx, s, deposits) if err != nil && r != nil { @@ -340,7 +340,7 @@ func TestFuzzProcessPreGenesisDeposit_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessPreGenesisDeposits(ctx, s, []*ethpb.Deposit{deposit}) if err != nil && r != nil { @@ -357,7 +357,7 @@ func TestFuzzProcessDeposit_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, _, err := ProcessDeposit(s, deposit, true) if err != nil && r != nil { @@ -373,7 +373,7 @@ func TestFuzzverifyDeposit_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(deposit) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) err = verifyDeposit(s, deposit) _ = err @@ -388,7 +388,7 @@ func TestFuzzProcessVoluntaryExits_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(e) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessVoluntaryExits(ctx, s, []*ethpb.SignedVoluntaryExit{e}) if err != nil && r != nil { @@ -404,7 +404,7 @@ func TestFuzzProcessVoluntaryExitsNoVerify_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(state) fuzzer.Fuzz(e) - s, err := v1.InitializeFromProtoUnsafe(state) + s, err := state_native.InitializeFromProtoUnsafePhase0(state) require.NoError(t, err) r, err := ProcessVoluntaryExits(context.Background(), s, []*ethpb.SignedVoluntaryExit{e}) if err != nil && r != nil { @@ -425,7 +425,7 @@ func TestFuzzVerifyExit_10000(_ *testing.T) { fuzzer.Fuzz(rawVal) fuzzer.Fuzz(fork) fuzzer.Fuzz(&slot) - val, err := v1.NewValidator(ðpb.Validator{}) + val, err := state_native.NewValidator(ðpb.Validator{}) _ = err err = VerifyExitAndSignature(val, slot, fork, ve, params.BeaconConfig().ZeroHash[:]) _ = err diff --git a/beacon-chain/core/blocks/deposit_test.go b/beacon-chain/core/blocks/deposit_test.go index 4f7455a3a4..2c5bdc8dff 100644 --- a/beacon-chain/core/blocks/deposit_test.go +++ b/beacon-chain/core/blocks/deposit_test.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -40,7 +40,7 @@ func TestProcessDeposits_SameValidatorMultipleDepositsSameBlock(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -80,7 +80,7 @@ func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) { Deposits: []*ethpb.Deposit{deposit}, }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ DepositRoot: []byte{0}, BlockHash: []byte{1}, @@ -111,7 +111,7 @@ func TestProcessDeposits_AddsNewValidatorDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -175,7 +175,7 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T) balances := []uint64{0, 50} root, err := depositTrie.HashTreeRoot() require.NoError(t, err) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: ðpb.Eth1Data{ @@ -203,7 +203,7 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -247,7 +247,7 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -305,7 +305,7 @@ func TestPreGenesisDeposits_SkipInvalidDeposit(t *testing.T) { }, } balances := []uint64{0} - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: eth1Data, @@ -383,7 +383,7 @@ func TestProcessDeposit_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T) root, err := depositTrie.HashTreeRoot() require.NoError(t, err) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Balances: balances, Eth1Data: ðpb.Eth1Data{ diff --git a/beacon-chain/core/blocks/eth1_data_test.go b/beacon-chain/core/blocks/eth1_data_test.go index a31b1910a0..3d5fdf5b9f 100644 --- a/beacon-chain/core/blocks/eth1_data_test.go +++ b/beacon-chain/core/blocks/eth1_data_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -70,7 +70,7 @@ func TestEth1DataHasEnoughSupport(t *testing.T) { c.EpochsPerEth1VotingPeriod = tt.votingPeriodLength params.OverrideBeaconConfig(c) - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1DataVotes: tt.stateVotes, }) require.NoError(t, err) @@ -160,7 +160,7 @@ func TestAreEth1DataEqual(t *testing.T) { } func TestProcessEth1Data_SetsCorrectly(t *testing.T) { - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1DataVotes: []*ethpb.Eth1Data{}, }) require.NoError(t, err) diff --git a/beacon-chain/core/blocks/exit_test.go b/beacon-chain/core/blocks/exit_test.go index 1a3ce95d5f..1fdb631133 100644 --- a/beacon-chain/core/blocks/exit_test.go +++ b/beacon-chain/core/blocks/exit_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -32,7 +32,7 @@ func TestProcessVoluntaryExits_NotActiveLongEnoughToExit(t *testing.T) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, }, } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Slot: 10, }) @@ -62,7 +62,7 @@ func TestProcessVoluntaryExits_ExitAlreadySubmitted(t *testing.T) { ExitEpoch: 10, }, } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Slot: 0, }) @@ -94,7 +94,7 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) { ActivationEpoch: 0, }, } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Fork: ðpb.Fork{ CurrentVersion: params.BeaconConfig().GenesisForkVersion, diff --git a/beacon-chain/core/blocks/proposer_slashing_regression_test.go b/beacon-chain/core/blocks/proposer_slashing_regression_test.go index 9ccb165d09..facf87d54d 100644 --- a/beacon-chain/core/blocks/proposer_slashing_regression_test.go +++ b/beacon-chain/core/blocks/proposer_slashing_regression_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/require" ) @@ -22,7 +22,7 @@ func TestVerifyProposerSlashing_BeaconFuzzIssue91(t *testing.T) { err = rawState.UnmarshalSSZ(file) require.NoError(t, err) - st, err := v1.InitializeFromProtoUnsafe(rawState) + st, err := state_native.InitializeFromProtoUnsafePhase0(rawState) require.NoError(t, err) file, err = os.ReadFile("testdata/beaconfuzz_91_proposer_slashing.ssz") diff --git a/beacon-chain/core/blocks/proposer_slashing_test.go b/beacon-chain/core/blocks/proposer_slashing_test.go index 7c9fd46057..3162481b18 100644 --- a/beacon-chain/core/blocks/proposer_slashing_test.go +++ b/beacon-chain/core/blocks/proposer_slashing_test.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" v "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -119,7 +119,7 @@ func TestProcessProposerSlashings_ValidatorNotSlashable(t *testing.T) { }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Slot: currentSlot, }) diff --git a/beacon-chain/core/blocks/withdrawals_test.go b/beacon-chain/core/blocks/withdrawals_test.go index 7957a5b9a6..30a83c1283 100644 --- a/beacon-chain/core/blocks/withdrawals_test.go +++ b/beacon-chain/core/blocks/withdrawals_test.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/crypto/bls" "github.com/prysmaticlabs/prysm/v3/crypto/hash/htr" @@ -37,7 +37,7 @@ func TestProcessBLSToExecutionChange(t *testing.T) { WithdrawalCredentials: digest[0][:], }, } - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Fork: ðpb.Fork{ CurrentVersion: params.BeaconConfig().GenesisForkVersion, @@ -85,7 +85,7 @@ func TestProcessBLSToExecutionChange(t *testing.T) { WithdrawalCredentials: digest[0][:], }, } - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Fork: ðpb.Fork{ CurrentVersion: params.BeaconConfig().GenesisForkVersion, @@ -123,7 +123,7 @@ func TestProcessBLSToExecutionChange(t *testing.T) { WithdrawalCredentials: params.BeaconConfig().ZeroHash[:], }, } - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Fork: ðpb.Fork{ CurrentVersion: params.BeaconConfig().GenesisForkVersion, @@ -168,7 +168,7 @@ func TestProcessBLSToExecutionChange(t *testing.T) { } registry[0].WithdrawalCredentials[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Fork: ðpb.Fork{ CurrentVersion: params.BeaconConfig().GenesisForkVersion, diff --git a/beacon-chain/core/epoch/BUILD.bazel b/beacon-chain/core/epoch/BUILD.bazel index da950d9da3..09da2c5159 100644 --- a/beacon-chain/core/epoch/BUILD.bazel +++ b/beacon-chain/core/epoch/BUILD.bazel @@ -34,7 +34,7 @@ go_test( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", diff --git a/beacon-chain/core/epoch/epoch_processing_fuzz_test.go b/beacon-chain/core/epoch/epoch_processing_fuzz_test.go index 1c60fe920a..8d16c954d4 100644 --- a/beacon-chain/core/epoch/epoch_processing_fuzz_test.go +++ b/beacon-chain/core/epoch/epoch_processing_fuzz_test.go @@ -4,7 +4,7 @@ import ( "testing" fuzz "github.com/google/gofuzz" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/require" ) @@ -15,7 +15,7 @@ func TestFuzzFinalUpdates_10000(t *testing.T) { for i := 0; i < 10000; i++ { fuzzer.Fuzz(base) - s, err := v1.InitializeFromProtoUnsafe(base) + s, err := state_native.InitializeFromProtoUnsafePhase0(base) require.NoError(t, err) _, err = ProcessFinalUpdates(s) _ = err diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 3ae0cad743..22af012c22 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -46,7 +46,7 @@ func TestUnslashedAttestingIndices_CanSortAndFilter(t *testing.T) { Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) indices, err := epoch.UnslashedAttestingIndices(context.Background(), beaconState, atts) @@ -92,7 +92,7 @@ func TestUnslashedAttestingIndices_DuplicatedAttestations(t *testing.T) { Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) indices, err := epoch.UnslashedAttestingIndices(context.Background(), beaconState, atts) @@ -138,7 +138,7 @@ func TestAttestingBalance_CorrectBalance(t *testing.T) { Validators: validators, Balances: balances, } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) balance, err := epoch.AttestingBalance(context.Background(), beaconState, atts) @@ -154,7 +154,7 @@ func TestProcessSlashings_NotSlashed(t *testing.T) { Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance}, Slashings: []uint64{0, 1e9}, } - s, err := v1.InitializeFromProto(base) + s, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplier) require.NoError(t, err) @@ -232,7 +232,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) { for i, tt := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { original := proto.Clone(tt.state) - s, err := v1.InitializeFromProto(tt.state) + s, err := state_native.InitializeFromProtoPhase0(tt.state) require.NoError(t, err) helpers.ClearCache() newState, err := epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplier) @@ -293,7 +293,7 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) { }, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := epoch.ProcessRegistryUpdates(context.Background(), beaconState) require.NoError(t, err) @@ -316,7 +316,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) { ActivationEpoch: params.BeaconConfig().FarFutureEpoch, }) } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) currentEpoch := time.CurrentEpoch(beaconState) newState, err := epoch.ProcessRegistryUpdates(context.Background(), beaconState) @@ -345,7 +345,7 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) { }, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := epoch.ProcessRegistryUpdates(context.Background(), beaconState) require.NoError(t, err) @@ -369,7 +369,7 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) { }, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := epoch.ProcessRegistryUpdates(context.Background(), beaconState) require.NoError(t, err) @@ -394,7 +394,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) { }, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := epoch.ProcessRegistryUpdates(context.Background(), beaconState) require.NoError(t, err) @@ -450,7 +450,7 @@ func TestProcessSlashings_BadValue(t *testing.T) { Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance}, Slashings: []uint64{math.MaxUint64, 1e9}, } - s, err := v1.InitializeFromProto(base) + s, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) _, err = epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplier) require.ErrorContains(t, "addition overflows", err) diff --git a/beacon-chain/core/epoch/precompute/BUILD.bazel b/beacon-chain/core/epoch/precompute/BUILD.bazel index f2eef9aedf..68fba9b7ad 100644 --- a/beacon-chain/core/epoch/precompute/BUILD.bazel +++ b/beacon-chain/core/epoch/precompute/BUILD.bazel @@ -50,8 +50,7 @@ go_test( "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", diff --git a/beacon-chain/core/epoch/precompute/justification_finalization_test.go b/beacon-chain/core/epoch/precompute/justification_finalization_test.go index 9b7ee5095b..a4a6aabde5 100644 --- a/beacon-chain/core/epoch/precompute/justification_finalization_test.go +++ b/beacon-chain/core/epoch/precompute/justification_finalization_test.go @@ -7,8 +7,7 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/epoch/precompute" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -40,7 +39,7 @@ func TestProcessJustificationAndFinalizationPreCompute_ConsecutiveEpochs(t *test Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 BlockRoots: blockRoots, } - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) attestedBalance := 4 * uint64(e) * 3 / 2 b := &precompute.Balance{PrevEpochTargetAttested: attestedBalance} @@ -77,7 +76,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyCurrentEpoch(t *te Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 BlockRoots: blockRoots, } - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) attestedBalance := 4 * uint64(e) * 3 / 2 b := &precompute.Balance{PrevEpochTargetAttested: attestedBalance} @@ -113,7 +112,7 @@ func TestProcessJustificationAndFinalizationPreCompute_JustifyPrevEpoch(t *testi Balances: []uint64{a, a, a, a}, // validator total balance should be 128000000000 BlockRoots: blockRoots, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) attestedBalance := 4 * uint64(e) * 3 / 2 b := &precompute.Balance{PrevEpochTargetAttested: attestedBalance} @@ -237,7 +236,7 @@ func TestUnrealizedCheckpoints(t *testing.T) { base.JustificationBits.SetBitAt(2, true) } - state, err := v2.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoAltair(base) require.NoError(t, err) _, _, err = altair.InitializePrecomputeValidators(context.Background(), state) @@ -254,7 +253,7 @@ func TestUnrealizedCheckpoints(t *testing.T) { } func Test_ComputeCheckpoints_CantUpdateToLower(t *testing.T) { - st, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + st, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Slot: params.BeaconConfig().SlotsPerEpoch * 2, CurrentJustifiedCheckpoint: ðpb.Checkpoint{ Epoch: 2, diff --git a/beacon-chain/core/epoch/precompute/new_test.go b/beacon-chain/core/epoch/precompute/new_test.go index ba18addea7..795e381040 100644 --- a/beacon-chain/core/epoch/precompute/new_test.go +++ b/beacon-chain/core/epoch/precompute/new_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/epoch/precompute" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/assert" @@ -14,7 +14,7 @@ import ( func TestNew(t *testing.T) { ffe := params.BeaconConfig().FarFutureEpoch - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: params.BeaconConfig().SlotsPerEpoch, // Validator 0 is slashed // Validator 1 is withdrawable diff --git a/beacon-chain/core/epoch/precompute/reward_penalty_test.go b/beacon-chain/core/epoch/precompute/reward_penalty_test.go index 04738a00b4..6f7fe6e4b3 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty_test.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty_test.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -38,7 +38,7 @@ func TestProcessRewardsAndPenaltiesPrecompute(t *testing.T) { } base.PreviousEpochAttestations = atts - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) vp, bp, err := New(context.Background(), beaconState) @@ -81,7 +81,7 @@ func TestAttestationDeltaPrecompute(t *testing.T) { } } base.PreviousEpochAttestations = atts - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) slashedAttestedIndices := []types.ValidatorIndex{1413} for _, i := range slashedAttestedIndices { @@ -165,7 +165,7 @@ func TestAttestationDeltas_ZeroEpoch(t *testing.T) { } } base.PreviousEpochAttestations = atts - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) pVals, pBal, err := New(context.Background(), beaconState) @@ -203,7 +203,7 @@ func TestAttestationDeltas_ZeroInclusionDelay(t *testing.T) { } } base.PreviousEpochAttestations = atts - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) pVals, pBal, err := New(context.Background(), beaconState) @@ -229,7 +229,7 @@ func TestProcessRewardsAndPenaltiesPrecompute_SlashedInactivePenalty(t *testing. } base.PreviousEpochAttestations = atts - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch*10)) @@ -303,7 +303,7 @@ func TestProposerDeltaPrecompute_HappyCase(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch validatorCount := uint64(10) base := buildState(e, validatorCount) - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) proposerIndex := types.ValidatorIndex(1) @@ -325,7 +325,7 @@ func TestProposerDeltaPrecompute_ValidatorIndexOutOfRange(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch validatorCount := uint64(10) base := buildState(e, validatorCount) - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) proposerIndex := types.ValidatorIndex(validatorCount) @@ -341,7 +341,7 @@ func TestProposerDeltaPrecompute_SlashedCase(t *testing.T) { e := params.BeaconConfig().SlotsPerEpoch validatorCount := uint64(10) base := buildState(e, validatorCount) - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) proposerIndex := types.ValidatorIndex(1) diff --git a/beacon-chain/core/epoch/precompute/slashing_test.go b/beacon-chain/core/epoch/precompute/slashing_test.go index d4b912e509..9c098fbe86 100644 --- a/beacon-chain/core/epoch/precompute/slashing_test.go +++ b/beacon-chain/core/epoch/precompute/slashing_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/epoch/precompute" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/assert" @@ -14,7 +14,7 @@ import ( ) func TestProcessSlashingsPrecompute_NotSlashedWithSlashedTrue(t *testing.T) { - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, Validators: []*ethpb.Validator{{Slashed: true}}, Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance}, @@ -29,7 +29,7 @@ func TestProcessSlashingsPrecompute_NotSlashedWithSlashedTrue(t *testing.T) { } func TestProcessSlashingsPrecompute_NotSlashedWithSlashedFalse(t *testing.T) { - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, Validators: []*ethpb.Validator{{}}, Balances: []uint64{params.BeaconConfig().MaxEffectiveBalance}, @@ -123,7 +123,7 @@ func TestProcessSlashingsPrecompute_SlashedLess(t *testing.T) { pBal := &precompute.Balance{ActiveCurrentEpoch: ab} original := proto.Clone(tt.state) - state, err := v1.InitializeFromProto(tt.state) + state, err := state_native.InitializeFromProtoPhase0(tt.state) require.NoError(t, err) require.NoError(t, precompute.ProcessSlashingsPrecompute(state, pBal)) assert.Equal(t, tt.want, state.Balances()[0], "ProcessSlashings({%v}) = newState; newState.Balances[0] = %d; wanted %d", original, state.Balances()[0]) diff --git a/beacon-chain/core/execution/BUILD.bazel b/beacon-chain/core/execution/BUILD.bazel index 9b79288572..f67f3e1124 100644 --- a/beacon-chain/core/execution/BUILD.bazel +++ b/beacon-chain/core/execution/BUILD.bazel @@ -12,7 +12,7 @@ go_library( deps = [ "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v3:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//proto/engine/v1:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/core/execution/upgrade.go b/beacon-chain/core/execution/upgrade.go index f0e71b8b48..d12679d769 100644 --- a/beacon-chain/core/execution/upgrade.go +++ b/beacon-chain/core/execution/upgrade.go @@ -3,7 +3,7 @@ package execution import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -81,5 +81,5 @@ func UpgradeToBellatrix(state state.BeaconState) (state.BeaconState, error) { }, } - return v3.InitializeFromProtoUnsafe(s) + return state_native.InitializeFromProtoUnsafeBellatrix(s) } diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index 6824c0cd5e..b753ea2af5 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -61,8 +61,7 @@ go_test( "//beacon-chain/cache:go_default_library", "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", diff --git a/beacon-chain/core/helpers/attestation_test.go b/beacon-chain/core/helpers/attestation_test.go index 99fa088d50..200507736c 100644 --- a/beacon-chain/core/helpers/attestation_test.go +++ b/beacon-chain/core/helpers/attestation_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -99,7 +99,7 @@ func TestAttestation_ComputeSubnetForAttestation(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 200, BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot), diff --git a/beacon-chain/core/helpers/beacon_committee_test.go b/beacon-chain/core/helpers/beacon_committee_test.go index 1f6c4decb4..ca48b30810 100644 --- a/beacon-chain/core/helpers/beacon_committee_test.go +++ b/beacon-chain/core/helpers/beacon_committee_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/container/slice" @@ -36,7 +36,7 @@ func TestComputeCommittee_WithoutCache(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 200, BlockRoots: make([][]byte, params.BeaconConfig().SlotsPerHistoricalRoot), @@ -92,7 +92,7 @@ func TestVerifyBitfieldLength_OK(t *testing.T) { func TestCommitteeAssignments_CannotRetrieveFutureEpoch(t *testing.T) { ClearCache() epoch := types.Epoch(1) - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, // Epoch 0. }) require.NoError(t, err) @@ -112,7 +112,7 @@ func TestCommitteeAssignments_NoProposerForSlot0(t *testing.T) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 2 * params.BeaconConfig().SlotsPerEpoch, // epoch 2 RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -143,7 +143,7 @@ func TestCommitteeAssignments_CanRetrieve(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 2 * params.BeaconConfig().SlotsPerEpoch, // epoch 2 RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -220,7 +220,7 @@ func TestCommitteeAssignments_CannotRetrieveFuture(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 2 * params.BeaconConfig().SlotsPerEpoch, // epoch 2 RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -244,7 +244,7 @@ func TestCommitteeAssignments_EverySlotHasMin1Proposer(t *testing.T) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 2 * params.BeaconConfig().SlotsPerEpoch, // epoch 2 RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -281,7 +281,7 @@ func TestVerifyAttestationBitfieldLengths_OK(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: activeRoots, }) @@ -381,7 +381,7 @@ func TestUpdateCommitteeCache_CanUpdate(t *testing.T) { } indices[i] = i } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -405,7 +405,7 @@ func BenchmarkComputeCommittee300000_WithPreCache(b *testing.B) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -439,7 +439,7 @@ func BenchmarkComputeCommittee3000000_WithPreCache(b *testing.B) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -473,7 +473,7 @@ func BenchmarkComputeCommittee128000_WithOutPreCache(b *testing.B) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -508,7 +508,7 @@ func BenchmarkComputeCommittee1000000_WithOutCache(b *testing.B) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -543,7 +543,7 @@ func BenchmarkComputeCommittee4000000_WithOutCache(b *testing.B) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -580,7 +580,7 @@ func TestBeaconCommitteeFromState_UpdateCacheForPreviousEpoch(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: params.BeaconConfig().SlotsPerEpoch, Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -605,7 +605,7 @@ func TestPrecomputeProposerIndices_Ok(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) diff --git a/beacon-chain/core/helpers/block_test.go b/beacon-chain/core/helpers/block_test.go index 4eacf013cf..a0553704a7 100644 --- a/beacon-chain/core/helpers/block_test.go +++ b/beacon-chain/core/helpers/block_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -61,7 +61,7 @@ func TestBlockRootAtSlot_CorrectBlockRoot(t *testing.T) { for i, tt := range tests { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { s.Slot = tt.stateSlot - state, err := v1.InitializeFromProto(s) + state, err := state_native.InitializeFromProtoPhase0(s) require.NoError(t, err) wantedSlot := tt.slot result, err := helpers.BlockRootAtSlot(state, wantedSlot) @@ -111,7 +111,7 @@ func TestBlockRootAtSlot_OutOfBounds(t *testing.T) { } for _, tt := range tests { state.Slot = tt.stateSlot - s, err := v1.InitializeFromProto(state) + s, err := state_native.InitializeFromProtoPhase0(state) require.NoError(t, err) _, err = helpers.BlockRootAtSlot(s, tt.slot) assert.ErrorContains(t, tt.expectedErr, err) diff --git a/beacon-chain/core/helpers/randao_test.go b/beacon-chain/core/helpers/randao_test.go index c3713a7d65..3c7cef6366 100644 --- a/beacon-chain/core/helpers/randao_test.go +++ b/beacon-chain/core/helpers/randao_test.go @@ -4,7 +4,7 @@ import ( "encoding/binary" "testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -20,7 +20,7 @@ func TestRandaoMix_OK(t *testing.T) { binary.LittleEndian.PutUint64(intInBytes, uint64(i)) randaoMixes[i] = intInBytes } - state, err := v1.InitializeFromProto(ðpb.BeaconState{RandaoMixes: randaoMixes}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{RandaoMixes: randaoMixes}) require.NoError(t, err) tests := []struct { epoch types.Epoch @@ -54,7 +54,7 @@ func TestRandaoMix_CopyOK(t *testing.T) { binary.LittleEndian.PutUint64(intInBytes, uint64(i)) randaoMixes[i] = intInBytes } - state, err := v1.InitializeFromProto(ðpb.BeaconState{RandaoMixes: randaoMixes}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{RandaoMixes: randaoMixes}) require.NoError(t, err) tests := []struct { epoch types.Epoch @@ -95,7 +95,7 @@ func TestGenerateSeed_OK(t *testing.T) { randaoMixes[i] = intInBytes } slot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().MinSeedLookahead * 10)) - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ RandaoMixes: randaoMixes, Slot: slot, }) diff --git a/beacon-chain/core/helpers/rewards_penalties_test.go b/beacon-chain/core/helpers/rewards_penalties_test.go index b3e2dd7efb..692517d6df 100644 --- a/beacon-chain/core/helpers/rewards_penalties_test.go +++ b/beacon-chain/core/helpers/rewards_penalties_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -14,7 +14,7 @@ import ( ) func TestTotalBalance_OK(t *testing.T) { - state, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: []*ethpb.Validator{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: []*ethpb.Validator{ {EffectiveBalance: 27 * 1e9}, {EffectiveBalance: 28 * 1e9}, {EffectiveBalance: 32 * 1e9}, {EffectiveBalance: 40 * 1e9}, }}) @@ -27,7 +27,7 @@ func TestTotalBalance_OK(t *testing.T) { } func TestTotalBalance_ReturnsEffectiveBalanceIncrement(t *testing.T) { - state, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: []*ethpb.Validator{}}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: []*ethpb.Validator{}}) require.NoError(t, err) balance := TotalBalance(state, []types.ValidatorIndex{}) @@ -47,7 +47,7 @@ func TestGetBalance_OK(t *testing.T) { {i: 2, b: []uint64{0, 0, 0}}, } for _, test := range tests { - state, err := v1.InitializeFromProto(ðpb.BeaconState{Balances: test.b}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Balances: test.b}) require.NoError(t, err) assert.Equal(t, test.b[test.i], state.Balances()[test.i], "Incorrect Validator balance") } @@ -66,7 +66,7 @@ func TestTotalActiveBalance(t *testing.T) { for i := 0; i < test.vCount; i++ { validators = append(validators, ðpb.Validator{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: 1}) } - state, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: validators}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: validators}) require.NoError(t, err) bal, err := TotalActiveBalance(state) require.NoError(t, err) @@ -87,7 +87,7 @@ func TestTotalActiveBal_ReturnMin(t *testing.T) { for i := 0; i < test.vCount; i++ { validators = append(validators, ðpb.Validator{EffectiveBalance: 1, ExitEpoch: 1}) } - state, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: validators}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: validators}) require.NoError(t, err) bal, err := TotalActiveBalance(state) require.NoError(t, err) @@ -109,7 +109,7 @@ func TestTotalActiveBalance_WithCache(t *testing.T) { for i := 0; i < test.vCount; i++ { validators = append(validators, ðpb.Validator{EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance, ExitEpoch: 1}) } - state, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: validators}) + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: validators}) require.NoError(t, err) bal, err := TotalActiveBalance(state) require.NoError(t, err) @@ -129,7 +129,7 @@ func TestIncreaseBalance_OK(t *testing.T) { {i: 2, b: []uint64{27 * 1e9, 28 * 1e9, 32 * 1e9}, nb: 33 * 1e9, eb: 65 * 1e9}, } for _, test := range tests { - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ {EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}}, Balances: test.b, @@ -153,7 +153,7 @@ func TestDecreaseBalance_OK(t *testing.T) { {i: 3, b: []uint64{27 * 1e9, 28 * 1e9, 1, 28 * 1e9}, nb: 28 * 1e9, eb: 0}, } for _, test := range tests { - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ {EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 3}}, Balances: test.b, @@ -167,7 +167,7 @@ func TestDecreaseBalance_OK(t *testing.T) { func TestFinalityDelay(t *testing.T) { base := buildState(params.BeaconConfig().SlotsPerEpoch*10, 1) base.FinalizedCheckpoint = ðpb.Checkpoint{Epoch: 3} - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) prevEpoch := types.Epoch(0) finalizedEpoch := types.Epoch(0) @@ -197,7 +197,7 @@ func TestFinalityDelay(t *testing.T) { func TestIsInInactivityLeak(t *testing.T) { base := buildState(params.BeaconConfig().SlotsPerEpoch*10, 1) base.FinalizedCheckpoint = ðpb.Checkpoint{Epoch: 3} - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) prevEpoch := types.Epoch(0) finalizedEpoch := types.Epoch(0) @@ -265,7 +265,7 @@ func TestIncreaseBadBalance_NotOK(t *testing.T) { {i: 2, b: []uint64{math.MaxUint64, math.MaxUint64, math.MaxUint64}, nb: 33 * 1e9}, } for _, test := range tests { - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ {EffectiveBalance: 4}, {EffectiveBalance: 4}, {EffectiveBalance: 4}}, Balances: test.b, diff --git a/beacon-chain/core/helpers/sync_committee_test.go b/beacon-chain/core/helpers/sync_committee_test.go index f7b47b6a53..63d5b0bca2 100644 --- a/beacon-chain/core/helpers/sync_committee_test.go +++ b/beacon-chain/core/helpers/sync_committee_test.go @@ -7,8 +7,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/cache" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -31,7 +30,7 @@ func TestIsCurrentEpochSyncCommittee_UsingCache(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -61,7 +60,7 @@ func TestIsCurrentEpochSyncCommittee_UsingCommittee(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -87,7 +86,7 @@ func TestIsCurrentEpochSyncCommittee_DoesNotExist(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -113,7 +112,7 @@ func TestIsNextEpochSyncCommittee_UsingCache(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -143,7 +142,7 @@ func TestIsNextEpochSyncCommittee_UsingCommittee(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -169,7 +168,7 @@ func TestIsNextEpochSyncCommittee_DoesNotExist(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -195,7 +194,7 @@ func TestCurrentEpochSyncSubcommitteeIndices_UsingCache(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -225,7 +224,7 @@ func TestCurrentEpochSyncSubcommitteeIndices_UsingCommittee(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -266,7 +265,7 @@ func TestCurrentEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -292,7 +291,7 @@ func TestNextEpochSyncSubcommitteeIndices_UsingCache(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -322,7 +321,7 @@ func TestNextEpochSyncSubcommitteeIndices_UsingCommittee(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -349,7 +348,7 @@ func TestNextEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) { syncCommittee.Pubkeys = append(syncCommittee.Pubkeys, bytesutil.PadTo(k, 48)) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, }) require.NoError(t, err) @@ -362,14 +361,14 @@ func TestNextEpochSyncSubcommitteeIndices_DoesNotExist(t *testing.T) { } func TestUpdateSyncCommitteeCache_BadSlot(t *testing.T) { - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 1, }) require.NoError(t, err) err = UpdateSyncCommitteeCache(state) require.ErrorContains(t, "not at the end of the epoch to update cache", err) - state, err = v1.InitializeFromProto(ðpb.BeaconState{ + state, err = state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: params.BeaconConfig().SlotsPerEpoch - 1, }) require.NoError(t, err) @@ -378,7 +377,7 @@ func TestUpdateSyncCommitteeCache_BadSlot(t *testing.T) { } func TestUpdateSyncCommitteeCache_BadRoot(t *testing.T) { - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: types.Slot(params.BeaconConfig().EpochsPerSyncCommitteePeriod)*params.BeaconConfig().SlotsPerEpoch - 1, LatestBlockHeader: ðpb.BeaconBlockHeader{StateRoot: params.BeaconConfig().ZeroHash[:]}, }) @@ -405,7 +404,7 @@ func TestIsCurrentEpochSyncCommittee_SameBlockRoot(t *testing.T) { for i := range blockRoots { blockRoots[i] = make([]byte, 32) } - state, err := v2.InitializeFromProto(ðpb.BeaconStateAltair{ + state, err := state_native.InitializeFromProtoAltair(ðpb.BeaconStateAltair{ Validators: validators, BlockRoots: blockRoots, }) diff --git a/beacon-chain/core/helpers/validators_test.go b/beacon-chain/core/helpers/validators_test.go index fa0f5cab5b..61a4ae20f1 100644 --- a/beacon-chain/core/helpers/validators_test.go +++ b/beacon-chain/core/helpers/validators_test.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/cache" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -47,7 +47,7 @@ func TestIsActiveValidatorUsingTrie_OK(t *testing.T) { {a: 64, b: true}, } val := ðpb.Validator{ActivationEpoch: 10, ExitEpoch: 100} - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: []*ethpb.Validator{val}}) + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: []*ethpb.Validator{val}}) require.NoError(t, err) for _, test := range tests { readOnlyVal, err := beaconState.ValidatorAtIndexReadOnly(0) @@ -137,7 +137,7 @@ func TestIsSlashableValidator_OK(t *testing.T) { assert.Equal(t, test.slashable, slashableValidator, "Expected active validator slashable to be %t", test.slashable) }) t.Run("with trie", func(t *testing.T) { - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{Validators: []*ethpb.Validator{test.validator}}) + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Validators: []*ethpb.Validator{test.validator}}) require.NoError(t, err) readOnlyVal, err := beaconState.ValidatorAtIndexReadOnly(0) require.NoError(t, err) @@ -161,7 +161,7 @@ func TestBeaconProposerIndex_OK(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 0, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -220,7 +220,7 @@ func TestBeaconProposerIndex_BadState(t *testing.T) { roots[i] = make([]byte, fieldparams.RootLength) } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: 0, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -244,7 +244,7 @@ func TestComputeProposerIndex_Compatibility(t *testing.T) { } } - state, err := v1.InitializeFromProto(ðpb.BeaconState{ + state, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) @@ -291,7 +291,7 @@ func TestActiveValidatorCount_Genesis(t *testing.T) { ExitEpoch: params.BeaconConfig().FarFutureEpoch, } } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -327,7 +327,7 @@ func TestChurnLimit_OK(t *testing.T) { } } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 1, Validators: validators, RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), @@ -490,7 +490,7 @@ func TestActiveValidatorIndices(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - s, err := v1.InitializeFromProto(tt.args.state) + s, err := state_native.InitializeFromProtoPhase0(tt.args.state) require.NoError(t, err) got, err := ActiveValidatorIndices(context.Background(), s, tt.args.epoch) if tt.wantedErr != "" { @@ -600,7 +600,7 @@ func TestComputeProposerIndex(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { bState := ðpb.BeaconState{Validators: tt.args.validators} - stTrie, err := v1.InitializeFromProtoUnsafe(bState) + stTrie, err := state_native.InitializeFromProtoUnsafePhase0(bState) require.NoError(t, err) got, err := ComputeProposerIndex(stTrie, tt.args.indices, tt.args.seed) if tt.wantedErr != "" { @@ -658,7 +658,7 @@ func TestIsIsEligibleForActivation(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - s, err := v1.InitializeFromProto(tt.state) + s, err := state_native.InitializeFromProtoPhase0(tt.state) require.NoError(t, err) assert.Equal(t, tt.want, IsEligibleForActivation(s, tt.validator), "IsEligibleForActivation()") }) diff --git a/beacon-chain/core/time/BUILD.bazel b/beacon-chain/core/time/BUILD.bazel index 8f03d5188c..411d8e4820 100644 --- a/beacon-chain/core/time/BUILD.bazel +++ b/beacon-chain/core/time/BUILD.bazel @@ -20,7 +20,7 @@ go_test( deps = [ ":go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/core/time/slot_epoch_test.go b/beacon-chain/core/time/slot_epoch_test.go index 40745d0298..a8bb6757af 100644 --- a/beacon-chain/core/time/slot_epoch_test.go +++ b/beacon-chain/core/time/slot_epoch_test.go @@ -5,7 +5,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -43,7 +43,7 @@ func TestCurrentEpoch_OK(t *testing.T) { {slot: 200, epoch: 6}, } for _, tt := range tests { - st, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot}) + st, err := state_native.InitializeFromProtoPhase0(ð.BeaconState{Slot: tt.slot}) require.NoError(t, err) assert.Equal(t, tt.epoch, time.CurrentEpoch(st), "ActiveCurrentEpoch(%d)", st.Slot()) } @@ -59,7 +59,7 @@ func TestPrevEpoch_OK(t *testing.T) { {slot: 2 * params.BeaconConfig().SlotsPerEpoch, epoch: 1}, } for _, tt := range tests { - st, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot}) + st, err := state_native.InitializeFromProtoPhase0(ð.BeaconState{Slot: tt.slot}) require.NoError(t, err) assert.Equal(t, tt.epoch, time.PrevEpoch(st), "ActivePrevEpoch(%d)", st.Slot()) } @@ -77,7 +77,7 @@ func TestNextEpoch_OK(t *testing.T) { {slot: 200, epoch: types.Epoch(200/params.BeaconConfig().SlotsPerEpoch + 1)}, } for _, tt := range tests { - st, err := v1.InitializeFromProto(ð.BeaconState{Slot: tt.slot}) + st, err := state_native.InitializeFromProtoPhase0(ð.BeaconState{Slot: tt.slot}) require.NoError(t, err) assert.Equal(t, tt.epoch, time.NextEpoch(st), "NextEpoch(%d)", st.Slot()) } @@ -179,7 +179,7 @@ func TestCanProcessEpoch_TrueOnEpochsLastSlot(t *testing.T) { for _, tt := range tests { b := ð.BeaconState{Slot: tt.slot} - s, err := v1.InitializeFromProto(b) + s, err := state_native.InitializeFromProtoPhase0(b) require.NoError(t, err) assert.Equal(t, tt.canProcessEpoch, time.CanProcessEpoch(s), "CanProcessEpoch(%d)", tt.slot) } diff --git a/beacon-chain/core/transition/BUILD.bazel b/beacon-chain/core/transition/BUILD.bazel index 1b174007bf..1ae2f19e1b 100644 --- a/beacon-chain/core/transition/BUILD.bazel +++ b/beacon-chain/core/transition/BUILD.bazel @@ -33,8 +33,8 @@ go_library( "//beacon-chain/core/transition/interop:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/v1:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/interfaces:go_default_library", @@ -82,7 +82,7 @@ go_test( "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/core/transition/benchmarks_test.go b/beacon-chain/core/transition/benchmarks_test.go index 6676b32b1e..7b66ce310e 100644 --- a/beacon-chain/core/transition/benchmarks_test.go +++ b/beacon-chain/core/transition/benchmarks_test.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -124,7 +124,7 @@ func BenchmarkHashTreeRootState_FullState(b *testing.B) { func BenchmarkMarshalState_FullState(b *testing.B) { beaconState, err := benchmark.PreGenstateFullEpochs() require.NoError(b, err) - natState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe()) + natState, err := state_native.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe()) require.NoError(b, err) b.Run("Proto_Marshal", func(b *testing.B) { b.ResetTimer() @@ -148,7 +148,7 @@ func BenchmarkMarshalState_FullState(b *testing.B) { func BenchmarkUnmarshalState_FullState(b *testing.B) { beaconState, err := benchmark.PreGenstateFullEpochs() require.NoError(b, err) - natState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe()) + natState, err := state_native.ProtobufBeaconStatePhase0(beaconState.InnerStateUnsafe()) require.NoError(b, err) protoObject, err := proto.Marshal(natState) require.NoError(b, err) diff --git a/beacon-chain/core/transition/skip_slot_cache_test.go b/beacon-chain/core/transition/skip_slot_cache_test.go index adafda4df1..92066792f4 100644 --- a/beacon-chain/core/transition/skip_slot_cache_test.go +++ b/beacon-chain/core/transition/skip_slot_cache_test.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v3/runtime/version" @@ -20,9 +20,9 @@ func TestSkipSlotCache_OK(t *testing.T) { transition.SkipSlotCache.Enable() defer transition.SkipSlotCache.Disable() bState, privs := util.DeterministicGenesisState(t, params.MinimalSpecConfig().MinGenesisActiveValidatorCount) - pbState, err := v1.ProtobufBeaconState(bState.CloneInnerState()) + pbState, err := state_native.ProtobufBeaconStatePhase0(bState.CloneInnerState()) require.NoError(t, err) - originalState, err := v1.InitializeFromProto(pbState) + originalState, err := state_native.InitializeFromProtoPhase0(pbState) require.NoError(t, err) blkCfg := util.DefaultBlockGenConfig() @@ -47,9 +47,9 @@ func TestSkipSlotCache_OK(t *testing.T) { func TestSkipSlotCache_ConcurrentMixup(t *testing.T) { bState, privs := util.DeterministicGenesisState(t, params.MinimalSpecConfig().MinGenesisActiveValidatorCount) - pbState, err := v1.ProtobufBeaconState(bState.CloneInnerState()) + pbState, err := state_native.ProtobufBeaconStatePhase0(bState.CloneInnerState()) require.NoError(t, err) - originalState, err := v1.InitializeFromProto(pbState) + originalState, err := state_native.InitializeFromProtoPhase0(pbState) require.NoError(t, err) blkCfg := util.DefaultBlockGenConfig() diff --git a/beacon-chain/core/transition/state.go b/beacon-chain/core/transition/state.go index f6d4d96f25..5a37a631fb 100644 --- a/beacon-chain/core/transition/state.go +++ b/beacon-chain/core/transition/state.go @@ -7,8 +7,8 @@ import ( b "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" ) @@ -176,7 +176,7 @@ func OptimizedGenesisBeaconState(genesisTime uint64, preState state.BeaconState, BodyRoot: bodyRoot[:], } - return v1.InitializeFromProto(st) + return state_native.InitializeFromProtoPhase0(st) } // EmptyGenesisState returns an empty beacon state object. @@ -203,7 +203,7 @@ func EmptyGenesisState() (state.BeaconState, error) { Eth1DataVotes: []*ethpb.Eth1Data{}, Eth1DepositIndex: 0, } - return v1.InitializeFromProto(st) + return state_native.InitializeFromProtoPhase0(st) } // IsValidGenesisState gets called whenever there's a deposit event, diff --git a/beacon-chain/core/transition/state_fuzz_test.go b/beacon-chain/core/transition/state_fuzz_test.go index 842f5ccf54..876d87f664 100644 --- a/beacon-chain/core/transition/state_fuzz_test.go +++ b/beacon-chain/core/transition/state_fuzz_test.go @@ -5,7 +5,7 @@ import ( "testing" fuzz "github.com/google/gofuzz" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/require" ) @@ -38,7 +38,7 @@ func TestOptimizedGenesisBeaconState_1000(t *testing.T) { fuzzer := fuzz.NewWithSeed(0) fuzzer.NilChance(0.1) var genesisTime uint64 - preState, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + preState, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) eth1Data := ðpb.Eth1Data{} for i := 0; i < 1000; i++ { diff --git a/beacon-chain/core/transition/state_test.go b/beacon-chain/core/transition/state_test.go index a171f4b820..8df3594f66 100644 --- a/beacon-chain/core/transition/state_test.go +++ b/beacon-chain/core/transition/state_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/crypto/hash" @@ -98,9 +98,9 @@ func TestGenesisState_HashEquality(t *testing.T) { state, err := transition.GenesisBeaconState(context.Background(), deposits, 0, ðpb.Eth1Data{BlockHash: make([]byte, 32)}) require.NoError(t, err) - pbState1, err := v1.ProtobufBeaconState(state1.CloneInnerState()) + pbState1, err := state_native.ProtobufBeaconStatePhase0(state1.CloneInnerState()) require.NoError(t, err) - pbstate, err := v1.ProtobufBeaconState(state.CloneInnerState()) + pbstate, err := state_native.ProtobufBeaconStatePhase0(state.CloneInnerState()) require.NoError(t, err) root1, err1 := hash.HashProto(pbState1) diff --git a/beacon-chain/core/transition/stateutils/BUILD.bazel b/beacon-chain/core/transition/stateutils/BUILD.bazel index be894c9b05..5bc9dcb3f5 100644 --- a/beacon-chain/core/transition/stateutils/BUILD.bazel +++ b/beacon-chain/core/transition/stateutils/BUILD.bazel @@ -22,7 +22,7 @@ go_test( srcs = ["validator_index_map_test.go"], deps = [ ":go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//consensus-types/primitives:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/core/transition/stateutils/validator_index_map_test.go b/beacon-chain/core/transition/stateutils/validator_index_map_test.go index fa1de8ea3c..5c88460dad 100644 --- a/beacon-chain/core/transition/stateutils/validator_index_map_test.go +++ b/beacon-chain/core/transition/stateutils/validator_index_map_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition/stateutils" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -24,7 +24,7 @@ func TestValidatorIndexMap_OK(t *testing.T) { }, }, } - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) tests := []struct { diff --git a/beacon-chain/core/transition/transition_fuzz_test.go b/beacon-chain/core/transition/transition_fuzz_test.go index 91ef016487..2ca61d2658 100644 --- a/beacon-chain/core/transition/transition_fuzz_test.go +++ b/beacon-chain/core/transition/transition_fuzz_test.go @@ -6,7 +6,7 @@ import ( fuzz "github.com/google/gofuzz" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -17,7 +17,7 @@ func TestFuzzExecuteStateTransition_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) sb := ðpb.SignedBeaconBlock{} fuzzer := fuzz.NewWithSeed(0) @@ -41,7 +41,7 @@ func TestFuzzCalculateStateRoot_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) sb := ðpb.SignedBeaconBlock{} fuzzer := fuzz.NewWithSeed(0) @@ -65,7 +65,7 @@ func TestFuzzProcessSlot_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) fuzzer := fuzz.NewWithSeed(0) fuzzer.NilChance(0.1) @@ -82,7 +82,7 @@ func TestFuzzProcessSlots_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) slot := types.Slot(0) fuzzer := fuzz.NewWithSeed(0) @@ -101,7 +101,7 @@ func TestFuzzprocessOperationsNoVerify_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) bb := ðpb.SignedBeaconBlock{} fuzzer := fuzz.NewWithSeed(0) @@ -124,7 +124,7 @@ func TestFuzzprocessOperationsNoVerify_1000(t *testing.T) { func TestFuzzverifyOperationLengths_10000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) bb := ðpb.SignedBeaconBlock{} fuzzer := fuzz.NewWithSeed(0) @@ -145,7 +145,7 @@ func TestFuzzverifyOperationLengths_10000(t *testing.T) { func TestFuzzCanProcessEpoch_10000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) fuzzer := fuzz.NewWithSeed(0) fuzzer.NilChance(0.1) @@ -159,7 +159,7 @@ func TestFuzzProcessEpochPrecompute_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) fuzzer := fuzz.NewWithSeed(0) fuzzer.NilChance(0.1) @@ -176,7 +176,7 @@ func TestFuzzProcessBlockForStateRoot_1000(t *testing.T) { SkipSlotCache.Disable() defer SkipSlotCache.Enable() ctx := context.Background() - state, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + state, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) sb := ðpb.SignedBeaconBlock{} fuzzer := fuzz.NewWithSeed(0) diff --git a/beacon-chain/core/transition/transition_test.go b/beacon-chain/core/transition/transition_test.go index c522f74b27..e88aa8f0f8 100644 --- a/beacon-chain/core/transition/transition_test.go +++ b/beacon-chain/core/transition/transition_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -35,7 +35,7 @@ func TestExecuteStateTransition_IncorrectSlot(t *testing.T) { base := ðpb.BeaconState{ Slot: 5, } - beaconState, err := v1.InitializeFromProto(base) + beaconState, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) block := ðpb.SignedBeaconBlock{ Block: ðpb.BeaconBlock{ @@ -383,7 +383,7 @@ func TestProcessEpochPrecompute_CanProcess(t *testing.T) { JustificationBits: bitfield.Bitvector4{0x00}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, } - s, err := v1.InitializeFromProto(base) + s, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) require.NoError(t, s.SetValidators([]*ethpb.Validator{})) newState, err := transition.ProcessEpochPrecompute(context.Background(), s) @@ -402,7 +402,7 @@ func TestProcessBlock_OverMaxProposerSlashings(t *testing.T) { } want := fmt.Sprintf("number of proposer slashings (%d) in block body exceeds allowed threshold of %d", len(b.Block.Body.ProposerSlashings), params.BeaconConfig().MaxProposerSlashings) - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) wsb, err := consensusblocks.NewSignedBeaconBlock(b) require.NoError(t, err) @@ -421,7 +421,7 @@ func TestProcessBlock_OverMaxAttesterSlashings(t *testing.T) { } want := fmt.Sprintf("number of attester slashings (%d) in block body exceeds allowed threshold of %d", len(b.Block.Body.AttesterSlashings), params.BeaconConfig().MaxAttesterSlashings) - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) wsb, err := consensusblocks.NewSignedBeaconBlock(b) require.NoError(t, err) @@ -439,7 +439,7 @@ func TestProcessBlock_OverMaxAttestations(t *testing.T) { } want := fmt.Sprintf("number of attestations (%d) in block body exceeds allowed threshold of %d", len(b.Block.Body.Attestations), params.BeaconConfig().MaxAttestations) - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) wsb, err := consensusblocks.NewSignedBeaconBlock(b) require.NoError(t, err) @@ -458,7 +458,7 @@ func TestProcessBlock_OverMaxVoluntaryExits(t *testing.T) { } want := fmt.Sprintf("number of voluntary exits (%d) in block body exceeds allowed threshold of %d", len(b.Block.Body.VoluntaryExits), maxExits) - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) wsb, err := consensusblocks.NewSignedBeaconBlock(b) require.NoError(t, err) @@ -471,7 +471,7 @@ func TestProcessBlock_IncorrectDeposits(t *testing.T) { Eth1Data: ðpb.Eth1Data{DepositCount: 100}, Eth1DepositIndex: 98, } - s, err := v1.InitializeFromProto(base) + s, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) b := ðpb.SignedBeaconBlock{ Block: ðpb.BeaconBlock{ @@ -490,7 +490,7 @@ func TestProcessBlock_IncorrectDeposits(t *testing.T) { func TestProcessSlots_SameSlotAsParentState(t *testing.T) { slot := types.Slot(2) - parentState, err := v1.InitializeFromProto(ðpb.BeaconState{Slot: slot}) + parentState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: slot}) require.NoError(t, err) _, err = transition.ProcessSlots(context.Background(), parentState, slot) @@ -499,7 +499,7 @@ func TestProcessSlots_SameSlotAsParentState(t *testing.T) { func TestProcessSlots_LowerSlotAsParentState(t *testing.T) { slot := types.Slot(2) - parentState, err := v1.InitializeFromProto(ðpb.BeaconState{Slot: slot}) + parentState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: slot}) require.NoError(t, err) _, err = transition.ProcessSlots(context.Background(), parentState, slot-1) diff --git a/beacon-chain/core/validators/BUILD.bazel b/beacon-chain/core/validators/BUILD.bazel index 31b0c50703..cab8f53a73 100644 --- a/beacon-chain/core/validators/BUILD.bazel +++ b/beacon-chain/core/validators/BUILD.bazel @@ -29,7 +29,7 @@ go_test( deps = [ "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/time:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/core/validators/validator_test.go b/beacon-chain/core/validators/validator_test.go index e9051ff2d7..e297f7e4a9 100644 --- a/beacon-chain/core/validators/validator_test.go +++ b/beacon-chain/core/validators/validator_test.go @@ -6,7 +6,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -46,7 +46,7 @@ func TestInitiateValidatorExit_AlreadyExited(t *testing.T) { base := ðpb.BeaconState{Validators: []*ethpb.Validator{{ ExitEpoch: exitEpoch}, }} - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := InitiateValidatorExit(context.Background(), state, 0) require.NoError(t, err) @@ -64,7 +64,7 @@ func TestInitiateValidatorExit_ProperExit(t *testing.T) { {ExitEpoch: exitedEpoch + 2}, {ExitEpoch: params.BeaconConfig().FarFutureEpoch}, }} - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := InitiateValidatorExit(context.Background(), state, idx) require.NoError(t, err) @@ -83,7 +83,7 @@ func TestInitiateValidatorExit_ChurnOverflow(t *testing.T) { {ExitEpoch: exitedEpoch + 2}, // overflow here {ExitEpoch: params.BeaconConfig().FarFutureEpoch}, }} - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) newState, err := InitiateValidatorExit(context.Background(), state, idx) require.NoError(t, err) @@ -104,7 +104,7 @@ func TestInitiateValidatorExit_WithdrawalOverflows(t *testing.T) { {ExitEpoch: params.BeaconConfig().FarFutureEpoch - 1}, {EffectiveBalance: params.BeaconConfig().EjectionBalance, ExitEpoch: params.BeaconConfig().FarFutureEpoch}, }} - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) _, err = InitiateValidatorExit(context.Background(), state, 1) require.ErrorContains(t, "addition overflows", err) @@ -129,7 +129,7 @@ func TestSlashValidator_OK(t *testing.T) { RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), Balances: balances, } - state, err := v1.InitializeFromProto(base) + state, err := state_native.InitializeFromProtoPhase0(base) require.NoError(t, err) slashedIdx := types.ValidatorIndex(3) @@ -214,7 +214,7 @@ func TestActivatedValidatorIndices(t *testing.T) { }, } for _, tt := range tests { - s, err := v1.InitializeFromProto(tt.state) + s, err := state_native.InitializeFromProtoPhase0(tt.state) require.NoError(t, err) activatedIndices := ActivatedValidatorIndices(time.CurrentEpoch(s), tt.state.Validators) assert.DeepEqual(t, tt.wanted, activatedIndices) @@ -268,7 +268,7 @@ func TestSlashedValidatorIndices(t *testing.T) { }, } for _, tt := range tests { - s, err := v1.InitializeFromProto(tt.state) + s, err := state_native.InitializeFromProtoPhase0(tt.state) require.NoError(t, err) slashedIndices := SlashedValidatorIndices(time.CurrentEpoch(s), tt.state.Validators) assert.DeepEqual(t, tt.wanted, slashedIndices) @@ -328,7 +328,7 @@ func TestExitedValidatorIndices(t *testing.T) { }, } for _, tt := range tests { - s, err := v1.InitializeFromProto(tt.state) + s, err := state_native.InitializeFromProtoPhase0(tt.state) require.NoError(t, err) activeCount, err := helpers.ActiveValidatorCount(context.Background(), s, time.PrevEpoch(s)) require.NoError(t, err) diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 50916bddf1..208c3adfba 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -41,9 +41,6 @@ go_library( "//beacon-chain/state:go_default_library", "//beacon-chain/state/genesis:go_default_library", "//beacon-chain/state/state-native:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", - "//beacon-chain/state/v3:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", @@ -106,8 +103,7 @@ go_test( "//beacon-chain/db/iface:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/genesis:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/features:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", diff --git a/beacon-chain/db/kv/genesis.go b/beacon-chain/db/kv/genesis.go index 1131f9d1f2..c9d70d2832 100644 --- a/beacon-chain/db/kv/genesis.go +++ b/beacon-chain/db/kv/genesis.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" dbIface "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/iface" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - statev1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -58,7 +58,7 @@ func (s *Store) LoadGenesis(ctx context.Context, sb []byte) error { if err := st.UnmarshalSSZ(sb); err != nil { return err } - gs, err := statev1.InitializeFromProtoUnsafe(st) + gs, err := state_native.InitializeFromProtoUnsafePhase0(st) if err != nil { return err } diff --git a/beacon-chain/db/kv/migration_state_validators_test.go b/beacon-chain/db/kv/migration_state_validators_test.go index 0d2286e5b1..99c2fdbae2 100644 --- a/beacon-chain/db/kv/migration_state_validators_test.go +++ b/beacon-chain/db/kv/migration_state_validators_test.go @@ -7,8 +7,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/features" "github.com/prysmaticlabs/prysm/v3/config/params" v1alpha1 "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -93,7 +92,7 @@ func Test_migrateStateValidators(t *testing.T) { assert.NoError(t, hashErr) individualHashes = append(individualHashes, hash[:]) } - pbState, err := v1.ProtobufBeaconState(st.InnerStateUnsafe()) + pbState, err := state_native.ProtobufBeaconStatePhase0(st.InnerStateUnsafe()) assert.NoError(t, err) validatorsFoundCount := 0 for _, val := range pbState.Validators { @@ -152,7 +151,7 @@ func Test_migrateStateValidators(t *testing.T) { } // check if all the validators that were in the state, are stored properly in the validator bucket - pbState, err := v1.ProtobufBeaconState(rcvdState.InnerStateUnsafe()) + pbState, err := state_native.ProtobufBeaconStatePhase0(rcvdState.InnerStateUnsafe()) assert.NoError(t, err) validatorsFoundCount := 0 for _, val := range pbState.Validators { @@ -255,7 +254,7 @@ func Test_migrateAltairStateValidators(t *testing.T) { } // check if all the validators that were in the state, are stored properly in the validator bucket - pbState, err := v2.ProtobufBeaconState(rcvdState.InnerStateUnsafe()) + pbState, err := state_native.ProtobufBeaconStateAltair(rcvdState.InnerStateUnsafe()) assert.NoError(t, err) validatorsFoundCount := 0 for _, val := range pbState.Validators { diff --git a/beacon-chain/db/kv/state.go b/beacon-chain/db/kv/state.go index 6d5be3bbee..1c3620661e 100644 --- a/beacon-chain/db/kv/state.go +++ b/beacon-chain/db/kv/state.go @@ -10,9 +10,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/genesis" statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" "github.com/prysmaticlabs/prysm/v3/config/features" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -467,7 +464,7 @@ func (s *Store) unmarshalState(_ context.Context, enc []byte, validatorEntries [ if ok { protoState.Validators = validatorEntries } - return v3.InitializeFromProtoUnsafe(protoState) + return statenative.InitializeFromProtoUnsafeBellatrix(protoState) case hasAltairKey(enc): // Marshal state bytes to altair beacon state. protoState := ðpb.BeaconStateAltair{} @@ -481,7 +478,7 @@ func (s *Store) unmarshalState(_ context.Context, enc []byte, validatorEntries [ if ok { protoState.Validators = validatorEntries } - return v2.InitializeFromProtoUnsafe(protoState) + return statenative.InitializeFromProtoUnsafeAltair(protoState) default: // Marshal state bytes to phase 0 beacon state. protoState := ðpb.BeaconState{} @@ -495,7 +492,7 @@ func (s *Store) unmarshalState(_ context.Context, enc []byte, validatorEntries [ if ok { protoState.Validators = validatorEntries } - return v1.InitializeFromProtoUnsafe(protoState) + return statenative.InitializeFromProtoUnsafePhase0(protoState) } } diff --git a/beacon-chain/deterministic-genesis/BUILD.bazel b/beacon-chain/deterministic-genesis/BUILD.bazel index e4b8f9db48..5539fb25d6 100644 --- a/beacon-chain/deterministic-genesis/BUILD.bazel +++ b/beacon-chain/deterministic-genesis/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//beacon-chain/db:go_default_library", "//beacon-chain/execution:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//runtime:go_default_library", diff --git a/beacon-chain/deterministic-genesis/service.go b/beacon-chain/deterministic-genesis/service.go index 60182909b6..ae16d18529 100644 --- a/beacon-chain/deterministic-genesis/service.go +++ b/beacon-chain/deterministic-genesis/service.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/db" "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/runtime" @@ -69,7 +69,7 @@ func (s *Service) Start() { if err := genesisState.UnmarshalSSZ(data); err != nil { log.WithError(err).Fatal("Could not unmarshal pre-loaded state") } - genesisTrie, err := v1.InitializeFromProto(genesisState) + genesisTrie, err := state_native.InitializeFromProtoPhase0(genesisState) if err != nil { log.WithError(err).Fatal("Could not get state trie") } @@ -84,7 +84,7 @@ func (s *Service) Start() { if err != nil { log.WithError(err).Fatal("Could not generate interop genesis state") } - genesisTrie, err := v1.InitializeFromProto(genesisState) + genesisTrie, err := state_native.InitializeFromProtoPhase0(genesisState) if err != nil { log.WithError(err).Fatal("Could not get state trie") } @@ -125,7 +125,7 @@ func (_ *Service) ChainStartEth1Data() *ethpb.Eth1Data { // PreGenesisState returns an empty beacon state. func (_ *Service) PreGenesisState() state.BeaconState { - s, err := v1.InitializeFromProto(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{}) if err != nil { panic("could not initialize state") } diff --git a/beacon-chain/execution/BUILD.bazel b/beacon-chain/execution/BUILD.bazel index c145cd0d5c..79a90bb64c 100644 --- a/beacon-chain/execution/BUILD.bazel +++ b/beacon-chain/execution/BUILD.bazel @@ -37,7 +37,6 @@ go_library( "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", - "//beacon-chain/state/v1:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/execution/service.go b/beacon-chain/execution/service.go index 2e35643b07..b843778fa7 100644 --- a/beacon-chain/execution/service.go +++ b/beacon-chain/execution/service.go @@ -30,7 +30,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/container/trie" contracts "github.com/prysmaticlabs/prysm/v3/contracts/deposit" @@ -726,7 +725,7 @@ func (s *Service) initializeEth1Data(ctx context.Context, eth1DataInDB *ethpb.ET } s.chainStartData = eth1DataInDB.ChainstartData if !reflect.ValueOf(eth1DataInDB.BeaconState).IsZero() { - s.preGenesisState, err = v1.InitializeFromProto(eth1DataInDB.BeaconState) + s.preGenesisState, err = native.InitializeFromProtoPhase0(eth1DataInDB.BeaconState) if err != nil { return errors.Wrap(err, "Could not initialize state trie") } diff --git a/beacon-chain/execution/testing/BUILD.bazel b/beacon-chain/execution/testing/BUILD.bazel index da6e20a087..0447c0085c 100644 --- a/beacon-chain/execution/testing/BUILD.bazel +++ b/beacon-chain/execution/testing/BUILD.bazel @@ -16,7 +16,7 @@ go_library( "//async/event:go_default_library", "//beacon-chain/execution/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/interfaces:go_default_library", diff --git a/beacon-chain/execution/testing/mock_faulty_powchain.go b/beacon-chain/execution/testing/mock_faulty_powchain.go index b97b6fb5a0..68194c8f02 100644 --- a/beacon-chain/execution/testing/mock_faulty_powchain.go +++ b/beacon-chain/execution/testing/mock_faulty_powchain.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/async/event" "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/types" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" ) @@ -55,7 +55,7 @@ func (*FaultyExecutionChain) ChainStartEth1Data() *ethpb.Eth1Data { // PreGenesisState -- func (*FaultyExecutionChain) PreGenesisState() state.BeaconState { - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) if err != nil { panic("could not initialize state") } diff --git a/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel b/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel index 383be406b2..84f8fea9fc 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel +++ b/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel @@ -62,7 +62,7 @@ go_test( "//beacon-chain/forkchoice:go_default_library", "//beacon-chain/forkchoice/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v3:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go index 9253159036..ca5eeeb474 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice" forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -57,7 +57,7 @@ func prepareForkchoiceState( LatestBlockHeader: blockHeader, } - st, err := v3.InitializeFromProto(base) + st, err := state_native.InitializeFromProtoBellatrix(base) return st, blockRoot, err } diff --git a/beacon-chain/forkchoice/protoarray/BUILD.bazel b/beacon-chain/forkchoice/protoarray/BUILD.bazel index 6031cee5aa..0c8752349e 100644 --- a/beacon-chain/forkchoice/protoarray/BUILD.bazel +++ b/beacon-chain/forkchoice/protoarray/BUILD.bazel @@ -63,7 +63,7 @@ go_test( "//beacon-chain/forkchoice:go_default_library", "//beacon-chain/forkchoice/types:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v3:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/beacon-chain/forkchoice/protoarray/ffg_update_test.go b/beacon-chain/forkchoice/protoarray/ffg_update_test.go index 3242e439d5..f5499de2f5 100644 --- a/beacon-chain/forkchoice/protoarray/ffg_update_test.go +++ b/beacon-chain/forkchoice/protoarray/ffg_update_test.go @@ -6,7 +6,7 @@ import ( forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" @@ -53,7 +53,7 @@ func prepareForkchoiceState( } base.BlockRoots[0] = append(base.BlockRoots[0], blockRoot[:]...) - st, err := v3.InitializeFromProto(base) + st, err := state_native.InitializeFromProtoBellatrix(base) return st, blockRoot, err } func TestFFGUpdates_OneBranch(t *testing.T) { diff --git a/beacon-chain/operations/voluntaryexits/BUILD.bazel b/beacon-chain/operations/voluntaryexits/BUILD.bazel index b9ed249655..f43f00c065 100644 --- a/beacon-chain/operations/voluntaryexits/BUILD.bazel +++ b/beacon-chain/operations/voluntaryexits/BUILD.bazel @@ -26,7 +26,7 @@ go_test( srcs = ["service_test.go"], embed = [":go_default_library"], deps = [ - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/operations/voluntaryexits/service_test.go b/beacon-chain/operations/voluntaryexits/service_test.go index 07475a7bc4..19acdb8632 100644 --- a/beacon-chain/operations/voluntaryexits/service_test.go +++ b/beacon-chain/operations/voluntaryexits/service_test.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -269,7 +269,7 @@ func TestPool_InsertVoluntaryExit(t *testing.T) { p := &Pool{ pending: tt.fields.pending, } - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{Validators: validators}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{Validators: validators}) require.NoError(t, err) p.InsertVoluntaryExit(ctx, s, tt.args.exit) if len(p.pending) != len(tt.want) { @@ -520,7 +520,7 @@ func TestPool_PendingExits(t *testing.T) { p := &Pool{ pending: tt.fields.pending, } - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{Validators: []*ethpb.Validator{{ExitEpoch: params.BeaconConfig().FarFutureEpoch}}}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{Validators: []*ethpb.Validator{{ExitEpoch: params.BeaconConfig().FarFutureEpoch}}}) require.NoError(t, err) if got := p.PendingExits(s, tt.args.slot, tt.fields.noLimit); !reflect.DeepEqual(got, tt.want) { t.Errorf("PendingExits() = %v, want %v", got, tt.want) diff --git a/beacon-chain/rpc/eth/beacon/BUILD.bazel b/beacon-chain/rpc/eth/beacon/BUILD.bazel index afaaf0482d..846bb70046 100644 --- a/beacon-chain/rpc/eth/beacon/BUILD.bazel +++ b/beacon-chain/rpc/eth/beacon/BUILD.bazel @@ -37,7 +37,6 @@ go_library( "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", - "//beacon-chain/state/v1:go_default_library", "//beacon-chain/sync:go_default_library", "//config/features:go_default_library", "//config/fieldparams:go_default_library", @@ -98,7 +97,7 @@ go_test( "//beacon-chain/rpc/statefetcher:go_default_library", "//beacon-chain/rpc/testutil:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/interfaces:go_default_library", diff --git a/beacon-chain/rpc/eth/beacon/validator.go b/beacon-chain/rpc/eth/beacon/validator.go index 0c0f192b28..de90417df4 100644 --- a/beacon-chain/rpc/eth/beacon/validator.go +++ b/beacon-chain/rpc/eth/beacon/validator.go @@ -9,7 +9,6 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -102,7 +101,7 @@ func (bs *Server) ListValidators(ctx context.Context, req *ethpb.StateValidators epoch := slots.ToEpoch(st.Slot()) filteredVals := make([]*ethpb.ValidatorContainer, 0, len(valContainers)) for _, vc := range valContainers { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(vc.Validator)) + readOnlyVal, err := statenative.NewValidator(migration.V1ValidatorToV1Alpha1(vc.Validator)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not convert validator: %v", err) } @@ -221,7 +220,7 @@ func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) ( allValidators := state.Validators() valContainers = make([]*ethpb.ValidatorContainer, len(allValidators)) for i, validator := range allValidators { - readOnlyVal, err := v1.NewValidator(validator) + readOnlyVal, err := statenative.NewValidator(validator) if err != nil { return nil, status.Errorf(codes.Internal, "Could not convert validator: %v", err) } @@ -264,7 +263,7 @@ func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) ( return nil, errors.Wrap(err, "could not get validator") } v1Validator := migration.V1Alpha1ValidatorToV1(validator) - readOnlyVal, err := v1.NewValidator(validator) + readOnlyVal, err := statenative.NewValidator(validator) if err != nil { return nil, status.Errorf(codes.Internal, "Could not convert validator: %v", err) } @@ -285,7 +284,7 @@ func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) ( } func handleValContainerErr(err error) error { - if outOfRangeErr, ok := err.(*v1.ValidatorIndexOutOfRangeError); ok { + if outOfRangeErr, ok := err.(*statenative.ValidatorIndexOutOfRangeError); ok { return status.Errorf(codes.InvalidArgument, "Invalid validator ID: %v", outOfRangeErr) } if invalidIdErr, ok := err.(*invalidValidatorIdError); ok { diff --git a/beacon-chain/rpc/eth/beacon/validator_test.go b/beacon-chain/rpc/eth/beacon/validator_test.go index a391354f96..7c84fed663 100644 --- a/beacon-chain/rpc/eth/beacon/validator_test.go +++ b/beacon-chain/rpc/eth/beacon/validator_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/statefetcher" "github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/testutil" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/eth/v1" @@ -380,7 +380,7 @@ func TestListValidators_Status(t *testing.T) { require.NoError(t, err) assert.Equal(t, len(resp.Data), 8192+2 /* 2 active */) for _, datum := range resp.Data { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) require.NoError(t, err) status, err := rpchelpers.ValidatorStatus(readOnlyVal, 0) require.NoError(t, err) @@ -417,7 +417,7 @@ func TestListValidators_Status(t *testing.T) { require.NoError(t, err) assert.Equal(t, len(resp.Data), 8192+1 /* 1 active_ongoing */) for _, datum := range resp.Data { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) require.NoError(t, err) status, err := rpchelpers.ValidatorSubStatus(readOnlyVal, 0) require.NoError(t, err) @@ -453,7 +453,7 @@ func TestListValidators_Status(t *testing.T) { require.NoError(t, err) assert.Equal(t, 4 /* 4 exited */, len(resp.Data)) for _, datum := range resp.Data { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) require.NoError(t, err) status, err := rpchelpers.ValidatorStatus(readOnlyVal, 35) require.NoError(t, err) @@ -488,7 +488,7 @@ func TestListValidators_Status(t *testing.T) { require.NoError(t, err) assert.Equal(t, 4 /* 4 exited */, len(resp.Data)) for _, datum := range resp.Data { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) require.NoError(t, err) status, err := rpchelpers.ValidatorSubStatus(readOnlyVal, 35) require.NoError(t, err) @@ -523,7 +523,7 @@ func TestListValidators_Status(t *testing.T) { require.NoError(t, err) assert.Equal(t, 2 /* 1 pending, 1 exited */, len(resp.Data)) for _, datum := range resp.Data { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(datum.Validator)) require.NoError(t, err) status, err := rpchelpers.ValidatorStatus(readOnlyVal, 35) require.NoError(t, err) diff --git a/beacon-chain/rpc/eth/helpers/BUILD.bazel b/beacon-chain/rpc/eth/helpers/BUILD.bazel index 01c0ea9dd0..aae2dfa73a 100644 --- a/beacon-chain/rpc/eth/helpers/BUILD.bazel +++ b/beacon-chain/rpc/eth/helpers/BUILD.bazel @@ -35,7 +35,7 @@ go_test( deps = [ "//api/grpc:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", diff --git a/beacon-chain/rpc/eth/helpers/validator_status_test.go b/beacon-chain/rpc/eth/helpers/validator_status_test.go index 340278784c..a53fa5efc8 100644 --- a/beacon-chain/rpc/eth/helpers/validator_status_test.go +++ b/beacon-chain/rpc/eth/helpers/validator_status_test.go @@ -4,7 +4,7 @@ import ( "strconv" "testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/eth/v1" @@ -140,7 +140,7 @@ func Test_ValidatorStatus(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(tt.args.validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(tt.args.validator)) require.NoError(t, err) got, err := ValidatorStatus(readOnlyVal, tt.args.epoch) require.NoError(t, err) @@ -278,7 +278,7 @@ func Test_ValidatorSubStatus(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(tt.args.validator)) + readOnlyVal, err := state_native.NewValidator(migration.V1ValidatorToV1Alpha1(tt.args.validator)) require.NoError(t, err) got, err := ValidatorSubStatus(readOnlyVal, tt.args.epoch) require.NoError(t, err) diff --git a/beacon-chain/rpc/eth/validator/BUILD.bazel b/beacon-chain/rpc/eth/validator/BUILD.bazel index 0d9c003fe3..28b2eccb83 100644 --- a/beacon-chain/rpc/eth/validator/BUILD.bazel +++ b/beacon-chain/rpc/eth/validator/BUILD.bazel @@ -22,7 +22,7 @@ go_library( "//beacon-chain/rpc/prysm/v1alpha1/validator:go_default_library", "//beacon-chain/rpc/statefetcher:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/sync:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", diff --git a/beacon-chain/rpc/eth/validator/validator.go b/beacon-chain/rpc/eth/validator/validator.go index 338076afba..7eb1874911 100644 --- a/beacon-chain/rpc/eth/validator/validator.go +++ b/beacon-chain/rpc/eth/validator/validator.go @@ -19,7 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/kv" rpchelpers "github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - statev1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -758,7 +758,7 @@ func (vs *Server) SubmitBeaconCommitteeSubscription(ctx context.Context, req *et validators := make([]state.ReadOnlyValidator, len(req.Data)) for i, sub := range req.Data { val, err := s.ValidatorAtIndexReadOnly(sub.ValidatorIndex) - if outOfRangeErr, ok := err.(*statev1.ValidatorIndexOutOfRangeError); ok { + if outOfRangeErr, ok := err.(*state_native.ValidatorIndexOutOfRangeError); ok { return nil, status.Errorf(codes.InvalidArgument, "Invalid validator ID: %v", outOfRangeErr) } validators[i] = val diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel index d0bc1eae22..0eb62189a5 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel @@ -102,9 +102,9 @@ go_test( "//beacon-chain/operations/slashings:go_default_library", "//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen/mock:go_default_library", - "//beacon-chain/state/v1:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//cmd:go_default_library", "//cmd/beacon-chain/flags:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go index 4b8c06baf9..7e2ac8b630 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go @@ -17,8 +17,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/v3/cmd" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -42,7 +42,7 @@ func TestServer_ListAttestations_NoResults(t *testing.T) { db := dbTest.SetupDB(t) ctx := context.Background() - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, }) require.NoError(t, err) @@ -70,7 +70,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) { db := dbTest.SetupDB(t) ctx := context.Background() - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, }) require.NoError(t, err) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go index 965e683aa0..5039bc72df 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go @@ -12,7 +12,7 @@ import ( blockfeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/block" statefeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/state" dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/features" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -163,7 +163,7 @@ func TestServer_GetChainHead(t *testing.T) { pjRoot, err := prevJustifiedBlock.Block.HashTreeRoot() require.NoError(t, err) - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 1, PreviousJustifiedCheckpoint: ðpb.Checkpoint{Epoch: 3, Root: pjRoot[:]}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Epoch: 2, Root: jRoot[:]}, @@ -258,7 +258,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) { pjRoot, err := prevJustifiedBlock.Block.HashTreeRoot() require.NoError(t, err) - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 1, PreviousJustifiedCheckpoint: ðpb.Checkpoint{Epoch: 3, Root: pjRoot[:]}, CurrentJustifiedCheckpoint: ðpb.Checkpoint{Epoch: 2, Root: jRoot[:]}, diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go index c9a8ac01dc..5a32e76554 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go @@ -19,9 +19,9 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/db" dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" mockstategen "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" "github.com/prysmaticlabs/prysm/v3/cmd" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" @@ -1327,7 +1327,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) { } func TestServer_GetValidatorQueue_PendingActivation(t *testing.T) { - headState, err := v1.InitializeFromProto(ðpb.BeaconState{ + headState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ { ActivationEpoch: helpers.ActivationExitEpoch(0), @@ -1426,7 +1426,7 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) { } func TestServer_GetValidatorQueue_PendingExit(t *testing.T) { - headState, err := v1.InitializeFromProto(ðpb.BeaconState{ + headState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ { ActivationEpoch: 0, diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel index bf7d550cfc..02a565d378 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel @@ -121,10 +121,9 @@ common_deps = [ "//beacon-chain/operations/voluntaryexits:go_default_library", "//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen/mock:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v3:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go index 714585f81f..3f2e00858d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator_test.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations" mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -30,7 +30,7 @@ import ( func TestSubmitAggregateAndProof_Syncing(t *testing.T) { ctx := context.Background() - s, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + s, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) aggregatorServer := &Server{ @@ -47,7 +47,7 @@ func TestSubmitAggregateAndProof_Syncing(t *testing.T) { func TestSubmitAggregateAndProof_CantFindValidatorIndex(t *testing.T) { ctx := context.Background() - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) require.NoError(t, err) @@ -70,7 +70,7 @@ func TestSubmitAggregateAndProof_CantFindValidatorIndex(t *testing.T) { func TestSubmitAggregateAndProof_IsAggregatorAndNoAtts(t *testing.T) { ctx := context.Background() - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), Validators: []*ethpb.Validator{ {PublicKey: pubKey(0)}, diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go index f4319397de..72d68734a5 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go @@ -12,8 +12,8 @@ import ( dbutil "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations" mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -202,7 +202,7 @@ func TestGetAttestationData_Optimistic(t *testing.T) { func TestAttestationDataSlot_handlesInProgressRequest(t *testing.T) { s := ðpb.BeaconState{Slot: 100} - state, err := v1.InitializeFromProto(s) + state, err := state_native.InitializeFromProtoPhase0(s) require.NoError(t, err) ctx := context.Background() chainService := &mock.ChainService{ diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go index 79545be1f3..6bf75597f1 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go @@ -23,8 +23,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/synccommittee" "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/voluntaryexits" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -914,6 +914,6 @@ func createState( } base.BlockRoots[0] = append(base.BlockRoots[0], blockRoot[:]...) - st, err := v3.InitializeFromProto(base) + st, err := state_native.InitializeFromProtoBellatrix(base) return st, blockRoot, err } diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go index 992e3bb0fc..a8c63834e8 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -25,8 +25,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/synccommittee" "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/voluntaryexits" mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -246,7 +246,7 @@ func TestProposer_PendingDeposits_OutsideEth1FollowWindow(t *testing.T) { }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: bytesutil.PadTo([]byte("0x0"), 32), DepositRoot: make([]byte, 32), @@ -378,7 +378,7 @@ func TestProposer_PendingDeposits_FollowsCorrectEth1Block(t *testing.T) { votes = append(votes, vote) } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: []byte("0x0"), DepositRoot: make([]byte, 32), @@ -597,7 +597,7 @@ func TestProposer_PendingDeposits_CantReturnMoreThanMax(t *testing.T) { }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: bytesutil.PadTo([]byte("0x0"), 32), DepositRoot: make([]byte, 32), @@ -695,7 +695,7 @@ func TestProposer_PendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) { }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: bytesutil.PadTo([]byte("0x0"), 32), DepositRoot: make([]byte, 32), @@ -793,7 +793,7 @@ func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) { }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: bytesutil.PadTo([]byte("0x0"), 32), DepositRoot: make([]byte, 32), @@ -909,7 +909,7 @@ func TestProposer_DepositTrie_RebuildTrie(t *testing.T) { }, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: bytesutil.PadTo([]byte("0x0"), 32), DepositRoot: make([]byte, 32), @@ -1131,7 +1131,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(52, earliestValidTime+2, []byte("second")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("first"), DepositCount: 1}, @@ -1167,7 +1167,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(52, earliestValidTime+2, []byte("second")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("earliest"), DepositCount: 1}, @@ -1203,7 +1203,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(51, earliestValidTime+1, []byte("first")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("first"), DepositCount: 1}, @@ -1240,7 +1240,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(51, earliestValidTime+1, []byte("first")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("before_range"), DepositCount: 1}, @@ -1277,7 +1277,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(100, latestValidTime, []byte("latest")). InsertBlock(101, latestValidTime+1, []byte("after_range")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("first"), DepositCount: 1}, @@ -1314,7 +1314,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(52, earliestValidTime+2, []byte("second")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("unknown"), DepositCount: 1}, @@ -1348,7 +1348,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(49, earliestValidTime-1, []byte("before_range")). InsertBlock(101, latestValidTime+1, []byte("after_range")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, }) require.NoError(t, err) @@ -1380,7 +1380,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(52, earliestValidTime+2, []byte("second")). InsertBlock(101, latestValidTime+1, []byte("after_range")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("before_range"), DepositCount: 1}, @@ -1414,7 +1414,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(50, earliestValidTime, []byte("earliest")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{}}) require.NoError(t, err) @@ -1444,7 +1444,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(50, earliestValidTime, []byte("earliest")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, }) require.NoError(t, err) @@ -1478,7 +1478,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(52, earliestValidTime+2, []byte("second")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("first"), DepositCount: 1}, @@ -1514,7 +1514,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { InsertBlock(52, earliestValidTime+2, []byte("second")). InsertBlock(100, latestValidTime, []byte("latest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("no_new_deposits"), DepositCount: 0}, @@ -1547,7 +1547,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { t.Skip() p := mockExecution.New().InsertBlock(50, earliestValidTime, []byte("earliest")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("earliest"), DepositCount: 1}, @@ -1581,7 +1581,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { // because of earliest block increment in the algorithm. InsertBlock(50, earliestValidTime+1, []byte("first")) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("before_range"), DepositCount: 1}, @@ -1620,7 +1620,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { depositCache, err := depositcache.New() require.NoError(t, err) - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: slot, Eth1DataVotes: []*ethpb.Eth1Data{ {BlockHash: []byte("earliest"), DepositCount: 1}, @@ -1761,7 +1761,7 @@ func TestProposer_Deposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t GenesisEth1Block: height, } - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Eth1Data: ðpb.Eth1Data{ BlockHash: bytesutil.PadTo([]byte("0x0"), 32), DepositRoot: make([]byte, 32), diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/server_mainnet_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/server_mainnet_test.go index ce6604ac60..cfda88fcc3 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/server_mainnet_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/server_mainnet_test.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/container/trie" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -71,7 +71,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) { root, err := depositTrie.HashTreeRoot() require.NoError(t, err) assert.NoError(t, depositCache.InsertDeposit(ctx, deposit, 10 /*blockNum*/, 0, root)) - s, err := v1.InitializeFromProtoUnsafe(beaconState) + s, err := state_native.InitializeFromProtoUnsafePhase0(beaconState) require.NoError(t, err) vs := &Server{ Ctx: context.Background(), diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/server_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/server_test.go index 1bb8afd838..3359032ec7 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/server_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/server_test.go @@ -13,7 +13,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/state" mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/crypto/bls" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -59,7 +59,7 @@ func TestValidatorIndex_StateEmpty(t *testing.T) { } func TestWaitForActivation_ContextClosed(t *testing.T) { - beaconState, err := v1.InitializeFromProto(ðpb.BeaconState{ + beaconState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 0, Validators: []*ethpb.Validator{}, }) @@ -137,7 +137,7 @@ func TestWaitForActivation_MultipleStatuses(t *testing.T) { block := util.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") - s, err := v1.InitializeFromProtoUnsafe(beaconState) + s, err := state_native.InitializeFromProtoUnsafePhase0(beaconState) require.NoError(t, err) vs := &Server{ Ctx: context.Background(), diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/status_mainnet_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/status_mainnet_test.go index 829b010c92..6941e8386d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/status_mainnet_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/status_mainnet_test.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/container/trie" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -63,7 +63,7 @@ func TestValidatorStatus_Active(t *testing.T) { WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch, PublicKey: pubkey}, }} - stateObj, err := v1.InitializeFromProtoUnsafe(st) + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(st) require.NoError(t, err) timestamp := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix() diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go index 812741057b..30b6a4c61e 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go @@ -12,8 +12,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" mockstategen "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -50,7 +50,7 @@ func TestValidatorStatus_DepositedEth1(t *testing.T) { 0: uint64(height), }, } - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) vs := &Server{ DepositFetcher: depositCache, @@ -95,7 +95,7 @@ func TestValidatorStatus_Deposited(t *testing.T) { 0: uint64(height), }, } - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{ + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ { PublicKey: pubKey1, @@ -147,7 +147,7 @@ func TestValidatorStatus_PartiallyDeposited(t *testing.T) { 0: uint64(height), }, } - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{ + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{ Validators: []*ethpb.Validator{ { PublicKey: pubKey1, @@ -255,7 +255,7 @@ func TestValidatorStatus_Exiting(t *testing.T) { ExitEpoch: exitEpoch, WithdrawableEpoch: withdrawableEpoch}, }} - stateObj, err := v1.InitializeFromProtoUnsafe(st) + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(st) require.NoError(t, err) depData := ðpb.Deposit_Data{ PublicKey: pubKey, @@ -314,7 +314,7 @@ func TestValidatorStatus_Slashing(t *testing.T) { PublicKey: pubKey, WithdrawableEpoch: epoch + 1}, }} - stateObj, err := v1.InitializeFromProtoUnsafe(st) + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(st) require.NoError(t, err) depData := ðpb.Deposit_Data{ PublicKey: pubKey, @@ -417,7 +417,7 @@ func TestValidatorStatus_UnknownStatus(t *testing.T) { depositCache, err := depositcache.New() require.NoError(t, err) - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{ + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{ Slot: 0, }) require.NoError(t, err) @@ -442,7 +442,7 @@ func TestActivationStatus_OK(t *testing.T) { deposits, _, err := util.DeterministicDepositsAndKeys(4) require.NoError(t, err) pubKeys := [][]byte{deposits[0].Data.PublicKey, deposits[1].Data.PublicKey, deposits[2].Data.PublicKey, deposits[3].Data.PublicKey} - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{ + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{ Slot: 4000, Validators: []*ethpb.Validator{ { @@ -663,7 +663,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) { deposits[4].Data.PublicKey, deposits[5].Data.PublicKey, } - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{ + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{ Slot: 4000, Validators: []*ethpb.Validator{ { @@ -803,7 +803,7 @@ func TestMultipleValidatorStatus_Indices(t *testing.T) { }, }, } - stateObj, err := v1.InitializeFromProtoUnsafe(beaconState) + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(beaconState) require.NoError(t, err) block := util.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() @@ -878,7 +878,7 @@ func TestValidatorStatus_Invalid(t *testing.T) { 0: uint64(height), }, } - stateObj, err := v1.InitializeFromProtoUnsafe(ðpb.BeaconState{}) + stateObj, err := state_native.InitializeFromProtoUnsafePhase0(ðpb.BeaconState{}) require.NoError(t, err) vs := &Server{ DepositFetcher: depositCache, diff --git a/beacon-chain/state/genesis/BUILD.bazel b/beacon-chain/state/genesis/BUILD.bazel index c8b5f6c807..9679ecb43a 100644 --- a/beacon-chain/state/genesis/BUILD.bazel +++ b/beacon-chain/state/genesis/BUILD.bazel @@ -8,7 +8,7 @@ go_library( visibility = ["//beacon-chain/db:__subpackages__"], deps = [ "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "@com_github_golang_snappy//:go_default_library", diff --git a/beacon-chain/state/genesis/genesis.go b/beacon-chain/state/genesis/genesis.go index d6ae3a2cfb..ff64e5f340 100644 --- a/beacon-chain/state/genesis/genesis.go +++ b/beacon-chain/state/genesis/genesis.go @@ -5,7 +5,7 @@ import ( "github.com/golang/snappy" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" ) @@ -36,5 +36,5 @@ func load(b []byte) (state.BeaconState, error) { if err := st.UnmarshalSSZ(b); err != nil { return nil, err } - return v1.InitializeFromProtoUnsafe(st) + return state_native.InitializeFromProtoUnsafePhase0(st) } diff --git a/beacon-chain/state/state-native/BUILD.bazel b/beacon-chain/state/state-native/BUILD.bazel index e82c6ff404..041a3a292c 100644 --- a/beacon-chain/state/state-native/BUILD.bazel +++ b/beacon-chain/state/state-native/BUILD.bazel @@ -39,21 +39,7 @@ go_library( "//config:minimal": ["beacon_state_minimal.go"], }), importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native", - visibility = [ - "//beacon-chain:__subpackages__", - "//contracts/deposit:__subpackages__", - "//proto/migration:__subpackages__", - "//proto/prysm/v1alpha1:__subpackages__", - "//proto/testing:__subpackages__", - "//runtime/interop:__subpackages__", - "//slasher/rpc:__subpackages__", - "//testing/benchmark:__pkg__", - "//testing/fuzz:__pkg__", - "//testing/spectest:__subpackages__", - "//testing/util:__pkg__", - "//tools/benchmark-files-gen:__pkg__", - "//tools/pcli:__pkg__", - ], + visibility = ["//visibility:public"], deps = [ "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", diff --git a/beacon-chain/state/stategen/BUILD.bazel b/beacon-chain/state/stategen/BUILD.bazel index 5aad61b60b..b5a0efbc4e 100644 --- a/beacon-chain/state/stategen/BUILD.bazel +++ b/beacon-chain/state/stategen/BUILD.bazel @@ -71,7 +71,7 @@ go_test( "//beacon-chain/db:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/blocks/testing:go_default_library", diff --git a/beacon-chain/state/stategen/hot_state_cache_test.go b/beacon-chain/state/stategen/hot_state_cache_test.go index dedb46371f..2d010acba3 100644 --- a/beacon-chain/state/stategen/hot_state_cache_test.go +++ b/beacon-chain/state/stategen/hot_state_cache_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/testing/assert" "github.com/prysmaticlabs/prysm/v3/testing/require" @@ -17,7 +17,7 @@ func TestHotStateCache_RoundTrip(t *testing.T) { assert.Equal(t, state.BeaconState(nil), s) assert.Equal(t, false, c.has(root), "Empty cache has an object") - s, err := v1.InitializeFromProto(ðpb.BeaconState{ + s, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 10, }) require.NoError(t, err) diff --git a/beacon-chain/state/v1/BUILD.bazel b/beacon-chain/state/v1/BUILD.bazel deleted file mode 100644 index b00f12683b..0000000000 --- a/beacon-chain/state/v1/BUILD.bazel +++ /dev/null @@ -1,56 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = [ - "doc.go", - "field_roots.go", - "getters_attestation.go", - "getters_block.go", - "getters_checkpoint.go", - "getters_eth1.go", - "getters_misc.go", - "getters_randao.go", - "getters_state.go", - "getters_validator.go", - "proofs.go", - "readonly_validator.go", - "setters_attestation.go", - "setters_block.go", - "setters_checkpoint.go", - "setters_eth1.go", - "setters_misc.go", - "setters_randao.go", - "setters_state.go", - "setters_validator.go", - "spec_parameters.go", - "state_trie.go", - "types.go", - "unsupported_getters.go", - "unsupported_setters.go", - ], - importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1", - visibility = ["//visibility:public"], - deps = [ - "//beacon-chain/state:go_default_library", - "//beacon-chain/state/fieldtrie:go_default_library", - "//beacon-chain/state/state-native:go_default_library", - "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/types:go_default_library", - "//config/fieldparams:go_default_library", - "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", - "//consensus-types/primitives:go_default_library", - "//container/slice:go_default_library", - "//crypto/hash:go_default_library", - "//encoding/bytesutil:go_default_library", - "//encoding/ssz:go_default_library", - "//proto/engine/v1:go_default_library", - "//proto/prysm/v1alpha1:go_default_library", - "//runtime/version:go_default_library", - "@com_github_pkg_errors//:go_default_library", - "@com_github_prysmaticlabs_go_bitfield//:go_default_library", - "@io_opencensus_go//trace:go_default_library", - "@org_golang_google_protobuf//proto:go_default_library", - ], -) diff --git a/beacon-chain/state/v1/doc.go b/beacon-chain/state/v1/doc.go deleted file mode 100644 index d47c3fb247..0000000000 --- a/beacon-chain/state/v1/doc.go +++ /dev/null @@ -1,40 +0,0 @@ -// Package v1 defines how the beacon chain state for Ethereum -// functions in the running beacon node, using an advanced, -// immutable implementation of the state data structure. -// -// BeaconState getters may be accessed from inside or outside the package. To -// avoid duplicating locks, we have internal and external versions of the -// getter The external function carries out the short-circuit conditions, -// obtains a read lock, then calls the internal function. The internal function -// carries out the short-circuit conditions and returns the required data -// without further locking, allowing it to be used by other package-level -// functions that already hold a lock. Hence the functions look something -// like this: -// -// func (b *BeaconState) Foo() uint64 { -// // Short-circuit conditions. -// if !b.hasInnerState() { -// return 0 -// } -// -// // Read lock. -// b.lock.RLock() -// defer b.lock.RUnlock() -// -// // Internal getter. -// return b.foo() -// } -// -// func (b *BeaconState) foo() uint64 { -// // Short-circuit conditions. -// if !b.hasInnerState() { -// return 0 -// } -// -// return b.state.foo -// } -// -// Although it is technically possible to remove the short-circuit conditions -// from the external function, that would require every read to obtain a lock -// even if the data was not present, leading to potential slowdowns. -package v1 diff --git a/beacon-chain/state/v1/field_roots.go b/beacon-chain/state/v1/field_roots.go deleted file mode 100644 index 671c8b7655..0000000000 --- a/beacon-chain/state/v1/field_roots.go +++ /dev/null @@ -1,14 +0,0 @@ -package v1 - -import ( - "context" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// computeFieldRoots returns the hash tree root computations of every field in -// the beacon state as a list of 32 byte roots. -func computeFieldRoots(ctx context.Context, state *ethpb.BeaconState) ([][]byte, error) { - return stateutil.ComputeFieldRootsWithHasherPhase0(ctx, state) -} diff --git a/beacon-chain/state/v1/getters_attestation.go b/beacon-chain/state/v1/getters_attestation.go deleted file mode 100644 index c25c177629..0000000000 --- a/beacon-chain/state/v1/getters_attestation.go +++ /dev/null @@ -1,55 +0,0 @@ -package v1 - -import ( - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// PreviousEpochAttestations corresponding to blocks on the beacon chain. -func (b *BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.PreviousEpochAttestations == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.previousEpochAttestations(), nil -} - -// previousEpochAttestations corresponding to blocks on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) previousEpochAttestations() []*ethpb.PendingAttestation { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyPendingAttestationSlice(b.state.PreviousEpochAttestations) -} - -// CurrentEpochAttestations corresponding to blocks on the beacon chain. -func (b *BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.CurrentEpochAttestations == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.currentEpochAttestations(), nil -} - -// currentEpochAttestations corresponding to blocks on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentEpochAttestations() []*ethpb.PendingAttestation { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyPendingAttestationSlice(b.state.CurrentEpochAttestations) -} diff --git a/beacon-chain/state/v1/getters_block.go b/beacon-chain/state/v1/getters_block.go deleted file mode 100644 index 22f7dfa864..0000000000 --- a/beacon-chain/state/v1/getters_block.go +++ /dev/null @@ -1,99 +0,0 @@ -package v1 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// LatestBlockHeader stored within the beacon state. -func (b *BeaconState) LatestBlockHeader() *ethpb.BeaconBlockHeader { - if !b.hasInnerState() { - return nil - } - if b.state.LatestBlockHeader == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.latestBlockHeader() -} - -// latestBlockHeader stored within the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) latestBlockHeader() *ethpb.BeaconBlockHeader { - if !b.hasInnerState() { - return nil - } - if b.state.LatestBlockHeader == nil { - return nil - } - - hdr := ðpb.BeaconBlockHeader{ - Slot: b.state.LatestBlockHeader.Slot, - ProposerIndex: b.state.LatestBlockHeader.ProposerIndex, - } - - parentRoot := make([]byte, len(b.state.LatestBlockHeader.ParentRoot)) - bodyRoot := make([]byte, len(b.state.LatestBlockHeader.BodyRoot)) - stateRoot := make([]byte, len(b.state.LatestBlockHeader.StateRoot)) - - copy(parentRoot, b.state.LatestBlockHeader.ParentRoot) - copy(bodyRoot, b.state.LatestBlockHeader.BodyRoot) - copy(stateRoot, b.state.LatestBlockHeader.StateRoot) - hdr.ParentRoot = parentRoot - hdr.BodyRoot = bodyRoot - hdr.StateRoot = stateRoot - return hdr -} - -// BlockRoots kept track of in the beacon state. -func (b *BeaconState) BlockRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.BlockRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.blockRoots() -} - -// blockRoots kept track of in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) blockRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.BlockRoots) -} - -// BlockRootAtIndex retrieves a specific block root based on an -// input index value. -func (b *BeaconState) BlockRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.BlockRoots == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.blockRootAtIndex(idx) -} - -// blockRootAtIndex retrieves a specific block root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) blockRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - return bytesutil.SafeCopyRootAtIndex(b.state.BlockRoots, idx) -} diff --git a/beacon-chain/state/v1/getters_checkpoint.go b/beacon-chain/state/v1/getters_checkpoint.go deleted file mode 100644 index 46de7eda8b..0000000000 --- a/beacon-chain/state/v1/getters_checkpoint.go +++ /dev/null @@ -1,160 +0,0 @@ -package v1 - -import ( - "bytes" - - "github.com/prysmaticlabs/go-bitfield" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// JustificationBits marking which epochs have been justified in the beacon chain. -func (b *BeaconState) JustificationBits() bitfield.Bitvector4 { - if !b.hasInnerState() { - return nil - } - if b.state.JustificationBits == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.justificationBits() -} - -// justificationBits marking which epochs have been justified in the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) justificationBits() bitfield.Bitvector4 { - if !b.hasInnerState() { - return nil - } - if b.state.JustificationBits == nil { - return nil - } - - res := make([]byte, len(b.state.JustificationBits.Bytes())) - copy(res, b.state.JustificationBits.Bytes()) - return res -} - -// PreviousJustifiedCheckpoint denoting an epoch and block root. -func (b *BeaconState) PreviousJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.PreviousJustifiedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.previousJustifiedCheckpoint() -} - -// previousJustifiedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) previousJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.PreviousJustifiedCheckpoint) -} - -// CurrentJustifiedCheckpoint denoting an epoch and block root. -func (b *BeaconState) CurrentJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.CurrentJustifiedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.currentJustifiedCheckpoint() -} - -// currentJustifiedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.CurrentJustifiedCheckpoint) -} - -// MatchCurrentJustifiedCheckpoint returns true if input justified checkpoint matches -// the current justified checkpoint in state. -func (b *BeaconState) MatchCurrentJustifiedCheckpoint(c *ethpb.Checkpoint) bool { - if !b.hasInnerState() { - return false - } - if b.state.CurrentJustifiedCheckpoint == nil { - return false - } - - if c.Epoch != b.state.CurrentJustifiedCheckpoint.Epoch { - return false - } - return bytes.Equal(c.Root, b.state.CurrentJustifiedCheckpoint.Root) -} - -// MatchPreviousJustifiedCheckpoint returns true if the input justified checkpoint matches -// the previous justified checkpoint in state. -func (b *BeaconState) MatchPreviousJustifiedCheckpoint(c *ethpb.Checkpoint) bool { - if !b.hasInnerState() { - return false - } - if b.state.PreviousJustifiedCheckpoint == nil { - return false - } - - if c.Epoch != b.state.PreviousJustifiedCheckpoint.Epoch { - return false - } - return bytes.Equal(c.Root, b.state.PreviousJustifiedCheckpoint.Root) -} - -// FinalizedCheckpoint denoting an epoch and block root. -func (b *BeaconState) FinalizedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.FinalizedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.finalizedCheckpoint() -} - -// finalizedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) finalizedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.FinalizedCheckpoint) -} - -// FinalizedCheckpointEpoch returns the epoch value of the finalized checkpoint. -func (b *BeaconState) FinalizedCheckpointEpoch() types.Epoch { - if !b.hasInnerState() { - return 0 - } - if b.state.FinalizedCheckpoint == nil { - return 0 - } - b.lock.RLock() - defer b.lock.RUnlock() - - return b.state.FinalizedCheckpoint.Epoch -} diff --git a/beacon-chain/state/v1/getters_eth1.go b/beacon-chain/state/v1/getters_eth1.go deleted file mode 100644 index d203f26f21..0000000000 --- a/beacon-chain/state/v1/getters_eth1.go +++ /dev/null @@ -1,91 +0,0 @@ -package v1 - -import ( - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// Eth1Data corresponding to the proof-of-work chain information stored in the beacon state. -func (b *BeaconState) Eth1Data() *ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1Data == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1Data() -} - -// eth1Data corresponding to the proof-of-work chain information stored in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1Data() *ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1Data == nil { - return nil - } - - return ethpb.CopyETH1Data(b.state.Eth1Data) -} - -// Eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain -// data retrieved from eth1. -func (b *BeaconState) Eth1DataVotes() []*ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1DataVotes == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1DataVotes() -} - -// eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain -// data retrieved from eth1. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1DataVotes() []*ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1DataVotes == nil { - return nil - } - - res := make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) - for i := 0; i < len(res); i++ { - res[i] = ethpb.CopyETH1Data(b.state.Eth1DataVotes[i]) - } - return res -} - -// Eth1DepositIndex corresponds to the index of the deposit made to the -// validator deposit contract at the time of this state's eth1 data. -func (b *BeaconState) Eth1DepositIndex() uint64 { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1DepositIndex() -} - -// eth1DepositIndex corresponds to the index of the deposit made to the -// validator deposit contract at the time of this state's eth1 data. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1DepositIndex() uint64 { - if !b.hasInnerState() { - return 0 - } - - return b.state.Eth1DepositIndex -} diff --git a/beacon-chain/state/v1/getters_misc.go b/beacon-chain/state/v1/getters_misc.go deleted file mode 100644 index 1b075d736a..0000000000 --- a/beacon-chain/state/v1/getters_misc.go +++ /dev/null @@ -1,163 +0,0 @@ -package v1 - -import ( - "github.com/prysmaticlabs/prysm/v3/config/params" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v3/runtime/version" -) - -// GenesisTime of the beacon state as a uint64. -func (b *BeaconState) GenesisTime() uint64 { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.genesisTime() -} - -// genesisTime of the beacon state as a uint64. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) genesisTime() uint64 { - if !b.hasInnerState() { - return 0 - } - - return b.state.GenesisTime -} - -// GenesisValidatorsRoot of the beacon state. -func (b *BeaconState) GenesisValidatorsRoot() []byte { - if !b.hasInnerState() { - return nil - } - if b.state.GenesisValidatorsRoot == nil { - return params.BeaconConfig().ZeroHash[:] - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.genesisValidatorsRoot() -} - -// genesisValidatorsRoot of the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) genesisValidatorsRoot() []byte { - if !b.hasInnerState() { - return nil - } - if b.state.GenesisValidatorsRoot == nil { - return params.BeaconConfig().ZeroHash[:] - } - - root := make([]byte, 32) - copy(root, b.state.GenesisValidatorsRoot) - return root -} - -// Version of the beacon state. This method -// is strictly meant to be used without a lock -// internally. -func (_ *BeaconState) Version() int { - return version.Phase0 -} - -// Slot of the current beacon chain state. -func (b *BeaconState) Slot() types.Slot { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.slot() -} - -// slot of the current beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) slot() types.Slot { - if !b.hasInnerState() { - return 0 - } - - return b.state.Slot -} - -// Fork version of the beacon chain. -func (b *BeaconState) Fork() *ethpb.Fork { - if !b.hasInnerState() { - return nil - } - if b.state.Fork == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.fork() -} - -// fork version of the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) fork() *ethpb.Fork { - if !b.hasInnerState() { - return nil - } - if b.state.Fork == nil { - return nil - } - - prevVersion := make([]byte, len(b.state.Fork.PreviousVersion)) - copy(prevVersion, b.state.Fork.PreviousVersion) - currVersion := make([]byte, len(b.state.Fork.CurrentVersion)) - copy(currVersion, b.state.Fork.CurrentVersion) - return ðpb.Fork{ - PreviousVersion: prevVersion, - CurrentVersion: currVersion, - Epoch: b.state.Fork.Epoch, - } -} - -// HistoricalRoots based on epochs stored in the beacon state. -func (b *BeaconState) HistoricalRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.HistoricalRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.historicalRoots() -} - -// historicalRoots based on epochs stored in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) historicalRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.HistoricalRoots) -} - -// balancesLength returns the length of the balances slice. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) balancesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.Balances == nil { - return 0 - } - - return len(b.state.Balances) -} diff --git a/beacon-chain/state/v1/getters_randao.go b/beacon-chain/state/v1/getters_randao.go deleted file mode 100644 index 7b6672aaa7..0000000000 --- a/beacon-chain/state/v1/getters_randao.go +++ /dev/null @@ -1,85 +0,0 @@ -package v1 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" -) - -// RandaoMixes of block proposers on the beacon chain. -func (b *BeaconState) RandaoMixes() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.RandaoMixes == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixes() -} - -// randaoMixes of block proposers on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixes() [][]byte { - if !b.hasInnerState() { - return nil - } - - return bytesutil.SafeCopy2dBytes(b.state.RandaoMixes) -} - -// RandaoMixAtIndex retrieves a specific block root based on an -// input index value. -func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.RandaoMixes == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixAtIndex(idx) -} - -// randaoMixAtIndex retrieves a specific block root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - return bytesutil.SafeCopyRootAtIndex(b.state.RandaoMixes, idx) -} - -// RandaoMixesLength returns the length of the randao mixes slice. -func (b *BeaconState) RandaoMixesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.RandaoMixes == nil { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixesLength() -} - -// randaoMixesLength returns the length of the randao mixes slice. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.RandaoMixes == nil { - return 0 - } - - return len(b.state.RandaoMixes) -} diff --git a/beacon-chain/state/v1/getters_state.go b/beacon-chain/state/v1/getters_state.go deleted file mode 100644 index abf55e16bf..0000000000 --- a/beacon-chain/state/v1/getters_state.go +++ /dev/null @@ -1,123 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// InnerStateUnsafe returns the pointer value of the underlying -// beacon state proto object, bypassing immutability. Use with care. -func (b *BeaconState) InnerStateUnsafe() interface{} { - if b == nil { - return nil - } - return b.state -} - -// CloneInnerState the beacon state into a protobuf for usage. -func (b *BeaconState) CloneInnerState() interface{} { - if b == nil || b.state == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - return ðpb.BeaconState{ - GenesisTime: b.genesisTime(), - GenesisValidatorsRoot: b.genesisValidatorsRoot(), - Slot: b.slot(), - Fork: b.fork(), - LatestBlockHeader: b.latestBlockHeader(), - BlockRoots: b.blockRoots(), - StateRoots: b.stateRoots(), - HistoricalRoots: b.historicalRoots(), - Eth1Data: b.eth1Data(), - Eth1DataVotes: b.eth1DataVotes(), - Eth1DepositIndex: b.eth1DepositIndex(), - Validators: b.validators(), - Balances: b.balances(), - RandaoMixes: b.randaoMixes(), - Slashings: b.slashings(), - PreviousEpochAttestations: b.previousEpochAttestations(), - CurrentEpochAttestations: b.currentEpochAttestations(), - JustificationBits: b.justificationBits(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(), - FinalizedCheckpoint: b.finalizedCheckpoint(), - } -} - -// hasInnerState detects if the internal reference to the state data structure -// is populated correctly. Returns false if nil. -func (b *BeaconState) hasInnerState() bool { - return b != nil && b.state != nil -} - -// StateRoots kept track of in the beacon state. -func (b *BeaconState) StateRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.StateRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.stateRoots() -} - -// StateRoots kept track of in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) stateRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.StateRoots) -} - -// StateRootAtIndex retrieves a specific state root based on an -// input index value. -func (b *BeaconState) StateRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.StateRoots == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.stateRootAtIndex(idx) -} - -// stateRootAtIndex retrieves a specific state root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) stateRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - return bytesutil.SafeCopyRootAtIndex(b.state.StateRoots, idx) -} - -// MarshalSSZ marshals the underlying beacon state to bytes. -func (b *BeaconState) MarshalSSZ() ([]byte, error) { - if !b.hasInnerState() { - return nil, errors.New("nil beacon state") - } - return b.state.MarshalSSZ() -} - -// ProtobufBeaconState transforms an input into beacon state in the form of protobuf. -// Error is returned if the input is not type protobuf beacon state. -func ProtobufBeaconState(s interface{}) (*ethpb.BeaconState, error) { - pbState, ok := s.(*ethpb.BeaconState) - if !ok { - return nil, errors.New("input is not type ethpb.BeaconState") - } - return pbState, nil -} diff --git a/beacon-chain/state/v1/getters_validator.go b/beacon-chain/state/v1/getters_validator.go deleted file mode 100644 index d6e6d08682..0000000000 --- a/beacon-chain/state/v1/getters_validator.go +++ /dev/null @@ -1,293 +0,0 @@ -package v1 - -import ( - "fmt" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// ValidatorIndexOutOfRangeError represents an error scenario where a validator does not exist -// at a given index in the validator's array. -type ValidatorIndexOutOfRangeError struct { - message string -} - -// NewValidatorIndexOutOfRangeError creates a new error instance. -func NewValidatorIndexOutOfRangeError(index types.ValidatorIndex) ValidatorIndexOutOfRangeError { - return ValidatorIndexOutOfRangeError{ - message: fmt.Sprintf("index %d out of range", index), - } -} - -// Error returns the underlying error message. -func (e *ValidatorIndexOutOfRangeError) Error() string { - return e.message -} - -// Validators participating in consensus on the beacon chain. -func (b *BeaconState) Validators() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.validators() -} - -// validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) validators() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - res := make([]*ethpb.Validator, len(b.state.Validators)) - for i := 0; i < len(res); i++ { - val := b.state.Validators[i] - if val == nil { - continue - } - res[i] = ethpb.CopyValidator(val) - } - return res -} - -// references of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. This does not -// copy fully and instead just copies the reference. -func (b *BeaconState) validatorsReferences() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - res := make([]*ethpb.Validator, len(b.state.Validators)) - for i := 0; i < len(res); i++ { - validator := b.state.Validators[i] - if validator == nil { - continue - } - // copy validator reference instead. - res[i] = validator - } - return res -} - -// ValidatorAtIndex is the validator at the provided index. -func (b *BeaconState) ValidatorAtIndex(idx types.ValidatorIndex) (*ethpb.Validator, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.Validators == nil { - return ðpb.Validator{}, nil - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - e := NewValidatorIndexOutOfRangeError(idx) - return nil, &e - } - - b.lock.RLock() - defer b.lock.RUnlock() - - val := b.state.Validators[idx] - return ethpb.CopyValidator(val), nil -} - -// ValidatorAtIndexReadOnly is the validator at the provided index. This method -// doesn't clone the validator. -func (b *BeaconState) ValidatorAtIndexReadOnly(idx types.ValidatorIndex) (state.ReadOnlyValidator, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.Validators == nil { - return nil, state.ErrNilValidatorsInState - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - e := NewValidatorIndexOutOfRangeError(idx) - return nil, &e - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return NewValidator(b.state.Validators[idx]) -} - -// ValidatorIndexByPubkey returns a given validator by its 48-byte public key. -func (b *BeaconState) ValidatorIndexByPubkey(key [fieldparams.BLSPubkeyLength]byte) (types.ValidatorIndex, bool) { - if b == nil || b.valMapHandler == nil || b.valMapHandler.IsNil() { - return 0, false - } - b.lock.RLock() - defer b.lock.RUnlock() - numOfVals := len(b.state.Validators) - - idx, ok := b.valMapHandler.Get(key) - if ok && types.ValidatorIndex(numOfVals) <= idx { - return types.ValidatorIndex(0), false - } - return idx, ok -} - -// PubkeyAtIndex returns the pubkey at the given -// validator index. -func (b *BeaconState) PubkeyAtIndex(idx types.ValidatorIndex) [fieldparams.BLSPubkeyLength]byte { - if !b.hasInnerState() { - return [fieldparams.BLSPubkeyLength]byte{} - } - if uint64(idx) >= uint64(len(b.state.Validators)) { - return [fieldparams.BLSPubkeyLength]byte{} - } - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.Validators[idx] == nil { - return [fieldparams.BLSPubkeyLength]byte{} - } - return bytesutil.ToBytes48(b.state.Validators[idx].PublicKey) -} - -// NumValidators returns the size of the validator registry. -func (b *BeaconState) NumValidators() int { - if !b.hasInnerState() { - return 0 - } - b.lock.RLock() - defer b.lock.RUnlock() - - return len(b.state.Validators) -} - -// ReadFromEveryValidator reads values from every validator and applies it to the provided function. -// -// WARNING: This method is potentially unsafe, as it exposes the actual validator registry. -func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if b.state.Validators == nil { - return errors.New("nil validators in state") - } - b.lock.RLock() - validators := b.state.Validators - b.lock.RUnlock() - - for i, v := range validators { - v, err := NewValidator(v) - if err != nil { - return err - } - if err := f(i, v); err != nil { - return err - } - } - return nil -} - -// Balances of validators participating in consensus on the beacon chain. -func (b *BeaconState) Balances() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Balances == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.balances() -} - -// balances of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) balances() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Balances == nil { - return nil - } - - res := make([]uint64, len(b.state.Balances)) - copy(res, b.state.Balances) - return res -} - -// BalanceAtIndex of validator with the provided index. -func (b *BeaconState) BalanceAtIndex(idx types.ValidatorIndex) (uint64, error) { - if !b.hasInnerState() { - return 0, ErrNilInnerState - } - if b.state.Balances == nil { - return 0, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if uint64(len(b.state.Balances)) <= uint64(idx) { - return 0, fmt.Errorf("index of %d does not exist", idx) - } - return b.state.Balances[idx], nil -} - -// BalancesLength returns the length of the balances slice. -func (b *BeaconState) BalancesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.Balances == nil { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.balancesLength() -} - -// Slashings of validators on the beacon chain. -func (b *BeaconState) Slashings() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Slashings == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.slashings() -} - -// slashings of validators on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) slashings() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Slashings == nil { - return nil - } - - res := make([]uint64, len(b.state.Slashings)) - copy(res, b.state.Slashings) - return res -} diff --git a/beacon-chain/state/v1/proofs.go b/beacon-chain/state/v1/proofs.go deleted file mode 100644 index a6f1536c44..0000000000 --- a/beacon-chain/state/v1/proofs.go +++ /dev/null @@ -1,54 +0,0 @@ -package v1 - -import ( - "context" - "encoding/binary" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" -) - -const ( - finalizedRootIndex = uint64(105) // Precomputed value. -) - -// FinalizedRootGeneralizedIndex for the beacon state. -func FinalizedRootGeneralizedIndex() uint64 { - return finalizedRootIndex -} - -// CurrentSyncCommitteeProof from the state's Merkle trie representation. -func (*BeaconState) CurrentSyncCommitteeProof(_ context.Context) ([][]byte, error) { - return nil, errors.New("CurrentSyncCommitteeProof() unsupported for v1 beacon state") -} - -// NextSyncCommitteeProof from the state's Merkle trie representation. -func (*BeaconState) NextSyncCommitteeProof(_ context.Context) ([][]byte, error) { - return nil, errors.New("NextSyncCommitteeProof() unsupported for v1 beacon state") -} - -// FinalizedRootProof crafts a Merkle proof for the finalized root -// contained within the finalized checkpoint of a beacon state. -func (b *BeaconState) FinalizedRootProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - cpt := b.state.FinalizedCheckpoint - // The epoch field of a finalized checkpoint is the neighbor - // index of the finalized root field in its Merkle tree representation - // of the checkpoint. This neighbor is the first element added to the proof. - epochBuf := make([]byte, 8) - binary.LittleEndian.PutUint64(epochBuf, uint64(cpt.Epoch)) - epochRoot := bytesutil.ToBytes32(epochBuf) - proof := make([][]byte, 0) - proof = append(proof, epochRoot[:]) - branch := fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(finalizedCheckpoint)) - proof = append(proof, branch...) - return proof, nil -} diff --git a/beacon-chain/state/v1/readonly_validator.go b/beacon-chain/state/v1/readonly_validator.go deleted file mode 100644 index 663f5b4c5a..0000000000 --- a/beacon-chain/state/v1/readonly_validator.go +++ /dev/null @@ -1,89 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -var ( - // ErrNilWrappedValidator returns when caller attempts to wrap a nil pointer validator. - ErrNilWrappedValidator = errors.New("nil validator cannot be wrapped as readonly") -) - -// readOnlyValidator returns a wrapper that only allows fields from a validator -// to be read, and prevents any modification of internal validator fields. -type readOnlyValidator struct { - validator *ethpb.Validator -} - -var _ = state.ReadOnlyValidator(readOnlyValidator{}) - -// NewValidator initializes the read only wrapper for validator. -func NewValidator(v *ethpb.Validator) (state.ReadOnlyValidator, error) { - rov := readOnlyValidator{ - validator: v, - } - if rov.IsNil() { - return nil, ErrNilWrappedValidator - } - return rov, nil -} - -// EffectiveBalance returns the effective balance of the -// read only validator. -func (v readOnlyValidator) EffectiveBalance() uint64 { - return v.validator.EffectiveBalance -} - -// ActivationEligibilityEpoch returns the activation eligibility epoch of the -// read only validator. -func (v readOnlyValidator) ActivationEligibilityEpoch() types.Epoch { - return v.validator.ActivationEligibilityEpoch -} - -// ActivationEpoch returns the activation epoch of the -// read only validator. -func (v readOnlyValidator) ActivationEpoch() types.Epoch { - return v.validator.ActivationEpoch -} - -// WithdrawableEpoch returns the withdrawable epoch of the -// read only validator. -func (v readOnlyValidator) WithdrawableEpoch() types.Epoch { - return v.validator.WithdrawableEpoch -} - -// ExitEpoch returns the exit epoch of the -// read only validator. -func (v readOnlyValidator) ExitEpoch() types.Epoch { - return v.validator.ExitEpoch -} - -// PublicKey returns the public key of the -// read only validator. -func (v readOnlyValidator) PublicKey() [fieldparams.BLSPubkeyLength]byte { - var pubkey [fieldparams.BLSPubkeyLength]byte - copy(pubkey[:], v.validator.PublicKey) - return pubkey -} - -// WithdrawalCredentials returns the withdrawal credentials of the -// read only validator. -func (v readOnlyValidator) WithdrawalCredentials() []byte { - creds := make([]byte, len(v.validator.WithdrawalCredentials)) - copy(creds, v.validator.WithdrawalCredentials) - return creds -} - -// Slashed returns the read only validator is slashed. -func (v readOnlyValidator) Slashed() bool { - return v.validator.Slashed -} - -// IsNil returns true if the validator is nil. -func (v readOnlyValidator) IsNil() bool { - return v.validator == nil -} diff --git a/beacon-chain/state/v1/setters_attestation.go b/beacon-chain/state/v1/setters_attestation.go deleted file mode 100644 index b50c0f1961..0000000000 --- a/beacon-chain/state/v1/setters_attestation.go +++ /dev/null @@ -1,98 +0,0 @@ -package v1 - -import ( - "fmt" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// RotateAttestations sets the previous epoch attestations to the current epoch attestations and -// then clears the current epoch attestations. -func (b *BeaconState) RotateAttestations() error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.setPreviousEpochAttestations(b.currentEpochAttestations()) - b.setCurrentEpochAttestations([]*ethpb.PendingAttestation{}) - return nil -} - -func (b *BeaconState) setPreviousEpochAttestations(val []*ethpb.PendingAttestation) { - b.sharedFieldReferences[previousEpochAttestations].MinusRef() - b.sharedFieldReferences[previousEpochAttestations] = stateutil.NewRef(1) - - b.state.PreviousEpochAttestations = val - b.markFieldAsDirty(previousEpochAttestations) - b.rebuildTrie[previousEpochAttestations] = true -} - -func (b *BeaconState) setCurrentEpochAttestations(val []*ethpb.PendingAttestation) { - b.sharedFieldReferences[currentEpochAttestations].MinusRef() - b.sharedFieldReferences[currentEpochAttestations] = stateutil.NewRef(1) - - b.state.CurrentEpochAttestations = val - b.markFieldAsDirty(currentEpochAttestations) - b.rebuildTrie[currentEpochAttestations] = true -} - -// AppendCurrentEpochAttestations for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendCurrentEpochAttestations(val *ethpb.PendingAttestation) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - atts := b.state.CurrentEpochAttestations - max := uint64(fieldparams.CurrentEpochAttestationsLength) - if uint64(len(atts)) >= max { - return fmt.Errorf("current pending attestation exceeds max length %d", max) - } - - if b.sharedFieldReferences[currentEpochAttestations].Refs() > 1 { - // Copy elements in underlying array by reference. - atts = make([]*ethpb.PendingAttestation, len(b.state.CurrentEpochAttestations)) - copy(atts, b.state.CurrentEpochAttestations) - b.sharedFieldReferences[currentEpochAttestations].MinusRef() - b.sharedFieldReferences[currentEpochAttestations] = stateutil.NewRef(1) - } - - b.state.CurrentEpochAttestations = append(atts, val) - b.markFieldAsDirty(currentEpochAttestations) - b.addDirtyIndices(currentEpochAttestations, []uint64{uint64(len(b.state.CurrentEpochAttestations) - 1)}) - return nil -} - -// AppendPreviousEpochAttestations for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendPreviousEpochAttestations(val *ethpb.PendingAttestation) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - atts := b.state.PreviousEpochAttestations - max := uint64(fieldparams.PreviousEpochAttestationsLength) - if uint64(len(atts)) >= max { - return fmt.Errorf("previous pending attestation exceeds max length %d", max) - } - - if b.sharedFieldReferences[previousEpochAttestations].Refs() > 1 { - atts = make([]*ethpb.PendingAttestation, len(b.state.PreviousEpochAttestations)) - copy(atts, b.state.PreviousEpochAttestations) - b.sharedFieldReferences[previousEpochAttestations].MinusRef() - b.sharedFieldReferences[previousEpochAttestations] = stateutil.NewRef(1) - } - - b.state.PreviousEpochAttestations = append(atts, val) - b.markFieldAsDirty(previousEpochAttestations) - b.addDirtyIndices(previousEpochAttestations, []uint64{uint64(len(b.state.PreviousEpochAttestations) - 1)}) - return nil -} diff --git a/beacon-chain/state/v1/setters_block.go b/beacon-chain/state/v1/setters_block.go deleted file mode 100644 index 3aada4089d..0000000000 --- a/beacon-chain/state/v1/setters_block.go +++ /dev/null @@ -1,68 +0,0 @@ -package v1 - -import ( - "fmt" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetLatestBlockHeader in the beacon state. -func (b *BeaconState) SetLatestBlockHeader(val *ethpb.BeaconBlockHeader) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.LatestBlockHeader = ethpb.CopyBeaconBlockHeader(val) - b.markFieldAsDirty(latestBlockHeader) - return nil -} - -// SetBlockRoots for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetBlockRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[blockRoots].MinusRef() - b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1) - - b.state.BlockRoots = val - b.markFieldAsDirty(blockRoots) - b.rebuildTrie[blockRoots] = true - return nil -} - -// UpdateBlockRootAtIndex for the beacon state. Updates the block root -// at a specific index to a new value. -func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.BlockRoots)) <= idx { - return fmt.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - r := b.state.BlockRoots - if ref := b.sharedFieldReferences[blockRoots]; ref.Refs() > 1 { - // Copy elements in underlying array by reference. - r = make([][]byte, len(b.state.BlockRoots)) - copy(r, b.state.BlockRoots) - ref.MinusRef() - b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1) - } - - r[idx] = blockRoot[:] - b.state.BlockRoots = r - - b.markFieldAsDirty(blockRoots) - b.addDirtyIndices(blockRoots, []uint64{idx}) - return nil -} diff --git a/beacon-chain/state/v1/setters_checkpoint.go b/beacon-chain/state/v1/setters_checkpoint.go deleted file mode 100644 index 0e815d634a..0000000000 --- a/beacon-chain/state/v1/setters_checkpoint.go +++ /dev/null @@ -1,58 +0,0 @@ -package v1 - -import ( - "github.com/prysmaticlabs/go-bitfield" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetJustificationBits for the beacon state. -func (b *BeaconState) SetJustificationBits(val bitfield.Bitvector4) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.JustificationBits = val - b.markFieldAsDirty(justificationBits) - return nil -} - -// SetPreviousJustifiedCheckpoint for the beacon state. -func (b *BeaconState) SetPreviousJustifiedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.PreviousJustifiedCheckpoint = val - b.markFieldAsDirty(previousJustifiedCheckpoint) - return nil -} - -// SetCurrentJustifiedCheckpoint for the beacon state. -func (b *BeaconState) SetCurrentJustifiedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.CurrentJustifiedCheckpoint = val - b.markFieldAsDirty(currentJustifiedCheckpoint) - return nil -} - -// SetFinalizedCheckpoint for the beacon state. -func (b *BeaconState) SetFinalizedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.FinalizedCheckpoint = val - b.markFieldAsDirty(finalizedCheckpoint) - return nil -} diff --git a/beacon-chain/state/v1/setters_eth1.go b/beacon-chain/state/v1/setters_eth1.go deleted file mode 100644 index 892f3b6b4c..0000000000 --- a/beacon-chain/state/v1/setters_eth1.go +++ /dev/null @@ -1,74 +0,0 @@ -package v1 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetEth1Data for the beacon state. -func (b *BeaconState) SetEth1Data(val *ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Eth1Data = val - b.markFieldAsDirty(eth1Data) - return nil -} - -// SetEth1DataVotes for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[eth1DataVotes].MinusRef() - b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) - - b.state.Eth1DataVotes = val - b.markFieldAsDirty(eth1DataVotes) - b.rebuildTrie[eth1DataVotes] = true - return nil -} - -// SetEth1DepositIndex for the beacon state. -func (b *BeaconState) SetEth1DepositIndex(val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Eth1DepositIndex = val - b.markFieldAsDirty(eth1DepositIndex) - return nil -} - -// AppendEth1DataVotes for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendEth1DataVotes(val *ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - votes := b.state.Eth1DataVotes - if b.sharedFieldReferences[eth1DataVotes].Refs() > 1 { - // Copy elements in underlying array by reference. - votes = make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) - copy(votes, b.state.Eth1DataVotes) - b.sharedFieldReferences[eth1DataVotes].MinusRef() - b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) - } - - b.state.Eth1DataVotes = append(votes, val) - b.markFieldAsDirty(eth1DataVotes) - b.addDirtyIndices(eth1DataVotes, []uint64{uint64(len(b.state.Eth1DataVotes) - 1)}) - return nil -} diff --git a/beacon-chain/state/v1/setters_misc.go b/beacon-chain/state/v1/setters_misc.go deleted file mode 100644 index 9553cd2834..0000000000 --- a/beacon-chain/state/v1/setters_misc.go +++ /dev/null @@ -1,182 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/crypto/hash" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "google.golang.org/protobuf/proto" -) - -// For our setters, we have a field reference counter through -// which we can track shared field references. This helps when -// performing state copies, as we simply copy the reference to the -// field. When we do need to modify these fields, we -// perform a full copy of the field. This is true of most of our -// fields except for the following below. -// 1) BlockRoots -// 2) StateRoots -// 3) Eth1DataVotes -// 4) RandaoMixes -// 5) HistoricalRoots -// 6) CurrentEpochAttestations -// 7) PreviousEpochAttestations -// 8) Validators -// -// The fields referred to above are instead copied by reference, where -// we simply copy the reference to the underlying object instead of the -// whole object. This is possible due to how we have structured our state -// as we copy the value on read, so as to ensure the underlying object is -// not mutated while it is being accessed during a state read. - -const ( - // This specifies the limit till which we process all dirty indices for a certain field. - // If we have more dirty indices than the threshold, then we rebuild the whole trie. This - // comes due to the fact that O(alogn) > O(n) beyond a certain value of a. - indicesLimit = 8000 -) - -// SetGenesisTime for the beacon state. -func (b *BeaconState) SetGenesisTime(val uint64) error { - b.lock.Lock() - defer b.lock.Unlock() - - b.state.GenesisTime = val - b.markFieldAsDirty(genesisTime) - return nil -} - -// SetGenesisValidatorsRoot for the beacon state. -func (b *BeaconState) SetGenesisValidatorsRoot(val []byte) error { - b.lock.Lock() - defer b.lock.Unlock() - - b.state.GenesisValidatorsRoot = val - b.markFieldAsDirty(genesisValidatorsRoot) - return nil -} - -// SetSlot for the beacon state. -func (b *BeaconState) SetSlot(val types.Slot) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Slot = val - b.markFieldAsDirty(slot) - return nil -} - -// SetFork version for the beacon chain. -func (b *BeaconState) SetFork(val *ethpb.Fork) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - fk, ok := proto.Clone(val).(*ethpb.Fork) - if !ok { - return errors.New("proto.Clone did not return a fork proto") - } - b.state.Fork = fk - b.markFieldAsDirty(fork) - return nil -} - -// SetHistoricalRoots for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetHistoricalRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[historicalRoots].MinusRef() - b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1) - - b.state.HistoricalRoots = val - b.markFieldAsDirty(historicalRoots) - return nil -} - -// AppendHistoricalRoots for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - roots := b.state.HistoricalRoots - if b.sharedFieldReferences[historicalRoots].Refs() > 1 { - roots = make([][]byte, len(b.state.HistoricalRoots)) - copy(roots, b.state.HistoricalRoots) - b.sharedFieldReferences[historicalRoots].MinusRef() - b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1) - } - - b.state.HistoricalRoots = append(roots, root[:]) - b.markFieldAsDirty(historicalRoots) - return nil -} - -// Recomputes the branch up the index in the Merkle trie representation -// of the beacon state. This method performs slice reads and the caller MUST -// hold the lock before calling this method. -func (b *BeaconState) recomputeRoot(idx int) { - hashFunc := hash.CustomSHA256Hasher() - layers := b.merkleLayers - // The merkle tree structure looks as follows: - // [[r1, r2, r3, r4], [parent1, parent2], [root]] - // Using information about the index which changed, idx, we recompute - // only its branch up the tree. - currentIndex := idx - root := b.merkleLayers[0][idx] - for i := 0; i < len(layers)-1; i++ { - isLeft := currentIndex%2 == 0 - neighborIdx := currentIndex ^ 1 - - neighbor := make([]byte, 32) - if layers[i] != nil && len(layers[i]) != 0 && neighborIdx < len(layers[i]) { - neighbor = layers[i][neighborIdx] - } - if isLeft { - parentHash := hashFunc(append(root, neighbor...)) - root = parentHash[:] - } else { - parentHash := hashFunc(append(neighbor, root...)) - root = parentHash[:] - } - parentIdx := currentIndex / 2 - // Update the cached layers at the parent index. - layers[i+1][parentIdx] = root - currentIndex = parentIdx - } - b.merkleLayers = layers -} - -func (b *BeaconState) markFieldAsDirty(field stateTypes.FieldIndex) { - b.dirtyFields[field] = true -} - -// addDirtyIndices adds the relevant dirty field indices, so that they -// can be recomputed. -func (b *BeaconState) addDirtyIndices(index stateTypes.FieldIndex, indices []uint64) { - if b.rebuildTrie[index] { - return - } - totalIndicesLen := len(b.dirtyIndices[index]) + len(indices) - if totalIndicesLen > indicesLimit { - b.rebuildTrie[index] = true - b.dirtyIndices[index] = []uint64{} - } else { - b.dirtyIndices[index] = append(b.dirtyIndices[index], indices...) - } -} diff --git a/beacon-chain/state/v1/setters_randao.go b/beacon-chain/state/v1/setters_randao.go deleted file mode 100644 index 938952ab97..0000000000 --- a/beacon-chain/state/v1/setters_randao.go +++ /dev/null @@ -1,53 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetRandaoMixes for the beacon state. Updates the entire -// randao mixes to a new value by overwriting the previous one. -func (b *BeaconState) SetRandaoMixes(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[randaoMixes].MinusRef() - b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1) - - b.state.RandaoMixes = val - b.markFieldAsDirty(randaoMixes) - b.rebuildTrie[randaoMixes] = true - return nil -} - -// UpdateRandaoMixesAtIndex for the beacon state. Updates the randao mixes -// at a specific index to a new value. -func (b *BeaconState) UpdateRandaoMixesAtIndex(idx uint64, val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.RandaoMixes)) <= idx { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - mixes := b.state.RandaoMixes - if refs := b.sharedFieldReferences[randaoMixes].Refs(); refs > 1 { - // Copy elements in underlying array by reference. - mixes = make([][]byte, len(b.state.RandaoMixes)) - copy(mixes, b.state.RandaoMixes) - b.sharedFieldReferences[randaoMixes].MinusRef() - b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1) - } - - mixes[idx] = val - b.state.RandaoMixes = mixes - b.markFieldAsDirty(randaoMixes) - b.addDirtyIndices(randaoMixes, []uint64{idx}) - - return nil -} diff --git a/beacon-chain/state/v1/setters_state.go b/beacon-chain/state/v1/setters_state.go deleted file mode 100644 index ed8b1dc179..0000000000 --- a/beacon-chain/state/v1/setters_state.go +++ /dev/null @@ -1,59 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetStateRoots for the beacon state. Updates the state roots -// to a new value by overwriting the previous value. -func (b *BeaconState) SetStateRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[stateRoots].MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - - b.state.StateRoots = val - b.markFieldAsDirty(stateRoots) - b.rebuildTrie[stateRoots] = true - return nil -} - -// UpdateStateRootAtIndex for the beacon state. Updates the state root -// at a specific index to a new value. -func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - - b.lock.RLock() - if uint64(len(b.state.StateRoots)) <= idx { - b.lock.RUnlock() - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.RUnlock() - - b.lock.Lock() - defer b.lock.Unlock() - - // Check if we hold the only reference to the shared state roots slice. - r := b.state.StateRoots - if ref := b.sharedFieldReferences[stateRoots]; ref.Refs() > 1 { - // Copy elements in underlying array by reference. - r = make([][]byte, len(b.state.StateRoots)) - copy(r, b.state.StateRoots) - ref.MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - } - - r[idx] = stateRoot[:] - b.state.StateRoots = r - - b.markFieldAsDirty(stateRoots) - b.addDirtyIndices(stateRoots, []uint64{idx}) - return nil -} diff --git a/beacon-chain/state/v1/setters_validator.go b/beacon-chain/state/v1/setters_validator.go deleted file mode 100644 index 2e05213edc..0000000000 --- a/beacon-chain/state/v1/setters_validator.go +++ /dev/null @@ -1,228 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetValidators for the beacon state. Updates the entire -// to a new value by overwriting the previous one. -func (b *BeaconState) SetValidators(val []*ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Validators = val - b.sharedFieldReferences[validators].MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - b.markFieldAsDirty(validators) - b.rebuildTrie[validators] = true - b.valMapHandler = stateutil.NewValMapHandler(b.state.Validators) - return nil -} - -// ApplyToEveryValidator applies the provided callback function to each validator in the -// validator registry. -func (b *BeaconState) ApplyToEveryValidator(f func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - v := b.state.Validators - if ref := b.sharedFieldReferences[validators]; ref.Refs() > 1 { - v = b.validatorsReferences() - ref.MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - b.lock.Unlock() - var changedVals []uint64 - for i, val := range v { - changed, newVal, err := f(i, val) - if err != nil { - return err - } - if changed { - changedVals = append(changedVals, uint64(i)) - v[i] = newVal - } - } - - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Validators = v - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, changedVals) - - return nil -} - -// UpdateValidatorAtIndex for the beacon state. Updates the validator -// at a specific index to a new value. -func (b *BeaconState) UpdateValidatorAtIndex(idx types.ValidatorIndex, val *ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - v := b.state.Validators - if ref := b.sharedFieldReferences[validators]; ref.Refs() > 1 { - v = b.validatorsReferences() - ref.MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - - v[idx] = val - b.state.Validators = v - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, []uint64{uint64(idx)}) - - return nil -} - -// SetBalances for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetBalances(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - - b.state.Balances = val - b.markFieldAsDirty(balances) - b.rebuildTrie[balances] = true - return nil -} - -// UpdateBalancesAtIndex for the beacon state. This method updates the balance -// at a specific index to a new value. -func (b *BeaconState) UpdateBalancesAtIndex(idx types.ValidatorIndex, val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Balances)) <= uint64(idx) { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - bals := b.state.Balances - if b.sharedFieldReferences[balances].Refs() > 1 { - bals = b.balances() - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - } - - bals[idx] = val - b.state.Balances = bals - b.markFieldAsDirty(balances) - b.addDirtyIndices(balances, []uint64{uint64(idx)}) - return nil -} - -// SetSlashings for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetSlashings(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[slashings].MinusRef() - b.sharedFieldReferences[slashings] = stateutil.NewRef(1) - - b.state.Slashings = val - b.markFieldAsDirty(slashings) - return nil -} - -// UpdateSlashingsAtIndex for the beacon state. Updates the slashings -// at a specific index to a new value. -func (b *BeaconState) UpdateSlashingsAtIndex(idx, val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Slashings)) <= idx { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - s := b.state.Slashings - if b.sharedFieldReferences[slashings].Refs() > 1 { - s = b.slashings() - b.sharedFieldReferences[slashings].MinusRef() - b.sharedFieldReferences[slashings] = stateutil.NewRef(1) - } - - s[idx] = val - - b.state.Slashings = s - - b.markFieldAsDirty(slashings) - return nil -} - -// AppendValidator for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendValidator(val *ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - vals := b.state.Validators - if b.sharedFieldReferences[validators].Refs() > 1 { - vals = b.validatorsReferences() - b.sharedFieldReferences[validators].MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - - // append validator to slice - b.state.Validators = append(vals, val) - valIdx := types.ValidatorIndex(len(b.state.Validators) - 1) - - b.valMapHandler.Set(bytesutil.ToBytes48(val.PublicKey), valIdx) - - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, []uint64{uint64(valIdx)}) - return nil -} - -// AppendBalance for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendBalance(bal uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - bals := b.state.Balances - if b.sharedFieldReferences[balances].Refs() > 1 { - bals = b.balances() - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - } - - b.state.Balances = append(bals, bal) - balIdx := len(b.state.Balances) - 1 - b.markFieldAsDirty(balances) - b.addDirtyIndices(balances, []uint64{uint64(balIdx)}) - return nil -} diff --git a/beacon-chain/state/v1/spec_parameters.go b/beacon-chain/state/v1/spec_parameters.go deleted file mode 100644 index 376e56b745..0000000000 --- a/beacon-chain/state/v1/spec_parameters.go +++ /dev/null @@ -1,11 +0,0 @@ -package v1 - -import "github.com/prysmaticlabs/prysm/v3/config/params" - -func (b *BeaconState) ProportionalSlashingMultiplier() (uint64, error) { - return params.BeaconConfig().ProportionalSlashingMultiplier, nil -} - -func (b *BeaconState) InactivityPenaltyQuotient() (uint64, error) { - return params.BeaconConfig().InactivityPenaltyQuotient, nil -} diff --git a/beacon-chain/state/v1/state_trie.go b/beacon-chain/state/v1/state_trie.go deleted file mode 100644 index 89effc0961..0000000000 --- a/beacon-chain/state/v1/state_trie.go +++ /dev/null @@ -1,410 +0,0 @@ -package v1 - -import ( - "context" - "runtime" - "sort" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - "github.com/prysmaticlabs/prysm/v3/config/params" - "github.com/prysmaticlabs/prysm/v3/container/slice" - "github.com/prysmaticlabs/prysm/v3/crypto/hash" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/v3/encoding/ssz" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "go.opencensus.io/trace" - "google.golang.org/protobuf/proto" -) - -// InitializeFromProto the beacon state from a protobuf representation. -func InitializeFromProto(st *ethpb.BeaconState) (state.BeaconState, error) { - return statenative.InitializeFromProtoUnsafePhase0(proto.Clone(st).(*ethpb.BeaconState)) -} - -// InitializeFromProtoUnsafe directly uses the beacon state protobuf pointer -// and sets it as the inner state of the BeaconState type. -func InitializeFromProtoUnsafe(st *ethpb.BeaconState) (state.BeaconState, error) { - return statenative.InitializeFromProtoUnsafePhase0(st) -} - -// Copy returns a deep copy of the beacon state. -func (b *BeaconState) Copy() state.BeaconState { - if !b.hasInnerState() { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - fieldCount := params.BeaconConfig().BeaconStateFieldCount - dst := &BeaconState{ - state: ðpb.BeaconState{ - // Primitive types, safe to copy. - GenesisTime: b.state.GenesisTime, - Slot: b.state.Slot, - Eth1DepositIndex: b.state.Eth1DepositIndex, - - // Large arrays, infrequently changed, constant size. - RandaoMixes: b.state.RandaoMixes, - StateRoots: b.state.StateRoots, - BlockRoots: b.state.BlockRoots, - PreviousEpochAttestations: b.state.PreviousEpochAttestations, - CurrentEpochAttestations: b.state.CurrentEpochAttestations, - Slashings: b.state.Slashings, - Eth1DataVotes: b.state.Eth1DataVotes, - - // Large arrays, increases over time. - Validators: b.state.Validators, - Balances: b.state.Balances, - HistoricalRoots: b.state.HistoricalRoots, - - // Everything else, too small to be concerned about, constant size. - Fork: b.fork(), - LatestBlockHeader: b.latestBlockHeader(), - Eth1Data: b.eth1Data(), - JustificationBits: b.justificationBits(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(), - FinalizedCheckpoint: b.finalizedCheckpoint(), - GenesisValidatorsRoot: b.genesisValidatorsRoot(), - }, - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - sharedFieldReferences: make(map[types.FieldIndex]*stateutil.Reference, 10), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - - // Share the reference to validator index map. - valMapHandler: b.valMapHandler, - } - - for field, ref := range b.sharedFieldReferences { - ref.AddRef() - dst.sharedFieldReferences[field] = ref - } - - // Increment ref for validator map - b.valMapHandler.AddRef() - - for i := range b.dirtyFields { - dst.dirtyFields[i] = true - } - - for i := range b.dirtyIndices { - indices := make([]uint64, len(b.dirtyIndices[i])) - copy(indices, b.dirtyIndices[i]) - dst.dirtyIndices[i] = indices - } - - for i := range b.rebuildTrie { - dst.rebuildTrie[i] = true - } - - for fldIdx, fieldTrie := range b.stateFieldLeaves { - dst.stateFieldLeaves[fldIdx] = fieldTrie - if fieldTrie.FieldReference() != nil { - fieldTrie.Lock() - fieldTrie.FieldReference().AddRef() - fieldTrie.Unlock() - } - } - - if b.merkleLayers != nil { - dst.merkleLayers = make([][][]byte, len(b.merkleLayers)) - for i, layer := range b.merkleLayers { - dst.merkleLayers[i] = make([][]byte, len(layer)) - for j, content := range layer { - dst.merkleLayers[i][j] = make([]byte, len(content)) - copy(dst.merkleLayers[i][j], content) - } - } - } - - state.StateCount.Inc() - // Finalizer runs when dst is being destroyed in garbage collection. - runtime.SetFinalizer(dst, finalizerCleanup) - return dst -} - -// HashTreeRoot of the beacon state retrieves the Merkle root of the trie -// representation of the beacon state based on the Ethereum Simple Serialize specification. -func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) { - ctx, span := trace.StartSpan(ctx, "beaconState.HashTreeRoot") - defer span.End() - - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return [32]byte{}, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return [32]byte{}, err - } - return bytesutil.ToBytes32(b.merkleLayers[len(b.merkleLayers)-1][0]), nil -} - -// Initializes the Merkle layers for the beacon state if they are empty. -// -// WARNING: Caller must acquire the mutex before using. -func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error { - if len(b.merkleLayers) > 0 { - return nil - } - fieldRoots, err := computeFieldRoots(ctx, b.state) - if err != nil { - return err - } - layers := stateutil.Merkleize(fieldRoots) - b.merkleLayers = layers - b.dirtyFields = make(map[types.FieldIndex]bool, params.BeaconConfig().BeaconStateFieldCount) - return nil -} - -// Recomputes the Merkle layers for the dirty fields in the state. -// -// WARNING: Caller must acquire the mutex before using. -func (b *BeaconState) recomputeDirtyFields(ctx context.Context) error { - for field := range b.dirtyFields { - root, err := b.rootSelector(ctx, field) - if err != nil { - return err - } - b.merkleLayers[0][field] = root[:] - b.recomputeRoot(int(field)) - delete(b.dirtyFields, field) - } - return nil -} - -// FieldReferencesCount returns the reference count held by each field. This -// also includes the field trie held by each field. -func (b *BeaconState) FieldReferencesCount() map[string]uint64 { - refMap := make(map[string]uint64) - b.lock.RLock() - defer b.lock.RUnlock() - for i, f := range b.sharedFieldReferences { - refMap[i.String(b.Version())] = uint64(f.Refs()) - } - for i, f := range b.stateFieldLeaves { - numOfRefs := uint64(f.FieldReference().Refs()) - f.RLock() - if !f.Empty() { - refMap[i.String(b.Version())+"_trie"] = numOfRefs - } - f.RUnlock() - } - return refMap -} - -// IsNil checks if the state and the underlying proto -// object are nil. -func (b *BeaconState) IsNil() bool { - return b == nil || b.state == nil -} - -func (b *BeaconState) rootSelector(ctx context.Context, field types.FieldIndex) ([32]byte, error) { - ctx, span := trace.StartSpan(ctx, "beaconState.rootSelector") - defer span.End() - span.AddAttributes(trace.StringAttribute("field", field.String(b.Version()))) - - hasher := hash.CustomSHA256Hasher() - switch field { - case genesisTime: - return ssz.Uint64Root(b.state.GenesisTime), nil - case genesisValidatorsRoot: - return bytesutil.ToBytes32(b.state.GenesisValidatorsRoot), nil - case slot: - return ssz.Uint64Root(uint64(b.state.Slot)), nil - case eth1DepositIndex: - return ssz.Uint64Root(b.state.Eth1DepositIndex), nil - case fork: - return ssz.ForkRoot(b.state.Fork) - case latestBlockHeader: - return stateutil.BlockHeaderRoot(b.state.LatestBlockHeader) - case blockRoots: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.BlockRoots, fieldparams.BlockRootsLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(blockRoots, b.state.BlockRoots) - case stateRoots: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.StateRoots, fieldparams.StateRootsLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(stateRoots, b.state.StateRoots) - case historicalRoots: - return ssz.ByteArrayRootWithLimit(b.state.HistoricalRoots, fieldparams.HistoricalRootsLength) - case eth1Data: - return stateutil.Eth1Root(hasher, b.state.Eth1Data) - case eth1DataVotes: - if b.rebuildTrie[field] { - err := b.resetFieldTrie( - field, - b.state.Eth1DataVotes, - fieldparams.Eth1DataVotesLength, - ) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(field, b.state.Eth1DataVotes) - case validators: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.Validators, fieldparams.ValidatorRegistryLimit) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, validators) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(validators, b.state.Validators) - case balances: - if b.rebuildTrie[field] { - maxBalCap := uint64(fieldparams.ValidatorRegistryLimit) - elemSize := uint64(8) - balLimit := (maxBalCap*elemSize + 31) / 32 - err := b.resetFieldTrie(field, b.state.Balances, balLimit) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(balances, b.state.Balances) - case randaoMixes: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.RandaoMixes, fieldparams.RandaoMixesLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(randaoMixes, b.state.RandaoMixes) - case slashings: - return ssz.SlashingsRoot(b.state.Slashings) - case previousEpochAttestations: - if b.rebuildTrie[field] { - err := b.resetFieldTrie( - field, - b.state.PreviousEpochAttestations, - fieldparams.PreviousEpochAttestationsLength, - ) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(field, b.state.PreviousEpochAttestations) - case currentEpochAttestations: - if b.rebuildTrie[field] { - err := b.resetFieldTrie( - field, - b.state.CurrentEpochAttestations, - fieldparams.CurrentEpochAttestationsLength, - ) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(field, b.state.CurrentEpochAttestations) - case justificationBits: - return bytesutil.ToBytes32(b.state.JustificationBits), nil - case previousJustifiedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.PreviousJustifiedCheckpoint) - case currentJustifiedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.CurrentJustifiedCheckpoint) - case finalizedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.FinalizedCheckpoint) - } - return [32]byte{}, errors.New("invalid field index provided") -} - -func (b *BeaconState) recomputeFieldTrie(index types.FieldIndex, elements interface{}) ([32]byte, error) { - fTrie := b.stateFieldLeaves[index] - fTrieMutex := fTrie.RWMutex - // We can't lock the trie directly because the trie's variable gets reassigned, - // and therefore we would call Unlock() on a different object. - fTrieMutex.Lock() - - if fTrie.Empty() { - err := b.resetFieldTrie(index, elements, fTrie.Length()) - if err != nil { - fTrieMutex.Unlock() - return [32]byte{}, err - } - // Reduce reference count as we are instantiating a new trie. - fTrie.FieldReference().MinusRef() - fTrieMutex.Unlock() - return b.stateFieldLeaves[index].TrieRoot() - } - - if fTrie.FieldReference().Refs() > 1 { - fTrie.FieldReference().MinusRef() - newTrie := fTrie.TransferTrie() - b.stateFieldLeaves[index] = newTrie - fTrie = newTrie - } - fTrieMutex.Unlock() - - // remove duplicate indexes - b.dirtyIndices[index] = slice.SetUint64(b.dirtyIndices[index]) - // sort indexes again - sort.Slice(b.dirtyIndices[index], func(i int, j int) bool { - return b.dirtyIndices[index][i] < b.dirtyIndices[index][j] - }) - root, err := fTrie.RecomputeTrie(b.dirtyIndices[index], elements) - if err != nil { - return [32]byte{}, err - } - b.dirtyIndices[index] = []uint64{} - return root, nil -} - -func (b *BeaconState) resetFieldTrie(index types.FieldIndex, elements interface{}, length uint64) error { - fTrie, err := fieldtrie.NewFieldTrie(index, fieldMap[index], elements, length) - if err != nil { - return err - } - b.stateFieldLeaves[index] = fTrie - b.dirtyIndices[index] = []uint64{} - return nil -} - -func finalizerCleanup(b *BeaconState) { - fieldCount := params.BeaconConfig().BeaconStateFieldCount - for field, v := range b.sharedFieldReferences { - v.MinusRef() - if b.stateFieldLeaves[field].FieldReference() != nil { - b.stateFieldLeaves[field].FieldReference().MinusRef() - } - } - for i := 0; i < fieldCount; i++ { - field := types.FieldIndex(i) - delete(b.stateFieldLeaves, field) - delete(b.dirtyIndices, field) - delete(b.dirtyFields, field) - delete(b.sharedFieldReferences, field) - delete(b.stateFieldLeaves, field) - } - state.StateCount.Sub(1) -} diff --git a/beacon-chain/state/v1/types.go b/beacon-chain/state/v1/types.go deleted file mode 100644 index 2d3994f0c4..0000000000 --- a/beacon-chain/state/v1/types.go +++ /dev/null @@ -1,78 +0,0 @@ -package v1 - -import ( - "sync" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - "github.com/prysmaticlabs/prysm/v3/config/params" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// Ensure type BeaconState below implements BeaconState interface. -var _ state.BeaconState = (*BeaconState)(nil) - -func init() { - fieldMap = make(map[types.FieldIndex]types.DataType, params.BeaconConfig().BeaconStateFieldCount) - // Initialize the fixed sized arrays. - fieldMap[types.BlockRoots] = types.BasicArray - fieldMap[types.StateRoots] = types.BasicArray - fieldMap[types.RandaoMixes] = types.BasicArray - - // Initialize the composite arrays. - fieldMap[types.Eth1DataVotes] = types.CompositeArray - fieldMap[types.Validators] = types.CompositeArray - fieldMap[types.PreviousEpochAttestations] = types.CompositeArray - fieldMap[types.CurrentEpochAttestations] = types.CompositeArray - fieldMap[types.Balances] = types.CompressedArray -} - -// fieldMap keeps track of each field -// to its corresponding data type. -var fieldMap map[types.FieldIndex]types.DataType - -// ErrNilInnerState returns when the inner state is nil and no copy set or get -// operations can be performed on state. -var ErrNilInnerState = errors.New("nil inner state") - -// 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(). -type BeaconState struct { - state *ethpb.BeaconState - lock sync.RWMutex - dirtyFields map[types.FieldIndex]bool - dirtyIndices map[types.FieldIndex][]uint64 - stateFieldLeaves map[types.FieldIndex]*fieldtrie.FieldTrie - rebuildTrie map[types.FieldIndex]bool - valMapHandler *stateutil.ValidatorMapHandler - merkleLayers [][][]byte - sharedFieldReferences map[types.FieldIndex]*stateutil.Reference -} - -// Field Aliases for values from the types package. -const ( - genesisTime = types.GenesisTime - genesisValidatorsRoot = types.GenesisValidatorsRoot - slot = types.Slot - fork = types.Fork - latestBlockHeader = types.LatestBlockHeader - blockRoots = types.BlockRoots - stateRoots = types.StateRoots - historicalRoots = types.HistoricalRoots - eth1Data = types.Eth1Data - eth1DataVotes = types.Eth1DataVotes - eth1DepositIndex = types.Eth1DepositIndex - validators = types.Validators - balances = types.Balances - randaoMixes = types.RandaoMixes - slashings = types.Slashings - previousEpochAttestations = types.PreviousEpochAttestations - currentEpochAttestations = types.CurrentEpochAttestations - justificationBits = types.JustificationBits - previousJustifiedCheckpoint = types.PreviousJustifiedCheckpoint - currentJustifiedCheckpoint = types.CurrentJustifiedCheckpoint - finalizedCheckpoint = types.FinalizedCheckpoint -) diff --git a/beacon-chain/state/v1/unsupported_getters.go b/beacon-chain/state/v1/unsupported_getters.go deleted file mode 100644 index f034afd211..0000000000 --- a/beacon-chain/state/v1/unsupported_getters.go +++ /dev/null @@ -1,42 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// CurrentEpochParticipation is not supported for phase 0 beacon state. -func (*BeaconState) CurrentEpochParticipation() ([]byte, error) { - return nil, errors.New("CurrentEpochParticipation is not supported for phase 0 beacon state") -} - -// PreviousEpochParticipation is not supported for phase 0 beacon state. -func (*BeaconState) PreviousEpochParticipation() ([]byte, error) { - return nil, errors.New("PreviousEpochParticipation is not supported for phase 0 beacon state") -} - -// UnrealizedCheckpointBalances is not supported for phase 0 beacon state. -func (*BeaconState) UnrealizedCheckpointBalances() (uint64, uint64, uint64, error) { - return 0, 0, 0, errors.New("UnrealizedCheckpointBalances is not supported for phase0 beacon state") -} - -// InactivityScores is not supported for phase 0 beacon state. -func (*BeaconState) InactivityScores() ([]uint64, error) { - return nil, errors.New("InactivityScores is not supported for phase 0 beacon state") -} - -// CurrentSyncCommittee is not supported for phase 0 beacon state. -func (*BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) { - return nil, errors.New("CurrentSyncCommittee is not supported for phase 0 beacon state") -} - -// NextSyncCommittee is not supported for phase 0 beacon state. -func (*BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) { - return nil, errors.New("NextSyncCommittee is not supported for phase 0 beacon state") -} - -// LatestExecutionPayloadHeader is not supported for phase 0 beacon state. -func (*BeaconState) LatestExecutionPayloadHeader() (*enginev1.ExecutionPayloadHeader, error) { - return nil, errors.New("LatestExecutionPayloadHeader is not supported for phase 0 beacon state") -} diff --git a/beacon-chain/state/v1/unsupported_setters.go b/beacon-chain/state/v1/unsupported_setters.go deleted file mode 100644 index da6f50f01d..0000000000 --- a/beacon-chain/state/v1/unsupported_setters.go +++ /dev/null @@ -1,62 +0,0 @@ -package v1 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// AppendCurrentParticipationBits is not supported for phase 0 beacon state. -func (*BeaconState) AppendCurrentParticipationBits(_ byte) error { - return errors.New("AppendCurrentParticipationBits is not supported for phase 0 beacon state") -} - -// AppendPreviousParticipationBits is not supported for phase 0 beacon state. -func (*BeaconState) AppendPreviousParticipationBits(_ byte) error { - return errors.New("AppendPreviousParticipationBits is not supported for phase 0 beacon state") -} - -// AppendInactivityScore is not supported for phase 0 beacon state. -func (*BeaconState) AppendInactivityScore(_ uint64) error { - return errors.New("AppendInactivityScore is not supported for phase 0 beacon state") -} - -// SetCurrentSyncCommittee is not supported for phase 0 beacon state. -func (*BeaconState) SetCurrentSyncCommittee(_ *ethpb.SyncCommittee) error { - return errors.New("SetCurrentSyncCommittee is not supported for phase 0 beacon state") -} - -// SetNextSyncCommittee is not supported for phase 0 beacon state. -func (*BeaconState) SetNextSyncCommittee(_ *ethpb.SyncCommittee) error { - return errors.New("SetNextSyncCommittee is not supported for phase 0 beacon state") -} - -// SetPreviousParticipationBits is not supported for phase 0 beacon state. -func (*BeaconState) SetPreviousParticipationBits(_ []byte) error { - return errors.New("SetPreviousParticipationBits is not supported for phase 0 beacon state") -} - -// SetCurrentParticipationBits is not supported for phase 0 beacon state. -func (*BeaconState) SetCurrentParticipationBits(_ []byte) error { - return errors.New("SetCurrentParticipationBits is not supported for phase 0 beacon state") -} - -// ModifyPreviousParticipationBits is not supported for phase 0 beacon state. -func (b *BeaconState) ModifyPreviousParticipationBits(_ func(val []byte) ([]byte, error)) error { - return errors.New("ModifyPreviousParticipationBits is not supported for phase 0 beacon state") -} - -// ModifyCurrentParticipationBits is not supported for phase 0 beacon state. -func (b *BeaconState) ModifyCurrentParticipationBits(_ func(val []byte) ([]byte, error)) error { - return errors.New("ModifyCurrentParticipationBits is not supported for phase 0 beacon state") -} - -// SetInactivityScores is not supported for phase 0 beacon state. -func (*BeaconState) SetInactivityScores(_ []uint64) error { - return errors.New("SetInactivityScores is not supported for phase 0 beacon state") -} - -// SetLatestExecutionPayloadHeader is not supported for phase 0 beacon state. -func (*BeaconState) SetLatestExecutionPayloadHeader(_ interfaces.ExecutionData) error { - return errors.New("SetLatestExecutionPayloadHeader is not supported for phase 0 beacon state") -} diff --git a/beacon-chain/state/v2/BUILD.bazel b/beacon-chain/state/v2/BUILD.bazel deleted file mode 100644 index 6a2654b09b..0000000000 --- a/beacon-chain/state/v2/BUILD.bazel +++ /dev/null @@ -1,59 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = [ - "deprecated_getters.go", - "deprecated_setters.go", - "error.go", - "field_roots.go", - "getters_block.go", - "getters_checkpoint.go", - "getters_eth1.go", - "getters_misc.go", - "getters_participation.go", - "getters_randao.go", - "getters_state.go", - "getters_sync_committee.go", - "getters_validator.go", - "proofs.go", - "setters_block.go", - "setters_checkpoint.go", - "setters_eth1.go", - "setters_misc.go", - "setters_participation.go", - "setters_randao.go", - "setters_state.go", - "setters_sync_committee.go", - "setters_validator.go", - "spec_parameters.go", - "state_trie.go", - "types.go", - ], - importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2", - visibility = ["//visibility:public"], - deps = [ - "//beacon-chain/core/time:go_default_library", - "//beacon-chain/state:go_default_library", - "//beacon-chain/state/fieldtrie:go_default_library", - "//beacon-chain/state/state-native:go_default_library", - "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/types:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//config/fieldparams:go_default_library", - "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", - "//consensus-types/primitives:go_default_library", - "//container/slice:go_default_library", - "//crypto/hash:go_default_library", - "//encoding/bytesutil:go_default_library", - "//encoding/ssz:go_default_library", - "//proto/engine/v1:go_default_library", - "//proto/prysm/v1alpha1:go_default_library", - "//runtime/version:go_default_library", - "@com_github_pkg_errors//:go_default_library", - "@com_github_prysmaticlabs_go_bitfield//:go_default_library", - "@io_opencensus_go//trace:go_default_library", - "@org_golang_google_protobuf//proto:go_default_library", - ], -) diff --git a/beacon-chain/state/v2/deprecated_getters.go b/beacon-chain/state/v2/deprecated_getters.go deleted file mode 100644 index 579514b7e8..0000000000 --- a/beacon-chain/state/v2/deprecated_getters.go +++ /dev/null @@ -1,22 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// PreviousEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) { - return nil, errors.New("PreviousEpochAttestations is not supported for hard fork 1 beacon state") -} - -// CurrentEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) { - return nil, errors.New("CurrentEpochAttestations is not supported for hard fork 1 beacon state") -} - -// LatestExecutionPayloadHeader is not supported for hard fork 1 beacon state. -func (*BeaconState) LatestExecutionPayloadHeader() (*enginev1.ExecutionPayloadHeader, error) { - return nil, errors.New("LatestExecutionPayloadHeader is not supported for hard fork 1 beacon state") -} diff --git a/beacon-chain/state/v2/deprecated_setters.go b/beacon-chain/state/v2/deprecated_setters.go deleted file mode 100644 index 314064ff89..0000000000 --- a/beacon-chain/state/v2/deprecated_setters.go +++ /dev/null @@ -1,27 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// AppendCurrentEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) AppendCurrentEpochAttestations(_ *ethpb.PendingAttestation) error { - return errors.New("AppendCurrentEpochAttestations is not supported for hard fork 1 beacon state") -} - -// AppendPreviousEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) AppendPreviousEpochAttestations(_ *ethpb.PendingAttestation) error { - return errors.New("AppendPreviousEpochAttestations is not supported for hard fork 1 beacon state") -} - -// RotateAttestations is not supported for HF1 beacon state. -func (*BeaconState) RotateAttestations() error { - return errors.New("RotateAttestations is not supported for hard fork 1 beacon state") -} - -// SetLatestExecutionPayloadHeader is not supported for hard fork 1 beacon state. -func (*BeaconState) SetLatestExecutionPayloadHeader(_ interfaces.ExecutionData) error { - return errors.New("SetLatestExecutionPayloadHeader is not supported for hard fork 1 beacon state") -} diff --git a/beacon-chain/state/v2/error.go b/beacon-chain/state/v2/error.go deleted file mode 100644 index a9ea20b9a6..0000000000 --- a/beacon-chain/state/v2/error.go +++ /dev/null @@ -1,5 +0,0 @@ -package v2 - -import "errors" - -var ErrNilParticipation = errors.New("nil epoch participation in state") diff --git a/beacon-chain/state/v2/field_roots.go b/beacon-chain/state/v2/field_roots.go deleted file mode 100644 index 3200b505ab..0000000000 --- a/beacon-chain/state/v2/field_roots.go +++ /dev/null @@ -1,14 +0,0 @@ -package v2 - -import ( - "context" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// computeFieldRoots returns the hash tree root computations of every field in -// the beacon state as a list of 32 byte roots. -func computeFieldRoots(ctx context.Context, state *ethpb.BeaconStateAltair) ([][]byte, error) { - return stateutil.ComputeFieldRootsWithHasherAltair(ctx, state) -} diff --git a/beacon-chain/state/v2/getters_block.go b/beacon-chain/state/v2/getters_block.go deleted file mode 100644 index 98948a756b..0000000000 --- a/beacon-chain/state/v2/getters_block.go +++ /dev/null @@ -1,99 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// LatestBlockHeader stored within the beacon state. -func (b *BeaconState) LatestBlockHeader() *ethpb.BeaconBlockHeader { - if !b.hasInnerState() { - return nil - } - if b.state.LatestBlockHeader == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.latestBlockHeader() -} - -// latestBlockHeader stored within the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) latestBlockHeader() *ethpb.BeaconBlockHeader { - if !b.hasInnerState() { - return nil - } - if b.state.LatestBlockHeader == nil { - return nil - } - - hdr := ðpb.BeaconBlockHeader{ - Slot: b.state.LatestBlockHeader.Slot, - ProposerIndex: b.state.LatestBlockHeader.ProposerIndex, - } - - parentRoot := make([]byte, len(b.state.LatestBlockHeader.ParentRoot)) - bodyRoot := make([]byte, len(b.state.LatestBlockHeader.BodyRoot)) - stateRoot := make([]byte, len(b.state.LatestBlockHeader.StateRoot)) - - copy(parentRoot, b.state.LatestBlockHeader.ParentRoot) - copy(bodyRoot, b.state.LatestBlockHeader.BodyRoot) - copy(stateRoot, b.state.LatestBlockHeader.StateRoot) - hdr.ParentRoot = parentRoot - hdr.BodyRoot = bodyRoot - hdr.StateRoot = stateRoot - return hdr -} - -// BlockRoots kept track of in the beacon state. -func (b *BeaconState) BlockRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.BlockRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.blockRoots() -} - -// blockRoots kept track of in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) blockRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.BlockRoots) -} - -// BlockRootAtIndex retrieves a specific block root based on an -// input index value. -func (b *BeaconState) BlockRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.BlockRoots == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.blockRootAtIndex(idx) -} - -// blockRootAtIndex retrieves a specific block root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) blockRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - return bytesutil.SafeCopyRootAtIndex(b.state.BlockRoots, idx) -} diff --git a/beacon-chain/state/v2/getters_checkpoint.go b/beacon-chain/state/v2/getters_checkpoint.go deleted file mode 100644 index 807bdb007a..0000000000 --- a/beacon-chain/state/v2/getters_checkpoint.go +++ /dev/null @@ -1,160 +0,0 @@ -package v2 - -import ( - "bytes" - - "github.com/prysmaticlabs/go-bitfield" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// JustificationBits marking which epochs have been justified in the beacon chain. -func (b *BeaconState) JustificationBits() bitfield.Bitvector4 { - if !b.hasInnerState() { - return nil - } - if b.state.JustificationBits == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.justificationBits() -} - -// justificationBits marking which epochs have been justified in the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) justificationBits() bitfield.Bitvector4 { - if !b.hasInnerState() { - return nil - } - if b.state.JustificationBits == nil { - return nil - } - - res := make([]byte, len(b.state.JustificationBits.Bytes())) - copy(res, b.state.JustificationBits.Bytes()) - return res -} - -// PreviousJustifiedCheckpoint denoting an epoch and block root. -func (b *BeaconState) PreviousJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.PreviousJustifiedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.previousJustifiedCheckpoint() -} - -// previousJustifiedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) previousJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.PreviousJustifiedCheckpoint) -} - -// CurrentJustifiedCheckpoint denoting an epoch and block root. -func (b *BeaconState) CurrentJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.CurrentJustifiedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.currentJustifiedCheckpoint() -} - -// currentJustifiedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.CurrentJustifiedCheckpoint) -} - -// MatchCurrentJustifiedCheckpoint returns true if input justified checkpoint matches -// the current justified checkpoint in state. -func (b *BeaconState) MatchCurrentJustifiedCheckpoint(c *ethpb.Checkpoint) bool { - if !b.hasInnerState() { - return false - } - if b.state.CurrentJustifiedCheckpoint == nil { - return false - } - - if c.Epoch != b.state.CurrentJustifiedCheckpoint.Epoch { - return false - } - return bytes.Equal(c.Root, b.state.CurrentJustifiedCheckpoint.Root) -} - -// MatchPreviousJustifiedCheckpoint returns true if the input justified checkpoint matches -// the previous justified checkpoint in state. -func (b *BeaconState) MatchPreviousJustifiedCheckpoint(c *ethpb.Checkpoint) bool { - if !b.hasInnerState() { - return false - } - if b.state.PreviousJustifiedCheckpoint == nil { - return false - } - - if c.Epoch != b.state.PreviousJustifiedCheckpoint.Epoch { - return false - } - return bytes.Equal(c.Root, b.state.PreviousJustifiedCheckpoint.Root) -} - -// FinalizedCheckpoint denoting an epoch and block root. -func (b *BeaconState) FinalizedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.FinalizedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.finalizedCheckpoint() -} - -// finalizedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) finalizedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.FinalizedCheckpoint) -} - -// FinalizedCheckpointEpoch returns the epoch value of the finalized checkpoint. -func (b *BeaconState) FinalizedCheckpointEpoch() types.Epoch { - if !b.hasInnerState() { - return 0 - } - if b.state.FinalizedCheckpoint == nil { - return 0 - } - b.lock.RLock() - defer b.lock.RUnlock() - - return b.state.FinalizedCheckpoint.Epoch -} diff --git a/beacon-chain/state/v2/getters_eth1.go b/beacon-chain/state/v2/getters_eth1.go deleted file mode 100644 index 22f0383961..0000000000 --- a/beacon-chain/state/v2/getters_eth1.go +++ /dev/null @@ -1,91 +0,0 @@ -package v2 - -import ( - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// Eth1Data corresponding to the proof-of-work chain information stored in the beacon state. -func (b *BeaconState) Eth1Data() *ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1Data == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1Data() -} - -// eth1Data corresponding to the proof-of-work chain information stored in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1Data() *ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1Data == nil { - return nil - } - - return ethpb.CopyETH1Data(b.state.Eth1Data) -} - -// Eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain -// data retrieved from eth1. -func (b *BeaconState) Eth1DataVotes() []*ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1DataVotes == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1DataVotes() -} - -// eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain -// data retrieved from eth1. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1DataVotes() []*ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1DataVotes == nil { - return nil - } - - res := make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) - for i := 0; i < len(res); i++ { - res[i] = ethpb.CopyETH1Data(b.state.Eth1DataVotes[i]) - } - return res -} - -// Eth1DepositIndex corresponds to the index of the deposit made to the -// validator deposit contract at the time of this state's eth1 data. -func (b *BeaconState) Eth1DepositIndex() uint64 { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1DepositIndex() -} - -// eth1DepositIndex corresponds to the index of the deposit made to the -// validator deposit contract at the time of this state's eth1 data. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1DepositIndex() uint64 { - if !b.hasInnerState() { - return 0 - } - - return b.state.Eth1DepositIndex -} diff --git a/beacon-chain/state/v2/getters_misc.go b/beacon-chain/state/v2/getters_misc.go deleted file mode 100644 index 4369d8e04b..0000000000 --- a/beacon-chain/state/v2/getters_misc.go +++ /dev/null @@ -1,164 +0,0 @@ -package v2 - -import ( - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - "github.com/prysmaticlabs/prysm/v3/config/params" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v3/runtime/version" -) - -// GenesisTime of the beacon state as a uint64. -func (b *BeaconState) GenesisTime() uint64 { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.genesisTime() -} - -// genesisTime of the beacon state as a uint64. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) genesisTime() uint64 { - if !b.hasInnerState() { - return 0 - } - - return b.state.GenesisTime -} - -// GenesisValidatorsRoot of the beacon state. -func (b *BeaconState) GenesisValidatorsRoot() []byte { - if !b.hasInnerState() { - return nil - } - if b.state.GenesisValidatorsRoot == nil { - return params.BeaconConfig().ZeroHash[:] - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.genesisValidatorsRoot() -} - -// genesisValidatorsRoot of the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) genesisValidatorsRoot() []byte { - if !b.hasInnerState() { - return nil - } - if b.state.GenesisValidatorsRoot == nil { - return params.BeaconConfig().ZeroHash[:] - } - - root := make([]byte, fieldparams.RootLength) - copy(root, b.state.GenesisValidatorsRoot) - return root -} - -// Version of the beacon state. This method -// is strictly meant to be used without a lock -// internally. -func (_ *BeaconState) Version() int { - return version.Altair -} - -// Slot of the current beacon chain state. -func (b *BeaconState) Slot() types.Slot { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.slot() -} - -// slot of the current beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) slot() types.Slot { - if !b.hasInnerState() { - return 0 - } - - return b.state.Slot -} - -// Fork version of the beacon chain. -func (b *BeaconState) Fork() *ethpb.Fork { - if !b.hasInnerState() { - return nil - } - if b.state.Fork == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.fork() -} - -// fork version of the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) fork() *ethpb.Fork { - if !b.hasInnerState() { - return nil - } - if b.state.Fork == nil { - return nil - } - - prevVersion := make([]byte, len(b.state.Fork.PreviousVersion)) - copy(prevVersion, b.state.Fork.PreviousVersion) - currVersion := make([]byte, len(b.state.Fork.CurrentVersion)) - copy(currVersion, b.state.Fork.CurrentVersion) - return ðpb.Fork{ - PreviousVersion: prevVersion, - CurrentVersion: currVersion, - Epoch: b.state.Fork.Epoch, - } -} - -// HistoricalRoots based on epochs stored in the beacon state. -func (b *BeaconState) HistoricalRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.HistoricalRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.historicalRoots() -} - -// historicalRoots based on epochs stored in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) historicalRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.HistoricalRoots) -} - -// balancesLength returns the length of the balances slice. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) balancesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.Balances == nil { - return 0 - } - - return len(b.state.Balances) -} diff --git a/beacon-chain/state/v2/getters_participation.go b/beacon-chain/state/v2/getters_participation.go deleted file mode 100644 index 6611552240..0000000000 --- a/beacon-chain/state/v2/getters_participation.go +++ /dev/null @@ -1,78 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// CurrentEpochParticipation corresponding to participation bits on the beacon chain. -func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.CurrentEpochParticipation == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.currentEpochParticipation(), nil -} - -// PreviousEpochParticipation corresponding to participation bits on the beacon chain. -func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.PreviousEpochParticipation == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.previousEpochParticipation(), nil -} - -// UnrealizedCheckpointBalances returns the total balances: active, target attested in -// current epoch and target attested in previous epoch. This function is used to -// compute the "unrealized justification" that a synced Beacon Block will have. -func (b *BeaconState) UnrealizedCheckpointBalances() (uint64, uint64, uint64, error) { - if !b.hasInnerState() { - return 0, 0, 0, ErrNilInnerState - } - currentEpoch := time.CurrentEpoch(b) - b.lock.RLock() - defer b.lock.RUnlock() - - cp := b.state.CurrentEpochParticipation - pp := b.state.PreviousEpochParticipation - if cp == nil || pp == nil { - return 0, 0, 0, ErrNilParticipation - } - return stateutil.UnrealizedCheckpointBalances(cp, pp, b.state.Validators, currentEpoch) - -} - -// currentEpochParticipation corresponding to participation bits on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentEpochParticipation() []byte { - if !b.hasInnerState() { - return nil - } - tmp := make([]byte, len(b.state.CurrentEpochParticipation)) - copy(tmp, b.state.CurrentEpochParticipation) - return tmp -} - -// previousEpochParticipation corresponding to participation bits on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) previousEpochParticipation() []byte { - if !b.hasInnerState() { - return nil - } - tmp := make([]byte, len(b.state.PreviousEpochParticipation)) - copy(tmp, b.state.PreviousEpochParticipation) - return tmp -} diff --git a/beacon-chain/state/v2/getters_randao.go b/beacon-chain/state/v2/getters_randao.go deleted file mode 100644 index b9a790ca67..0000000000 --- a/beacon-chain/state/v2/getters_randao.go +++ /dev/null @@ -1,85 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" -) - -// RandaoMixes of block proposers on the beacon chain. -func (b *BeaconState) RandaoMixes() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.RandaoMixes == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixes() -} - -// randaoMixes of block proposers on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixes() [][]byte { - if !b.hasInnerState() { - return nil - } - - return bytesutil.SafeCopy2dBytes(b.state.RandaoMixes) -} - -// RandaoMixAtIndex retrieves a specific block root based on an -// input index value. -func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.RandaoMixes == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixAtIndex(idx) -} - -// randaoMixAtIndex retrieves a specific block root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - return bytesutil.SafeCopyRootAtIndex(b.state.RandaoMixes, idx) -} - -// RandaoMixesLength returns the length of the randao mixes slice. -func (b *BeaconState) RandaoMixesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.RandaoMixes == nil { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixesLength() -} - -// randaoMixesLength returns the length of the randao mixes slice. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.RandaoMixes == nil { - return 0 - } - - return len(b.state.RandaoMixes) -} diff --git a/beacon-chain/state/v2/getters_state.go b/beacon-chain/state/v2/getters_state.go deleted file mode 100644 index 1ee3656772..0000000000 --- a/beacon-chain/state/v2/getters_state.go +++ /dev/null @@ -1,126 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// InnerStateUnsafe returns the pointer value of the underlying -// beacon state proto object, bypassing immutability. Use with care. -func (b *BeaconState) InnerStateUnsafe() interface{} { - if b == nil { - return nil - } - return b.state -} - -// CloneInnerState the beacon state into a protobuf for usage. -func (b *BeaconState) CloneInnerState() interface{} { - if b == nil || b.state == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - return ðpb.BeaconStateAltair{ - GenesisTime: b.genesisTime(), - GenesisValidatorsRoot: b.genesisValidatorsRoot(), - Slot: b.slot(), - Fork: b.fork(), - LatestBlockHeader: b.latestBlockHeader(), - BlockRoots: b.blockRoots(), - StateRoots: b.stateRoots(), - HistoricalRoots: b.historicalRoots(), - Eth1Data: b.eth1Data(), - Eth1DataVotes: b.eth1DataVotes(), - Eth1DepositIndex: b.eth1DepositIndex(), - Validators: b.validators(), - Balances: b.balances(), - RandaoMixes: b.randaoMixes(), - Slashings: b.slashings(), - CurrentEpochParticipation: b.currentEpochParticipation(), - PreviousEpochParticipation: b.previousEpochParticipation(), - JustificationBits: b.justificationBits(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(), - FinalizedCheckpoint: b.finalizedCheckpoint(), - InactivityScores: b.inactivityScores(), - CurrentSyncCommittee: b.currentSyncCommittee(), - NextSyncCommittee: b.nextSyncCommittee(), - } -} - -// hasInnerState detects if the internal reference to the state data structure -// is populated correctly. Returns false if nil. -func (b *BeaconState) hasInnerState() bool { - return b != nil && b.state != nil -} - -// StateRoots kept track of in the beacon state. -func (b *BeaconState) StateRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.StateRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.stateRoots() -} - -// StateRoots kept track of in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) stateRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.StateRoots) -} - -// StateRootAtIndex retrieves a specific state root based on an -// input index value. -func (b *BeaconState) StateRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.StateRoots == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.stateRootAtIndex(idx) -} - -// stateRootAtIndex retrieves a specific state root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) stateRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - return bytesutil.SafeCopyRootAtIndex(b.state.StateRoots, idx) -} - -// MarshalSSZ marshals the underlying beacon state to bytes. -func (b *BeaconState) MarshalSSZ() ([]byte, error) { - if !b.hasInnerState() { - return nil, errors.New("nil beacon state") - } - return b.state.MarshalSSZ() -} - -// ProtobufBeaconState transforms an input into beacon state hard fork 1 in the form of protobuf. -// Error is returned if the input is not type protobuf beacon state. -func ProtobufBeaconState(s interface{}) (*ethpb.BeaconStateAltair, error) { - pbState, ok := s.(*ethpb.BeaconStateAltair) - if !ok { - return nil, errors.New("input is not type pb.BeaconStateAltair") - } - return pbState, nil -} diff --git a/beacon-chain/state/v2/getters_sync_committee.go b/beacon-chain/state/v2/getters_sync_committee.go deleted file mode 100644 index b849f4b559..0000000000 --- a/beacon-chain/state/v2/getters_sync_committee.go +++ /dev/null @@ -1,69 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// currentSyncCommittee of the current sync committee in beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentSyncCommittee() *ethpb.SyncCommittee { - if !b.hasInnerState() { - return nil - } - - return CopySyncCommittee(b.state.CurrentSyncCommittee) -} - -// nextSyncCommittee of the next sync committee in beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) nextSyncCommittee() *ethpb.SyncCommittee { - if !b.hasInnerState() { - return nil - } - - return CopySyncCommittee(b.state.NextSyncCommittee) -} - -// CurrentSyncCommittee of the current sync committee in beacon chain state. -func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.CurrentSyncCommittee == nil { - return nil, nil - } - - return b.currentSyncCommittee(), nil -} - -// NextSyncCommittee of the next sync committee in beacon chain state. -func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.NextSyncCommittee == nil { - return nil, nil - } - - return b.nextSyncCommittee(), nil -} - -// CopySyncCommittee copies the provided sync committee object. -func CopySyncCommittee(data *ethpb.SyncCommittee) *ethpb.SyncCommittee { - if data == nil { - return nil - } - return ðpb.SyncCommittee{ - Pubkeys: bytesutil.SafeCopy2dBytes(data.Pubkeys), - AggregatePubkey: bytesutil.SafeCopyBytes(data.AggregatePubkey), - } -} diff --git a/beacon-chain/state/v2/getters_validator.go b/beacon-chain/state/v2/getters_validator.go deleted file mode 100644 index 82d348970b..0000000000 --- a/beacon-chain/state/v2/getters_validator.go +++ /dev/null @@ -1,324 +0,0 @@ -package v2 - -import ( - "fmt" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// ValidatorIndexOutOfRangeError represents an error scenario where a validator does not exist -// at a given index in the validator's array. -type ValidatorIndexOutOfRangeError struct { - message string -} - -// NewValidatorIndexOutOfRangeError creates a new error instance. -func NewValidatorIndexOutOfRangeError(index types.ValidatorIndex) ValidatorIndexOutOfRangeError { - return ValidatorIndexOutOfRangeError{ - message: fmt.Sprintf("index %d out of range", index), - } -} - -// Error returns the underlying error message. -func (e *ValidatorIndexOutOfRangeError) Error() string { - return e.message -} - -// Validators participating in consensus on the beacon chain. -func (b *BeaconState) Validators() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.validators() -} - -// validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) validators() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - res := make([]*ethpb.Validator, len(b.state.Validators)) - for i := 0; i < len(res); i++ { - val := b.state.Validators[i] - if val == nil { - continue - } - res[i] = ethpb.CopyValidator(val) - } - return res -} - -// references of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. This does not -// copy fully and instead just copies the reference. -func (b *BeaconState) validatorsReferences() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - res := make([]*ethpb.Validator, len(b.state.Validators)) - for i := 0; i < len(res); i++ { - validator := b.state.Validators[i] - if validator == nil { - continue - } - // copy validator reference instead. - res[i] = validator - } - return res -} - -// ValidatorAtIndex is the validator at the provided index. -func (b *BeaconState) ValidatorAtIndex(idx types.ValidatorIndex) (*ethpb.Validator, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.Validators == nil { - return ðpb.Validator{}, nil - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - e := NewValidatorIndexOutOfRangeError(idx) - return nil, &e - } - - b.lock.RLock() - defer b.lock.RUnlock() - - val := b.state.Validators[idx] - return ethpb.CopyValidator(val), nil -} - -// ValidatorAtIndexReadOnly is the validator at the provided index. This method -// doesn't clone the validator. -func (b *BeaconState) ValidatorAtIndexReadOnly(idx types.ValidatorIndex) (state.ReadOnlyValidator, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.Validators == nil { - return nil, state.ErrNilValidatorsInState - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - e := NewValidatorIndexOutOfRangeError(idx) - return nil, &e - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return v1.NewValidator(b.state.Validators[idx]) -} - -// ValidatorIndexByPubkey returns a given validator by its 48-byte public key. -func (b *BeaconState) ValidatorIndexByPubkey(key [fieldparams.BLSPubkeyLength]byte) (types.ValidatorIndex, bool) { - if b == nil || b.valMapHandler == nil || b.valMapHandler.IsNil() { - return 0, false - } - b.lock.RLock() - defer b.lock.RUnlock() - numOfVals := len(b.state.Validators) - - idx, ok := b.valMapHandler.Get(key) - if ok && types.ValidatorIndex(numOfVals) <= idx { - return types.ValidatorIndex(0), false - } - return idx, ok -} - -// PubkeyAtIndex returns the pubkey at the given -// validator index. -func (b *BeaconState) PubkeyAtIndex(idx types.ValidatorIndex) [fieldparams.BLSPubkeyLength]byte { - if !b.hasInnerState() { - return [fieldparams.BLSPubkeyLength]byte{} - } - if uint64(idx) >= uint64(len(b.state.Validators)) { - return [fieldparams.BLSPubkeyLength]byte{} - } - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.Validators[idx] == nil { - return [fieldparams.BLSPubkeyLength]byte{} - } - return bytesutil.ToBytes48(b.state.Validators[idx].PublicKey) -} - -// NumValidators returns the size of the validator registry. -func (b *BeaconState) NumValidators() int { - if !b.hasInnerState() { - return 0 - } - b.lock.RLock() - defer b.lock.RUnlock() - - return len(b.state.Validators) -} - -// ReadFromEveryValidator reads values from every validator and applies it to the provided function. -// -// WARNING: This method is potentially unsafe, as it exposes the actual validator registry. -func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if b.state.Validators == nil { - return errors.New("nil validators in state") - } - b.lock.RLock() - validators := b.state.Validators - b.lock.RUnlock() - - for i, v := range validators { - v, err := v1.NewValidator(v) - if err != nil { - return err - } - if err := f(i, v); err != nil { - return err - } - } - return nil -} - -// Balances of validators participating in consensus on the beacon chain. -func (b *BeaconState) Balances() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Balances == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.balances() -} - -// balances of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) balances() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Balances == nil { - return nil - } - - res := make([]uint64, len(b.state.Balances)) - copy(res, b.state.Balances) - return res -} - -// BalanceAtIndex of validator with the provided index. -func (b *BeaconState) BalanceAtIndex(idx types.ValidatorIndex) (uint64, error) { - if !b.hasInnerState() { - return 0, ErrNilInnerState - } - if b.state.Balances == nil { - return 0, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if uint64(len(b.state.Balances)) <= uint64(idx) { - return 0, fmt.Errorf("index of %d does not exist", idx) - } - return b.state.Balances[idx], nil -} - -// BalancesLength returns the length of the balances slice. -func (b *BeaconState) BalancesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.Balances == nil { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.balancesLength() -} - -// Slashings of validators on the beacon chain. -func (b *BeaconState) Slashings() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Slashings == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.slashings() -} - -// slashings of validators on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) slashings() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Slashings == nil { - return nil - } - - res := make([]uint64, len(b.state.Slashings)) - copy(res, b.state.Slashings) - return res -} - -// inactivityScores of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) inactivityScores() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.InactivityScores == nil { - return nil - } - - res := make([]uint64, len(b.state.InactivityScores)) - copy(res, b.state.InactivityScores) - return res -} - -// InactivityScores of validators participating in consensus on the beacon chain. -func (b *BeaconState) InactivityScores() ([]uint64, error) { - if !b.hasInnerState() { - return nil, nil - } - if b.state.InactivityScores == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.inactivityScores(), nil -} diff --git a/beacon-chain/state/v2/proofs.go b/beacon-chain/state/v2/proofs.go deleted file mode 100644 index 1831f4d9b9..0000000000 --- a/beacon-chain/state/v2/proofs.go +++ /dev/null @@ -1,83 +0,0 @@ -package v2 - -import ( - "context" - "encoding/binary" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" -) - -const ( - finalizedRootIndex = uint64(105) // Precomputed value. -) - -// FinalizedRootGeneralizedIndex for the beacon state. -func FinalizedRootGeneralizedIndex() uint64 { - return finalizedRootIndex -} - -// CurrentSyncCommitteeGeneralizedIndex for the beacon state. -func CurrentSyncCommitteeGeneralizedIndex() uint64 { - return uint64(currentSyncCommittee) -} - -// NextSyncCommitteeGeneralizedIndex for the beacon state. -func NextSyncCommitteeGeneralizedIndex() uint64 { - return uint64(nextSyncCommittee) -} - -// CurrentSyncCommitteeProof from the state's Merkle trie representation. -func (b *BeaconState) CurrentSyncCommitteeProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - // In case the Merkle layers of the trie are not populated, we need - // to perform some initialization. - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - // Our beacon state uses a "dirty" fields pattern which requires us to - // recompute branches of the Merkle layers that are marked as dirty. - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - return fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(currentSyncCommittee)), nil -} - -// NextSyncCommitteeProof from the state's Merkle trie representation. -func (b *BeaconState) NextSyncCommitteeProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - return fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(nextSyncCommittee)), nil -} - -// FinalizedRootProof crafts a Merkle proof for the finalized root -// contained within the finalized checkpoint of a beacon state. -func (b *BeaconState) FinalizedRootProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - cpt := b.state.FinalizedCheckpoint - // The epoch field of a finalized checkpoint is the neighbor - // index of the finalized root field in its Merkle tree representation - // of the checkpoint. This neighbor is the first element added to the proof. - epochBuf := make([]byte, 8) - binary.LittleEndian.PutUint64(epochBuf, uint64(cpt.Epoch)) - epochRoot := bytesutil.ToBytes32(epochBuf) - proof := make([][]byte, 0) - proof = append(proof, epochRoot[:]) - branch := fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(finalizedCheckpoint)) - proof = append(proof, branch...) - return proof, nil -} diff --git a/beacon-chain/state/v2/setters_block.go b/beacon-chain/state/v2/setters_block.go deleted file mode 100644 index 16177948b0..0000000000 --- a/beacon-chain/state/v2/setters_block.go +++ /dev/null @@ -1,68 +0,0 @@ -package v2 - -import ( - "fmt" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetLatestBlockHeader in the beacon state. -func (b *BeaconState) SetLatestBlockHeader(val *ethpb.BeaconBlockHeader) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.LatestBlockHeader = ethpb.CopyBeaconBlockHeader(val) - b.markFieldAsDirty(latestBlockHeader) - return nil -} - -// SetBlockRoots for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetBlockRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[blockRoots].MinusRef() - b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1) - - b.state.BlockRoots = val - b.markFieldAsDirty(blockRoots) - b.rebuildTrie[blockRoots] = true - return nil -} - -// UpdateBlockRootAtIndex for the beacon state. Updates the block root -// at a specific index to a new value. -func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.BlockRoots)) <= idx { - return fmt.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - r := b.state.BlockRoots - if ref := b.sharedFieldReferences[blockRoots]; ref.Refs() > 1 { - // Copy elements in underlying array by reference. - r = make([][]byte, len(b.state.BlockRoots)) - copy(r, b.state.BlockRoots) - ref.MinusRef() - b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1) - } - - r[idx] = blockRoot[:] - b.state.BlockRoots = r - - b.markFieldAsDirty(blockRoots) - b.addDirtyIndices(blockRoots, []uint64{idx}) - return nil -} diff --git a/beacon-chain/state/v2/setters_checkpoint.go b/beacon-chain/state/v2/setters_checkpoint.go deleted file mode 100644 index 54110ad764..0000000000 --- a/beacon-chain/state/v2/setters_checkpoint.go +++ /dev/null @@ -1,58 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/go-bitfield" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetJustificationBits for the beacon state. -func (b *BeaconState) SetJustificationBits(val bitfield.Bitvector4) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.JustificationBits = val - b.markFieldAsDirty(justificationBits) - return nil -} - -// SetPreviousJustifiedCheckpoint for the beacon state. -func (b *BeaconState) SetPreviousJustifiedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.PreviousJustifiedCheckpoint = val - b.markFieldAsDirty(previousJustifiedCheckpoint) - return nil -} - -// SetCurrentJustifiedCheckpoint for the beacon state. -func (b *BeaconState) SetCurrentJustifiedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.CurrentJustifiedCheckpoint = val - b.markFieldAsDirty(currentJustifiedCheckpoint) - return nil -} - -// SetFinalizedCheckpoint for the beacon state. -func (b *BeaconState) SetFinalizedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.FinalizedCheckpoint = val - b.markFieldAsDirty(finalizedCheckpoint) - return nil -} diff --git a/beacon-chain/state/v2/setters_eth1.go b/beacon-chain/state/v2/setters_eth1.go deleted file mode 100644 index c2d6a9a6e8..0000000000 --- a/beacon-chain/state/v2/setters_eth1.go +++ /dev/null @@ -1,74 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetEth1Data for the beacon state. -func (b *BeaconState) SetEth1Data(val *ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Eth1Data = val - b.markFieldAsDirty(eth1Data) - return nil -} - -// SetEth1DataVotes for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[eth1DataVotes].MinusRef() - b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) - - b.state.Eth1DataVotes = val - b.markFieldAsDirty(eth1DataVotes) - b.rebuildTrie[eth1DataVotes] = true - return nil -} - -// SetEth1DepositIndex for the beacon state. -func (b *BeaconState) SetEth1DepositIndex(val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Eth1DepositIndex = val - b.markFieldAsDirty(eth1DepositIndex) - return nil -} - -// AppendEth1DataVotes for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendEth1DataVotes(val *ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - votes := b.state.Eth1DataVotes - if b.sharedFieldReferences[eth1DataVotes].Refs() > 1 { - // Copy elements in underlying array by reference. - votes = make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) - copy(votes, b.state.Eth1DataVotes) - b.sharedFieldReferences[eth1DataVotes].MinusRef() - b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) - } - - b.state.Eth1DataVotes = append(votes, val) - b.markFieldAsDirty(eth1DataVotes) - b.addDirtyIndices(eth1DataVotes, []uint64{uint64(len(b.state.Eth1DataVotes) - 1)}) - return nil -} diff --git a/beacon-chain/state/v2/setters_misc.go b/beacon-chain/state/v2/setters_misc.go deleted file mode 100644 index 0485e816b5..0000000000 --- a/beacon-chain/state/v2/setters_misc.go +++ /dev/null @@ -1,181 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/crypto/hash" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "google.golang.org/protobuf/proto" -) - -// For our setters, we have a field reference counter through -// which we can track shared field references. This helps when -// performing state copies, as we simply copy the reference to the -// field. When we do need to do need to modify these fields, we -// perform a full copy of the field. This is true of most of our -// fields except for the following below. -// 1) BlockRoots -// 2) StateRoots -// 3) Eth1DataVotes -// 4) RandaoMixes -// 5) HistoricalRoots -// 6) CurrentParticipationBits -// 7) PreviousParticipationBits -// -// The fields referred to above are instead copied by reference, where -// we simply copy the reference to the underlying object instead of the -// whole object. This is possible due to how we have structured our state -// as we copy the value on read, so as to ensure the underlying object is -// not mutated while it is being accessed during a state read. - -const ( - // This specifies the limit till which we process all dirty indices for a certain field. - // If we have more dirty indices than the threshold, then we rebuild the whole trie. This - // comes due to the fact that O(alogn) > O(n) beyond a certain value of a. - indicesLimit = 8000 -) - -// SetGenesisTime for the beacon state. -func (b *BeaconState) SetGenesisTime(val uint64) error { - b.lock.Lock() - defer b.lock.Unlock() - - b.state.GenesisTime = val - b.markFieldAsDirty(genesisTime) - return nil -} - -// SetGenesisValidatorsRoot for the beacon state. -func (b *BeaconState) SetGenesisValidatorsRoot(val []byte) error { - b.lock.Lock() - defer b.lock.Unlock() - - b.state.GenesisValidatorsRoot = val - b.markFieldAsDirty(genesisValidatorsRoot) - return nil -} - -// SetSlot for the beacon state. -func (b *BeaconState) SetSlot(val types.Slot) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Slot = val - b.markFieldAsDirty(slot) - return nil -} - -// SetFork version for the beacon chain. -func (b *BeaconState) SetFork(val *ethpb.Fork) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - fk, ok := proto.Clone(val).(*ethpb.Fork) - if !ok { - return errors.New("proto.Clone did not return a fork proto") - } - b.state.Fork = fk - b.markFieldAsDirty(fork) - return nil -} - -// SetHistoricalRoots for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetHistoricalRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[historicalRoots].MinusRef() - b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1) - - b.state.HistoricalRoots = val - b.markFieldAsDirty(historicalRoots) - return nil -} - -// AppendHistoricalRoots for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - roots := b.state.HistoricalRoots - if b.sharedFieldReferences[historicalRoots].Refs() > 1 { - roots = make([][]byte, len(b.state.HistoricalRoots)) - copy(roots, b.state.HistoricalRoots) - b.sharedFieldReferences[historicalRoots].MinusRef() - b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1) - } - - b.state.HistoricalRoots = append(roots, root[:]) - b.markFieldAsDirty(historicalRoots) - return nil -} - -// Recomputes the branch up the index in the Merkle trie representation -// of the beacon state. This method performs slice reads and the caller MUST -// hold the lock before calling this method. -func (b *BeaconState) recomputeRoot(idx int) { - hashFunc := hash.CustomSHA256Hasher() - layers := b.merkleLayers - // The merkle tree structure looks as follows: - // [[r1, r2, r3, r4], [parent1, parent2], [root]] - // Using information about the index which changed, idx, we recompute - // only its branch up the tree. - currentIndex := idx - root := b.merkleLayers[0][idx] - for i := 0; i < len(layers)-1; i++ { - isLeft := currentIndex%2 == 0 - neighborIdx := currentIndex ^ 1 - - neighbor := make([]byte, 32) - if layers[i] != nil && len(layers[i]) != 0 && neighborIdx < len(layers[i]) { - neighbor = layers[i][neighborIdx] - } - if isLeft { - parentHash := hashFunc(append(root, neighbor...)) - root = parentHash[:] - } else { - parentHash := hashFunc(append(neighbor, root...)) - root = parentHash[:] - } - parentIdx := currentIndex / 2 - // Update the cached layers at the parent index. - layers[i+1][parentIdx] = root - currentIndex = parentIdx - } - b.merkleLayers = layers -} - -func (b *BeaconState) markFieldAsDirty(field stateTypes.FieldIndex) { - b.dirtyFields[field] = true -} - -// addDirtyIndices adds the relevant dirty field indices, so that they -// can be recomputed. -func (b *BeaconState) addDirtyIndices(index stateTypes.FieldIndex, indices []uint64) { - if b.rebuildTrie[index] { - return - } - totalIndicesLen := len(b.dirtyIndices[index]) + len(indices) - if totalIndicesLen > indicesLimit { - b.rebuildTrie[index] = true - b.dirtyIndices[index] = []uint64{} - } else { - b.dirtyIndices[index] = append(b.dirtyIndices[index], indices...) - } -} diff --git a/beacon-chain/state/v2/setters_participation.go b/beacon-chain/state/v2/setters_participation.go deleted file mode 100644 index a6b5058ad1..0000000000 --- a/beacon-chain/state/v2/setters_participation.go +++ /dev/null @@ -1,155 +0,0 @@ -package v2 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetPreviousParticipationBits for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetPreviousParticipationBits(val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[previousEpochParticipationBits].MinusRef() - b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) - - b.state.PreviousEpochParticipation = val - b.markFieldAsDirty(previousEpochParticipationBits) - b.rebuildTrie[previousEpochParticipationBits] = true - return nil -} - -// SetCurrentParticipationBits for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetCurrentParticipationBits(val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[currentEpochParticipationBits].MinusRef() - b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) - - b.state.CurrentEpochParticipation = val - b.markFieldAsDirty(currentEpochParticipationBits) - b.rebuildTrie[currentEpochParticipationBits] = true - return nil -} - -// AppendCurrentParticipationBits for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendCurrentParticipationBits(val byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - participation := b.state.CurrentEpochParticipation - if b.sharedFieldReferences[currentEpochParticipationBits].Refs() > 1 { - // Copy elements in underlying array by reference. - participation = make([]byte, len(b.state.CurrentEpochParticipation)) - copy(participation, b.state.CurrentEpochParticipation) - b.sharedFieldReferences[currentEpochParticipationBits].MinusRef() - b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) - } - - b.state.CurrentEpochParticipation = append(participation, val) - b.markFieldAsDirty(currentEpochParticipationBits) - b.addDirtyIndices(currentEpochParticipationBits, []uint64{uint64(len(b.state.CurrentEpochParticipation) - 1)}) - return nil -} - -// AppendPreviousParticipationBits for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendPreviousParticipationBits(val byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - bits := b.state.PreviousEpochParticipation - if b.sharedFieldReferences[previousEpochParticipationBits].Refs() > 1 { - bits = make([]byte, len(b.state.PreviousEpochParticipation)) - copy(bits, b.state.PreviousEpochParticipation) - b.sharedFieldReferences[previousEpochParticipationBits].MinusRef() - b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) - } - - b.state.PreviousEpochParticipation = append(bits, val) - b.markFieldAsDirty(previousEpochParticipationBits) - b.addDirtyIndices(previousEpochParticipationBits, []uint64{uint64(len(b.state.PreviousEpochParticipation) - 1)}) - - return nil -} - -// ModifyPreviousParticipationBits modifies the previous participation bitfield via -// the provided mutator function. -func (b *BeaconState) ModifyPreviousParticipationBits(mutator func(val []byte) ([]byte, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - - participation := b.state.PreviousEpochParticipation - if b.sharedFieldReferences[previousEpochParticipationBits].Refs() > 1 { - // Copy elements in underlying array by reference. - participation = make([]byte, len(b.state.PreviousEpochParticipation)) - copy(participation, b.state.PreviousEpochParticipation) - b.sharedFieldReferences[previousEpochParticipationBits].MinusRef() - b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) - } - // Lock is released so that mutator can - // acquire it. - b.lock.Unlock() - - var err error - participation, err = mutator(participation) - if err != nil { - return err - } - b.lock.Lock() - defer b.lock.Unlock() - b.state.PreviousEpochParticipation = participation - b.markFieldAsDirty(previousEpochParticipationBits) - b.rebuildTrie[previousEpochParticipationBits] = true - return nil -} - -// ModifyCurrentParticipationBits modifies the current participation bitfield via -// the provided mutator function. -func (b *BeaconState) ModifyCurrentParticipationBits(mutator func(val []byte) ([]byte, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - - participation := b.state.CurrentEpochParticipation - if b.sharedFieldReferences[currentEpochParticipationBits].Refs() > 1 { - // Copy elements in underlying array by reference. - participation = make([]byte, len(b.state.CurrentEpochParticipation)) - copy(participation, b.state.CurrentEpochParticipation) - b.sharedFieldReferences[currentEpochParticipationBits].MinusRef() - b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) - } - // Lock is released so that mutator can - // acquire it. - b.lock.Unlock() - - var err error - participation, err = mutator(participation) - if err != nil { - return err - } - b.lock.Lock() - defer b.lock.Unlock() - b.state.CurrentEpochParticipation = participation - b.markFieldAsDirty(currentEpochParticipationBits) - b.rebuildTrie[currentEpochParticipationBits] = true - return nil -} diff --git a/beacon-chain/state/v2/setters_randao.go b/beacon-chain/state/v2/setters_randao.go deleted file mode 100644 index 7869740b7c..0000000000 --- a/beacon-chain/state/v2/setters_randao.go +++ /dev/null @@ -1,53 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetRandaoMixes for the beacon state. Updates the entire -// randao mixes to a new value by overwriting the previous one. -func (b *BeaconState) SetRandaoMixes(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[randaoMixes].MinusRef() - b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1) - - b.state.RandaoMixes = val - b.markFieldAsDirty(randaoMixes) - b.rebuildTrie[randaoMixes] = true - return nil -} - -// UpdateRandaoMixesAtIndex for the beacon state. Updates the randao mixes -// at a specific index to a new value. -func (b *BeaconState) UpdateRandaoMixesAtIndex(idx uint64, val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.RandaoMixes)) <= idx { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - mixes := b.state.RandaoMixes - if refs := b.sharedFieldReferences[randaoMixes].Refs(); refs > 1 { - // Copy elements in underlying array by reference. - mixes = make([][]byte, len(b.state.RandaoMixes)) - copy(mixes, b.state.RandaoMixes) - b.sharedFieldReferences[randaoMixes].MinusRef() - b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1) - } - - mixes[idx] = val - b.state.RandaoMixes = mixes - b.markFieldAsDirty(randaoMixes) - b.addDirtyIndices(randaoMixes, []uint64{idx}) - - return nil -} diff --git a/beacon-chain/state/v2/setters_state.go b/beacon-chain/state/v2/setters_state.go deleted file mode 100644 index f70954f2d6..0000000000 --- a/beacon-chain/state/v2/setters_state.go +++ /dev/null @@ -1,59 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetStateRoots for the beacon state. Updates the state roots -// to a new value by overwriting the previous value. -func (b *BeaconState) SetStateRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[stateRoots].MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - - b.state.StateRoots = val - b.markFieldAsDirty(stateRoots) - b.rebuildTrie[stateRoots] = true - return nil -} - -// UpdateStateRootAtIndex for the beacon state. Updates the state root -// at a specific index to a new value. -func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - - b.lock.RLock() - if uint64(len(b.state.StateRoots)) <= idx { - b.lock.RUnlock() - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.RUnlock() - - b.lock.Lock() - defer b.lock.Unlock() - - // Check if we hold the only reference to the shared state roots slice. - r := b.state.StateRoots - if ref := b.sharedFieldReferences[stateRoots]; ref.Refs() > 1 { - // Copy elements in underlying array by reference. - r = make([][]byte, len(b.state.StateRoots)) - copy(r, b.state.StateRoots) - ref.MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - } - - r[idx] = stateRoot[:] - b.state.StateRoots = r - - b.markFieldAsDirty(stateRoots) - b.addDirtyIndices(stateRoots, []uint64{idx}) - return nil -} diff --git a/beacon-chain/state/v2/setters_sync_committee.go b/beacon-chain/state/v2/setters_sync_committee.go deleted file mode 100644 index 3cd393839d..0000000000 --- a/beacon-chain/state/v2/setters_sync_committee.go +++ /dev/null @@ -1,31 +0,0 @@ -package v2 - -import ( - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetCurrentSyncCommittee for the beacon state. -func (b *BeaconState) SetCurrentSyncCommittee(val *ethpb.SyncCommittee) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.CurrentSyncCommittee = val - b.markFieldAsDirty(currentSyncCommittee) - return nil -} - -// SetNextSyncCommittee for the beacon state. -func (b *BeaconState) SetNextSyncCommittee(val *ethpb.SyncCommittee) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.NextSyncCommittee = val - b.markFieldAsDirty(nextSyncCommittee) - return nil -} diff --git a/beacon-chain/state/v2/setters_validator.go b/beacon-chain/state/v2/setters_validator.go deleted file mode 100644 index 57c4866149..0000000000 --- a/beacon-chain/state/v2/setters_validator.go +++ /dev/null @@ -1,265 +0,0 @@ -package v2 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetValidators for the beacon state. Updates the entire -// to a new value by overwriting the previous one. -func (b *BeaconState) SetValidators(val []*ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Validators = val - b.sharedFieldReferences[validators].MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - b.markFieldAsDirty(validators) - b.rebuildTrie[validators] = true - b.valMapHandler = stateutil.NewValMapHandler(b.state.Validators) - return nil -} - -// ApplyToEveryValidator applies the provided callback function to each validator in the -// validator registry. -func (b *BeaconState) ApplyToEveryValidator(f func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - v := b.state.Validators - if ref := b.sharedFieldReferences[validators]; ref.Refs() > 1 { - v = b.validatorsReferences() - ref.MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - b.lock.Unlock() - var changedVals []uint64 - for i, val := range v { - changed, newVal, err := f(i, val) - if err != nil { - return err - } - if changed { - changedVals = append(changedVals, uint64(i)) - v[i] = newVal - } - } - - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Validators = v - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, changedVals) - - return nil -} - -// UpdateValidatorAtIndex for the beacon state. Updates the validator -// at a specific index to a new value. -func (b *BeaconState) UpdateValidatorAtIndex(idx types.ValidatorIndex, val *ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - v := b.state.Validators - if ref := b.sharedFieldReferences[validators]; ref.Refs() > 1 { - v = b.validatorsReferences() - ref.MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - - v[idx] = val - b.state.Validators = v - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, []uint64{uint64(idx)}) - - return nil -} - -// SetBalances for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetBalances(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - - b.state.Balances = val - b.rebuildTrie[balances] = true - b.markFieldAsDirty(balances) - return nil -} - -// UpdateBalancesAtIndex for the beacon state. This method updates the balance -// at a specific index to a new value. -func (b *BeaconState) UpdateBalancesAtIndex(idx types.ValidatorIndex, val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Balances)) <= uint64(idx) { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - bals := b.state.Balances - if b.sharedFieldReferences[balances].Refs() > 1 { - bals = b.balances() - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - } - - bals[idx] = val - b.state.Balances = bals - b.markFieldAsDirty(balances) - b.addDirtyIndices(balances, []uint64{uint64(idx)}) - return nil -} - -// SetSlashings for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetSlashings(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[slashings].MinusRef() - b.sharedFieldReferences[slashings] = stateutil.NewRef(1) - - b.state.Slashings = val - b.markFieldAsDirty(slashings) - return nil -} - -// UpdateSlashingsAtIndex for the beacon state. Updates the slashings -// at a specific index to a new value. -func (b *BeaconState) UpdateSlashingsAtIndex(idx, val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Slashings)) <= idx { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - s := b.state.Slashings - if b.sharedFieldReferences[slashings].Refs() > 1 { - s = b.slashings() - b.sharedFieldReferences[slashings].MinusRef() - b.sharedFieldReferences[slashings] = stateutil.NewRef(1) - } - - s[idx] = val - - b.state.Slashings = s - - b.markFieldAsDirty(slashings) - return nil -} - -// AppendValidator for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendValidator(val *ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - vals := b.state.Validators - if b.sharedFieldReferences[validators].Refs() > 1 { - vals = b.validatorsReferences() - b.sharedFieldReferences[validators].MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - - // append validator to slice - b.state.Validators = append(vals, val) - valIdx := types.ValidatorIndex(len(b.state.Validators) - 1) - - b.valMapHandler.Set(bytesutil.ToBytes48(val.PublicKey), valIdx) - - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, []uint64{uint64(valIdx)}) - return nil -} - -// AppendBalance for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendBalance(bal uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - bals := b.state.Balances - if b.sharedFieldReferences[balances].Refs() > 1 { - bals = b.balances() - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - } - - b.state.Balances = append(bals, bal) - balIdx := len(b.state.Balances) - 1 - b.markFieldAsDirty(balances) - b.addDirtyIndices(balances, []uint64{uint64(balIdx)}) - return nil -} - -// AppendInactivityScore for the beacon state. -func (b *BeaconState) AppendInactivityScore(s uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - scores := b.state.InactivityScores - if b.sharedFieldReferences[inactivityScores].Refs() > 1 { - scores = b.inactivityScores() - b.sharedFieldReferences[inactivityScores].MinusRef() - b.sharedFieldReferences[inactivityScores] = stateutil.NewRef(1) - } - - b.state.InactivityScores = append(scores, s) - b.markFieldAsDirty(inactivityScores) - return nil -} - -// SetInactivityScores for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetInactivityScores(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[inactivityScores].MinusRef() - b.sharedFieldReferences[inactivityScores] = stateutil.NewRef(1) - - b.state.InactivityScores = val - b.markFieldAsDirty(inactivityScores) - return nil -} diff --git a/beacon-chain/state/v2/spec_parameters.go b/beacon-chain/state/v2/spec_parameters.go deleted file mode 100644 index 89c20f796f..0000000000 --- a/beacon-chain/state/v2/spec_parameters.go +++ /dev/null @@ -1,11 +0,0 @@ -package v2 - -import "github.com/prysmaticlabs/prysm/v3/config/params" - -func (b *BeaconState) ProportionalSlashingMultiplier() (uint64, error) { - return params.BeaconConfig().ProportionalSlashingMultiplierAltair, nil -} - -func (b *BeaconState) InactivityPenaltyQuotient() (uint64, error) { - return params.BeaconConfig().InactivityPenaltyQuotientAltair, nil -} diff --git a/beacon-chain/state/v2/state_trie.go b/beacon-chain/state/v2/state_trie.go deleted file mode 100644 index f691c4770f..0000000000 --- a/beacon-chain/state/v2/state_trie.go +++ /dev/null @@ -1,397 +0,0 @@ -package v2 - -import ( - "context" - "runtime" - "sort" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - "github.com/prysmaticlabs/prysm/v3/config/params" - "github.com/prysmaticlabs/prysm/v3/container/slice" - "github.com/prysmaticlabs/prysm/v3/crypto/hash" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/v3/encoding/ssz" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "go.opencensus.io/trace" - "google.golang.org/protobuf/proto" -) - -// InitializeFromProto the beacon state from a protobuf representation. -func InitializeFromProto(st *ethpb.BeaconStateAltair) (state.BeaconState, error) { - return statenative.InitializeFromProtoUnsafeAltair(proto.Clone(st).(*ethpb.BeaconStateAltair)) -} - -// InitializeFromProtoUnsafe directly uses the beacon state protobuf pointer -// and sets it as the inner state of the BeaconState type. -func InitializeFromProtoUnsafe(st *ethpb.BeaconStateAltair) (state.BeaconState, error) { - return statenative.InitializeFromProtoUnsafeAltair(st) -} - -// Copy returns a deep copy of the beacon state. -func (b *BeaconState) Copy() state.BeaconState { - if !b.hasInnerState() { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - fieldCount := params.BeaconConfig().BeaconStateAltairFieldCount - - dst := &BeaconState{ - state: ðpb.BeaconStateAltair{ - // Primitive types, safe to copy. - GenesisTime: b.state.GenesisTime, - Slot: b.state.Slot, - Eth1DepositIndex: b.state.Eth1DepositIndex, - - // Large arrays, infrequently changed, constant size. - RandaoMixes: b.state.RandaoMixes, - StateRoots: b.state.StateRoots, - BlockRoots: b.state.BlockRoots, - Slashings: b.state.Slashings, - Eth1DataVotes: b.state.Eth1DataVotes, - - // Large arrays, increases over time. - Validators: b.state.Validators, - Balances: b.state.Balances, - HistoricalRoots: b.state.HistoricalRoots, - PreviousEpochParticipation: b.state.PreviousEpochParticipation, - CurrentEpochParticipation: b.state.CurrentEpochParticipation, - InactivityScores: b.state.InactivityScores, - - // Everything else, too small to be concerned about, constant size. - Fork: b.fork(), - LatestBlockHeader: b.latestBlockHeader(), - Eth1Data: b.eth1Data(), - JustificationBits: b.justificationBits(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(), - FinalizedCheckpoint: b.finalizedCheckpoint(), - GenesisValidatorsRoot: b.genesisValidatorsRoot(), - CurrentSyncCommittee: b.currentSyncCommittee(), - NextSyncCommittee: b.nextSyncCommittee(), - }, - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - sharedFieldReferences: make(map[types.FieldIndex]*stateutil.Reference, 11), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - - // Share the reference to validator index map. - valMapHandler: b.valMapHandler, - } - - for field, ref := range b.sharedFieldReferences { - ref.AddRef() - dst.sharedFieldReferences[field] = ref - } - - // Increment ref for validator map - b.valMapHandler.AddRef() - - for i := range b.dirtyFields { - dst.dirtyFields[i] = true - } - - for i := range b.dirtyIndices { - indices := make([]uint64, len(b.dirtyIndices[i])) - copy(indices, b.dirtyIndices[i]) - dst.dirtyIndices[i] = indices - } - - for i := range b.rebuildTrie { - dst.rebuildTrie[i] = true - } - - for fldIdx, fieldTrie := range b.stateFieldLeaves { - dst.stateFieldLeaves[fldIdx] = fieldTrie - if fieldTrie.FieldReference() != nil { - fieldTrie.Lock() - fieldTrie.FieldReference().AddRef() - fieldTrie.Unlock() - } - } - - if b.merkleLayers != nil { - dst.merkleLayers = make([][][]byte, len(b.merkleLayers)) - for i, layer := range b.merkleLayers { - dst.merkleLayers[i] = make([][]byte, len(layer)) - for j, content := range layer { - dst.merkleLayers[i][j] = make([]byte, len(content)) - copy(dst.merkleLayers[i][j], content) - } - } - } - - state.StateCount.Inc() - // Finalizer runs when dst is being destroyed in garbage collection. - runtime.SetFinalizer(dst, finalizerCleanup) - - return dst -} - -// HashTreeRoot of the beacon state retrieves the Merkle root of the trie -// representation of the beacon state based on the eth2 Simple Serialize specification. -func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) { - ctx, span := trace.StartSpan(ctx, "beaconStateAltair.HashTreeRoot") - defer span.End() - - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return [32]byte{}, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return [32]byte{}, err - } - return bytesutil.ToBytes32(b.merkleLayers[len(b.merkleLayers)-1][0]), nil -} - -// Initializes the Merkle layers for the beacon state if they are empty. -// -// WARNING: Caller must acquire the mutex before using. -func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error { - if len(b.merkleLayers) > 0 { - return nil - } - fieldRoots, err := computeFieldRoots(ctx, b.state) - if err != nil { - return err - } - layers := stateutil.Merkleize(fieldRoots) - b.merkleLayers = layers - b.dirtyFields = make(map[types.FieldIndex]bool, params.BeaconConfig().BeaconStateAltairFieldCount) - return nil -} - -// Recomputes the Merkle layers for the dirty fields in the state. -// -// WARNING: Caller must acquire the mutex before using. -func (b *BeaconState) recomputeDirtyFields(ctx context.Context) error { - for field := range b.dirtyFields { - root, err := b.rootSelector(ctx, field) - if err != nil { - return err - } - b.merkleLayers[0][field] = root[:] - b.recomputeRoot(int(field)) - delete(b.dirtyFields, field) - } - return nil -} - -// FieldReferencesCount returns the reference count held by each field. This -// also includes the field trie held by each field. -func (b *BeaconState) FieldReferencesCount() map[string]uint64 { - refMap := make(map[string]uint64) - b.lock.RLock() - defer b.lock.RUnlock() - for i, f := range b.sharedFieldReferences { - refMap[i.String(b.Version())] = uint64(f.Refs()) - } - for i, f := range b.stateFieldLeaves { - numOfRefs := uint64(f.FieldReference().Refs()) - f.RLock() - if !f.Empty() { - refMap[i.String(b.Version())+"_trie"] = numOfRefs - } - f.RUnlock() - } - return refMap -} - -// IsNil checks if the state and the underlying proto -// object are nil. -func (b *BeaconState) IsNil() bool { - return b == nil || b.state == nil -} - -func (b *BeaconState) rootSelector(ctx context.Context, field types.FieldIndex) ([32]byte, error) { - ctx, span := trace.StartSpan(ctx, "beaconState.rootSelector") - defer span.End() - span.AddAttributes(trace.StringAttribute("field", field.String(b.Version()))) - - hasher := hash.CustomSHA256Hasher() - switch field { - case genesisTime: - return ssz.Uint64Root(b.state.GenesisTime), nil - case genesisValidatorsRoot: - return bytesutil.ToBytes32(b.state.GenesisValidatorsRoot), nil - case slot: - return ssz.Uint64Root(uint64(b.state.Slot)), nil - case eth1DepositIndex: - return ssz.Uint64Root(b.state.Eth1DepositIndex), nil - case fork: - return ssz.ForkRoot(b.state.Fork) - case latestBlockHeader: - return stateutil.BlockHeaderRoot(b.state.LatestBlockHeader) - case blockRoots: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.BlockRoots, fieldparams.BlockRootsLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(blockRoots, b.state.BlockRoots) - case stateRoots: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.StateRoots, fieldparams.StateRootsLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(stateRoots, b.state.StateRoots) - case historicalRoots: - return ssz.ByteArrayRootWithLimit(b.state.HistoricalRoots, fieldparams.HistoricalRootsLength) - case eth1Data: - return stateutil.Eth1Root(hasher, b.state.Eth1Data) - case eth1DataVotes: - if b.rebuildTrie[field] { - err := b.resetFieldTrie( - field, - b.state.Eth1DataVotes, - fieldparams.Eth1DataVotesLength, - ) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(field, b.state.Eth1DataVotes) - case validators: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.Validators, fieldparams.ValidatorRegistryLimit) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, validators) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(validators, b.state.Validators) - case balances: - if b.rebuildTrie[field] { - maxBalCap := uint64(fieldparams.ValidatorRegistryLimit) - elemSize := uint64(8) - balLimit := (maxBalCap*elemSize + 31) / 32 - err := b.resetFieldTrie(field, b.state.Balances, balLimit) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(balances, b.state.Balances) - case randaoMixes: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.RandaoMixes, fieldparams.RandaoMixesLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(randaoMixes, b.state.RandaoMixes) - case slashings: - return ssz.SlashingsRoot(b.state.Slashings) - case previousEpochParticipationBits: - return stateutil.ParticipationBitsRoot(b.state.PreviousEpochParticipation) - case currentEpochParticipationBits: - return stateutil.ParticipationBitsRoot(b.state.CurrentEpochParticipation) - case justificationBits: - return bytesutil.ToBytes32(b.state.JustificationBits), nil - case previousJustifiedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.PreviousJustifiedCheckpoint) - case currentJustifiedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.CurrentJustifiedCheckpoint) - case finalizedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.FinalizedCheckpoint) - case inactivityScores: - return stateutil.Uint64ListRootWithRegistryLimit(b.state.InactivityScores) - case currentSyncCommittee: - return stateutil.SyncCommitteeRoot(b.state.CurrentSyncCommittee) - case nextSyncCommittee: - return stateutil.SyncCommitteeRoot(b.state.NextSyncCommittee) - } - return [32]byte{}, errors.New("invalid field index provided") -} - -func (b *BeaconState) recomputeFieldTrie(index types.FieldIndex, elements interface{}) ([32]byte, error) { - fTrie := b.stateFieldLeaves[index] - fTrieMutex := fTrie.RWMutex - // We can't lock the trie directly because the trie's variable gets reassigned, - // and therefore we would call Unlock() on a different object. - fTrieMutex.Lock() - - if fTrie.Empty() { - err := b.resetFieldTrie(index, elements, fTrie.Length()) - if err != nil { - fTrieMutex.Unlock() - return [32]byte{}, err - } - // Reduce reference count as we are instantiating a new trie. - fTrie.FieldReference().MinusRef() - fTrieMutex.Unlock() - return b.stateFieldLeaves[index].TrieRoot() - } - - if fTrie.FieldReference().Refs() > 1 { - fTrie.FieldReference().MinusRef() - newTrie := fTrie.TransferTrie() - b.stateFieldLeaves[index] = newTrie - fTrie = newTrie - } - fTrieMutex.Unlock() - - // remove duplicate indexes - b.dirtyIndices[index] = slice.SetUint64(b.dirtyIndices[index]) - // sort indexes again - sort.Slice(b.dirtyIndices[index], func(i int, j int) bool { - return b.dirtyIndices[index][i] < b.dirtyIndices[index][j] - }) - root, err := fTrie.RecomputeTrie(b.dirtyIndices[index], elements) - if err != nil { - return [32]byte{}, err - } - b.dirtyIndices[index] = []uint64{} - return root, nil -} - -func (b *BeaconState) resetFieldTrie(index types.FieldIndex, elements interface{}, length uint64) error { - fTrie, err := fieldtrie.NewFieldTrie(index, fieldMap[index], elements, length) - if err != nil { - return err - } - b.stateFieldLeaves[index] = fTrie - b.dirtyIndices[index] = []uint64{} - return nil -} - -func finalizerCleanup(b *BeaconState) { - fieldCount := params.BeaconConfig().BeaconStateAltairFieldCount - for field, v := range b.sharedFieldReferences { - v.MinusRef() - if b.stateFieldLeaves[field].FieldReference() != nil { - b.stateFieldLeaves[field].FieldReference().MinusRef() - } - } - for i := 0; i < fieldCount; i++ { - field := types.FieldIndex(i) - delete(b.stateFieldLeaves, field) - delete(b.dirtyIndices, field) - delete(b.dirtyFields, field) - delete(b.sharedFieldReferences, field) - delete(b.stateFieldLeaves, field) - } - state.StateCount.Sub(1) -} diff --git a/beacon-chain/state/v2/testdata/fuzz/FuzzV2StateHashTreeRoot/52875ab39ad0eeec927085f3330d00508d015fe3c204b6bc6607296f64ec221c b/beacon-chain/state/v2/testdata/fuzz/FuzzV2StateHashTreeRoot/52875ab39ad0eeec927085f3330d00508d015fe3c204b6bc6607296f64ec221c deleted file mode 100644 index 609d1ea987..0000000000 --- a/beacon-chain/state/v2/testdata/fuzz/FuzzV2StateHashTreeRoot/52875ab39ad0eeec927085f3330d00508d015fe3c204b6bc6607296f64ec221c +++ /dev/null @@ -1,3 +0,0 @@ -go test fuzz v1 -[]byte("") -uint64(117) diff --git a/beacon-chain/state/v2/types.go b/beacon-chain/state/v2/types.go deleted file mode 100644 index 9c25012f62..0000000000 --- a/beacon-chain/state/v2/types.go +++ /dev/null @@ -1,78 +0,0 @@ -package v2 - -import ( - "sync" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - "github.com/prysmaticlabs/prysm/v3/config/params" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -func init() { - fieldMap = make(map[types.FieldIndex]types.DataType, params.BeaconConfig().BeaconStateFieldCount) - - // Initialize the fixed sized arrays. - fieldMap[types.BlockRoots] = types.BasicArray - fieldMap[types.StateRoots] = types.BasicArray - fieldMap[types.RandaoMixes] = types.BasicArray - - // Initialize the composite arrays. - fieldMap[types.Eth1DataVotes] = types.CompositeArray - fieldMap[types.Validators] = types.CompositeArray - - // Initialize Compressed Arrays - fieldMap[types.Balances] = types.CompressedArray -} - -// fieldMap keeps track of each field -// to its corresponding data type. -var fieldMap map[types.FieldIndex]types.DataType - -// ErrNilInnerState returns when the inner state is nil and no copy set or get -// operations can be performed on state. -var ErrNilInnerState = errors.New("nil inner state") - -// BeaconState defines a struct containing utilities for the eth2 chain state, defining -// getters and setters for its respective values and helpful functions such as HashTreeRoot(). -type BeaconState struct { - state *ethpb.BeaconStateAltair - lock sync.RWMutex - dirtyFields map[types.FieldIndex]bool - dirtyIndices map[types.FieldIndex][]uint64 - stateFieldLeaves map[types.FieldIndex]*fieldtrie.FieldTrie - rebuildTrie map[types.FieldIndex]bool - valMapHandler *stateutil.ValidatorMapHandler - merkleLayers [][][]byte - sharedFieldReferences map[types.FieldIndex]*stateutil.Reference -} - -// Field Aliases for values from the types package. -const ( - genesisTime = types.GenesisTime - genesisValidatorsRoot = types.GenesisValidatorsRoot - slot = types.Slot - fork = types.Fork - latestBlockHeader = types.LatestBlockHeader - blockRoots = types.BlockRoots - stateRoots = types.StateRoots - historicalRoots = types.HistoricalRoots - eth1Data = types.Eth1Data - eth1DataVotes = types.Eth1DataVotes - eth1DepositIndex = types.Eth1DepositIndex - validators = types.Validators - balances = types.Balances - randaoMixes = types.RandaoMixes - slashings = types.Slashings - previousEpochParticipationBits = types.PreviousEpochParticipationBits - currentEpochParticipationBits = types.CurrentEpochParticipationBits - justificationBits = types.JustificationBits - previousJustifiedCheckpoint = types.PreviousJustifiedCheckpoint - currentJustifiedCheckpoint = types.CurrentJustifiedCheckpoint - finalizedCheckpoint = types.FinalizedCheckpoint - inactivityScores = types.InactivityScores - currentSyncCommittee = types.CurrentSyncCommittee - nextSyncCommittee = types.NextSyncCommittee -) diff --git a/beacon-chain/state/v3/BUILD.bazel b/beacon-chain/state/v3/BUILD.bazel deleted file mode 100644 index cc8927199b..0000000000 --- a/beacon-chain/state/v3/BUILD.bazel +++ /dev/null @@ -1,61 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = [ - "deprecated_getters.go", - "deprecated_setters.go", - "error.go", - "field_roots.go", - "getters_block.go", - "getters_checkpoint.go", - "getters_eth1.go", - "getters_misc.go", - "getters_participation.go", - "getters_payload_header.go", - "getters_randao.go", - "getters_state.go", - "getters_sync_committee.go", - "getters_validator.go", - "proofs.go", - "setters_block.go", - "setters_checkpoint.go", - "setters_eth1.go", - "setters_misc.go", - "setters_participation.go", - "setters_payload_header.go", - "setters_randao.go", - "setters_state.go", - "setters_sync_committee.go", - "setters_validator.go", - "spec_parameters.go", - "state_trie.go", - "types.go", - ], - importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3", - visibility = ["//visibility:public"], - deps = [ - "//beacon-chain/core/time:go_default_library", - "//beacon-chain/state:go_default_library", - "//beacon-chain/state/fieldtrie:go_default_library", - "//beacon-chain/state/state-native:go_default_library", - "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/types:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//config/fieldparams:go_default_library", - "//config/params:go_default_library", - "//consensus-types/interfaces:go_default_library", - "//consensus-types/primitives:go_default_library", - "//container/slice:go_default_library", - "//crypto/hash:go_default_library", - "//encoding/bytesutil:go_default_library", - "//encoding/ssz:go_default_library", - "//proto/engine/v1:go_default_library", - "//proto/prysm/v1alpha1:go_default_library", - "//runtime/version:go_default_library", - "@com_github_pkg_errors//:go_default_library", - "@com_github_prysmaticlabs_go_bitfield//:go_default_library", - "@io_opencensus_go//trace:go_default_library", - "@org_golang_google_protobuf//proto:go_default_library", - ], -) diff --git a/beacon-chain/state/v3/deprecated_getters.go b/beacon-chain/state/v3/deprecated_getters.go deleted file mode 100644 index ca92ef49de..0000000000 --- a/beacon-chain/state/v3/deprecated_getters.go +++ /dev/null @@ -1,16 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// PreviousEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) { - return nil, errors.New("PreviousEpochAttestations is not supported for version Bellatrix beacon state") -} - -// CurrentEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) { - return nil, errors.New("CurrentEpochAttestations is not supported for version Bellatrix beacon state") -} diff --git a/beacon-chain/state/v3/deprecated_setters.go b/beacon-chain/state/v3/deprecated_setters.go deleted file mode 100644 index 7f761d7802..0000000000 --- a/beacon-chain/state/v3/deprecated_setters.go +++ /dev/null @@ -1,21 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// AppendCurrentEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) AppendCurrentEpochAttestations(_ *ethpb.PendingAttestation) error { - return errors.New("AppendCurrentEpochAttestations is not supported for Bellatrix beacon state") -} - -// AppendPreviousEpochAttestations is not supported for HF1 beacon state. -func (*BeaconState) AppendPreviousEpochAttestations(_ *ethpb.PendingAttestation) error { - return errors.New("AppendPreviousEpochAttestations is not supported for version Bellatrix beacon state") -} - -// RotateAttestations is not supported for HF1 beacon state. -func (*BeaconState) RotateAttestations() error { - return errors.New("RotateAttestations is not supported for version Bellatrix beacon state") -} diff --git a/beacon-chain/state/v3/error.go b/beacon-chain/state/v3/error.go deleted file mode 100644 index f2a058a8d9..0000000000 --- a/beacon-chain/state/v3/error.go +++ /dev/null @@ -1,5 +0,0 @@ -package v3 - -import "errors" - -var ErrNilParticipation = errors.New("nil epoch participation in state") diff --git a/beacon-chain/state/v3/field_roots.go b/beacon-chain/state/v3/field_roots.go deleted file mode 100644 index c16b519607..0000000000 --- a/beacon-chain/state/v3/field_roots.go +++ /dev/null @@ -1,14 +0,0 @@ -package v3 - -import ( - "context" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// computeFieldRoots returns the hash tree root computations of every field in -// the beacon state as a list of 32 byte roots. -func computeFieldRoots(ctx context.Context, state *ethpb.BeaconStateBellatrix) ([][]byte, error) { - return stateutil.ComputeFieldRootsWithHasherBellatrix(ctx, state) -} diff --git a/beacon-chain/state/v3/getters_block.go b/beacon-chain/state/v3/getters_block.go deleted file mode 100644 index ec59a28bb2..0000000000 --- a/beacon-chain/state/v3/getters_block.go +++ /dev/null @@ -1,99 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// LatestBlockHeader stored within the beacon state. -func (b *BeaconState) LatestBlockHeader() *ethpb.BeaconBlockHeader { - if !b.hasInnerState() { - return nil - } - if b.state.LatestBlockHeader == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.latestBlockHeader() -} - -// latestBlockHeader stored within the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) latestBlockHeader() *ethpb.BeaconBlockHeader { - if !b.hasInnerState() { - return nil - } - if b.state.LatestBlockHeader == nil { - return nil - } - - hdr := ðpb.BeaconBlockHeader{ - Slot: b.state.LatestBlockHeader.Slot, - ProposerIndex: b.state.LatestBlockHeader.ProposerIndex, - } - - parentRoot := make([]byte, len(b.state.LatestBlockHeader.ParentRoot)) - bodyRoot := make([]byte, len(b.state.LatestBlockHeader.BodyRoot)) - stateRoot := make([]byte, len(b.state.LatestBlockHeader.StateRoot)) - - copy(parentRoot, b.state.LatestBlockHeader.ParentRoot) - copy(bodyRoot, b.state.LatestBlockHeader.BodyRoot) - copy(stateRoot, b.state.LatestBlockHeader.StateRoot) - hdr.ParentRoot = parentRoot - hdr.BodyRoot = bodyRoot - hdr.StateRoot = stateRoot - return hdr -} - -// BlockRoots kept track of in the beacon state. -func (b *BeaconState) BlockRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.BlockRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.blockRoots() -} - -// blockRoots kept track of in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) blockRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.BlockRoots) -} - -// BlockRootAtIndex retrieves a specific block root based on an -// input index value. -func (b *BeaconState) BlockRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.BlockRoots == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.blockRootAtIndex(idx) -} - -// blockRootAtIndex retrieves a specific block root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) blockRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - return bytesutil.SafeCopyRootAtIndex(b.state.BlockRoots, idx) -} diff --git a/beacon-chain/state/v3/getters_checkpoint.go b/beacon-chain/state/v3/getters_checkpoint.go deleted file mode 100644 index 94443bff65..0000000000 --- a/beacon-chain/state/v3/getters_checkpoint.go +++ /dev/null @@ -1,160 +0,0 @@ -package v3 - -import ( - "bytes" - - "github.com/prysmaticlabs/go-bitfield" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// JustificationBits marking which epochs have been justified in the beacon chain. -func (b *BeaconState) JustificationBits() bitfield.Bitvector4 { - if !b.hasInnerState() { - return nil - } - if b.state.JustificationBits == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.justificationBits() -} - -// justificationBits marking which epochs have been justified in the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) justificationBits() bitfield.Bitvector4 { - if !b.hasInnerState() { - return nil - } - if b.state.JustificationBits == nil { - return nil - } - - res := make([]byte, len(b.state.JustificationBits.Bytes())) - copy(res, b.state.JustificationBits.Bytes()) - return res -} - -// PreviousJustifiedCheckpoint denoting an epoch and block root. -func (b *BeaconState) PreviousJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.PreviousJustifiedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.previousJustifiedCheckpoint() -} - -// previousJustifiedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) previousJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.PreviousJustifiedCheckpoint) -} - -// CurrentJustifiedCheckpoint denoting an epoch and block root. -func (b *BeaconState) CurrentJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.CurrentJustifiedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.currentJustifiedCheckpoint() -} - -// currentJustifiedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentJustifiedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.CurrentJustifiedCheckpoint) -} - -// MatchCurrentJustifiedCheckpoint returns true if input justified checkpoint matches -// the current justified checkpoint in state. -func (b *BeaconState) MatchCurrentJustifiedCheckpoint(c *ethpb.Checkpoint) bool { - if !b.hasInnerState() { - return false - } - if b.state.CurrentJustifiedCheckpoint == nil { - return false - } - - if c.Epoch != b.state.CurrentJustifiedCheckpoint.Epoch { - return false - } - return bytes.Equal(c.Root, b.state.CurrentJustifiedCheckpoint.Root) -} - -// MatchPreviousJustifiedCheckpoint returns true if the input justified checkpoint matches -// the previous justified checkpoint in state. -func (b *BeaconState) MatchPreviousJustifiedCheckpoint(c *ethpb.Checkpoint) bool { - if !b.hasInnerState() { - return false - } - if b.state.PreviousJustifiedCheckpoint == nil { - return false - } - - if c.Epoch != b.state.PreviousJustifiedCheckpoint.Epoch { - return false - } - return bytes.Equal(c.Root, b.state.PreviousJustifiedCheckpoint.Root) -} - -// FinalizedCheckpoint denoting an epoch and block root. -func (b *BeaconState) FinalizedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - if b.state.FinalizedCheckpoint == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.finalizedCheckpoint() -} - -// finalizedCheckpoint denoting an epoch and block root. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) finalizedCheckpoint() *ethpb.Checkpoint { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyCheckpoint(b.state.FinalizedCheckpoint) -} - -// FinalizedCheckpointEpoch returns the epoch value of the finalized checkpoint. -func (b *BeaconState) FinalizedCheckpointEpoch() types.Epoch { - if !b.hasInnerState() { - return 0 - } - if b.state.FinalizedCheckpoint == nil { - return 0 - } - b.lock.RLock() - defer b.lock.RUnlock() - - return b.state.FinalizedCheckpoint.Epoch -} diff --git a/beacon-chain/state/v3/getters_eth1.go b/beacon-chain/state/v3/getters_eth1.go deleted file mode 100644 index c72e590833..0000000000 --- a/beacon-chain/state/v3/getters_eth1.go +++ /dev/null @@ -1,91 +0,0 @@ -package v3 - -import ( - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// Eth1Data corresponding to the proof-of-work chain information stored in the beacon state. -func (b *BeaconState) Eth1Data() *ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1Data == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1Data() -} - -// eth1Data corresponding to the proof-of-work chain information stored in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1Data() *ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1Data == nil { - return nil - } - - return ethpb.CopyETH1Data(b.state.Eth1Data) -} - -// Eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain -// data retrieved from eth1. -func (b *BeaconState) Eth1DataVotes() []*ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1DataVotes == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1DataVotes() -} - -// eth1DataVotes corresponds to votes from Ethereum on the canonical proof-of-work chain -// data retrieved from eth1. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1DataVotes() []*ethpb.Eth1Data { - if !b.hasInnerState() { - return nil - } - if b.state.Eth1DataVotes == nil { - return nil - } - - res := make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) - for i := 0; i < len(res); i++ { - res[i] = ethpb.CopyETH1Data(b.state.Eth1DataVotes[i]) - } - return res -} - -// Eth1DepositIndex corresponds to the index of the deposit made to the -// validator deposit contract at the time of this state's eth1 data. -func (b *BeaconState) Eth1DepositIndex() uint64 { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.eth1DepositIndex() -} - -// eth1DepositIndex corresponds to the index of the deposit made to the -// validator deposit contract at the time of this state's eth1 data. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) eth1DepositIndex() uint64 { - if !b.hasInnerState() { - return 0 - } - - return b.state.Eth1DepositIndex -} diff --git a/beacon-chain/state/v3/getters_misc.go b/beacon-chain/state/v3/getters_misc.go deleted file mode 100644 index f6c1bb4899..0000000000 --- a/beacon-chain/state/v3/getters_misc.go +++ /dev/null @@ -1,163 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/config/params" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/v3/runtime/version" -) - -// GenesisTime of the beacon state as a uint64. -func (b *BeaconState) GenesisTime() uint64 { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.genesisTime() -} - -// genesisTime of the beacon state as a uint64. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) genesisTime() uint64 { - if !b.hasInnerState() { - return 0 - } - - return b.state.GenesisTime -} - -// GenesisValidatorsRoot of the beacon state. -func (b *BeaconState) GenesisValidatorsRoot() []byte { - if !b.hasInnerState() { - return nil - } - if b.state.GenesisValidatorsRoot == nil { - return params.BeaconConfig().ZeroHash[:] - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.genesisValidatorsRoot() -} - -// genesisValidatorsRoot of the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) genesisValidatorsRoot() []byte { - if !b.hasInnerState() { - return nil - } - if b.state.GenesisValidatorsRoot == nil { - return params.BeaconConfig().ZeroHash[:] - } - - root := make([]byte, 32) - copy(root, b.state.GenesisValidatorsRoot) - return root -} - -// Version of the beacon state. This method -// is strictly meant to be used without a lock -// internally. -func (_ *BeaconState) Version() int { - return version.Bellatrix -} - -// Slot of the current beacon chain state. -func (b *BeaconState) Slot() types.Slot { - if !b.hasInnerState() { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.slot() -} - -// slot of the current beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) slot() types.Slot { - if !b.hasInnerState() { - return 0 - } - - return b.state.Slot -} - -// Fork version of the beacon chain. -func (b *BeaconState) Fork() *ethpb.Fork { - if !b.hasInnerState() { - return nil - } - if b.state.Fork == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.fork() -} - -// fork version of the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) fork() *ethpb.Fork { - if !b.hasInnerState() { - return nil - } - if b.state.Fork == nil { - return nil - } - - prevVersion := make([]byte, len(b.state.Fork.PreviousVersion)) - copy(prevVersion, b.state.Fork.PreviousVersion) - currVersion := make([]byte, len(b.state.Fork.CurrentVersion)) - copy(currVersion, b.state.Fork.CurrentVersion) - return ðpb.Fork{ - PreviousVersion: prevVersion, - CurrentVersion: currVersion, - Epoch: b.state.Fork.Epoch, - } -} - -// HistoricalRoots based on epochs stored in the beacon state. -func (b *BeaconState) HistoricalRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.HistoricalRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.historicalRoots() -} - -// historicalRoots based on epochs stored in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) historicalRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.HistoricalRoots) -} - -// balancesLength returns the length of the balances slice. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) balancesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.Balances == nil { - return 0 - } - - return len(b.state.Balances) -} diff --git a/beacon-chain/state/v3/getters_participation.go b/beacon-chain/state/v3/getters_participation.go deleted file mode 100644 index 026c8d02a4..0000000000 --- a/beacon-chain/state/v3/getters_participation.go +++ /dev/null @@ -1,78 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// CurrentEpochParticipation corresponding to participation bits on the beacon chain. -func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.CurrentEpochParticipation == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.currentEpochParticipation(), nil -} - -// PreviousEpochParticipation corresponding to participation bits on the beacon chain. -func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.PreviousEpochParticipation == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.previousEpochParticipation(), nil -} - -// UnrealizedCheckpointBalances returns the total balances: active, target attested in -// current epoch and target attested in previous epoch. This function is used to -// compute the "unrealized justification" that a synced Beacon Block will have. -func (b *BeaconState) UnrealizedCheckpointBalances() (uint64, uint64, uint64, error) { - if !b.hasInnerState() { - return 0, 0, 0, ErrNilInnerState - } - currentEpoch := time.CurrentEpoch(b) - b.lock.RLock() - defer b.lock.RUnlock() - - cp := b.state.CurrentEpochParticipation - pp := b.state.PreviousEpochParticipation - if cp == nil || pp == nil { - return 0, 0, 0, ErrNilParticipation - } - return stateutil.UnrealizedCheckpointBalances(cp, pp, b.state.Validators, currentEpoch) - -} - -// currentEpochParticipation corresponding to participation bits on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentEpochParticipation() []byte { - if !b.hasInnerState() { - return nil - } - tmp := make([]byte, len(b.state.CurrentEpochParticipation)) - copy(tmp, b.state.CurrentEpochParticipation) - return tmp -} - -// previousEpochParticipation corresponding to participation bits on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) previousEpochParticipation() []byte { - if !b.hasInnerState() { - return nil - } - tmp := make([]byte, len(b.state.PreviousEpochParticipation)) - copy(tmp, b.state.PreviousEpochParticipation) - return tmp -} diff --git a/beacon-chain/state/v3/getters_payload_header.go b/beacon-chain/state/v3/getters_payload_header.go deleted file mode 100644 index 8007e35b8b..0000000000 --- a/beacon-chain/state/v3/getters_payload_header.go +++ /dev/null @@ -1,31 +0,0 @@ -package v3 - -import ( - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// LatestExecutionPayloadHeader of the beacon state. -func (b *BeaconState) LatestExecutionPayloadHeader() (*enginev1.ExecutionPayloadHeader, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.LatestExecutionPayloadHeader == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.latestExecutionPayloadHeader(), nil -} - -// latestExecutionPayloadHeader of the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) latestExecutionPayloadHeader() *enginev1.ExecutionPayloadHeader { - if !b.hasInnerState() { - return nil - } - - return ethpb.CopyExecutionPayloadHeader(b.state.LatestExecutionPayloadHeader) -} diff --git a/beacon-chain/state/v3/getters_randao.go b/beacon-chain/state/v3/getters_randao.go deleted file mode 100644 index e7324004fc..0000000000 --- a/beacon-chain/state/v3/getters_randao.go +++ /dev/null @@ -1,85 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" -) - -// RandaoMixes of block proposers on the beacon chain. -func (b *BeaconState) RandaoMixes() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.RandaoMixes == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixes() -} - -// randaoMixes of block proposers on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixes() [][]byte { - if !b.hasInnerState() { - return nil - } - - return bytesutil.SafeCopy2dBytes(b.state.RandaoMixes) -} - -// RandaoMixAtIndex retrieves a specific block root based on an -// input index value. -func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.RandaoMixes == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixAtIndex(idx) -} - -// randaoMixAtIndex retrieves a specific block root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - return bytesutil.SafeCopyRootAtIndex(b.state.RandaoMixes, idx) -} - -// RandaoMixesLength returns the length of the randao mixes slice. -func (b *BeaconState) RandaoMixesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.RandaoMixes == nil { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.randaoMixesLength() -} - -// randaoMixesLength returns the length of the randao mixes slice. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) randaoMixesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.RandaoMixes == nil { - return 0 - } - - return len(b.state.RandaoMixes) -} diff --git a/beacon-chain/state/v3/getters_state.go b/beacon-chain/state/v3/getters_state.go deleted file mode 100644 index 37b69633c4..0000000000 --- a/beacon-chain/state/v3/getters_state.go +++ /dev/null @@ -1,127 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// InnerStateUnsafe returns the pointer value of the underlying -// beacon state proto object, bypassing immutability. Use with care. -func (b *BeaconState) InnerStateUnsafe() interface{} { - if b == nil { - return nil - } - return b.state -} - -// CloneInnerState the beacon state into a protobuf for usage. -func (b *BeaconState) CloneInnerState() interface{} { - if b == nil || b.state == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - return ðpb.BeaconStateBellatrix{ - GenesisTime: b.genesisTime(), - GenesisValidatorsRoot: b.genesisValidatorsRoot(), - Slot: b.slot(), - Fork: b.fork(), - LatestBlockHeader: b.latestBlockHeader(), - BlockRoots: b.blockRoots(), - StateRoots: b.stateRoots(), - HistoricalRoots: b.historicalRoots(), - Eth1Data: b.eth1Data(), - Eth1DataVotes: b.eth1DataVotes(), - Eth1DepositIndex: b.eth1DepositIndex(), - Validators: b.validators(), - Balances: b.balances(), - RandaoMixes: b.randaoMixes(), - Slashings: b.slashings(), - CurrentEpochParticipation: b.currentEpochParticipation(), - PreviousEpochParticipation: b.previousEpochParticipation(), - JustificationBits: b.justificationBits(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(), - FinalizedCheckpoint: b.finalizedCheckpoint(), - InactivityScores: b.inactivityScores(), - CurrentSyncCommittee: b.currentSyncCommittee(), - NextSyncCommittee: b.nextSyncCommittee(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeader(), - } -} - -// hasInnerState detects if the internal reference to the state data structure -// is populated correctly. Returns false if nil. -func (b *BeaconState) hasInnerState() bool { - return b != nil && b.state != nil -} - -// StateRoots kept track of in the beacon state. -func (b *BeaconState) StateRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - if b.state.StateRoots == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.stateRoots() -} - -// StateRoots kept track of in the beacon state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) stateRoots() [][]byte { - if !b.hasInnerState() { - return nil - } - return bytesutil.SafeCopy2dBytes(b.state.StateRoots) -} - -// StateRootAtIndex retrieves a specific state root based on an -// input index value. -func (b *BeaconState) StateRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.StateRoots == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.stateRootAtIndex(idx) -} - -// stateRootAtIndex retrieves a specific state root based on an -// input index value. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) stateRootAtIndex(idx uint64) ([]byte, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - return bytesutil.SafeCopyRootAtIndex(b.state.StateRoots, idx) -} - -// MarshalSSZ marshals the underlying beacon state to bytes. -func (b *BeaconState) MarshalSSZ() ([]byte, error) { - if !b.hasInnerState() { - return nil, errors.New("nil beacon state") - } - return b.state.MarshalSSZ() -} - -// ProtobufBeaconState transforms an input into beacon state Bellatrix in the form of protobuf. -// Error is returned if the input is not type protobuf beacon state. -func ProtobufBeaconState(s interface{}) (*ethpb.BeaconStateBellatrix, error) { - pbState, ok := s.(*ethpb.BeaconStateBellatrix) - if !ok { - return nil, errors.New("input is not type pb.BeaconStateBellatrix") - } - return pbState, nil -} diff --git a/beacon-chain/state/v3/getters_sync_committee.go b/beacon-chain/state/v3/getters_sync_committee.go deleted file mode 100644 index 995f57ec54..0000000000 --- a/beacon-chain/state/v3/getters_sync_committee.go +++ /dev/null @@ -1,69 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// currentSyncCommittee of the current sync committee in beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) currentSyncCommittee() *ethpb.SyncCommittee { - if !b.hasInnerState() { - return nil - } - - return CopySyncCommittee(b.state.CurrentSyncCommittee) -} - -// nextSyncCommittee of the next sync committee in beacon chain state. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) nextSyncCommittee() *ethpb.SyncCommittee { - if !b.hasInnerState() { - return nil - } - - return CopySyncCommittee(b.state.NextSyncCommittee) -} - -// CurrentSyncCommittee of the current sync committee in beacon chain state. -func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.CurrentSyncCommittee == nil { - return nil, nil - } - - return b.currentSyncCommittee(), nil -} - -// NextSyncCommittee of the next sync committee in beacon chain state. -func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.NextSyncCommittee == nil { - return nil, nil - } - - return b.nextSyncCommittee(), nil -} - -// CopySyncCommittee copies the provided sync committee object. -func CopySyncCommittee(data *ethpb.SyncCommittee) *ethpb.SyncCommittee { - if data == nil { - return nil - } - return ðpb.SyncCommittee{ - Pubkeys: bytesutil.SafeCopy2dBytes(data.Pubkeys), - AggregatePubkey: bytesutil.SafeCopyBytes(data.AggregatePubkey), - } -} diff --git a/beacon-chain/state/v3/getters_validator.go b/beacon-chain/state/v3/getters_validator.go deleted file mode 100644 index 11d67986b5..0000000000 --- a/beacon-chain/state/v3/getters_validator.go +++ /dev/null @@ -1,324 +0,0 @@ -package v3 - -import ( - "fmt" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// ValidatorIndexOutOfRangeError represents an error scenario where a validator does not exist -// at a given index in the validator's array. -type ValidatorIndexOutOfRangeError struct { - message string -} - -// NewValidatorIndexOutOfRangeError creates a new error instance. -func NewValidatorIndexOutOfRangeError(index types.ValidatorIndex) ValidatorIndexOutOfRangeError { - return ValidatorIndexOutOfRangeError{ - message: fmt.Sprintf("index %d out of range", index), - } -} - -// Error returns the underlying error message. -func (e *ValidatorIndexOutOfRangeError) Error() string { - return e.message -} - -// Validators participating in consensus on the beacon chain. -func (b *BeaconState) Validators() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.validators() -} - -// validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) validators() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - res := make([]*ethpb.Validator, len(b.state.Validators)) - for i := 0; i < len(res); i++ { - val := b.state.Validators[i] - if val == nil { - continue - } - res[i] = ethpb.CopyValidator(val) - } - return res -} - -// references of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. This does not -// copy fully and instead just copies the reference. -func (b *BeaconState) validatorsReferences() []*ethpb.Validator { - if !b.hasInnerState() { - return nil - } - if b.state.Validators == nil { - return nil - } - - res := make([]*ethpb.Validator, len(b.state.Validators)) - for i := 0; i < len(res); i++ { - validator := b.state.Validators[i] - if validator == nil { - continue - } - // copy validator reference instead. - res[i] = validator - } - return res -} - -// ValidatorAtIndex is the validator at the provided index. -func (b *BeaconState) ValidatorAtIndex(idx types.ValidatorIndex) (*ethpb.Validator, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.Validators == nil { - return ðpb.Validator{}, nil - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - e := NewValidatorIndexOutOfRangeError(idx) - return nil, &e - } - - b.lock.RLock() - defer b.lock.RUnlock() - - val := b.state.Validators[idx] - return ethpb.CopyValidator(val), nil -} - -// ValidatorAtIndexReadOnly is the validator at the provided index. This method -// doesn't clone the validator. -func (b *BeaconState) ValidatorAtIndexReadOnly(idx types.ValidatorIndex) (state.ReadOnlyValidator, error) { - if !b.hasInnerState() { - return nil, ErrNilInnerState - } - if b.state.Validators == nil { - return nil, state.ErrNilValidatorsInState - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - e := NewValidatorIndexOutOfRangeError(idx) - return nil, &e - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return v1.NewValidator(b.state.Validators[idx]) -} - -// ValidatorIndexByPubkey returns a given validator by its 48-byte public key. -func (b *BeaconState) ValidatorIndexByPubkey(key [fieldparams.BLSPubkeyLength]byte) (types.ValidatorIndex, bool) { - if b == nil || b.valMapHandler == nil || b.valMapHandler.IsNil() { - return 0, false - } - b.lock.RLock() - defer b.lock.RUnlock() - numOfVals := len(b.state.Validators) - - idx, ok := b.valMapHandler.Get(key) - if ok && types.ValidatorIndex(numOfVals) <= idx { - return types.ValidatorIndex(0), false - } - return idx, ok -} - -// PubkeyAtIndex returns the pubkey at the given -// validator index. -func (b *BeaconState) PubkeyAtIndex(idx types.ValidatorIndex) [fieldparams.BLSPubkeyLength]byte { - if !b.hasInnerState() { - return [fieldparams.BLSPubkeyLength]byte{} - } - if uint64(idx) >= uint64(len(b.state.Validators)) { - return [fieldparams.BLSPubkeyLength]byte{} - } - b.lock.RLock() - defer b.lock.RUnlock() - - if b.state.Validators[idx] == nil { - return [fieldparams.BLSPubkeyLength]byte{} - } - return bytesutil.ToBytes48(b.state.Validators[idx].PublicKey) -} - -// NumValidators returns the size of the validator registry. -func (b *BeaconState) NumValidators() int { - if !b.hasInnerState() { - return 0 - } - b.lock.RLock() - defer b.lock.RUnlock() - - return len(b.state.Validators) -} - -// ReadFromEveryValidator reads values from every validator and applies it to the provided function. -// -// WARNING: This method is potentially unsafe, as it exposes the actual validator registry. -func (b *BeaconState) ReadFromEveryValidator(f func(idx int, val state.ReadOnlyValidator) error) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if b.state.Validators == nil { - return errors.New("nil validators in state") - } - b.lock.RLock() - validators := b.state.Validators - b.lock.RUnlock() - - for i, v := range validators { - v, err := v1.NewValidator(v) - if err != nil { - return err - } - if err := f(i, v); err != nil { - return err - } - } - return nil -} - -// Balances of validators participating in consensus on the beacon chain. -func (b *BeaconState) Balances() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Balances == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.balances() -} - -// balances of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) balances() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Balances == nil { - return nil - } - - res := make([]uint64, len(b.state.Balances)) - copy(res, b.state.Balances) - return res -} - -// BalanceAtIndex of validator with the provided index. -func (b *BeaconState) BalanceAtIndex(idx types.ValidatorIndex) (uint64, error) { - if !b.hasInnerState() { - return 0, ErrNilInnerState - } - if b.state.Balances == nil { - return 0, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - if uint64(len(b.state.Balances)) <= uint64(idx) { - return 0, fmt.Errorf("index of %d does not exist", idx) - } - return b.state.Balances[idx], nil -} - -// BalancesLength returns the length of the balances slice. -func (b *BeaconState) BalancesLength() int { - if !b.hasInnerState() { - return 0 - } - if b.state.Balances == nil { - return 0 - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.balancesLength() -} - -// Slashings of validators on the beacon chain. -func (b *BeaconState) Slashings() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Slashings == nil { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.slashings() -} - -// slashings of validators on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) slashings() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.Slashings == nil { - return nil - } - - res := make([]uint64, len(b.state.Slashings)) - copy(res, b.state.Slashings) - return res -} - -// inactivityScores of validators participating in consensus on the beacon chain. -// This assumes that a lock is already held on BeaconState. -func (b *BeaconState) inactivityScores() []uint64 { - if !b.hasInnerState() { - return nil - } - if b.state.InactivityScores == nil { - return nil - } - - res := make([]uint64, len(b.state.InactivityScores)) - copy(res, b.state.InactivityScores) - return res -} - -// InactivityScores of validators participating in consensus on the beacon chain. -func (b *BeaconState) InactivityScores() ([]uint64, error) { - if !b.hasInnerState() { - return nil, nil - } - if b.state.InactivityScores == nil { - return nil, nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - - return b.inactivityScores(), nil -} diff --git a/beacon-chain/state/v3/proofs.go b/beacon-chain/state/v3/proofs.go deleted file mode 100644 index 5ba251d217..0000000000 --- a/beacon-chain/state/v3/proofs.go +++ /dev/null @@ -1,83 +0,0 @@ -package v3 - -import ( - "context" - "encoding/binary" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" -) - -const ( - finalizedRootIndex = uint64(105) // Precomputed value. -) - -// FinalizedRootGeneralizedIndex for the beacon state. -func FinalizedRootGeneralizedIndex() uint64 { - return finalizedRootIndex -} - -// CurrentSyncCommitteeGeneralizedIndex for the beacon state. -func CurrentSyncCommitteeGeneralizedIndex() uint64 { - return uint64(currentSyncCommittee) -} - -// NextSyncCommitteeGeneralizedIndex for the beacon state. -func NextSyncCommitteeGeneralizedIndex() uint64 { - return uint64(nextSyncCommittee) -} - -// CurrentSyncCommitteeProof from the state's Merkle trie representation. -func (b *BeaconState) CurrentSyncCommitteeProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - // In case the Merkle layers of the trie are not populated, we need - // to perform some initialization. - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - // Our beacon state uses a "dirty" fields pattern which requires us to - // recompute branches of the Merkle layers that are marked as dirty. - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - return fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(currentSyncCommittee)), nil -} - -// NextSyncCommitteeProof from the state's Merkle trie representation. -func (b *BeaconState) NextSyncCommitteeProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - return fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(nextSyncCommittee)), nil -} - -// FinalizedRootProof crafts a Merkle proof for the finalized root -// contained within the finalized checkpoint of a beacon state. -func (b *BeaconState) FinalizedRootProof(ctx context.Context) ([][]byte, error) { - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return nil, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return nil, err - } - cpt := b.state.FinalizedCheckpoint - // The epoch field of a finalized checkpoint is the neighbor - // index of the finalized root field in its Merkle tree representation - // of the checkpoint. This neighbor is the first element added to the proof. - epochBuf := make([]byte, 8) - binary.LittleEndian.PutUint64(epochBuf, uint64(cpt.Epoch)) - epochRoot := bytesutil.ToBytes32(epochBuf) - proof := make([][]byte, 0) - proof = append(proof, epochRoot[:]) - branch := fieldtrie.ProofFromMerkleLayers(b.merkleLayers, int(finalizedCheckpoint)) - proof = append(proof, branch...) - return proof, nil -} diff --git a/beacon-chain/state/v3/setters_block.go b/beacon-chain/state/v3/setters_block.go deleted file mode 100644 index dae6b18873..0000000000 --- a/beacon-chain/state/v3/setters_block.go +++ /dev/null @@ -1,68 +0,0 @@ -package v3 - -import ( - "fmt" - - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetLatestBlockHeader in the beacon state. -func (b *BeaconState) SetLatestBlockHeader(val *ethpb.BeaconBlockHeader) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.LatestBlockHeader = ethpb.CopyBeaconBlockHeader(val) - b.markFieldAsDirty(latestBlockHeader) - return nil -} - -// SetBlockRoots for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetBlockRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[blockRoots].MinusRef() - b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1) - - b.state.BlockRoots = val - b.markFieldAsDirty(blockRoots) - b.rebuildTrie[blockRoots] = true - return nil -} - -// UpdateBlockRootAtIndex for the beacon state. Updates the block root -// at a specific index to a new value. -func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.BlockRoots)) <= idx { - return fmt.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - r := b.state.BlockRoots - if ref := b.sharedFieldReferences[blockRoots]; ref.Refs() > 1 { - // Copy elements in underlying array by reference. - r = make([][]byte, len(b.state.BlockRoots)) - copy(r, b.state.BlockRoots) - ref.MinusRef() - b.sharedFieldReferences[blockRoots] = stateutil.NewRef(1) - } - - r[idx] = blockRoot[:] - b.state.BlockRoots = r - - b.markFieldAsDirty(blockRoots) - b.addDirtyIndices(blockRoots, []uint64{idx}) - return nil -} diff --git a/beacon-chain/state/v3/setters_checkpoint.go b/beacon-chain/state/v3/setters_checkpoint.go deleted file mode 100644 index 8f027b422f..0000000000 --- a/beacon-chain/state/v3/setters_checkpoint.go +++ /dev/null @@ -1,58 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/go-bitfield" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetJustificationBits for the beacon state. -func (b *BeaconState) SetJustificationBits(val bitfield.Bitvector4) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.JustificationBits = val - b.markFieldAsDirty(justificationBits) - return nil -} - -// SetPreviousJustifiedCheckpoint for the beacon state. -func (b *BeaconState) SetPreviousJustifiedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.PreviousJustifiedCheckpoint = val - b.markFieldAsDirty(previousJustifiedCheckpoint) - return nil -} - -// SetCurrentJustifiedCheckpoint for the beacon state. -func (b *BeaconState) SetCurrentJustifiedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.CurrentJustifiedCheckpoint = val - b.markFieldAsDirty(currentJustifiedCheckpoint) - return nil -} - -// SetFinalizedCheckpoint for the beacon state. -func (b *BeaconState) SetFinalizedCheckpoint(val *ethpb.Checkpoint) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.FinalizedCheckpoint = val - b.markFieldAsDirty(finalizedCheckpoint) - return nil -} diff --git a/beacon-chain/state/v3/setters_eth1.go b/beacon-chain/state/v3/setters_eth1.go deleted file mode 100644 index 0684fccb02..0000000000 --- a/beacon-chain/state/v3/setters_eth1.go +++ /dev/null @@ -1,74 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetEth1Data for the beacon state. -func (b *BeaconState) SetEth1Data(val *ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Eth1Data = val - b.markFieldAsDirty(eth1Data) - return nil -} - -// SetEth1DataVotes for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[eth1DataVotes].MinusRef() - b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) - - b.state.Eth1DataVotes = val - b.markFieldAsDirty(eth1DataVotes) - b.rebuildTrie[eth1DataVotes] = true - return nil -} - -// SetEth1DepositIndex for the beacon state. -func (b *BeaconState) SetEth1DepositIndex(val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Eth1DepositIndex = val - b.markFieldAsDirty(eth1DepositIndex) - return nil -} - -// AppendEth1DataVotes for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendEth1DataVotes(val *ethpb.Eth1Data) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - votes := b.state.Eth1DataVotes - if b.sharedFieldReferences[eth1DataVotes].Refs() > 1 { - // Copy elements in underlying array by reference. - votes = make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) - copy(votes, b.state.Eth1DataVotes) - b.sharedFieldReferences[eth1DataVotes].MinusRef() - b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) - } - - b.state.Eth1DataVotes = append(votes, val) - b.markFieldAsDirty(eth1DataVotes) - b.addDirtyIndices(eth1DataVotes, []uint64{uint64(len(b.state.Eth1DataVotes) - 1)}) - return nil -} diff --git a/beacon-chain/state/v3/setters_misc.go b/beacon-chain/state/v3/setters_misc.go deleted file mode 100644 index 170f4099ea..0000000000 --- a/beacon-chain/state/v3/setters_misc.go +++ /dev/null @@ -1,181 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - stateTypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/crypto/hash" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "google.golang.org/protobuf/proto" -) - -// For our setters, we have a field reference counter through -// which we can track shared field references. This helps when -// performing state copies, as we simply copy the reference to the -// field. When we do need to do need to modify these fields, we -// perform a full copy of the field. This is true of most of our -// fields except for the following below. -// 1) BlockRoots -// 2) StateRoots -// 3) Eth1DataVotes -// 4) RandaoMixes -// 5) HistoricalRoots -// 6) CurrentParticipationBits -// 7) PreviousParticipationBits -// -// The fields referred to above are instead copied by reference, where -// we simply copy the reference to the underlying object instead of the -// whole object. This is possible due to how we have structured our state -// as we copy the value on read, so as to ensure the underlying object is -// not mutated while it is being accessed during a state read. - -const ( - // This specifies the limit till which we process all dirty indices for a certain field. - // If we have more dirty indices than the threshold, then we rebuild the whole trie. This - // comes due to the fact that O(alogn) > O(n) beyond a certain value of a. - indicesLimit = 8000 -) - -// SetGenesisTime for the beacon state. -func (b *BeaconState) SetGenesisTime(val uint64) error { - b.lock.Lock() - defer b.lock.Unlock() - - b.state.GenesisTime = val - b.markFieldAsDirty(genesisTime) - return nil -} - -// SetGenesisValidatorsRoot for the beacon state. -func (b *BeaconState) SetGenesisValidatorsRoot(val []byte) error { - b.lock.Lock() - defer b.lock.Unlock() - - b.state.GenesisValidatorsRoot = val - b.markFieldAsDirty(genesisValidatorsRoot) - return nil -} - -// SetSlot for the beacon state. -func (b *BeaconState) SetSlot(val types.Slot) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Slot = val - b.markFieldAsDirty(slot) - return nil -} - -// SetFork version for the beacon chain. -func (b *BeaconState) SetFork(val *ethpb.Fork) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - fk, ok := proto.Clone(val).(*ethpb.Fork) - if !ok { - return errors.New("proto.Clone did not return a fork proto") - } - b.state.Fork = fk - b.markFieldAsDirty(fork) - return nil -} - -// SetHistoricalRoots for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetHistoricalRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[historicalRoots].MinusRef() - b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1) - - b.state.HistoricalRoots = val - b.markFieldAsDirty(historicalRoots) - return nil -} - -// AppendHistoricalRoots for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - roots := b.state.HistoricalRoots - if b.sharedFieldReferences[historicalRoots].Refs() > 1 { - roots = make([][]byte, len(b.state.HistoricalRoots)) - copy(roots, b.state.HistoricalRoots) - b.sharedFieldReferences[historicalRoots].MinusRef() - b.sharedFieldReferences[historicalRoots] = stateutil.NewRef(1) - } - - b.state.HistoricalRoots = append(roots, root[:]) - b.markFieldAsDirty(historicalRoots) - return nil -} - -// Recomputes the branch up the index in the Merkle trie representation -// of the beacon state. This method performs slice reads and the caller MUST -// hold the lock before calling this method. -func (b *BeaconState) recomputeRoot(idx int) { - hashFunc := hash.CustomSHA256Hasher() - layers := b.merkleLayers - // The merkle tree structure looks as follows: - // [[r1, r2, r3, r4], [parent1, parent2], [root]] - // Using information about the index which changed, idx, we recompute - // only its branch up the tree. - currentIndex := idx - root := b.merkleLayers[0][idx] - for i := 0; i < len(layers)-1; i++ { - isLeft := currentIndex%2 == 0 - neighborIdx := currentIndex ^ 1 - - neighbor := make([]byte, 32) - if layers[i] != nil && len(layers[i]) != 0 && neighborIdx < len(layers[i]) { - neighbor = layers[i][neighborIdx] - } - if isLeft { - parentHash := hashFunc(append(root, neighbor...)) - root = parentHash[:] - } else { - parentHash := hashFunc(append(neighbor, root...)) - root = parentHash[:] - } - parentIdx := currentIndex / 2 - // Update the cached layers at the parent index. - layers[i+1][parentIdx] = root - currentIndex = parentIdx - } - b.merkleLayers = layers -} - -func (b *BeaconState) markFieldAsDirty(field stateTypes.FieldIndex) { - b.dirtyFields[field] = true -} - -// addDirtyIndices adds the relevant dirty field indices, so that they -// can be recomputed. -func (b *BeaconState) addDirtyIndices(index stateTypes.FieldIndex, indices []uint64) { - if b.rebuildTrie[index] { - return - } - totalIndicesLen := len(b.dirtyIndices[index]) + len(indices) - if totalIndicesLen > indicesLimit { - b.rebuildTrie[index] = true - b.dirtyIndices[index] = []uint64{} - } else { - b.dirtyIndices[index] = append(b.dirtyIndices[index], indices...) - } -} diff --git a/beacon-chain/state/v3/setters_participation.go b/beacon-chain/state/v3/setters_participation.go deleted file mode 100644 index 4722b10e2b..0000000000 --- a/beacon-chain/state/v3/setters_participation.go +++ /dev/null @@ -1,146 +0,0 @@ -package v3 - -import ( - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetPreviousParticipationBits for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetPreviousParticipationBits(val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[previousEpochParticipationBits].MinusRef() - b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) - - b.state.PreviousEpochParticipation = val - b.markFieldAsDirty(previousEpochParticipationBits) - b.rebuildTrie[previousEpochParticipationBits] = true - return nil -} - -// SetCurrentParticipationBits for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetCurrentParticipationBits(val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[currentEpochParticipationBits].MinusRef() - b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) - - b.state.CurrentEpochParticipation = val - b.markFieldAsDirty(currentEpochParticipationBits) - b.rebuildTrie[currentEpochParticipationBits] = true - return nil -} - -// AppendCurrentParticipationBits for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendCurrentParticipationBits(val byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - participation := b.state.CurrentEpochParticipation - if b.sharedFieldReferences[currentEpochParticipationBits].Refs() > 1 { - // Copy elements in underlying array by reference. - participation = make([]byte, len(b.state.CurrentEpochParticipation)) - copy(participation, b.state.CurrentEpochParticipation) - b.sharedFieldReferences[currentEpochParticipationBits].MinusRef() - b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) - } - - b.state.CurrentEpochParticipation = append(participation, val) - b.markFieldAsDirty(currentEpochParticipationBits) - b.addDirtyIndices(currentEpochParticipationBits, []uint64{uint64(len(b.state.CurrentEpochParticipation) - 1)}) - return nil -} - -// AppendPreviousParticipationBits for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendPreviousParticipationBits(val byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - bits := b.state.PreviousEpochParticipation - if b.sharedFieldReferences[previousEpochParticipationBits].Refs() > 1 { - bits = make([]byte, len(b.state.PreviousEpochParticipation)) - copy(bits, b.state.PreviousEpochParticipation) - b.sharedFieldReferences[previousEpochParticipationBits].MinusRef() - b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) - } - - b.state.PreviousEpochParticipation = append(bits, val) - b.markFieldAsDirty(previousEpochParticipationBits) - b.addDirtyIndices(previousEpochParticipationBits, []uint64{uint64(len(b.state.PreviousEpochParticipation) - 1)}) - - return nil -} - -func (b *BeaconState) ModifyCurrentParticipationBits(mutator func(val []byte) ([]byte, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - - participation := b.state.CurrentEpochParticipation - if b.sharedFieldReferences[currentEpochParticipationBits].Refs() > 1 { - // Copy elements in underlying array by reference. - participation = make([]byte, len(b.state.CurrentEpochParticipation)) - copy(participation, b.state.CurrentEpochParticipation) - b.sharedFieldReferences[currentEpochParticipationBits].MinusRef() - b.sharedFieldReferences[currentEpochParticipationBits] = stateutil.NewRef(1) - } - b.lock.Unlock() - var err error - participation, err = mutator(participation) - if err != nil { - return err - } - b.lock.Lock() - defer b.lock.Unlock() - b.state.CurrentEpochParticipation = participation - b.markFieldAsDirty(currentEpochParticipationBits) - b.rebuildTrie[currentEpochParticipationBits] = true - return nil -} - -func (b *BeaconState) ModifyPreviousParticipationBits(mutator func(val []byte) ([]byte, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - - participation := b.state.PreviousEpochParticipation - if b.sharedFieldReferences[previousEpochParticipationBits].Refs() > 1 { - // Copy elements in underlying array by reference. - participation = make([]byte, len(b.state.PreviousEpochParticipation)) - copy(participation, b.state.PreviousEpochParticipation) - b.sharedFieldReferences[previousEpochParticipationBits].MinusRef() - b.sharedFieldReferences[previousEpochParticipationBits] = stateutil.NewRef(1) - } - b.lock.Unlock() - - var err error - participation, err = mutator(participation) - if err != nil { - return err - } - b.lock.Lock() - defer b.lock.Unlock() - b.state.PreviousEpochParticipation = participation - b.markFieldAsDirty(previousEpochParticipationBits) - b.rebuildTrie[previousEpochParticipationBits] = true - return nil -} diff --git a/beacon-chain/state/v3/setters_payload_header.go b/beacon-chain/state/v3/setters_payload_header.go deleted file mode 100644 index f040d56844..0000000000 --- a/beacon-chain/state/v3/setters_payload_header.go +++ /dev/null @@ -1,24 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" - enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1" -) - -// SetLatestExecutionPayloadHeader for the beacon state. -func (b *BeaconState) SetLatestExecutionPayloadHeader(val interfaces.ExecutionData) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - header, ok := val.Proto().(*enginev1.ExecutionPayloadHeader) - if !ok { - return errors.New("value must be an execution payload header") - } - b.state.LatestExecutionPayloadHeader = header - b.markFieldAsDirty(latestExecutionPayloadHeader) - return nil -} diff --git a/beacon-chain/state/v3/setters_randao.go b/beacon-chain/state/v3/setters_randao.go deleted file mode 100644 index 4d0c311f55..0000000000 --- a/beacon-chain/state/v3/setters_randao.go +++ /dev/null @@ -1,53 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetRandaoMixes for the beacon state. Updates the entire -// randao mixes to a new value by overwriting the previous one. -func (b *BeaconState) SetRandaoMixes(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[randaoMixes].MinusRef() - b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1) - - b.state.RandaoMixes = val - b.markFieldAsDirty(randaoMixes) - b.rebuildTrie[randaoMixes] = true - return nil -} - -// UpdateRandaoMixesAtIndex for the beacon state. Updates the randao mixes -// at a specific index to a new value. -func (b *BeaconState) UpdateRandaoMixesAtIndex(idx uint64, val []byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.RandaoMixes)) <= idx { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - mixes := b.state.RandaoMixes - if refs := b.sharedFieldReferences[randaoMixes].Refs(); refs > 1 { - // Copy elements in underlying array by reference. - mixes = make([][]byte, len(b.state.RandaoMixes)) - copy(mixes, b.state.RandaoMixes) - b.sharedFieldReferences[randaoMixes].MinusRef() - b.sharedFieldReferences[randaoMixes] = stateutil.NewRef(1) - } - - mixes[idx] = val - b.state.RandaoMixes = mixes - b.markFieldAsDirty(randaoMixes) - b.addDirtyIndices(randaoMixes, []uint64{idx}) - - return nil -} diff --git a/beacon-chain/state/v3/setters_state.go b/beacon-chain/state/v3/setters_state.go deleted file mode 100644 index 8447055cba..0000000000 --- a/beacon-chain/state/v3/setters_state.go +++ /dev/null @@ -1,59 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" -) - -// SetStateRoots for the beacon state. Updates the state roots -// to a new value by overwriting the previous value. -func (b *BeaconState) SetStateRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[stateRoots].MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - - b.state.StateRoots = val - b.markFieldAsDirty(stateRoots) - b.rebuildTrie[stateRoots] = true - return nil -} - -// UpdateStateRootAtIndex for the beacon state. Updates the state root -// at a specific index to a new value. -func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - - b.lock.RLock() - if uint64(len(b.state.StateRoots)) <= idx { - b.lock.RUnlock() - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.RUnlock() - - b.lock.Lock() - defer b.lock.Unlock() - - // Check if we hold the only reference to the shared state roots slice. - r := b.state.StateRoots - if ref := b.sharedFieldReferences[stateRoots]; ref.Refs() > 1 { - // Copy elements in underlying array by reference. - r = make([][]byte, len(b.state.StateRoots)) - copy(r, b.state.StateRoots) - ref.MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - } - - r[idx] = stateRoot[:] - b.state.StateRoots = r - - b.markFieldAsDirty(stateRoots) - b.addDirtyIndices(stateRoots, []uint64{idx}) - return nil -} diff --git a/beacon-chain/state/v3/setters_sync_committee.go b/beacon-chain/state/v3/setters_sync_committee.go deleted file mode 100644 index 906ffee1ed..0000000000 --- a/beacon-chain/state/v3/setters_sync_committee.go +++ /dev/null @@ -1,31 +0,0 @@ -package v3 - -import ( - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetCurrentSyncCommittee for the beacon state. -func (b *BeaconState) SetCurrentSyncCommittee(val *ethpb.SyncCommittee) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.CurrentSyncCommittee = val - b.markFieldAsDirty(currentSyncCommittee) - return nil -} - -// SetNextSyncCommittee for the beacon state. -func (b *BeaconState) SetNextSyncCommittee(val *ethpb.SyncCommittee) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.NextSyncCommittee = val - b.markFieldAsDirty(nextSyncCommittee) - return nil -} diff --git a/beacon-chain/state/v3/setters_validator.go b/beacon-chain/state/v3/setters_validator.go deleted file mode 100644 index 19be115e70..0000000000 --- a/beacon-chain/state/v3/setters_validator.go +++ /dev/null @@ -1,265 +0,0 @@ -package v3 - -import ( - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -// SetValidators for the beacon state. Updates the entire -// to a new value by overwriting the previous one. -func (b *BeaconState) SetValidators(val []*ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Validators = val - b.sharedFieldReferences[validators].MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - b.markFieldAsDirty(validators) - b.rebuildTrie[validators] = true - b.valMapHandler = stateutil.NewValMapHandler(b.state.Validators) - return nil -} - -// ApplyToEveryValidator applies the provided callback function to each validator in the -// validator registry. -func (b *BeaconState) ApplyToEveryValidator(f func(idx int, val *ethpb.Validator) (bool, *ethpb.Validator, error)) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - v := b.state.Validators - if ref := b.sharedFieldReferences[validators]; ref.Refs() > 1 { - v = b.validatorsReferences() - ref.MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - b.lock.Unlock() - var changedVals []uint64 - for i, val := range v { - changed, newVal, err := f(i, val) - if err != nil { - return err - } - if changed { - changedVals = append(changedVals, uint64(i)) - v[i] = newVal - } - } - - b.lock.Lock() - defer b.lock.Unlock() - - b.state.Validators = v - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, changedVals) - - return nil -} - -// UpdateValidatorAtIndex for the beacon state. Updates the validator -// at a specific index to a new value. -func (b *BeaconState) UpdateValidatorAtIndex(idx types.ValidatorIndex, val *ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Validators)) <= uint64(idx) { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - v := b.state.Validators - if ref := b.sharedFieldReferences[validators]; ref.Refs() > 1 { - v = b.validatorsReferences() - ref.MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - - v[idx] = val - b.state.Validators = v - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, []uint64{uint64(idx)}) - - return nil -} - -// SetBalances for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetBalances(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - - b.state.Balances = val - b.markFieldAsDirty(balances) - b.rebuildTrie[balances] = true - return nil -} - -// UpdateBalancesAtIndex for the beacon state. This method updates the balance -// at a specific index to a new value. -func (b *BeaconState) UpdateBalancesAtIndex(idx types.ValidatorIndex, val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Balances)) <= uint64(idx) { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - bals := b.state.Balances - if b.sharedFieldReferences[balances].Refs() > 1 { - bals = b.balances() - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - } - - bals[idx] = val - b.state.Balances = bals - b.markFieldAsDirty(balances) - b.addDirtyIndices(balances, []uint64{uint64(idx)}) - return nil -} - -// SetSlashings for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetSlashings(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[slashings].MinusRef() - b.sharedFieldReferences[slashings] = stateutil.NewRef(1) - - b.state.Slashings = val - b.markFieldAsDirty(slashings) - return nil -} - -// UpdateSlashingsAtIndex for the beacon state. Updates the slashings -// at a specific index to a new value. -func (b *BeaconState) UpdateSlashingsAtIndex(idx, val uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - if uint64(len(b.state.Slashings)) <= idx { - return errors.Errorf("invalid index provided %d", idx) - } - b.lock.Lock() - defer b.lock.Unlock() - - s := b.state.Slashings - if b.sharedFieldReferences[slashings].Refs() > 1 { - s = b.slashings() - b.sharedFieldReferences[slashings].MinusRef() - b.sharedFieldReferences[slashings] = stateutil.NewRef(1) - } - - s[idx] = val - - b.state.Slashings = s - - b.markFieldAsDirty(slashings) - return nil -} - -// AppendValidator for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendValidator(val *ethpb.Validator) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - vals := b.state.Validators - if b.sharedFieldReferences[validators].Refs() > 1 { - vals = b.validatorsReferences() - b.sharedFieldReferences[validators].MinusRef() - b.sharedFieldReferences[validators] = stateutil.NewRef(1) - } - - // append validator to slice - b.state.Validators = append(vals, val) - valIdx := types.ValidatorIndex(len(b.state.Validators) - 1) - - b.valMapHandler.Set(bytesutil.ToBytes48(val.PublicKey), valIdx) - - b.markFieldAsDirty(validators) - b.addDirtyIndices(validators, []uint64{uint64(valIdx)}) - return nil -} - -// AppendBalance for the beacon state. Appends the new value -// to the the end of list. -func (b *BeaconState) AppendBalance(bal uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - bals := b.state.Balances - if b.sharedFieldReferences[balances].Refs() > 1 { - bals = b.balances() - b.sharedFieldReferences[balances].MinusRef() - b.sharedFieldReferences[balances] = stateutil.NewRef(1) - } - - b.state.Balances = append(bals, bal) - balIdx := len(b.state.Balances) - 1 - b.markFieldAsDirty(balances) - b.addDirtyIndices(balances, []uint64{uint64(balIdx)}) - return nil -} - -// AppendInactivityScore for the beacon state. -func (b *BeaconState) AppendInactivityScore(s uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - scores := b.state.InactivityScores - if b.sharedFieldReferences[inactivityScores].Refs() > 1 { - scores = b.inactivityScores() - b.sharedFieldReferences[inactivityScores].MinusRef() - b.sharedFieldReferences[inactivityScores] = stateutil.NewRef(1) - } - - b.state.InactivityScores = append(scores, s) - b.markFieldAsDirty(inactivityScores) - return nil -} - -// SetInactivityScores for the beacon state. Updates the entire -// list to a new value by overwriting the previous one. -func (b *BeaconState) SetInactivityScores(val []uint64) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[inactivityScores].MinusRef() - b.sharedFieldReferences[inactivityScores] = stateutil.NewRef(1) - - b.state.InactivityScores = val - b.markFieldAsDirty(inactivityScores) - return nil -} diff --git a/beacon-chain/state/v3/spec_parameters.go b/beacon-chain/state/v3/spec_parameters.go deleted file mode 100644 index d68005a7f5..0000000000 --- a/beacon-chain/state/v3/spec_parameters.go +++ /dev/null @@ -1,11 +0,0 @@ -package v3 - -import "github.com/prysmaticlabs/prysm/v3/config/params" - -func (b *BeaconState) ProportionalSlashingMultiplier() (uint64, error) { - return params.BeaconConfig().ProportionalSlashingMultiplierBellatrix, nil -} - -func (b *BeaconState) InactivityPenaltyQuotient() (uint64, error) { - return params.BeaconConfig().InactivityPenaltyQuotientBellatrix, nil -} diff --git a/beacon-chain/state/v3/state_trie.go b/beacon-chain/state/v3/state_trie.go deleted file mode 100644 index 8ebc7396f0..0000000000 --- a/beacon-chain/state/v3/state_trie.go +++ /dev/null @@ -1,395 +0,0 @@ -package v3 - -import ( - "context" - "runtime" - "sort" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" - "github.com/prysmaticlabs/prysm/v3/config/params" - "github.com/prysmaticlabs/prysm/v3/container/slice" - "github.com/prysmaticlabs/prysm/v3/crypto/hash" - "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/v3/encoding/ssz" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" - "go.opencensus.io/trace" - "google.golang.org/protobuf/proto" -) - -// InitializeFromProto the beacon state from a protobuf representation. -func InitializeFromProto(st *ethpb.BeaconStateBellatrix) (state.BeaconState, error) { - return statenative.InitializeFromProtoUnsafeBellatrix(proto.Clone(st).(*ethpb.BeaconStateBellatrix)) -} - -// InitializeFromProtoUnsafe directly uses the beacon state protobuf pointer -// and sets it as the inner state of the BeaconState type. -func InitializeFromProtoUnsafe(st *ethpb.BeaconStateBellatrix) (state.BeaconState, error) { - return statenative.InitializeFromProtoUnsafeBellatrix(st) -} - -// Copy returns a deep copy of the beacon state. -func (b *BeaconState) Copy() state.BeaconState { - if !b.hasInnerState() { - return nil - } - - b.lock.RLock() - defer b.lock.RUnlock() - fieldCount := params.BeaconConfig().BeaconStateBellatrixFieldCount - - dst := &BeaconState{ - state: ðpb.BeaconStateBellatrix{ - // Primitive types, safe to copy. - GenesisTime: b.state.GenesisTime, - Slot: b.state.Slot, - Eth1DepositIndex: b.state.Eth1DepositIndex, - - // Large arrays, infrequently changed, constant size. - RandaoMixes: b.state.RandaoMixes, - StateRoots: b.state.StateRoots, - BlockRoots: b.state.BlockRoots, - Slashings: b.state.Slashings, - Eth1DataVotes: b.state.Eth1DataVotes, - - // Large arrays, increases over time. - Validators: b.state.Validators, - Balances: b.state.Balances, - HistoricalRoots: b.state.HistoricalRoots, - PreviousEpochParticipation: b.state.PreviousEpochParticipation, - CurrentEpochParticipation: b.state.CurrentEpochParticipation, - InactivityScores: b.state.InactivityScores, - - // Everything else, too small to be concerned about, constant size. - Fork: b.fork(), - LatestBlockHeader: b.latestBlockHeader(), - Eth1Data: b.eth1Data(), - JustificationBits: b.justificationBits(), - PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint(), - CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint(), - FinalizedCheckpoint: b.finalizedCheckpoint(), - GenesisValidatorsRoot: b.genesisValidatorsRoot(), - CurrentSyncCommittee: b.currentSyncCommittee(), - NextSyncCommittee: b.nextSyncCommittee(), - LatestExecutionPayloadHeader: b.latestExecutionPayloadHeader(), - }, - dirtyFields: make(map[types.FieldIndex]bool, fieldCount), - dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount), - rebuildTrie: make(map[types.FieldIndex]bool, fieldCount), - sharedFieldReferences: make(map[types.FieldIndex]*stateutil.Reference, 11), - stateFieldLeaves: make(map[types.FieldIndex]*fieldtrie.FieldTrie, fieldCount), - - // Copy on write validator index map. - valMapHandler: b.valMapHandler, - } - - for field, ref := range b.sharedFieldReferences { - ref.AddRef() - dst.sharedFieldReferences[field] = ref - } - - // Increment ref for validator map - b.valMapHandler.AddRef() - - for i := range b.dirtyFields { - dst.dirtyFields[i] = true - } - - for i := range b.dirtyIndices { - indices := make([]uint64, len(b.dirtyIndices[i])) - copy(indices, b.dirtyIndices[i]) - dst.dirtyIndices[i] = indices - } - - for i := range b.rebuildTrie { - dst.rebuildTrie[i] = true - } - - for fldIdx, fieldTrie := range b.stateFieldLeaves { - dst.stateFieldLeaves[fldIdx] = fieldTrie - if fieldTrie.FieldReference() != nil { - fieldTrie.Lock() - fieldTrie.FieldReference().AddRef() - fieldTrie.Unlock() - } - } - - if b.merkleLayers != nil { - dst.merkleLayers = make([][][]byte, len(b.merkleLayers)) - for i, layer := range b.merkleLayers { - dst.merkleLayers[i] = make([][]byte, len(layer)) - for j, content := range layer { - dst.merkleLayers[i][j] = make([]byte, len(content)) - copy(dst.merkleLayers[i][j], content) - } - } - } - state.StateCount.Inc() - // Finalizer runs when dst is being destroyed in garbage collection. - runtime.SetFinalizer(dst, finalizerCleanup) - - return dst -} - -// HashTreeRoot of the beacon state retrieves the Merkle root of the trie -// representation of the beacon state based on the eth2 Simple Serialize specification. -func (b *BeaconState) HashTreeRoot(ctx context.Context) ([32]byte, error) { - ctx, span := trace.StartSpan(ctx, "BeaconStateBellatrix.HashTreeRoot") - defer span.End() - - b.lock.Lock() - defer b.lock.Unlock() - if err := b.initializeMerkleLayers(ctx); err != nil { - return [32]byte{}, err - } - if err := b.recomputeDirtyFields(ctx); err != nil { - return [32]byte{}, err - } - return bytesutil.ToBytes32(b.merkleLayers[len(b.merkleLayers)-1][0]), nil -} - -// Initializes the Merkle layers for the beacon state if they are empty. -// -// WARNING: Caller must acquire the mutex before using. -func (b *BeaconState) initializeMerkleLayers(ctx context.Context) error { - if len(b.merkleLayers) > 0 { - return nil - } - fieldRoots, err := computeFieldRoots(ctx, b.state) - if err != nil { - return err - } - layers := stateutil.Merkleize(fieldRoots) - b.merkleLayers = layers - b.dirtyFields = make(map[types.FieldIndex]bool, params.BeaconConfig().BeaconStateBellatrixFieldCount) - return nil -} - -// Recomputes the Merkle layers for the dirty fields in the state. -// -// WARNING: Caller must acquire the mutex before using. -func (b *BeaconState) recomputeDirtyFields(_ context.Context) error { - for field := range b.dirtyFields { - root, err := b.rootSelector(field) - if err != nil { - return err - } - b.merkleLayers[0][field] = root[:] - b.recomputeRoot(int(field)) - delete(b.dirtyFields, field) - } - return nil -} - -// FieldReferencesCount returns the reference count held by each field. This -// also includes the field trie held by each field. -func (b *BeaconState) FieldReferencesCount() map[string]uint64 { - refMap := make(map[string]uint64) - b.lock.RLock() - defer b.lock.RUnlock() - for i, f := range b.sharedFieldReferences { - refMap[i.String(b.Version())] = uint64(f.Refs()) - } - for i, f := range b.stateFieldLeaves { - numOfRefs := uint64(f.FieldReference().Refs()) - f.RLock() - if !f.Empty() { - refMap[i.String(b.Version())+"_trie"] = numOfRefs - } - f.RUnlock() - } - return refMap -} - -// IsNil checks if the state and the underlying proto -// object are nil. -func (b *BeaconState) IsNil() bool { - return b == nil || b.state == nil -} - -func (b *BeaconState) rootSelector(field types.FieldIndex) ([32]byte, error) { - hasher := hash.CustomSHA256Hasher() - switch field { - case genesisTime: - return ssz.Uint64Root(b.state.GenesisTime), nil - case genesisValidatorsRoot: - return bytesutil.ToBytes32(b.state.GenesisValidatorsRoot), nil - case slot: - return ssz.Uint64Root(uint64(b.state.Slot)), nil - case eth1DepositIndex: - return ssz.Uint64Root(b.state.Eth1DepositIndex), nil - case fork: - return ssz.ForkRoot(b.state.Fork) - case latestBlockHeader: - return stateutil.BlockHeaderRoot(b.state.LatestBlockHeader) - case blockRoots: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.BlockRoots, fieldparams.BlockRootsLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(blockRoots, b.state.BlockRoots) - case stateRoots: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.StateRoots, fieldparams.StateRootsLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(stateRoots, b.state.StateRoots) - case historicalRoots: - return ssz.ByteArrayRootWithLimit(b.state.HistoricalRoots, fieldparams.HistoricalRootsLength) - case eth1Data: - return stateutil.Eth1Root(hasher, b.state.Eth1Data) - case eth1DataVotes: - if b.rebuildTrie[field] { - err := b.resetFieldTrie( - field, - b.state.Eth1DataVotes, - fieldparams.Eth1DataVotesLength, - ) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(field, b.state.Eth1DataVotes) - case validators: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.Validators, fieldparams.ValidatorRegistryLimit) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, validators) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(validators, b.state.Validators) - case balances: - if b.rebuildTrie[field] { - maxBalCap := uint64(fieldparams.ValidatorRegistryLimit) - elemSize := uint64(8) - balLimit := (maxBalCap*elemSize + 31) / 32 - err := b.resetFieldTrie(field, b.state.Balances, balLimit) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(balances, b.state.Balances) - case randaoMixes: - if b.rebuildTrie[field] { - err := b.resetFieldTrie(field, b.state.RandaoMixes, fieldparams.RandaoMixesLength) - if err != nil { - return [32]byte{}, err - } - delete(b.rebuildTrie, field) - return b.stateFieldLeaves[field].TrieRoot() - } - return b.recomputeFieldTrie(randaoMixes, b.state.RandaoMixes) - case slashings: - return ssz.SlashingsRoot(b.state.Slashings) - case previousEpochParticipationBits: - return stateutil.ParticipationBitsRoot(b.state.PreviousEpochParticipation) - case currentEpochParticipationBits: - return stateutil.ParticipationBitsRoot(b.state.CurrentEpochParticipation) - case justificationBits: - return bytesutil.ToBytes32(b.state.JustificationBits), nil - case previousJustifiedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.PreviousJustifiedCheckpoint) - case currentJustifiedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.CurrentJustifiedCheckpoint) - case finalizedCheckpoint: - return ssz.CheckpointRoot(hasher, b.state.FinalizedCheckpoint) - case inactivityScores: - return stateutil.Uint64ListRootWithRegistryLimit(b.state.InactivityScores) - case currentSyncCommittee: - return stateutil.SyncCommitteeRoot(b.state.CurrentSyncCommittee) - case nextSyncCommittee: - return stateutil.SyncCommitteeRoot(b.state.NextSyncCommittee) - case latestExecutionPayloadHeader: - return b.state.LatestExecutionPayloadHeader.HashTreeRoot() - } - return [32]byte{}, errors.New("invalid field index provided") -} - -func (b *BeaconState) recomputeFieldTrie(index types.FieldIndex, elements interface{}) ([32]byte, error) { - fTrie := b.stateFieldLeaves[index] - fTrieMutex := fTrie.RWMutex - // We can't lock the trie directly because the trie's variable gets reassigned, - // and therefore we would call Unlock() on a different object. - fTrieMutex.Lock() - - if fTrie.Empty() { - err := b.resetFieldTrie(index, elements, fTrie.Length()) - if err != nil { - fTrieMutex.Unlock() - return [32]byte{}, err - } - // Reduce reference count as we are instantiating a new trie. - fTrie.FieldReference().MinusRef() - fTrieMutex.Unlock() - return b.stateFieldLeaves[index].TrieRoot() - } - - if fTrie.FieldReference().Refs() > 1 { - fTrie.FieldReference().MinusRef() - newTrie := fTrie.TransferTrie() - b.stateFieldLeaves[index] = newTrie - fTrie = newTrie - } - fTrieMutex.Unlock() - - // remove duplicate indexes - b.dirtyIndices[index] = slice.SetUint64(b.dirtyIndices[index]) - // sort indexes again - sort.Slice(b.dirtyIndices[index], func(i int, j int) bool { - return b.dirtyIndices[index][i] < b.dirtyIndices[index][j] - }) - root, err := fTrie.RecomputeTrie(b.dirtyIndices[index], elements) - if err != nil { - return [32]byte{}, err - } - b.dirtyIndices[index] = []uint64{} - return root, nil -} - -func (b *BeaconState) resetFieldTrie(index types.FieldIndex, elements interface{}, length uint64) error { - fTrie, err := fieldtrie.NewFieldTrie(index, fieldMap[index], elements, length) - if err != nil { - return err - } - b.stateFieldLeaves[index] = fTrie - b.dirtyIndices[index] = []uint64{} - return nil -} - -func finalizerCleanup(b *BeaconState) { - fieldCount := params.BeaconConfig().BeaconStateBellatrixFieldCount - for field, v := range b.sharedFieldReferences { - v.MinusRef() - if b.stateFieldLeaves[field].FieldReference() != nil { - b.stateFieldLeaves[field].FieldReference().MinusRef() - } - } - for i := 0; i < fieldCount; i++ { - field := types.FieldIndex(i) - delete(b.stateFieldLeaves, field) - delete(b.dirtyIndices, field) - delete(b.dirtyFields, field) - delete(b.sharedFieldReferences, field) - delete(b.stateFieldLeaves, field) - } - state.StateCount.Sub(1) -} diff --git a/beacon-chain/state/v3/types.go b/beacon-chain/state/v3/types.go deleted file mode 100644 index 62a62d0eab..0000000000 --- a/beacon-chain/state/v3/types.go +++ /dev/null @@ -1,77 +0,0 @@ -package v3 - -import ( - "sync" - - "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/fieldtrie" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/types" - "github.com/prysmaticlabs/prysm/v3/config/params" - ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" -) - -func init() { - fieldMap = make(map[types.FieldIndex]types.DataType, params.BeaconConfig().BeaconStateBellatrixFieldCount) - - // Initialize the fixed sized arrays. - fieldMap[types.BlockRoots] = types.BasicArray - fieldMap[types.StateRoots] = types.BasicArray - fieldMap[types.RandaoMixes] = types.BasicArray - - // Initialize the composite arrays. - fieldMap[types.Eth1DataVotes] = types.CompositeArray - fieldMap[types.Validators] = types.CompositeArray - fieldMap[types.Balances] = types.CompressedArray -} - -// Field Aliases for values from the types package. -const ( - genesisTime = types.GenesisTime - genesisValidatorsRoot = types.GenesisValidatorsRoot - slot = types.Slot - fork = types.Fork - latestBlockHeader = types.LatestBlockHeader - blockRoots = types.BlockRoots - stateRoots = types.StateRoots - historicalRoots = types.HistoricalRoots - eth1Data = types.Eth1Data - eth1DataVotes = types.Eth1DataVotes - eth1DepositIndex = types.Eth1DepositIndex - validators = types.Validators - balances = types.Balances - randaoMixes = types.RandaoMixes - slashings = types.Slashings - previousEpochParticipationBits = types.PreviousEpochParticipationBits - currentEpochParticipationBits = types.CurrentEpochParticipationBits - justificationBits = types.JustificationBits - previousJustifiedCheckpoint = types.PreviousJustifiedCheckpoint - currentJustifiedCheckpoint = types.CurrentJustifiedCheckpoint - finalizedCheckpoint = types.FinalizedCheckpoint - inactivityScores = types.InactivityScores - currentSyncCommittee = types.CurrentSyncCommittee - nextSyncCommittee = types.NextSyncCommittee - latestExecutionPayloadHeader = types.LatestExecutionPayloadHeader -) - -// fieldMap keeps track of each field -// to its corresponding data type. -var fieldMap map[types.FieldIndex]types.DataType - -// ErrNilInnerState returns when the inner state is nil and no copy set or get -// operations can be performed on state. -var ErrNilInnerState = errors.New("nil inner state") - -// BeaconState defines a struct containing utilities for the eth2 chain state, defining -// getters and setters for its respective values and helpful functions such as HashTreeRoot(). -type BeaconState struct { - state *ethpb.BeaconStateBellatrix - lock sync.RWMutex - dirtyFields map[types.FieldIndex]bool - dirtyIndices map[types.FieldIndex][]uint64 - stateFieldLeaves map[types.FieldIndex]*fieldtrie.FieldTrie - rebuildTrie map[types.FieldIndex]bool - valMapHandler *stateutil.ValidatorMapHandler - merkleLayers [][][]byte - sharedFieldReferences map[types.FieldIndex]*stateutil.Reference -} diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 815108dba0..2684759f70 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -190,8 +190,8 @@ go_test( "//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stategen:go_default_library", - "//beacon-chain/state/v1:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", "//cache/lru:go_default_library", "//cmd/beacon-chain/flags:go_default_library", diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index aef520e277..0ed8c18c06 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -68,7 +68,6 @@ go_test( "//beacon-chain/p2p/testing:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/v1:go_default_library", "//beacon-chain/sync:go_default_library", "//cmd/beacon-chain/flags:go_default_library", "//config/features:go_default_library", diff --git a/beacon-chain/sync/rpc_status_test.go b/beacon-chain/sync/rpc_status_test.go index bd714c938f..91b6544ef6 100644 --- a/beacon-chain/sync/rpc_status_test.go +++ b/beacon-chain/sync/rpc_status_test.go @@ -18,7 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/peers" p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" p2ptypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/types" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" "github.com/prysmaticlabs/prysm/v3/config/params" consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -265,7 +265,7 @@ func TestHandshakeHandlers_Roundtrip(t *testing.T) { Attnets: bytesutil.PadTo([]byte{'C', 'D'}, 8), }) - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Slot: 5, }) require.NoError(t, err) diff --git a/beacon-chain/sync/service_test.go b/beacon-chain/sync/service_test.go index e6f9be5f31..113749cf8a 100644 --- a/beacon-chain/sync/service_test.go +++ b/beacon-chain/sync/service_test.go @@ -12,7 +12,7 @@ import ( statefeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/state" dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing" p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" "github.com/prysmaticlabs/prysm/v3/crypto/bls" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -23,7 +23,7 @@ import ( ) func TestService_StatusZeroEpoch(t *testing.T) { - bState, err := v1.InitializeFromProto(ðpb.BeaconState{Slot: 0}) + bState, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: 0}) require.NoError(t, err) r := &Service{ cfg: &config{ diff --git a/beacon-chain/sync/validate_proposer_slashing_test.go b/beacon-chain/sync/validate_proposer_slashing_test.go index 6ac52d4fec..254ee3840d 100644 --- a/beacon-chain/sync/validate_proposer_slashing_test.go +++ b/beacon-chain/sync/validate_proposer_slashing_test.go @@ -17,7 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p" p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -45,7 +45,7 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be } currentSlot := types.Slot(0) - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: validators, Slot: currentSlot, Balances: validatorBalances, diff --git a/beacon-chain/sync/validate_voluntary_exit_test.go b/beacon-chain/sync/validate_voluntary_exit_test.go index 310ea6b099..d06e8fd354 100644 --- a/beacon-chain/sync/validate_voluntary_exit_test.go +++ b/beacon-chain/sync/validate_voluntary_exit_test.go @@ -18,7 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p" p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing" lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru" "github.com/prysmaticlabs/prysm/v3/config/params" @@ -41,7 +41,7 @@ func setupValidExit(t *testing.T) (*ethpb.SignedVoluntaryExit, state.BeaconState ActivationEpoch: 0, }, } - st, err := v1.InitializeFromProto(ðpb.BeaconState{ + st, err := state_native.InitializeFromProtoPhase0(ðpb.BeaconState{ Validators: registry, Fork: ðpb.Fork{ CurrentVersion: params.BeaconConfig().GenesisForkVersion, diff --git a/encoding/ssz/detect/BUILD.bazel b/encoding/ssz/detect/BUILD.bazel index ee518aa1ac..ede366fdaa 100644 --- a/encoding/ssz/detect/BUILD.bazel +++ b/encoding/ssz/detect/BUILD.bazel @@ -10,9 +10,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", - "//beacon-chain/state/v3:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/encoding/ssz/detect/configfork.go b/encoding/ssz/detect/configfork.go index d0b6989294..7510012ed1 100644 --- a/encoding/ssz/detect/configfork.go +++ b/encoding/ssz/detect/configfork.go @@ -3,6 +3,7 @@ package detect import ( "fmt" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" @@ -11,9 +12,6 @@ import ( "github.com/pkg/errors" ssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -89,7 +87,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state. if err != nil { return nil, errors.Wrapf(err, "failed to unmarshal state, detected fork=%s", forkName) } - s, err = v1.InitializeFromProtoUnsafe(st) + s, err = state_native.InitializeFromProtoUnsafePhase0(st) if err != nil { return nil, errors.Wrapf(err, "failed to init state trie from state, detected fork=%s", forkName) } @@ -99,7 +97,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state. if err != nil { return nil, errors.Wrapf(err, "failed to unmarshal state, detected fork=%s", forkName) } - s, err = v2.InitializeFromProtoUnsafe(st) + s, err = state_native.InitializeFromProtoUnsafeAltair(st) if err != nil { return nil, errors.Wrapf(err, "failed to init state trie from state, detected fork=%s", forkName) } @@ -109,7 +107,7 @@ func (cf *VersionedUnmarshaler) UnmarshalBeaconState(marshaled []byte) (s state. if err != nil { return nil, errors.Wrapf(err, "failed to unmarshal state, detected fork=%s", forkName) } - s, err = v3.InitializeFromProtoUnsafe(st) + s, err = state_native.InitializeFromProtoUnsafeBellatrix(st) if err != nil { return nil, errors.Wrapf(err, "failed to init state trie from state, detected fork=%s", forkName) } diff --git a/proto/testing/BUILD.bazel b/proto/testing/BUILD.bazel index 2d26d1d1e6..4aeacf2df7 100644 --- a/proto/testing/BUILD.bazel +++ b/proto/testing/BUILD.bazel @@ -53,17 +53,16 @@ go_test( tags = ["spectest"], deps = [ "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//config/params:go_default_library", "//config/fieldparams:go_default_library", - "//proto/prysm/v1alpha1:go_default_library", + "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", - "//testing/util:go_default_library", + "//proto/prysm/v1alpha1:go_default_library", "//testing/assert:go_default_library", "//testing/require:go_default_library", - "@com_github_prysmaticlabs_fastssz//:go_default_library", + "//testing/util:go_default_library", "@com_github_ghodss_yaml//:go_default_library", "@com_github_golang_snappy//:go_default_library", + "@com_github_prysmaticlabs_fastssz//:go_default_library", "@io_bazel_rules_go//go/tools/bazel:go_default_library", ], ) diff --git a/testing/benchmark/BUILD.bazel b/testing/benchmark/BUILD.bazel index bbe374274c..0548748994 100644 --- a/testing/benchmark/BUILD.bazel +++ b/testing/benchmark/BUILD.bazel @@ -8,7 +8,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "@io_bazel_rules_go//go/tools/bazel:go_default_library", diff --git a/testing/benchmark/pregen.go b/testing/benchmark/pregen.go index 7adc445af8..238a6566ea 100644 --- a/testing/benchmark/pregen.go +++ b/testing/benchmark/pregen.go @@ -8,7 +8,7 @@ import ( "github.com/bazelbuild/rules_go/go/tools/bazel" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" ) @@ -53,7 +53,7 @@ func PreGenState1Epoch() (state.BeaconState, error) { if err := beaconState.UnmarshalSSZ(beaconBytes); err != nil { return nil, err } - return v1.InitializeFromProto(beaconState) + return state_native.InitializeFromProtoPhase0(beaconState) } // PreGenstateFullEpochs unmarshals the pre-generated beacon state after 2 epoch of full block processing and returns it. @@ -70,7 +70,7 @@ func PreGenstateFullEpochs() (state.BeaconState, error) { if err := beaconState.UnmarshalSSZ(beaconBytes); err != nil { return nil, err } - return v1.InitializeFromProto(beaconState) + return state_native.InitializeFromProtoPhase0(beaconState) } // PreGenFullBlock unmarshals the pre-generated signed beacon block containing an epochs worth of attestations and returns it. diff --git a/testing/util/BUILD.bazel b/testing/util/BUILD.bazel index 09f1ca211b..bddcb275bd 100644 --- a/testing/util/BUILD.bazel +++ b/testing/util/BUILD.bazel @@ -30,10 +30,8 @@ go_library( "//beacon-chain/db/iface:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//beacon-chain/state/stateutil:go_default_library", - "//beacon-chain/state/v1:go_default_library", - "//beacon-chain/state/v2:go_default_library", - "//beacon-chain/state/v3:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", diff --git a/testing/util/altair.go b/testing/util/altair.go index 79c8fc4ad3..fcf987c070 100644 --- a/testing/util/altair.go +++ b/testing/util/altair.go @@ -14,8 +14,8 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - stateAltair "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" @@ -214,7 +214,7 @@ func buildGenesisBeaconState(genesisTime uint64, preState state.BeaconState, eth AggregatePubkey: bytesutil.PadTo([]byte{}, params.BeaconConfig().BLSPubkeyLength), } - return stateAltair.InitializeFromProto(st) + return state_native.InitializeFromProtoAltair(st) } func emptyGenesisState() (state.BeaconState, error) { @@ -241,7 +241,7 @@ func emptyGenesisState() (state.BeaconState, error) { Eth1DataVotes: []*ethpb.Eth1Data{}, Eth1DepositIndex: 0, } - return stateAltair.InitializeFromProto(st) + return state_native.InitializeFromProtoAltair(st) } // NewBeaconBlockAltair creates a beacon block with minimum marshalable fields. diff --git a/testing/util/attestation.go b/testing/util/attestation.go index a448dc54f7..ef88c3645c 100644 --- a/testing/util/attestation.go +++ b/testing/util/attestation.go @@ -11,9 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -71,31 +69,31 @@ func GenerateAttestations( var headState state.BeaconState switch bState.Version() { case version.Phase0: - pbState, err := v1.ProtobufBeaconState(bState.CloneInnerState()) + pbState, err := state_native.ProtobufBeaconStatePhase0(bState.CloneInnerState()) if err != nil { return nil, err } - genState, err := v1.InitializeFromProtoUnsafe(pbState) + genState, err := state_native.InitializeFromProtoUnsafePhase0(pbState) if err != nil { return nil, err } headState = genState case version.Altair: - pbState, err := v2.ProtobufBeaconState(bState.CloneInnerState()) + pbState, err := state_native.ProtobufBeaconStateAltair(bState.CloneInnerState()) if err != nil { return nil, err } - genState, err := v2.InitializeFromProtoUnsafe(pbState) + genState, err := state_native.InitializeFromProtoUnsafeAltair(pbState) if err != nil { return nil, err } headState = genState case version.Bellatrix: - pbState, err := v3.ProtobufBeaconState(bState.CloneInnerState()) + pbState, err := state_native.ProtobufBeaconStateBellatrix(bState.CloneInnerState()) if err != nil { return nil, err } - genState, err := v3.InitializeFromProtoUnsafe(pbState) + genState, err := state_native.InitializeFromProtoUnsafeBellatrix(pbState) if err != nil { return nil, err } diff --git a/testing/util/bellatrix_state.go b/testing/util/bellatrix_state.go index b29e05cd37..1a7adf0b12 100644 --- a/testing/util/bellatrix_state.go +++ b/testing/util/bellatrix_state.go @@ -7,8 +7,8 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -83,7 +83,7 @@ func emptyGenesisStateBellatrix() (state.BeaconState, error) { LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeader{}, } - return v3.InitializeFromProto(st) + return state_native.InitializeFromProtoBellatrix(st) } func buildGenesisBeaconStateBellatrix(genesisTime uint64, preState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) { @@ -240,5 +240,5 @@ func buildGenesisBeaconStateBellatrix(genesisTime uint64, preState state.BeaconS TransactionsRoot: make([]byte, 32), } - return v3.InitializeFromProto(st) + return state_native.InitializeFromProtoBellatrix(st) } diff --git a/testing/util/state.go b/testing/util/state.go index eaa96fb623..83cbbce1aa 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -10,9 +10,7 @@ import ( b "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/iface" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" - v2 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v2" - v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/crypto/bls" @@ -96,7 +94,7 @@ func NewBeaconState(options ...NewBeaconStateOption) (state.BeaconState, error) } } - var st, err = v1.InitializeFromProtoUnsafe(seed) + var st, err = state_native.InitializeFromProtoUnsafePhase0(seed) if err != nil { return nil, err } @@ -151,7 +149,7 @@ func NewBeaconStateAltair(options ...func(state *ethpb.BeaconStateAltair) error) } } - var st, err = v2.InitializeFromProtoUnsafe(seed) + var st, err = state_native.InitializeFromProtoUnsafeAltair(seed) if err != nil { return nil, err } @@ -218,7 +216,7 @@ func NewBeaconStateBellatrix(options ...func(state *ethpb.BeaconStateBellatrix) } } - var st, err = v3.InitializeFromProtoUnsafe(seed) + var st, err = state_native.InitializeFromProtoUnsafeBellatrix(seed) if err != nil { return nil, err } diff --git a/tools/benchmark-files-gen/BUILD.bazel b/tools/benchmark-files-gen/BUILD.bazel index a0b9c88d2b..b931750ab3 100644 --- a/tools/benchmark-files-gen/BUILD.bazel +++ b/tools/benchmark-files-gen/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/state:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/primitives:go_default_library", diff --git a/tools/benchmark-files-gen/main.go b/tools/benchmark-files-gen/main.go index 56ef41b4ab..6819b805f6 100644 --- a/tools/benchmark-files-gen/main.go +++ b/tools/benchmark-files-gen/main.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/config/params" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -234,5 +234,5 @@ func genesisBeaconState() (state.BeaconState, error) { if err := genesisState.UnmarshalSSZ(beaconBytes); err != nil { return nil, errors.Wrap(err, "cannot unmarshal genesis state file") } - return v1.InitializeFromProtoUnsafe(genesisState) + return state_native.InitializeFromProtoUnsafePhase0(genesisState) } diff --git a/tools/pcli/BUILD.bazel b/tools/pcli/BUILD.bazel index 44afb9bbd0..8979815356 100644 --- a/tools/pcli/BUILD.bazel +++ b/tools/pcli/BUILD.bazel @@ -11,7 +11,7 @@ go_library( visibility = ["//visibility:private"], deps = [ "//beacon-chain/core/transition:go_default_library", - "//beacon-chain/state/v1:go_default_library", + "//beacon-chain/state/state-native:go_default_library", "//consensus-types/blocks:go_default_library", "//encoding/ssz/equality:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/tools/pcli/main.go b/tools/pcli/main.go index f0eec590af..00928aad8e 100644 --- a/tools/pcli/main.go +++ b/tools/pcli/main.go @@ -11,7 +11,7 @@ import ( "github.com/kr/pretty" fssz "github.com/prysmaticlabs/fastssz" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition" - v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1" + state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native" "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v3/encoding/ssz/equality" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" @@ -161,7 +161,7 @@ func main() { if err := dataFetcher(preStatePath, preState); err != nil { log.Fatal(err) } - stateObj, err := v1.InitializeFromProto(preState) + stateObj, err := state_native.InitializeFromProtoPhase0(preState) if err != nil { log.Fatal(err) }