From 7fa3ebfaa8ff97959bc12b56f88d199fa7139e15 Mon Sep 17 00:00:00 2001 From: terencechain Date: Wed, 11 Jan 2023 14:20:15 -0800 Subject: [PATCH] Add historical summaries to state and processing (#11842) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add historical summaries to state and processing * Process historical roots test * Passing spec tests * Fix shas and tests * Fix mainnet spectest sha * Fix tests * Update beacon-chain/core/epoch/epoch_processing.go Co-authored-by: Radosław Kapka * Update beacon-chain/core/epoch/epoch_processing_test.go Co-authored-by: Radosław Kapka * Update proto/prysm/v1alpha1/beacon_state.proto Co-authored-by: Radosław Kapka * Update beacon-chain/state/state-native/hasher.go Co-authored-by: Radosław Kapka * Radek's feedback * Getters error * Dont return * Fix else * Fix tests * Fix test * Rm white space Co-authored-by: Radosław Kapka --- WORKSPACE | 10 +- beacon-chain/core/altair/transition.go | 2 +- beacon-chain/core/altair/upgrade.go | 6 +- beacon-chain/core/altair/upgrade_test.go | 6 +- beacon-chain/core/capella/upgrade.go | 7 +- beacon-chain/core/capella/upgrade_test.go | 5 +- beacon-chain/core/epoch/BUILD.bazel | 5 + beacon-chain/core/epoch/epoch_processing.go | 53 +++-- .../core/epoch/epoch_processing_test.go | 85 ++++++- beacon-chain/core/execution/upgrade.go | 6 +- beacon-chain/core/execution/upgrade_test.go | 6 +- beacon-chain/state/interfaces.go | 4 +- .../state-native/beacon_state_mainnet.go | 1 + .../state-native/beacon_state_minimal.go | 1 + .../state/state-native/getters_misc.go | 33 ++- .../state/state-native/getters_state.go | 2 + beacon-chain/state/state-native/hasher.go | 46 ++++ .../state/state-native/hasher_test.go | 5 + .../state/state-native/setters_misc.go | 30 ++- beacon-chain/state/state-native/state_trie.go | 8 +- .../state/state-native/types/types.go | 5 + config/params/mainnet_config.go | 2 +- proto/migration/v1alpha1_to_v1.go | 6 +- proto/migration/v1alpha1_to_v2.go | 19 +- proto/migration/v1alpha1_to_v2_test.go | 2 - proto/prysm/v1alpha1/beacon_state.pb.go | 225 ++++++++++++------ proto/prysm/v1alpha1/beacon_state.proto | 7 + proto/prysm/v1alpha1/cloners.go | 15 ++ proto/prysm/v1alpha1/cloners_test.go | 12 + proto/prysm/v1alpha1/generated.ssz.go | 161 ++++++++++++- .../capella/epoch_processing/BUILD.bazel | 2 +- .../historical_roots_update_test.go | 11 - .../historical_summaries_update_test.go | 11 + .../capella/epoch_processing/BUILD.bazel | 2 +- .../historical_roots_summaries_test.go | 11 + .../historical_roots_update_test.go | 11 - .../historical_roots_update.go | 2 +- .../historical_roots_update.go | 2 +- .../capella/epoch_processing/BUILD.bazel | 2 +- ...date.go => historical_summaries_update.go} | 16 +- .../shared/capella/ssz_static/ssz_static.go | 2 + .../historical_roots_update.go | 2 +- testing/util/state.go | 2 +- tools/exploredb/main.go | 9 +- 44 files changed, 697 insertions(+), 163 deletions(-) delete mode 100644 testing/spectest/mainnet/capella/epoch_processing/historical_roots_update_test.go create mode 100644 testing/spectest/mainnet/capella/epoch_processing/historical_summaries_update_test.go create mode 100644 testing/spectest/minimal/capella/epoch_processing/historical_roots_summaries_test.go delete mode 100644 testing/spectest/minimal/capella/epoch_processing/historical_roots_update_test.go rename testing/spectest/shared/capella/epoch_processing/{historical_roots_update.go => historical_summaries_update.go} (51%) diff --git a/WORKSPACE b/WORKSPACE index d0a1f2226a..1970f870a7 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -188,7 +188,7 @@ filegroup( url = "https://github.com/eth-clients/slashing-protection-interchange-tests/archive/b8413ca42dc92308019d0d4db52c87e9e125c4e9.tar.gz", ) -consensus_spec_version = "v1.3.0-alpha.2" +consensus_spec_version = "v1.3.0-rc.0" bls_test_version = "v0.1.1" @@ -204,7 +204,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "a92c41058dc17ced811cc85570cd6f8af761aedfcbd2dd7dd4fb64ac961d76f9", + sha256 = "44c39a68242a4b731865040ea3009ea1a695ee3377d2891cecf8e6a721f0102b", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version, ) @@ -220,7 +220,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "49a7944da92429ac8f41347f19837762247cdbf00e628c285d1b826e58e4096d", + sha256 = "c9aaf6f7c1ca1264ec9a45872d5058f3377ebdd9dbcb987796f7302d86f98934", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version, ) @@ -236,7 +236,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "d19673e9cd55e0c8d45eefc33b60978e14c166d0e891976fcaa114085312adcb", + sha256 = "78400c82f1978147feeab54e3deccb29c024efa13d6753adc8687ae008bae246", url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version, ) @@ -251,7 +251,7 @@ filegroup( visibility = ["//visibility:public"], ) """, - sha256 = "a72b7457c403f6b76567d4d7bec19d01bedf7d5ef1d6f2c3a9e09ee86d401a14", + sha256 = "531eff00498acf5965d8890d83e3561a64f7b23a75d7f312915291482da2bf52", strip_prefix = "consensus-specs-" + consensus_spec_version[1:], url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version, ) diff --git a/beacon-chain/core/altair/transition.go b/beacon-chain/core/altair/transition.go index b0c40c7690..f48b790a32 100644 --- a/beacon-chain/core/altair/transition.go +++ b/beacon-chain/core/altair/transition.go @@ -93,7 +93,7 @@ func ProcessEpoch(ctx context.Context, state state.BeaconState) (state.BeaconSta if err != nil { return nil, err } - state, err = e.ProcessHistoricalRootsUpdate(state) + state, err = e.ProcessHistoricalDataUpdate(state) if err != nil { return nil, err } diff --git a/beacon-chain/core/altair/upgrade.go b/beacon-chain/core/altair/upgrade.go index d972719634..78ce5b8102 100644 --- a/beacon-chain/core/altair/upgrade.go +++ b/beacon-chain/core/altair/upgrade.go @@ -67,6 +67,10 @@ func UpgradeToAltair(ctx context.Context, state state.BeaconState) (state.Beacon epoch := time.CurrentEpoch(state) numValidators := state.NumValidators() + hrs, err := state.HistoricalRoots() + if err != nil { + return nil, err + } s := ðpb.BeaconStateAltair{ GenesisTime: state.GenesisTime(), GenesisValidatorsRoot: state.GenesisValidatorsRoot(), @@ -79,7 +83,7 @@ func UpgradeToAltair(ctx context.Context, state state.BeaconState) (state.Beacon LatestBlockHeader: state.LatestBlockHeader(), BlockRoots: state.BlockRoots(), StateRoots: state.StateRoots(), - HistoricalRoots: state.HistoricalRoots(), + HistoricalRoots: hrs, Eth1Data: state.Eth1Data(), Eth1DataVotes: state.Eth1DataVotes(), Eth1DepositIndex: state.Eth1DepositIndex(), diff --git a/beacon-chain/core/altair/upgrade_test.go b/beacon-chain/core/altair/upgrade_test.go index 50e85bfd05..b0aa22b0c5 100644 --- a/beacon-chain/core/altair/upgrade_test.go +++ b/beacon-chain/core/altair/upgrade_test.go @@ -82,7 +82,11 @@ func TestUpgradeToAltair(t *testing.T) { require.DeepSSZEqual(t, preForkState.LatestBlockHeader(), aState.LatestBlockHeader()) require.DeepSSZEqual(t, preForkState.BlockRoots(), aState.BlockRoots()) require.DeepSSZEqual(t, preForkState.StateRoots(), aState.StateRoots()) - require.DeepSSZEqual(t, preForkState.HistoricalRoots(), aState.HistoricalRoots()) + r1, err := preForkState.HistoricalRoots() + require.NoError(t, err) + r2, err := aState.HistoricalRoots() + require.NoError(t, err) + require.DeepSSZEqual(t, r1, r2) require.DeepSSZEqual(t, preForkState.Eth1Data(), aState.Eth1Data()) require.DeepSSZEqual(t, preForkState.Eth1DataVotes(), aState.Eth1DataVotes()) require.DeepSSZEqual(t, preForkState.Eth1DepositIndex(), aState.Eth1DepositIndex()) diff --git a/beacon-chain/core/capella/upgrade.go b/beacon-chain/core/capella/upgrade.go index 6163f7ea81..7941c5c00a 100644 --- a/beacon-chain/core/capella/upgrade.go +++ b/beacon-chain/core/capella/upgrade.go @@ -42,6 +42,10 @@ func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) { return nil, err } + hrs, err := state.HistoricalRoots() + if err != nil { + return nil, err + } s := ðpb.BeaconStateCapella{ GenesisTime: state.GenesisTime(), GenesisValidatorsRoot: state.GenesisValidatorsRoot(), @@ -54,7 +58,7 @@ func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) { LatestBlockHeader: state.LatestBlockHeader(), BlockRoots: state.BlockRoots(), StateRoots: state.StateRoots(), - HistoricalRoots: state.HistoricalRoots(), + HistoricalRoots: hrs, Eth1Data: state.Eth1Data(), Eth1DataVotes: state.Eth1DataVotes(), Eth1DepositIndex: state.Eth1DepositIndex(), @@ -90,6 +94,7 @@ func UpgradeToCapella(state state.BeaconState) (state.BeaconState, error) { }, NextWithdrawalIndex: 0, NextWithdrawalValidatorIndex: 0, + HistoricalSummaries: make([]*ethpb.HistoricalSummary, 0), } return state_native.InitializeFromProtoUnsafeCapella(s) diff --git a/beacon-chain/core/capella/upgrade_test.go b/beacon-chain/core/capella/upgrade_test.go index 1f0809b6ac..4787d73889 100644 --- a/beacon-chain/core/capella/upgrade_test.go +++ b/beacon-chain/core/capella/upgrade_test.go @@ -25,7 +25,6 @@ func TestUpgradeToCapella(t *testing.T) { require.DeepSSZEqual(t, preForkState.LatestBlockHeader(), mSt.LatestBlockHeader()) require.DeepSSZEqual(t, preForkState.BlockRoots(), mSt.BlockRoots()) require.DeepSSZEqual(t, preForkState.StateRoots(), mSt.StateRoots()) - require.DeepSSZEqual(t, preForkState.HistoricalRoots(), mSt.HistoricalRoots()) require.DeepSSZEqual(t, preForkState.Eth1Data(), mSt.Eth1Data()) require.DeepSSZEqual(t, preForkState.Eth1DataVotes(), mSt.Eth1DataVotes()) require.DeepSSZEqual(t, preForkState.Eth1DepositIndex(), mSt.Eth1DepositIndex()) @@ -98,4 +97,8 @@ func TestUpgradeToCapella(t *testing.T) { lwvi, err := mSt.NextWithdrawalValidatorIndex() require.NoError(t, err) require.Equal(t, types.ValidatorIndex(0), lwvi) + + summaries, err := mSt.HistoricalSummaries() + require.NoError(t, err) + require.Equal(t, 0, len(summaries)) } diff --git a/beacon-chain/core/epoch/BUILD.bazel b/beacon-chain/core/epoch/BUILD.bazel index 09da2c5159..84293bb213 100644 --- a/beacon-chain/core/epoch/BUILD.bazel +++ b/beacon-chain/core/epoch/BUILD.bazel @@ -13,11 +13,14 @@ go_library( "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", + "//beacon-chain/state/stateutil:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/primitives:go_default_library", "//math:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//proto/prysm/v1alpha1/attestation:go_default_library", + "//runtime/version:go_default_library", "@com_github_pkg_errors//:go_default_library", ], ) @@ -33,8 +36,10 @@ go_test( deps = [ "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/time:go_default_library", + "//beacon-chain/core/transition:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", + "//beacon-chain/state/stateutil: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.go b/beacon-chain/core/epoch/epoch_processing.go index 7ebae510eb..5bfc5f5680 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -14,11 +14,14 @@ import ( "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/v3/beacon-chain/state" + "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil" + 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/math" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/attestation" + "github.com/prysmaticlabs/prysm/v3/runtime/version" ) // sortableIndices implements the Sort interface to sort newly activated validator indices @@ -349,33 +352,39 @@ func ProcessRandaoMixesReset(state state.BeaconState) (state.BeaconState, error) return state, nil } -// ProcessHistoricalRootsUpdate processes the updates to historical root accumulator during epoch processing. -// -// Spec pseudocode definition: -// -// def process_historical_roots_update(state: BeaconState) -> None: -// # Set historical root accumulator -// next_epoch = Epoch(get_current_epoch(state) + 1) -// if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0: -// historical_batch = HistoricalBatch(block_roots=state.block_roots, state_roots=state.state_roots) -// state.historical_roots.append(hash_tree_root(historical_batch)) -func ProcessHistoricalRootsUpdate(state state.BeaconState) (state.BeaconState, error) { +// ProcessHistoricalDataUpdate processes the updates to historical data during epoch processing. +// From Capella onward, per spec,state's historical summaries are updated instead of historical roots. +func ProcessHistoricalDataUpdate(state state.BeaconState) (state.BeaconState, error) { currentEpoch := time.CurrentEpoch(state) nextEpoch := currentEpoch + 1 // Set historical root accumulator. epochsPerHistoricalRoot := params.BeaconConfig().SlotsPerHistoricalRoot.DivSlot(params.BeaconConfig().SlotsPerEpoch) if nextEpoch.Mod(uint64(epochsPerHistoricalRoot)) == 0 { - historicalBatch := ðpb.HistoricalBatch{ - BlockRoots: state.BlockRoots(), - StateRoots: state.StateRoots(), - } - batchRoot, err := historicalBatch.HashTreeRoot() - if err != nil { - return nil, errors.Wrap(err, "could not hash historical batch") - } - if err := state.AppendHistoricalRoots(batchRoot); err != nil { - return nil, err + if state.Version() >= version.Capella { + br, err := stateutil.ArraysRoot(state.BlockRoots(), fieldparams.BlockRootsLength) + if err != nil { + return nil, err + } + sr, err := stateutil.ArraysRoot(state.StateRoots(), fieldparams.StateRootsLength) + if err != nil { + return nil, err + } + if err := state.AppendHistoricalSummaries(ðpb.HistoricalSummary{BlockSummaryRoot: br[:], StateSummaryRoot: sr[:]}); err != nil { + return nil, err + } + } else { + historicalBatch := ðpb.HistoricalBatch{ + BlockRoots: state.BlockRoots(), + StateRoots: state.StateRoots(), + } + batchRoot, err := historicalBatch.HashTreeRoot() + if err != nil { + return nil, errors.Wrap(err, "could not hash historical batch") + } + if err := state.AppendHistoricalRoots(batchRoot); err != nil { + return nil, err + } } } @@ -426,7 +435,7 @@ func ProcessFinalUpdates(state state.BeaconState) (state.BeaconState, error) { } // Set historical root accumulator. - state, err = ProcessHistoricalRootsUpdate(state) + state, err = ProcessHistoricalDataUpdate(state) if err != nil { return nil, err } diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 22af012c22..84108a65ea 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -10,8 +10,10 @@ 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" + "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" fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams" "github.com/prysmaticlabs/prysm/v3/config/params" types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" @@ -274,7 +276,9 @@ func TestProcessFinalUpdates_CanProcess(t *testing.T) { assert.DeepNotEqual(t, params.BeaconConfig().ZeroHash[:], mix, "latest RANDAO still zero hashes") // Verify historical root accumulator was appended. - assert.Equal(t, 1, len(newS.HistoricalRoots()), "Unexpected slashed balance") + roots, err := newS.HistoricalRoots() + require.NoError(t, err) + assert.Equal(t, 1, len(roots), "Unexpected slashed balance") currAtt, err := newS.CurrentEpochAttestations() require.NoError(t, err) assert.NotNil(t, currAtt, "Nil value stored in current epoch attestations instead of empty slice") @@ -455,3 +459,82 @@ func TestProcessSlashings_BadValue(t *testing.T) { _, err = epoch.ProcessSlashings(s, params.BeaconConfig().ProportionalSlashingMultiplier) require.ErrorContains(t, "addition overflows", err) } + +func TestProcessHistoricalDataUpdate(t *testing.T) { + tests := []struct { + name string + st func() state.BeaconState + verifier func(state.BeaconState) + }{ + { + name: "no change", + st: func() state.BeaconState { + st, _ := util.DeterministicGenesisState(t, 1) + return st + }, + verifier: func(st state.BeaconState) { + roots, err := st.HistoricalRoots() + require.NoError(t, err) + require.Equal(t, 0, len(roots)) + }, + }, + { + name: "before capella can process and get historical root", + st: func() state.BeaconState { + st, _ := util.DeterministicGenesisState(t, 1) + st, err := transition.ProcessSlots(context.Background(), st, params.BeaconConfig().SlotsPerHistoricalRoot-1) + require.NoError(t, err) + return st + }, + verifier: func(st state.BeaconState) { + roots, err := st.HistoricalRoots() + require.NoError(t, err) + require.Equal(t, 1, len(roots)) + + b := ðpb.HistoricalBatch{ + BlockRoots: st.BlockRoots(), + StateRoots: st.StateRoots(), + } + r, err := b.HashTreeRoot() + require.NoError(t, err) + require.DeepEqual(t, r[:], roots[0]) + + _, err = st.HistoricalSummaries() + require.ErrorContains(t, "HistoricalSummaries is not supported for phase0", err) + }, + }, + { + name: "after capella can process and get historical summary", + st: func() state.BeaconState { + st, _ := util.DeterministicGenesisStateCapella(t, 1) + st, err := transition.ProcessSlots(context.Background(), st, params.BeaconConfig().SlotsPerHistoricalRoot-1) + require.NoError(t, err) + return st + }, + verifier: func(st state.BeaconState) { + summaries, err := st.HistoricalSummaries() + require.NoError(t, err) + require.Equal(t, 1, len(summaries)) + + br, err := stateutil.ArraysRoot(st.BlockRoots(), fieldparams.BlockRootsLength) + require.NoError(t, err) + sr, err := stateutil.ArraysRoot(st.StateRoots(), fieldparams.StateRootsLength) + require.NoError(t, err) + b := ðpb.HistoricalSummary{ + BlockSummaryRoot: br[:], + StateSummaryRoot: sr[:], + } + require.DeepEqual(t, b, summaries[0]) + _, err = st.HistoricalRoots() + require.ErrorContains(t, "HistoricalRoots is not supported for capella", err) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := epoch.ProcessHistoricalDataUpdate(tt.st()) + require.NoError(t, err) + tt.verifier(got) + }) + } +} diff --git a/beacon-chain/core/execution/upgrade.go b/beacon-chain/core/execution/upgrade.go index d12679d769..0f489788ff 100644 --- a/beacon-chain/core/execution/upgrade.go +++ b/beacon-chain/core/execution/upgrade.go @@ -35,6 +35,10 @@ func UpgradeToBellatrix(state state.BeaconState) (state.BeaconState, error) { return nil, err } + hrs, err := state.HistoricalRoots() + if err != nil { + return nil, err + } s := ðpb.BeaconStateBellatrix{ GenesisTime: state.GenesisTime(), GenesisValidatorsRoot: state.GenesisValidatorsRoot(), @@ -47,7 +51,7 @@ func UpgradeToBellatrix(state state.BeaconState) (state.BeaconState, error) { LatestBlockHeader: state.LatestBlockHeader(), BlockRoots: state.BlockRoots(), StateRoots: state.StateRoots(), - HistoricalRoots: state.HistoricalRoots(), + HistoricalRoots: hrs, Eth1Data: state.Eth1Data(), Eth1DataVotes: state.Eth1DataVotes(), Eth1DepositIndex: state.Eth1DepositIndex(), diff --git a/beacon-chain/core/execution/upgrade_test.go b/beacon-chain/core/execution/upgrade_test.go index 40e4494f3b..ea436599ad 100644 --- a/beacon-chain/core/execution/upgrade_test.go +++ b/beacon-chain/core/execution/upgrade_test.go @@ -24,7 +24,11 @@ func TestUpgradeToBellatrix(t *testing.T) { require.DeepSSZEqual(t, preForkState.LatestBlockHeader(), mSt.LatestBlockHeader()) require.DeepSSZEqual(t, preForkState.BlockRoots(), mSt.BlockRoots()) require.DeepSSZEqual(t, preForkState.StateRoots(), mSt.StateRoots()) - require.DeepSSZEqual(t, preForkState.HistoricalRoots(), mSt.HistoricalRoots()) + r1, err := preForkState.HistoricalRoots() + require.NoError(t, err) + r2, err := mSt.HistoricalRoots() + require.NoError(t, err) + require.DeepSSZEqual(t, r1, r2) require.DeepSSZEqual(t, preForkState.Eth1Data(), mSt.Eth1Data()) require.DeepSSZEqual(t, preForkState.Eth1DataVotes(), mSt.Eth1DataVotes()) require.DeepSSZEqual(t, preForkState.Eth1DepositIndex(), mSt.Eth1DepositIndex()) diff --git a/beacon-chain/state/interfaces.go b/beacon-chain/state/interfaces.go index 4cb24ebef0..ee740617eb 100644 --- a/beacon-chain/state/interfaces.go +++ b/beacon-chain/state/interfaces.go @@ -57,7 +57,8 @@ type ReadOnlyBeaconState interface { Slot() types.Slot Fork() *ethpb.Fork LatestBlockHeader() *ethpb.BeaconBlockHeader - HistoricalRoots() [][]byte + HistoricalRoots() ([][]byte, error) + HistoricalSummaries() ([]*ethpb.HistoricalSummary, error) Slashings() []uint64 FieldReferencesCount() map[string]uint64 MarshalSSZ() ([]byte, error) @@ -85,6 +86,7 @@ type WriteOnlyBeaconState interface { SetSlashings(val []uint64) error UpdateSlashingsAtIndex(idx, val uint64) error AppendHistoricalRoots(root [32]byte) error + AppendHistoricalSummaries(*ethpb.HistoricalSummary) error SetLatestExecutionPayloadHeader(payload interfaces.ExecutionData) error SetNextWithdrawalIndex(i uint64) error SetNextWithdrawalValidatorIndex(i types.ValidatorIndex) error diff --git a/beacon-chain/state/state-native/beacon_state_mainnet.go b/beacon-chain/state/state-native/beacon_state_mainnet.go index 4b37a0d276..66fc51dd9a 100644 --- a/beacon-chain/state/state-native/beacon_state_mainnet.go +++ b/beacon-chain/state/state-native/beacon_state_mainnet.go @@ -27,6 +27,7 @@ type BeaconState struct { blockRoots *customtypes.BlockRoots stateRoots *customtypes.StateRoots historicalRoots customtypes.HistoricalRoots + historicalSummaries []*ethpb.HistoricalSummary eth1Data *ethpb.Eth1Data eth1DataVotes []*ethpb.Eth1Data eth1DepositIndex uint64 diff --git a/beacon-chain/state/state-native/beacon_state_minimal.go b/beacon-chain/state/state-native/beacon_state_minimal.go index 11679c83b1..b9a61a8eba 100644 --- a/beacon-chain/state/state-native/beacon_state_minimal.go +++ b/beacon-chain/state/state-native/beacon_state_minimal.go @@ -27,6 +27,7 @@ type BeaconState struct { blockRoots *customtypes.BlockRoots stateRoots *customtypes.StateRoots historicalRoots customtypes.HistoricalRoots + historicalSummaries []*ethpb.HistoricalSummary eth1Data *ethpb.Eth1Data eth1DataVotes []*ethpb.Eth1Data eth1DepositIndex uint64 diff --git a/beacon-chain/state/state-native/getters_misc.go b/beacon-chain/state/state-native/getters_misc.go index 95050d1da4..e1a0872711 100644 --- a/beacon-chain/state/state-native/getters_misc.go +++ b/beacon-chain/state/state-native/getters_misc.go @@ -3,6 +3,7 @@ package state_native import ( types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v3/runtime/version" ) // GenesisTime of the beacon state as a uint64. @@ -67,15 +68,19 @@ func (b *BeaconState) forkVal() *ethpb.Fork { } // HistoricalRoots based on epochs stored in the beacon state. -func (b *BeaconState) HistoricalRoots() [][]byte { +func (b *BeaconState) HistoricalRoots() ([][]byte, error) { + if b.version > version.Bellatrix { + return nil, errNotSupported("HistoricalRoots", b.version) + } + if b.historicalRoots == nil { - return nil + return nil, nil } b.lock.RLock() defer b.lock.RUnlock() - return b.historicalRoots.Slice() + return b.historicalRoots.Slice(), nil } // balancesLength returns the length of the balances slice. @@ -87,3 +92,25 @@ func (b *BeaconState) balancesLength() int { return len(b.balances) } + +// HistoricalSummaries of the beacon state. +func (b *BeaconState) HistoricalSummaries() ([]*ethpb.HistoricalSummary, error) { + if b.version < version.Capella { + return nil, errNotSupported("HistoricalSummaries", b.version) + } + + if b.historicalSummaries == nil { + return nil, nil + } + + b.lock.RLock() + defer b.lock.RUnlock() + + return b.historicalSummariesVal(), nil +} + +// historicalSummariesVal of the beacon state. +// This assumes that a lock is already held on BeaconState. +func (b *BeaconState) historicalSummariesVal() []*ethpb.HistoricalSummary { + return ethpb.CopyHistoricalSummaries(b.historicalSummaries) +} diff --git a/beacon-chain/state/state-native/getters_state.go b/beacon-chain/state/state-native/getters_state.go index 89c3eab37d..9aa0adf5ff 100644 --- a/beacon-chain/state/state-native/getters_state.go +++ b/beacon-chain/state/state-native/getters_state.go @@ -126,6 +126,7 @@ func (b *BeaconState) ToProtoUnsafe() interface{} { LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapella, NextWithdrawalIndex: b.nextWithdrawalIndex, NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex, + HistoricalSummaries: b.historicalSummaries, } default: return nil @@ -252,6 +253,7 @@ func (b *BeaconState) ToProto() interface{} { LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapellaVal(), NextWithdrawalIndex: b.nextWithdrawalIndex, NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex, + HistoricalSummaries: b.historicalSummariesVal(), } default: return nil diff --git a/beacon-chain/state/state-native/hasher.go b/beacon-chain/state/state-native/hasher.go index 471085e703..c1879b7611 100644 --- a/beacon-chain/state/state-native/hasher.go +++ b/beacon-chain/state/state-native/hasher.go @@ -1,8 +1,10 @@ package state_native import ( + "bytes" "context" "encoding/binary" + "fmt" "github.com/pkg/errors" nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types" @@ -12,6 +14,7 @@ import ( "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" "github.com/prysmaticlabs/prysm/v3/runtime/version" "go.opencensus.io/trace" ) @@ -255,7 +258,50 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b nextWithdrawalValidatorIndexRoot := make([]byte, 32) binary.LittleEndian.PutUint64(nextWithdrawalValidatorIndexRoot, uint64(state.nextWithdrawalValidatorIndex)) fieldRoots[nativetypes.NextWithdrawalValidatorIndex.RealPosition()] = nextWithdrawalValidatorIndexRoot + + // Historical summary root. + historicalSummaryRoot, err := historicalSummaryRoot(state.historicalSummaries) + if err != nil { + return nil, errors.Wrap(err, "could not compute historical summary merkleization") + } + fieldRoots[nativetypes.HistoricalSummaries.RealPosition()] = historicalSummaryRoot[:] } return fieldRoots, nil } + +func historicalSummaryRoot(summaries []*ethpb.HistoricalSummary) ([32]byte, error) { + max := uint64(fieldparams.HistoricalRootsLength) + if uint64(len(summaries)) > max { + return [32]byte{}, fmt.Errorf("historical summary exceeds max length %d", max) + } + + hasher := hash.CustomSHA256Hasher() + roots := make([][32]byte, len(summaries)) + for i := 0; i < len(summaries); i++ { + r, err := summaries[i].HashTreeRoot() + if err != nil { + return [32]byte{}, errors.Wrap(err, "could not merkleize historical summary") + } + roots[i] = r + } + + summariesRoot, err := ssz.BitwiseMerkleize( + hasher, + roots, + uint64(len(roots)), + fieldparams.HistoricalRootsLength, + ) + if err != nil { + return [32]byte{}, errors.Wrap(err, "could not compute historical summaries merkleization") + } + summariesLenBuf := new(bytes.Buffer) + if err := binary.Write(summariesLenBuf, binary.LittleEndian, uint64(len(summaries))); err != nil { + return [32]byte{}, errors.Wrap(err, "could not marshal historical summary length") + } + // We need to mix in the length of the slice. + summariesLenRoot := make([]byte, 32) + copy(summariesLenRoot, summariesLenBuf.Bytes()) + res := ssz.MixInLength(summariesRoot, summariesLenRoot) + return res, nil +} diff --git a/beacon-chain/state/state-native/hasher_test.go b/beacon-chain/state/state-native/hasher_test.go index 416277a968..5223ea3fbd 100644 --- a/beacon-chain/state/state-native/hasher_test.go +++ b/beacon-chain/state/state-native/hasher_test.go @@ -258,6 +258,10 @@ func TestComputeFieldRootsWithHasher_Capella(t *testing.T) { require.NoError(t, beaconState.SetLatestExecutionPayloadHeader(wrappedHeader)) require.NoError(t, beaconState.SetNextWithdrawalIndex(123)) require.NoError(t, beaconState.SetNextWithdrawalValidatorIndex(123)) + require.NoError(t, beaconState.AppendHistoricalSummaries(ðpb.HistoricalSummary{ + BlockSummaryRoot: bytesutil.PadTo([]byte("block summary root"), 32), + StateSummaryRoot: bytesutil.PadTo([]byte("state summary root"), 32), + })) nativeState, ok := beaconState.(*statenative.BeaconState) require.Equal(t, true, ok) @@ -298,6 +302,7 @@ func TestComputeFieldRootsWithHasher_Capella(t *testing.T) { {0x39, 0x29, 0x16, 0xe8, 0x5a, 0xd2, 0xb, 0xbb, 0x1f, 0xef, 0x6a, 0xe0, 0x2d, 0xa6, 0x6a, 0x46, 0x81, 0xba, 0xcf, 0x86, 0xfc, 0x16, 0x22, 0x2a, 0x9b, 0x72, 0x96, 0x71, 0x2b, 0xc7, 0x5b, 0x9d}, {0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, {0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, + {0xa1, 0x4, 0x64, 0x31, 0x2a, 0xa, 0x49, 0x31, 0x1c, 0x1, 0x41, 0x17, 0xc0, 0x52, 0x52, 0xfa, 0x4c, 0xf4, 0x95, 0x4f, 0x5c, 0xb0, 0x5a, 0x40, 0xc1, 0x32, 0x39, 0xc3, 0x7c, 0xb7, 0x2c, 0x27}, } assert.DeepEqual(t, expected, root) } diff --git a/beacon-chain/state/state-native/setters_misc.go b/beacon-chain/state/state-native/setters_misc.go index 6ec54d8799..81d20839b3 100644 --- a/beacon-chain/state/state-native/setters_misc.go +++ b/beacon-chain/state/state-native/setters_misc.go @@ -9,6 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/v3/crypto/hash" "github.com/prysmaticlabs/prysm/v3/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1" + "github.com/prysmaticlabs/prysm/v3/runtime/version" "google.golang.org/protobuf/proto" ) @@ -106,11 +107,15 @@ func (b *BeaconState) SetHistoricalRoots(val [][]byte) error { } // AppendHistoricalRoots for the beacon state. Appends the new value -// to the the end of list. +// to the end of list. func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error { b.lock.Lock() defer b.lock.Unlock() + if b.version > version.Bellatrix { + return errNotSupported("AppendHistoricalRoots", b.version) + } + roots := b.historicalRoots if b.sharedFieldReferences[nativetypes.HistoricalRoots].Refs() > 1 { roots = make([][32]byte, len(b.historicalRoots)) @@ -124,6 +129,29 @@ func (b *BeaconState) AppendHistoricalRoots(root [32]byte) error { return nil } +// AppendHistoricalSummaries for the beacon state. Appends the new value +// to the end of list. +func (b *BeaconState) AppendHistoricalSummaries(summary *ethpb.HistoricalSummary) error { + b.lock.Lock() + defer b.lock.Unlock() + + if b.version < version.Capella { + return errNotSupported("AppendHistoricalSummaries", b.version) + } + + summaries := b.historicalSummaries + if b.sharedFieldReferences[nativetypes.HistoricalSummaries].Refs() > 1 { + summaries = make([]*ethpb.HistoricalSummary, len(b.historicalSummaries)) + copy(summaries, b.historicalSummaries) + b.sharedFieldReferences[nativetypes.HistoricalSummaries].MinusRef() + b.sharedFieldReferences[nativetypes.HistoricalSummaries] = stateutil.NewRef(1) + } + + b.historicalSummaries = append(summaries, summary) + b.markFieldAsDirty(nativetypes.HistoricalSummaries) + 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. diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index cd7c939ebc..175a1dbcea 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -82,13 +82,14 @@ var capellaFields = append( nativetypes.LatestExecutionPayloadHeaderCapella, nativetypes.NextWithdrawalIndex, nativetypes.NextWithdrawalValidatorIndex, + nativetypes.HistoricalSummaries, ) const ( phase0SharedFieldRefCount = 10 altairSharedFieldRefCount = 11 bellatrixSharedFieldRefCount = 12 - capellaSharedFieldRefCount = 13 + capellaSharedFieldRefCount = 14 ) // InitializeFromProtoPhase0 the beacon state from a protobuf representation. @@ -433,6 +434,7 @@ func InitializeFromProtoUnsafeCapella(st *ethpb.BeaconStateCapella) (state.Beaco latestExecutionPayloadHeaderCapella: st.LatestExecutionPayloadHeader, nextWithdrawalIndex: st.NextWithdrawalIndex, nextWithdrawalValidatorIndex: st.NextWithdrawalValidatorIndex, + historicalSummaries: st.HistoricalSummaries, dirtyFields: make(map[nativetypes.FieldIndex]bool, fieldCount), dirtyIndices: make(map[nativetypes.FieldIndex][]uint64, fieldCount), @@ -466,6 +468,7 @@ func InitializeFromProtoUnsafeCapella(st *ethpb.BeaconStateCapella) (state.Beaco b.sharedFieldReferences[nativetypes.CurrentEpochParticipationBits] = stateutil.NewRef(1) b.sharedFieldReferences[nativetypes.InactivityScores] = stateutil.NewRef(1) b.sharedFieldReferences[nativetypes.LatestExecutionPayloadHeaderCapella] = stateutil.NewRef(1) // New in Capella. + b.sharedFieldReferences[nativetypes.HistoricalSummaries] = stateutil.NewRef(1) // New in Capella. state.StateCount.Inc() // Finalizer runs when dst is being destroyed in garbage collection. @@ -530,6 +533,7 @@ func (b *BeaconState) Copy() state.BeaconState { nextSyncCommittee: b.nextSyncCommitteeVal(), latestExecutionPayloadHeader: b.latestExecutionPayloadHeaderVal(), latestExecutionPayloadHeaderCapella: b.latestExecutionPayloadHeaderCapellaVal(), + historicalSummaries: b.historicalSummariesVal(), dirtyFields: make(map[nativetypes.FieldIndex]bool, fieldCount), dirtyIndices: make(map[nativetypes.FieldIndex][]uint64, fieldCount), @@ -833,6 +837,8 @@ func (b *BeaconState) rootSelector(ctx context.Context, field nativetypes.FieldI return ssz.Uint64Root(b.nextWithdrawalIndex), nil case nativetypes.NextWithdrawalValidatorIndex: return ssz.Uint64Root(uint64(b.nextWithdrawalValidatorIndex)), nil + case nativetypes.HistoricalSummaries: + return historicalSummaryRoot(b.historicalSummaries) } return [32]byte{}, errors.New("invalid field index provided") } diff --git a/beacon-chain/state/state-native/types/types.go b/beacon-chain/state/state-native/types/types.go index 36372ecef0..35e22e29ed 100644 --- a/beacon-chain/state/state-native/types/types.go +++ b/beacon-chain/state/state-native/types/types.go @@ -71,6 +71,8 @@ func (f FieldIndex) String(_ int) string { return "NextWithdrawalIndex" case NextWithdrawalValidatorIndex: return "NextWithdrawalValidatorIndex" + case HistoricalSummaries: + return "HistoricalSummaries" default: return "" } @@ -134,6 +136,8 @@ func (f FieldIndex) RealPosition() int { return 25 case NextWithdrawalValidatorIndex: return 26 + case HistoricalSummaries: + return 27 default: return -1 } @@ -191,4 +195,5 @@ const ( LatestExecutionPayloadHeaderCapella NextWithdrawalIndex NextWithdrawalValidatorIndex + HistoricalSummaries ) diff --git a/config/params/mainnet_config.go b/config/params/mainnet_config.go index 9a0e36b0d0..3eefff8140 100644 --- a/config/params/mainnet_config.go +++ b/config/params/mainnet_config.go @@ -191,7 +191,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{ BeaconStateFieldCount: 21, BeaconStateAltairFieldCount: 24, BeaconStateBellatrixFieldCount: 25, - BeaconStateCapellaFieldCount: 27, + BeaconStateCapellaFieldCount: 28, // Slasher related values. WeakSubjectivityPeriod: 54000, diff --git a/proto/migration/v1alpha1_to_v1.go b/proto/migration/v1alpha1_to_v1.go index 605127c677..08a1240725 100644 --- a/proto/migration/v1alpha1_to_v1.go +++ b/proto/migration/v1alpha1_to_v1.go @@ -441,6 +441,10 @@ func BeaconStateToProto(state state.BeaconState) (*ethpbv1.BeaconState, error) { } } + hRoot, err := state.HistoricalRoots() + if err != nil { + return nil, errors.Wrapf(err, "could not get historical roots from state") + } result := ðpbv1.BeaconState{ GenesisTime: state.GenesisTime(), GenesisValidatorsRoot: bytesutil.SafeCopyBytes(state.GenesisValidatorsRoot()), @@ -459,7 +463,7 @@ func BeaconStateToProto(state state.BeaconState) (*ethpbv1.BeaconState, error) { }, BlockRoots: bytesutil.SafeCopy2dBytes(state.BlockRoots()), StateRoots: bytesutil.SafeCopy2dBytes(state.StateRoots()), - HistoricalRoots: bytesutil.SafeCopy2dBytes(state.HistoricalRoots()), + HistoricalRoots: bytesutil.SafeCopy2dBytes(hRoot), Eth1Data: ðpbv1.Eth1Data{ DepositRoot: bytesutil.SafeCopyBytes(sourceEth1Data.DepositRoot), DepositCount: sourceEth1Data.DepositCount, diff --git a/proto/migration/v1alpha1_to_v2.go b/proto/migration/v1alpha1_to_v2.go index bdfaee7f5e..6ae0774b55 100644 --- a/proto/migration/v1alpha1_to_v2.go +++ b/proto/migration/v1alpha1_to_v2.go @@ -371,6 +371,11 @@ func BeaconStateAltairToProto(altairState state.BeaconState) (*ethpbv2.BeaconSta return nil, errors.Wrap(err, "could not get next sync committee") } + hrs, err := altairState.HistoricalRoots() + if err != nil { + return nil, errors.Wrap(err, "could not get historical roots") + } + result := ðpbv2.BeaconState{ GenesisTime: altairState.GenesisTime(), GenesisValidatorsRoot: bytesutil.SafeCopyBytes(altairState.GenesisValidatorsRoot()), @@ -389,7 +394,7 @@ func BeaconStateAltairToProto(altairState state.BeaconState) (*ethpbv2.BeaconSta }, BlockRoots: bytesutil.SafeCopy2dBytes(altairState.BlockRoots()), StateRoots: bytesutil.SafeCopy2dBytes(altairState.StateRoots()), - HistoricalRoots: bytesutil.SafeCopy2dBytes(altairState.HistoricalRoots()), + HistoricalRoots: bytesutil.SafeCopy2dBytes(hrs), Eth1Data: ðpbv1.Eth1Data{ DepositRoot: bytesutil.SafeCopyBytes(sourceEth1Data.DepositRoot), DepositCount: sourceEth1Data.DepositCount, @@ -493,6 +498,11 @@ func BeaconStateBellatrixToProto(st state.BeaconState) (*ethpbv2.BeaconStateBell return nil, errors.New("execution payload header has incorrect type") } + hRoots, err := st.HistoricalRoots() + if err != nil { + return nil, errors.Wrap(err, "could not get historical roots") + } + result := ðpbv2.BeaconStateBellatrix{ GenesisTime: st.GenesisTime(), GenesisValidatorsRoot: bytesutil.SafeCopyBytes(st.GenesisValidatorsRoot()), @@ -511,7 +521,7 @@ func BeaconStateBellatrixToProto(st state.BeaconState) (*ethpbv2.BeaconStateBell }, BlockRoots: bytesutil.SafeCopy2dBytes(st.BlockRoots()), StateRoots: bytesutil.SafeCopy2dBytes(st.StateRoots()), - HistoricalRoots: bytesutil.SafeCopy2dBytes(st.HistoricalRoots()), + HistoricalRoots: bytesutil.SafeCopy2dBytes(hRoots), Eth1Data: ðpbv1.Eth1Data{ DepositRoot: bytesutil.SafeCopyBytes(sourceEth1Data.DepositRoot), DepositCount: sourceEth1Data.DepositCount, @@ -655,9 +665,8 @@ func BeaconStateCapellaToProto(st state.BeaconState) (*ethpbv2.BeaconStateCapell StateRoot: bytesutil.SafeCopyBytes(sourceLatestBlockHeader.StateRoot), BodyRoot: bytesutil.SafeCopyBytes(sourceLatestBlockHeader.BodyRoot), }, - BlockRoots: bytesutil.SafeCopy2dBytes(st.BlockRoots()), - StateRoots: bytesutil.SafeCopy2dBytes(st.StateRoots()), - HistoricalRoots: bytesutil.SafeCopy2dBytes(st.HistoricalRoots()), + BlockRoots: bytesutil.SafeCopy2dBytes(st.BlockRoots()), + StateRoots: bytesutil.SafeCopy2dBytes(st.StateRoots()), Eth1Data: ðpbv1.Eth1Data{ DepositRoot: bytesutil.SafeCopyBytes(sourceEth1Data.DepositRoot), DepositCount: sourceEth1Data.DepositCount, diff --git a/proto/migration/v1alpha1_to_v2_test.go b/proto/migration/v1alpha1_to_v2_test.go index d94915237b..40e548c8fd 100644 --- a/proto/migration/v1alpha1_to_v2_test.go +++ b/proto/migration/v1alpha1_to_v2_test.go @@ -689,8 +689,6 @@ func TestBeaconStateCapellaToProto(t *testing.T) { assert.DeepEqual(t, bytesutil.PadTo([]byte("blockroots"), 32), result.BlockRoots[0]) assert.Equal(t, 8192, len(result.StateRoots)) assert.DeepEqual(t, bytesutil.PadTo([]byte("stateroots"), 32), result.StateRoots[0]) - assert.Equal(t, 1, len(result.HistoricalRoots)) - assert.DeepEqual(t, bytesutil.PadTo([]byte("historicalroots"), 32), result.HistoricalRoots[0]) resultEth1Data := result.Eth1Data require.NotNil(t, resultEth1Data) assert.DeepEqual(t, bytesutil.PadTo([]byte("e1ddepositroot"), 32), resultEth1Data.DepositRoot) diff --git a/proto/prysm/v1alpha1/beacon_state.pb.go b/proto/prysm/v1alpha1/beacon_state.pb.go index 199ab95e18..4f547319e1 100755 --- a/proto/prysm/v1alpha1/beacon_state.pb.go +++ b/proto/prysm/v1alpha1/beacon_state.pb.go @@ -1340,6 +1340,7 @@ type BeaconStateCapella struct { LatestExecutionPayloadHeader *v1.ExecutionPayloadHeaderCapella `protobuf:"bytes,10001,opt,name=latest_execution_payload_header,json=latestExecutionPayloadHeader,proto3" json:"latest_execution_payload_header,omitempty"` NextWithdrawalIndex uint64 `protobuf:"varint,11001,opt,name=next_withdrawal_index,json=nextWithdrawalIndex,proto3" json:"next_withdrawal_index,omitempty"` NextWithdrawalValidatorIndex github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex `protobuf:"varint,11002,opt,name=next_withdrawal_validator_index,json=nextWithdrawalValidatorIndex,proto3" json:"next_withdrawal_validator_index,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.ValidatorIndex"` + HistoricalSummaries []*HistoricalSummary `protobuf:"bytes,11003,rep,name=historical_summaries,json=historicalSummaries,proto3" json:"historical_summaries,omitempty" ssz-max:"16777216"` } func (x *BeaconStateCapella) Reset() { @@ -1563,6 +1564,13 @@ func (x *BeaconStateCapella) GetNextWithdrawalValidatorIndex() github_com_prysma return github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex(0) } +func (x *BeaconStateCapella) GetHistoricalSummaries() []*HistoricalSummary { + if x != nil { + return x.HistoricalSummaries + } + return nil +} + type PowBlock struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1626,6 +1634,61 @@ func (x *PowBlock) GetTotalDifficulty() []byte { return nil } +type HistoricalSummary struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + BlockSummaryRoot []byte `protobuf:"bytes,1,opt,name=block_summary_root,json=blockSummaryRoot,proto3" json:"block_summary_root,omitempty" ssz-size:"32"` + StateSummaryRoot []byte `protobuf:"bytes,2,opt,name=state_summary_root,json=stateSummaryRoot,proto3" json:"state_summary_root,omitempty" ssz-size:"32"` +} + +func (x *HistoricalSummary) Reset() { + *x = HistoricalSummary{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HistoricalSummary) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HistoricalSummary) ProtoMessage() {} + +func (x *HistoricalSummary) ProtoReflect() protoreflect.Message { + mi := &file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes[15] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HistoricalSummary.ProtoReflect.Descriptor instead. +func (*HistoricalSummary) Descriptor() ([]byte, []int) { + return file_proto_prysm_v1alpha1_beacon_state_proto_rawDescGZIP(), []int{15} +} + +func (x *HistoricalSummary) GetBlockSummaryRoot() []byte { + if x != nil { + return x.BlockSummaryRoot + } + return nil +} + +func (x *HistoricalSummary) GetStateSummaryRoot() []byte { + if x != nil { + return x.StateSummaryRoot + } + return nil +} + var File_proto_prysm_v1alpha1_beacon_state_proto protoreflect.FileDescriptor var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{ @@ -2073,7 +2136,7 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{ 0x69, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x1c, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x61, - 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x9d, 0x10, 0x0a, 0x12, + 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x89, 0x11, 0x0a, 0x12, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x61, 0x70, 0x65, 0x6c, 0x6c, 0x61, 0x12, 0x22, 0x0a, 0x0c, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0xe9, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x67, 0x65, 0x6e, 0x65, 0x73, @@ -2203,27 +2266,41 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc = []byte{ 0x70, 0x65, 0x73, 0x2f, 0x70, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x52, 0x1c, 0x6e, 0x65, 0x78, 0x74, 0x57, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x61, 0x6c, 0x56, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x8d, 0x01, 0x0a, 0x08, - 0x50, 0x6f, 0x77, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x25, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, - 0x18, 0x02, 0x33, 0x32, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, - 0x27, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0a, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x48, 0x61, 0x73, 0x68, 0x12, 0x31, 0x0a, 0x10, 0x74, 0x6f, 0x74, 0x61, - 0x6c, 0x5f, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61, - 0x6c, 0x44, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x42, 0x9b, 0x01, 0x0a, 0x19, - 0x6f, 0x72, 0x67, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, - 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x10, 0x42, 0x65, 0x61, 0x63, 0x6f, - 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3a, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, - 0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x31, 0x61, - 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x65, 0x74, 0x68, 0xaa, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, - 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x45, 0x74, 0x68, 0x2e, 0x56, 0x31, 0x41, 0x6c, 0x70, 0x68, 0x61, - 0x31, 0xca, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x5c, 0x45, 0x74, 0x68, - 0x5c, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x6a, 0x0a, 0x14, 0x68, + 0x69, 0x73, 0x74, 0x6f, 0x72, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, + 0x69, 0x65, 0x73, 0x18, 0xfb, 0x55, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x65, 0x74, 0x68, + 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, + 0x61, 0x31, 0x2e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x69, 0x63, 0x61, 0x6c, 0x53, 0x75, 0x6d, + 0x6d, 0x61, 0x72, 0x79, 0x42, 0x0c, 0x92, 0xb5, 0x18, 0x08, 0x31, 0x36, 0x37, 0x37, 0x37, 0x32, + 0x31, 0x36, 0x52, 0x13, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x69, 0x63, 0x61, 0x6c, 0x53, 0x75, + 0x6d, 0x6d, 0x61, 0x72, 0x69, 0x65, 0x73, 0x22, 0x8d, 0x01, 0x0a, 0x08, 0x50, 0x6f, 0x77, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x25, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x68, 0x61, + 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, + 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68, 0x12, 0x27, 0x0a, 0x0b, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, + 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, + 0x48, 0x61, 0x73, 0x68, 0x12, 0x31, 0x0a, 0x10, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x64, 0x69, + 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, + 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x44, 0x69, 0x66, + 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x22, 0x7f, 0x0a, 0x11, 0x48, 0x69, 0x73, 0x74, 0x6f, + 0x72, 0x69, 0x63, 0x61, 0x6c, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x34, 0x0a, 0x12, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x72, 0x6f, + 0x6f, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, + 0x52, 0x10, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x6f, + 0x6f, 0x74, 0x12, 0x34, 0x0a, 0x12, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x75, 0x6d, 0x6d, + 0x61, 0x72, 0x79, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x06, + 0x8a, 0xb5, 0x18, 0x02, 0x33, 0x32, 0x52, 0x10, 0x73, 0x74, 0x61, 0x74, 0x65, 0x53, 0x75, 0x6d, + 0x6d, 0x61, 0x72, 0x79, 0x52, 0x6f, 0x6f, 0x74, 0x42, 0x9b, 0x01, 0x0a, 0x19, 0x6f, 0x72, 0x67, + 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x10, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x53, 0x74, + 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, 0x74, 0x69, 0x63, + 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, + 0x61, 0x31, 0x3b, 0x65, 0x74, 0x68, 0xaa, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, + 0x6d, 0x2e, 0x45, 0x74, 0x68, 0x2e, 0x56, 0x31, 0x41, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, + 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x5c, 0x45, 0x74, 0x68, 0x5c, 0x76, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2238,7 +2315,7 @@ func file_proto_prysm_v1alpha1_beacon_state_proto_rawDescGZIP() []byte { return file_proto_prysm_v1alpha1_beacon_state_proto_rawDescData } -var file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes = make([]protoimpl.MessageInfo, 15) +var file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes = make([]protoimpl.MessageInfo, 16) var file_proto_prysm_v1alpha1_beacon_state_proto_goTypes = []interface{}{ (*BeaconState)(nil), // 0: ethereum.eth.v1alpha1.BeaconState (*BeaconStateAltair)(nil), // 1: ethereum.eth.v1alpha1.BeaconStateAltair @@ -2255,64 +2332,66 @@ var file_proto_prysm_v1alpha1_beacon_state_proto_goTypes = []interface{}{ (*BeaconStateBellatrix)(nil), // 12: ethereum.eth.v1alpha1.BeaconStateBellatrix (*BeaconStateCapella)(nil), // 13: ethereum.eth.v1alpha1.BeaconStateCapella (*PowBlock)(nil), // 14: ethereum.eth.v1alpha1.PowBlock - (*BeaconBlockHeader)(nil), // 15: ethereum.eth.v1alpha1.BeaconBlockHeader - (*Eth1Data)(nil), // 16: ethereum.eth.v1alpha1.Eth1Data - (*Validator)(nil), // 17: ethereum.eth.v1alpha1.Validator - (*Checkpoint)(nil), // 18: ethereum.eth.v1alpha1.Checkpoint - (*AttestationData)(nil), // 19: ethereum.eth.v1alpha1.AttestationData - (*v1.ExecutionPayloadHeader)(nil), // 20: ethereum.engine.v1.ExecutionPayloadHeader - (*v1.ExecutionPayloadHeaderCapella)(nil), // 21: ethereum.engine.v1.ExecutionPayloadHeaderCapella + (*HistoricalSummary)(nil), // 15: ethereum.eth.v1alpha1.HistoricalSummary + (*BeaconBlockHeader)(nil), // 16: ethereum.eth.v1alpha1.BeaconBlockHeader + (*Eth1Data)(nil), // 17: ethereum.eth.v1alpha1.Eth1Data + (*Validator)(nil), // 18: ethereum.eth.v1alpha1.Validator + (*Checkpoint)(nil), // 19: ethereum.eth.v1alpha1.Checkpoint + (*AttestationData)(nil), // 20: ethereum.eth.v1alpha1.AttestationData + (*v1.ExecutionPayloadHeader)(nil), // 21: ethereum.engine.v1.ExecutionPayloadHeader + (*v1.ExecutionPayloadHeaderCapella)(nil), // 22: ethereum.engine.v1.ExecutionPayloadHeaderCapella } var file_proto_prysm_v1alpha1_beacon_state_proto_depIdxs = []int32{ 2, // 0: ethereum.eth.v1alpha1.BeaconState.fork:type_name -> ethereum.eth.v1alpha1.Fork - 15, // 1: ethereum.eth.v1alpha1.BeaconState.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader - 16, // 2: ethereum.eth.v1alpha1.BeaconState.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data - 16, // 3: ethereum.eth.v1alpha1.BeaconState.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data - 17, // 4: ethereum.eth.v1alpha1.BeaconState.validators:type_name -> ethereum.eth.v1alpha1.Validator + 16, // 1: ethereum.eth.v1alpha1.BeaconState.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader + 17, // 2: ethereum.eth.v1alpha1.BeaconState.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data + 17, // 3: ethereum.eth.v1alpha1.BeaconState.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data + 18, // 4: ethereum.eth.v1alpha1.BeaconState.validators:type_name -> ethereum.eth.v1alpha1.Validator 3, // 5: ethereum.eth.v1alpha1.BeaconState.previous_epoch_attestations:type_name -> ethereum.eth.v1alpha1.PendingAttestation 3, // 6: ethereum.eth.v1alpha1.BeaconState.current_epoch_attestations:type_name -> ethereum.eth.v1alpha1.PendingAttestation - 18, // 7: ethereum.eth.v1alpha1.BeaconState.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 8: ethereum.eth.v1alpha1.BeaconState.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 9: ethereum.eth.v1alpha1.BeaconState.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 7: ethereum.eth.v1alpha1.BeaconState.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 8: ethereum.eth.v1alpha1.BeaconState.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 9: ethereum.eth.v1alpha1.BeaconState.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint 2, // 10: ethereum.eth.v1alpha1.BeaconStateAltair.fork:type_name -> ethereum.eth.v1alpha1.Fork - 15, // 11: ethereum.eth.v1alpha1.BeaconStateAltair.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader - 16, // 12: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data - 16, // 13: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data - 17, // 14: ethereum.eth.v1alpha1.BeaconStateAltair.validators:type_name -> ethereum.eth.v1alpha1.Validator - 18, // 15: ethereum.eth.v1alpha1.BeaconStateAltair.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 16: ethereum.eth.v1alpha1.BeaconStateAltair.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 17: ethereum.eth.v1alpha1.BeaconStateAltair.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 16, // 11: ethereum.eth.v1alpha1.BeaconStateAltair.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader + 17, // 12: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data + 17, // 13: ethereum.eth.v1alpha1.BeaconStateAltair.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data + 18, // 14: ethereum.eth.v1alpha1.BeaconStateAltair.validators:type_name -> ethereum.eth.v1alpha1.Validator + 19, // 15: ethereum.eth.v1alpha1.BeaconStateAltair.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 16: ethereum.eth.v1alpha1.BeaconStateAltair.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 17: ethereum.eth.v1alpha1.BeaconStateAltair.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint 10, // 18: ethereum.eth.v1alpha1.BeaconStateAltair.current_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee 10, // 19: ethereum.eth.v1alpha1.BeaconStateAltair.next_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee - 19, // 20: ethereum.eth.v1alpha1.PendingAttestation.data:type_name -> ethereum.eth.v1alpha1.AttestationData + 20, // 20: ethereum.eth.v1alpha1.PendingAttestation.data:type_name -> ethereum.eth.v1alpha1.AttestationData 2, // 21: ethereum.eth.v1alpha1.CheckPtInfo.fork:type_name -> ethereum.eth.v1alpha1.Fork 2, // 22: ethereum.eth.v1alpha1.BeaconStateBellatrix.fork:type_name -> ethereum.eth.v1alpha1.Fork - 15, // 23: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader - 16, // 24: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data - 16, // 25: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data - 17, // 26: ethereum.eth.v1alpha1.BeaconStateBellatrix.validators:type_name -> ethereum.eth.v1alpha1.Validator - 18, // 27: ethereum.eth.v1alpha1.BeaconStateBellatrix.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 28: ethereum.eth.v1alpha1.BeaconStateBellatrix.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 29: ethereum.eth.v1alpha1.BeaconStateBellatrix.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 16, // 23: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader + 17, // 24: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data + 17, // 25: ethereum.eth.v1alpha1.BeaconStateBellatrix.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data + 18, // 26: ethereum.eth.v1alpha1.BeaconStateBellatrix.validators:type_name -> ethereum.eth.v1alpha1.Validator + 19, // 27: ethereum.eth.v1alpha1.BeaconStateBellatrix.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 28: ethereum.eth.v1alpha1.BeaconStateBellatrix.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 29: ethereum.eth.v1alpha1.BeaconStateBellatrix.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint 10, // 30: ethereum.eth.v1alpha1.BeaconStateBellatrix.current_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee 10, // 31: ethereum.eth.v1alpha1.BeaconStateBellatrix.next_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee - 20, // 32: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_execution_payload_header:type_name -> ethereum.engine.v1.ExecutionPayloadHeader + 21, // 32: ethereum.eth.v1alpha1.BeaconStateBellatrix.latest_execution_payload_header:type_name -> ethereum.engine.v1.ExecutionPayloadHeader 2, // 33: ethereum.eth.v1alpha1.BeaconStateCapella.fork:type_name -> ethereum.eth.v1alpha1.Fork - 15, // 34: ethereum.eth.v1alpha1.BeaconStateCapella.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader - 16, // 35: ethereum.eth.v1alpha1.BeaconStateCapella.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data - 16, // 36: ethereum.eth.v1alpha1.BeaconStateCapella.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data - 17, // 37: ethereum.eth.v1alpha1.BeaconStateCapella.validators:type_name -> ethereum.eth.v1alpha1.Validator - 18, // 38: ethereum.eth.v1alpha1.BeaconStateCapella.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 39: ethereum.eth.v1alpha1.BeaconStateCapella.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint - 18, // 40: ethereum.eth.v1alpha1.BeaconStateCapella.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 16, // 34: ethereum.eth.v1alpha1.BeaconStateCapella.latest_block_header:type_name -> ethereum.eth.v1alpha1.BeaconBlockHeader + 17, // 35: ethereum.eth.v1alpha1.BeaconStateCapella.eth1_data:type_name -> ethereum.eth.v1alpha1.Eth1Data + 17, // 36: ethereum.eth.v1alpha1.BeaconStateCapella.eth1_data_votes:type_name -> ethereum.eth.v1alpha1.Eth1Data + 18, // 37: ethereum.eth.v1alpha1.BeaconStateCapella.validators:type_name -> ethereum.eth.v1alpha1.Validator + 19, // 38: ethereum.eth.v1alpha1.BeaconStateCapella.previous_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 39: ethereum.eth.v1alpha1.BeaconStateCapella.current_justified_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint + 19, // 40: ethereum.eth.v1alpha1.BeaconStateCapella.finalized_checkpoint:type_name -> ethereum.eth.v1alpha1.Checkpoint 10, // 41: ethereum.eth.v1alpha1.BeaconStateCapella.current_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee 10, // 42: ethereum.eth.v1alpha1.BeaconStateCapella.next_sync_committee:type_name -> ethereum.eth.v1alpha1.SyncCommittee - 21, // 43: ethereum.eth.v1alpha1.BeaconStateCapella.latest_execution_payload_header:type_name -> ethereum.engine.v1.ExecutionPayloadHeaderCapella - 44, // [44:44] is the sub-list for method output_type - 44, // [44:44] is the sub-list for method input_type - 44, // [44:44] is the sub-list for extension type_name - 44, // [44:44] is the sub-list for extension extendee - 0, // [0:44] is the sub-list for field type_name + 22, // 43: ethereum.eth.v1alpha1.BeaconStateCapella.latest_execution_payload_header:type_name -> ethereum.engine.v1.ExecutionPayloadHeaderCapella + 15, // 44: ethereum.eth.v1alpha1.BeaconStateCapella.historical_summaries:type_name -> ethereum.eth.v1alpha1.HistoricalSummary + 45, // [45:45] is the sub-list for method output_type + 45, // [45:45] is the sub-list for method input_type + 45, // [45:45] is the sub-list for extension type_name + 45, // [45:45] is the sub-list for extension extendee + 0, // [0:45] is the sub-list for field type_name } func init() { file_proto_prysm_v1alpha1_beacon_state_proto_init() } @@ -2504,6 +2583,18 @@ func file_proto_prysm_v1alpha1_beacon_state_proto_init() { return nil } } + file_proto_prysm_v1alpha1_beacon_state_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HistoricalSummary); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -2511,7 +2602,7 @@ func file_proto_prysm_v1alpha1_beacon_state_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_prysm_v1alpha1_beacon_state_proto_rawDesc, NumEnums: 0, - NumMessages: 15, + NumMessages: 16, NumExtensions: 0, NumServices: 0, }, diff --git a/proto/prysm/v1alpha1/beacon_state.proto b/proto/prysm/v1alpha1/beacon_state.proto index 87296c1a70..394d4dc9fb 100644 --- a/proto/prysm/v1alpha1/beacon_state.proto +++ b/proto/prysm/v1alpha1/beacon_state.proto @@ -286,6 +286,7 @@ message BeaconStateCapella { // Capella fields [11001-12000] uint64 next_withdrawal_index = 11001; // [New in Capella] uint64 next_withdrawal_validator_index = 11002 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.ValidatorIndex"]; // [New in Capella] + repeated HistoricalSummary historical_summaries = 11003 [(ethereum.eth.ext.ssz_max) = "16777216"]; // [New in Capella] } // PowBlock is a definition from Bellatrix fork choice spec to represent a block with total difficulty in the PoW chain. @@ -299,3 +300,9 @@ message PowBlock { bytes parent_hash = 2 [(ethereum.eth.ext.ssz_size) = "32"]; bytes total_difficulty = 3 [(ethereum.eth.ext.ssz_size) = "32"]; } + +// HistoricalSummary matches the components of the phase0 `HistoricalBatch` making the two hash_tree_root-compatible. +message HistoricalSummary { + bytes block_summary_root = 1 [(ethereum.eth.ext.ssz_size) = "32"]; + bytes state_summary_root = 2 [(ethereum.eth.ext.ssz_size) = "32"]; +} \ No newline at end of file diff --git a/proto/prysm/v1alpha1/cloners.go b/proto/prysm/v1alpha1/cloners.go index 6d984bc137..a586a4c072 100644 --- a/proto/prysm/v1alpha1/cloners.go +++ b/proto/prysm/v1alpha1/cloners.go @@ -698,3 +698,18 @@ func CopyBLSToExecutionChanges(changes []*SignedBLSToExecutionChange) []*SignedB return res } + +// CopyHistoricalSummaries copies the historical summaries. +func CopyHistoricalSummaries(summaries []*HistoricalSummary) []*HistoricalSummary { + if summaries == nil { + return nil + } + newSummaries := make([]*HistoricalSummary, len(summaries)) + for i, s := range summaries { + newSummaries[i] = &HistoricalSummary{ + BlockSummaryRoot: bytesutil.SafeCopyBytes(s.BlockSummaryRoot), + StateSummaryRoot: bytesutil.SafeCopyBytes(s.StateSummaryRoot), + } + } + return newSummaries +} diff --git a/proto/prysm/v1alpha1/cloners_test.go b/proto/prysm/v1alpha1/cloners_test.go index b24deefd14..d833cddb00 100644 --- a/proto/prysm/v1alpha1/cloners_test.go +++ b/proto/prysm/v1alpha1/cloners_test.go @@ -492,6 +492,18 @@ func TestCopyBLSToExecutionChanges(t *testing.T) { } } +func TestCopyHistoricalSummaries(t *testing.T) { + summaries := []*v1alpha1.HistoricalSummary{ + {BlockSummaryRoot: []byte("block summary root 0"), StateSummaryRoot: []byte("state summary root 0")}, + {BlockSummaryRoot: []byte("block summary root 1"), StateSummaryRoot: []byte("state summary root 1")}, + } + + got := v1alpha1.CopyHistoricalSummaries(summaries) + if !reflect.DeepEqual(got, summaries) { + t.Errorf("TestCopyHistoricalSummariesing() = %v, want %v", got, summaries) + } +} + func genAttestation() *v1alpha1.Attestation { return &v1alpha1.Attestation{ AggregationBits: bytes(32), diff --git a/proto/prysm/v1alpha1/generated.ssz.go b/proto/prysm/v1alpha1/generated.ssz.go index e75ffa2029..e0113c7a75 100644 --- a/proto/prysm/v1alpha1/generated.ssz.go +++ b/proto/prysm/v1alpha1/generated.ssz.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: 8962105c98680286d2c628c358c5a37aeef5a3f92bfab69b89b13a7510b05da4 +// Hash: 3c0d8421c1f6481f3d4ead7196377f9bc43d0813e6826e42f07e18d617494e1e package eth import ( @@ -10070,7 +10070,7 @@ func (b *BeaconStateCapella) MarshalSSZ() ([]byte, error) { // MarshalSSZTo ssz marshals the BeaconStateCapella object to a target array func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { dst = buf - offset := int(2736649) + offset := int(2736653) // Field (0) 'GenesisTime' dst = ssz.MarshalUint64(dst, b.GenesisTime) @@ -10248,6 +10248,10 @@ func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { // Field (26) 'NextWithdrawalValidatorIndex' dst = ssz.MarshalUint64(dst, uint64(b.NextWithdrawalValidatorIndex)) + // Offset (27) 'HistoricalSummaries' + dst = ssz.WriteOffset(dst, offset) + offset += len(b.HistoricalSummaries) * 64 + // Field (7) 'HistoricalRoots' if size := len(b.HistoricalRoots); size > 16777216 { err = ssz.ErrListTooBigFn("--.HistoricalRoots", size, 16777216) @@ -10320,6 +10324,17 @@ func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { return } + // Field (27) 'HistoricalSummaries' + if size := len(b.HistoricalSummaries); size > 16777216 { + err = ssz.ErrListTooBigFn("--.HistoricalSummaries", size, 16777216) + return + } + for ii := 0; ii < len(b.HistoricalSummaries); ii++ { + if dst, err = b.HistoricalSummaries[ii].MarshalSSZTo(dst); err != nil { + return + } + } + return } @@ -10327,12 +10342,12 @@ func (b *BeaconStateCapella) MarshalSSZTo(buf []byte) (dst []byte, err error) { func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { var err error size := uint64(len(buf)) - if size < 2736649 { + if size < 2736653 { return ssz.ErrSize } tail := buf - var o7, o9, o11, o12, o15, o16, o21, o24 uint64 + var o7, o9, o11, o12, o15, o16, o21, o24, o27 uint64 // Field (0) 'GenesisTime' b.GenesisTime = ssz.UnmarshallUint64(buf[0:8]) @@ -10385,7 +10400,7 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { return ssz.ErrOffset } - if o7 < 2736649 { + if o7 < 2736653 { return ssz.ErrInvalidVariableOffset } @@ -10502,6 +10517,11 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { // Field (26) 'NextWithdrawalValidatorIndex' b.NextWithdrawalValidatorIndex = github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.ValidatorIndex(ssz.UnmarshallUint64(buf[2736641:2736649])) + // Offset (27) 'HistoricalSummaries' + if o27 = ssz.ReadOffset(buf[2736649:2736653]); o27 > size || o24 > o27 { + return ssz.ErrOffset + } + // Field (7) 'HistoricalRoots' { buf = tail[o7:o9] @@ -10606,7 +10626,7 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { // Field (24) 'LatestExecutionPayloadHeader' { - buf = tail[o24:] + buf = tail[o24:o27] if b.LatestExecutionPayloadHeader == nil { b.LatestExecutionPayloadHeader = new(v1.ExecutionPayloadHeaderCapella) } @@ -10614,12 +10634,30 @@ func (b *BeaconStateCapella) UnmarshalSSZ(buf []byte) error { return err } } + + // Field (27) 'HistoricalSummaries' + { + buf = tail[o27:] + num, err := ssz.DivideInt2(len(buf), 64, 16777216) + if err != nil { + return err + } + b.HistoricalSummaries = make([]*HistoricalSummary, num) + for ii := 0; ii < num; ii++ { + if b.HistoricalSummaries[ii] == nil { + b.HistoricalSummaries[ii] = new(HistoricalSummary) + } + if err = b.HistoricalSummaries[ii].UnmarshalSSZ(buf[ii*64 : (ii+1)*64]); err != nil { + return err + } + } + } return err } // SizeSSZ returns the ssz encoded size in bytes for the BeaconStateCapella object func (b *BeaconStateCapella) SizeSSZ() (size int) { - size = 2736649 + size = 2736653 // Field (7) 'HistoricalRoots' size += len(b.HistoricalRoots) * 32 @@ -10648,6 +10686,9 @@ func (b *BeaconStateCapella) SizeSSZ() (size int) { } size += b.LatestExecutionPayloadHeader.SizeSSZ() + // Field (27) 'HistoricalSummaries' + size += len(b.HistoricalSummaries) * 64 + return } @@ -10953,6 +10994,26 @@ func (b *BeaconStateCapella) HashTreeRootWith(hh *ssz.Hasher) (err error) { // Field (26) 'NextWithdrawalValidatorIndex' hh.PutUint64(uint64(b.NextWithdrawalValidatorIndex)) + // Field (27) 'HistoricalSummaries' + { + subIndx := hh.Index() + num := uint64(len(b.HistoricalSummaries)) + if num > 16777216 { + err = ssz.ErrIncorrectListSize + return + } + for _, elem := range b.HistoricalSummaries { + if err = elem.HashTreeRootWith(hh); err != nil { + return + } + } + if ssz.EnableVectorizedHTR { + hh.MerkleizeWithMixinVectorizedHTR(subIndx, num, 16777216) + } else { + hh.MerkleizeWithMixin(subIndx, num, 16777216) + } + } + if ssz.EnableVectorizedHTR { hh.MerkleizeVectorizedHTR(indx) } else { @@ -11067,6 +11128,92 @@ func (p *PowBlock) HashTreeRootWith(hh *ssz.Hasher) (err error) { return } +// MarshalSSZ ssz marshals the HistoricalSummary object +func (h *HistoricalSummary) MarshalSSZ() ([]byte, error) { + return ssz.MarshalSSZ(h) +} + +// MarshalSSZTo ssz marshals the HistoricalSummary object to a target array +func (h *HistoricalSummary) MarshalSSZTo(buf []byte) (dst []byte, err error) { + dst = buf + + // Field (0) 'BlockSummaryRoot' + if size := len(h.BlockSummaryRoot); size != 32 { + err = ssz.ErrBytesLengthFn("--.BlockSummaryRoot", size, 32) + return + } + dst = append(dst, h.BlockSummaryRoot...) + + // Field (1) 'StateSummaryRoot' + if size := len(h.StateSummaryRoot); size != 32 { + err = ssz.ErrBytesLengthFn("--.StateSummaryRoot", size, 32) + return + } + dst = append(dst, h.StateSummaryRoot...) + + return +} + +// UnmarshalSSZ ssz unmarshals the HistoricalSummary object +func (h *HistoricalSummary) UnmarshalSSZ(buf []byte) error { + var err error + size := uint64(len(buf)) + if size != 64 { + return ssz.ErrSize + } + + // Field (0) 'BlockSummaryRoot' + if cap(h.BlockSummaryRoot) == 0 { + h.BlockSummaryRoot = make([]byte, 0, len(buf[0:32])) + } + h.BlockSummaryRoot = append(h.BlockSummaryRoot, buf[0:32]...) + + // Field (1) 'StateSummaryRoot' + if cap(h.StateSummaryRoot) == 0 { + h.StateSummaryRoot = make([]byte, 0, len(buf[32:64])) + } + h.StateSummaryRoot = append(h.StateSummaryRoot, buf[32:64]...) + + return err +} + +// SizeSSZ returns the ssz encoded size in bytes for the HistoricalSummary object +func (h *HistoricalSummary) SizeSSZ() (size int) { + size = 64 + return +} + +// HashTreeRoot ssz hashes the HistoricalSummary object +func (h *HistoricalSummary) HashTreeRoot() ([32]byte, error) { + return ssz.HashWithDefaultHasher(h) +} + +// HashTreeRootWith ssz hashes the HistoricalSummary object with a hasher +func (h *HistoricalSummary) HashTreeRootWith(hh *ssz.Hasher) (err error) { + indx := hh.Index() + + // Field (0) 'BlockSummaryRoot' + if size := len(h.BlockSummaryRoot); size != 32 { + err = ssz.ErrBytesLengthFn("--.BlockSummaryRoot", size, 32) + return + } + hh.PutBytes(h.BlockSummaryRoot) + + // Field (1) 'StateSummaryRoot' + if size := len(h.StateSummaryRoot); size != 32 { + err = ssz.ErrBytesLengthFn("--.StateSummaryRoot", size, 32) + return + } + hh.PutBytes(h.StateSummaryRoot) + + if ssz.EnableVectorizedHTR { + hh.MerkleizeVectorizedHTR(indx) + } else { + hh.Merkleize(indx) + } + return +} + // MarshalSSZ ssz marshals the Status object func (s *Status) MarshalSSZ() ([]byte, error) { return ssz.MarshalSSZ(s) diff --git a/testing/spectest/mainnet/capella/epoch_processing/BUILD.bazel b/testing/spectest/mainnet/capella/epoch_processing/BUILD.bazel index c5d233079e..45ad7275e1 100644 --- a/testing/spectest/mainnet/capella/epoch_processing/BUILD.bazel +++ b/testing/spectest/mainnet/capella/epoch_processing/BUILD.bazel @@ -6,7 +6,7 @@ go_test( srcs = [ "effective_balance_updates_test.go", "eth1_data_reset_test.go", - "historical_roots_update_test.go", + "historical_summaries_update_test.go", "inactivity_updates_test.go", "justification_and_finalization_test.go", "participation_flag_updates_test.go", diff --git a/testing/spectest/mainnet/capella/epoch_processing/historical_roots_update_test.go b/testing/spectest/mainnet/capella/epoch_processing/historical_roots_update_test.go deleted file mode 100644 index 1fc333d365..0000000000 --- a/testing/spectest/mainnet/capella/epoch_processing/historical_roots_update_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package epoch_processing - -import ( - "testing" - - "github.com/prysmaticlabs/prysm/v3/testing/spectest/shared/capella/epoch_processing" -) - -func TestMainnet_Capella_EpochProcessing_HistoricalRootsUpdate(t *testing.T) { - epoch_processing.RunHistoricalRootsUpdateTests(t, "mainnet") -} diff --git a/testing/spectest/mainnet/capella/epoch_processing/historical_summaries_update_test.go b/testing/spectest/mainnet/capella/epoch_processing/historical_summaries_update_test.go new file mode 100644 index 0000000000..9f2276a2db --- /dev/null +++ b/testing/spectest/mainnet/capella/epoch_processing/historical_summaries_update_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v3/testing/spectest/shared/capella/epoch_processing" +) + +func TestMainnet_Capella_EpochProcessing_HistoricalSummariesUpdate(t *testing.T) { + epoch_processing.RunHistoricalSummariesUpdateTests(t, "mainnet") +} diff --git a/testing/spectest/minimal/capella/epoch_processing/BUILD.bazel b/testing/spectest/minimal/capella/epoch_processing/BUILD.bazel index e676da6aec..5436e10245 100644 --- a/testing/spectest/minimal/capella/epoch_processing/BUILD.bazel +++ b/testing/spectest/minimal/capella/epoch_processing/BUILD.bazel @@ -6,7 +6,7 @@ go_test( srcs = [ "effective_balance_updates_test.go", "eth1_data_reset_test.go", - "historical_roots_update_test.go", + "historical_roots_summaries_test.go", "inactivity_updates_test.go", "justification_and_finalization_test.go", "participation_flag_updates_test.go", diff --git a/testing/spectest/minimal/capella/epoch_processing/historical_roots_summaries_test.go b/testing/spectest/minimal/capella/epoch_processing/historical_roots_summaries_test.go new file mode 100644 index 0000000000..0cc80c6b4e --- /dev/null +++ b/testing/spectest/minimal/capella/epoch_processing/historical_roots_summaries_test.go @@ -0,0 +1,11 @@ +package epoch_processing + +import ( + "testing" + + "github.com/prysmaticlabs/prysm/v3/testing/spectest/shared/capella/epoch_processing" +) + +func TestMinimal_Capella_EpochProcessing_HistoricalSummariesUpdate(t *testing.T) { + epoch_processing.RunHistoricalSummariesUpdateTests(t, "minimal") +} diff --git a/testing/spectest/minimal/capella/epoch_processing/historical_roots_update_test.go b/testing/spectest/minimal/capella/epoch_processing/historical_roots_update_test.go deleted file mode 100644 index b4578c4d4d..0000000000 --- a/testing/spectest/minimal/capella/epoch_processing/historical_roots_update_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package epoch_processing - -import ( - "testing" - - "github.com/prysmaticlabs/prysm/v3/testing/spectest/shared/capella/epoch_processing" -) - -func TestMinimal_Capella_EpochProcessing_HistoricalRootsUpdate(t *testing.T) { - epoch_processing.RunHistoricalRootsUpdateTests(t, "minimal") -} diff --git a/testing/spectest/shared/altair/epoch_processing/historical_roots_update.go b/testing/spectest/shared/altair/epoch_processing/historical_roots_update.go index fcf77f46e0..f6991b616f 100644 --- a/testing/spectest/shared/altair/epoch_processing/historical_roots_update.go +++ b/testing/spectest/shared/altair/epoch_processing/historical_roots_update.go @@ -27,7 +27,7 @@ func RunHistoricalRootsUpdateTests(t *testing.T, config string) { } func processHistoricalRootsUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { - st, err := epoch.ProcessHistoricalRootsUpdate(st) + st, err := epoch.ProcessHistoricalDataUpdate(st) require.NoError(t, err, "Could not process final updates") return st, nil } diff --git a/testing/spectest/shared/bellatrix/epoch_processing/historical_roots_update.go b/testing/spectest/shared/bellatrix/epoch_processing/historical_roots_update.go index 8e5ad5e6fc..716a709b94 100644 --- a/testing/spectest/shared/bellatrix/epoch_processing/historical_roots_update.go +++ b/testing/spectest/shared/bellatrix/epoch_processing/historical_roots_update.go @@ -27,7 +27,7 @@ func RunHistoricalRootsUpdateTests(t *testing.T, config string) { } func processHistoricalRootsUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { - st, err := epoch.ProcessHistoricalRootsUpdate(st) + st, err := epoch.ProcessHistoricalDataUpdate(st) require.NoError(t, err, "Could not process final updates") return st, nil } diff --git a/testing/spectest/shared/capella/epoch_processing/BUILD.bazel b/testing/spectest/shared/capella/epoch_processing/BUILD.bazel index 1fd464ab09..18f79e6f63 100644 --- a/testing/spectest/shared/capella/epoch_processing/BUILD.bazel +++ b/testing/spectest/shared/capella/epoch_processing/BUILD.bazel @@ -7,7 +7,7 @@ go_library( "effective_balance_updates.go", "eth1_data_reset.go", "helpers.go", - "historical_roots_update.go", + "historical_summaries_update.go", "inactivity_updates.go", "justification_and_finalization.go", "participation_flag_updates.go", diff --git a/testing/spectest/shared/capella/epoch_processing/historical_roots_update.go b/testing/spectest/shared/capella/epoch_processing/historical_summaries_update.go similarity index 51% rename from testing/spectest/shared/capella/epoch_processing/historical_roots_update.go rename to testing/spectest/shared/capella/epoch_processing/historical_summaries_update.go index 9723f99cfc..1a3274d2b8 100644 --- a/testing/spectest/shared/capella/epoch_processing/historical_roots_update.go +++ b/testing/spectest/shared/capella/epoch_processing/historical_summaries_update.go @@ -10,24 +10,24 @@ import ( "github.com/prysmaticlabs/prysm/v3/testing/spectest/utils" ) -// RunHistoricalRootsUpdateTests executes "epoch_processing/historical_roots_update" tests. -func RunHistoricalRootsUpdateTests(t *testing.T, config string) { +// RunHistoricalSummariesUpdateTests executes "epoch_processing/historical_summaries_update" tests. +func RunHistoricalSummariesUpdateTests(t *testing.T, config string) { require.NoError(t, utils.SetConfig(t, config)) - testFolders, testsFolderPath := utils.TestFolders(t, config, "capella", "epoch_processing/historical_roots_update/pyspec_tests") + testFolders, testsFolderPath := utils.TestFolders(t, config, "capella", "epoch_processing/historical_summaries_update/pyspec_tests") if len(testFolders) == 0 { - t.Fatalf("No test folders found for %s/%s/%s", config, "capella", "epoch_processing/historical_roots_update/pyspec_tests") + t.Fatalf("No test folders found for %s/%s/%s", config, "capella", "epoch_processing/historical_summaries_update/pyspec_tests") } for _, folder := range testFolders { t.Run(folder.Name(), func(t *testing.T) { folderPath := path.Join(testsFolderPath, folder.Name()) - RunEpochOperationTest(t, folderPath, processHistoricalRootsUpdateWrapper) + RunEpochOperationTest(t, folderPath, processHistoricalSummariesUpdateWrapper) }) } } -func processHistoricalRootsUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { - st, err := epoch.ProcessHistoricalRootsUpdate(st) - require.NoError(t, err, "Could not process final updates") +func processHistoricalSummariesUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { + st, err := epoch.ProcessHistoricalDataUpdate(st) + require.NoError(t, err, "Could not process historical summary updates") return st, nil } diff --git a/testing/spectest/shared/capella/ssz_static/ssz_static.go b/testing/spectest/shared/capella/ssz_static/ssz_static.go index bc94b51d0e..cffbbd741b 100644 --- a/testing/spectest/shared/capella/ssz_static/ssz_static.go +++ b/testing/spectest/shared/capella/ssz_static/ssz_static.go @@ -107,6 +107,8 @@ func unmarshalledSSZ(t *testing.T, serializedBytes []byte, folderName string) (i obj = ðpb.SyncAggregatorSelectionData{} case "SyncCommittee": obj = ðpb.SyncCommittee{} + case "HistoricalSummary": + obj = ðpb.HistoricalSummary{} case "LightClientOptimisticUpdate": t.Skip("not a beacon node type, this is a light node type") return nil, nil diff --git a/testing/spectest/shared/phase0/epoch_processing/historical_roots_update.go b/testing/spectest/shared/phase0/epoch_processing/historical_roots_update.go index 2ab5147afd..25c62e8101 100644 --- a/testing/spectest/shared/phase0/epoch_processing/historical_roots_update.go +++ b/testing/spectest/shared/phase0/epoch_processing/historical_roots_update.go @@ -27,7 +27,7 @@ func RunHistoricalRootsUpdateTests(t *testing.T, config string) { } func processHistoricalRootsUpdateWrapper(t *testing.T, st state.BeaconState) (state.BeaconState, error) { - st, err := epoch.ProcessHistoricalRootsUpdate(st) + st, err := epoch.ProcessHistoricalDataUpdate(st) require.NoError(t, err, "Could not process final updates") return st, nil } diff --git a/testing/util/state.go b/testing/util/state.go index 1c6ba7b068..50e116f1bc 100644 --- a/testing/util/state.go +++ b/testing/util/state.go @@ -260,7 +260,7 @@ func NewBeaconStateCapella(options ...func(state *ethpb.BeaconStateCapella) erro CurrentVersion: make([]byte, 4), }, Eth1DataVotes: make([]*ethpb.Eth1Data, 0), - HistoricalRoots: make([][]byte, 0), + HistoricalSummaries: make([]*ethpb.HistoricalSummary, 0), JustificationBits: bitfield.Bitvector4{0x0}, FinalizedCheckpoint: ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}, LatestBlockHeader: HydrateBeaconHeader(ðpb.BeaconBlockHeader{}), diff --git a/tools/exploredb/main.go b/tools/exploredb/main.go index 6cf0b4d236..76f8bb4c37 100644 --- a/tools/exploredb/main.go +++ b/tools/exploredb/main.go @@ -336,8 +336,13 @@ func printStates(stateC <-chan *modifiedState, doneC chan<- bool) { log.Infof("block_roots : size = %s, count = %d", humanize.Bytes(size), count) size, count = sizeAndCountOfByteList(st.StateRoots()) log.Infof("state_roots : size = %s, count = %d", humanize.Bytes(size), count) - size, count = sizeAndCountOfByteList(st.HistoricalRoots()) - log.Infof("historical_roots : size = %s, count = %d", humanize.Bytes(size), count) + roots, err := st.HistoricalRoots() + if err != nil { + log.WithError(err).Error("could not get historical roots") + } else { + size, count = sizeAndCountOfByteList(roots) + log.Infof("historical_roots : size = %s, count = %d", humanize.Bytes(size), count) + } log.Infof("eth1_data : sizeSSZ = %s", humanize.Bytes(uint64(st.Eth1Data().SizeSSZ()))) size, count = sizeAndCountGeneric(st.Eth1DataVotes(), nil) log.Infof("eth1_data_votes : sizeSSZ = %s, count = %d", humanize.Bytes(size), count)