Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/server/structs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//consensus-types/blocks:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/assert:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion api/server/structs/conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
"github.com/OffchainLabs/prysm/v7/testing/assert"
Expand Down Expand Up @@ -488,7 +489,7 @@ func TestBeaconStateGloasFromConsensus(t *testing.T) {
state.GenesisTime = 123
state.GenesisValidatorsRoot = bytes.Repeat([]byte{0x10}, 32)
state.Slot = 5
state.ProposerLookahead = []uint64{1, 2}
state.ProposerLookahead = []primitives.ValidatorIndex{1, 2}
state.LatestExecutionPayloadBid = &eth.ExecutionPayloadBid{
ParentBlockHash: bytes.Repeat([]byte{0x11}, 32),
ParentBlockRoot: bytes.Repeat([]byte{0x12}, 32),
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/blockchain/gloas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func prepareGloasForkchoiceState(
ExecutionPayloadAvailability: make([]byte, 1024),
LatestBlockHash: make([]byte, 32),
PayloadExpectedWithdrawals: make([]*enginev1.Withdrawal, 0),
ProposerLookahead: make([]uint64, 64),
ProposerLookahead: make([]primitives.ValidatorIndex, 64),
}

st, err := state_native.InitializeFromProtoUnsafeGloas(base)
Expand Down Expand Up @@ -146,7 +146,7 @@ func testGloasState(t *testing.T, slot primitives.Slot, parentRoot [32]byte, blo
ExecutionPayloadAvailability: make([]byte, 1024),
LatestBlockHash: make([]byte, 32),
PayloadExpectedWithdrawals: make([]*enginev1.Withdrawal, 0),
ProposerLookahead: make([]uint64, 64),
ProposerLookahead: make([]primitives.ValidatorIndex, 64),
}

bid := util.HydrateSignedExecutionPayloadBid(&ethpb.SignedExecutionPayloadBid{
Expand Down Expand Up @@ -797,7 +797,7 @@ func TestSaveHead_GloasForkBoundary_PreforkBidForcesEmptyHead(t *testing.T) {
ExecutionPayloadAvailability: make([]byte, 1024),
LatestBlockHash: make([]byte, 32),
PayloadExpectedWithdrawals: make([]*enginev1.Withdrawal, 0),
ProposerLookahead: make([]uint64, 64),
ProposerLookahead: make([]primitives.ValidatorIndex, 64),
})
require.NoError(t, err2)
oldRoot := bytesutil.ToBytes32([]byte("oldroot1"))
Expand Down Expand Up @@ -874,7 +874,7 @@ func TestSaveHead_GloasForkBoundary_PostforkBidSetsFullHead(t *testing.T) {
ExecutionPayloadAvailability: make([]byte, 1024),
LatestBlockHash: make([]byte, 32),
PayloadExpectedWithdrawals: make([]*enginev1.Withdrawal, 0),
ProposerLookahead: make([]uint64, 64),
ProposerLookahead: make([]primitives.ValidatorIndex, 64),
})
require.NoError(t, err2)
oldRoot2 := bytesutil.ToBytes32([]byte("oldroot2"))
Expand Down
6 changes: 4 additions & 2 deletions beacon-chain/core/electra/effective_balance_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ func ProcessEffectiveBalanceUpdates(st state.BeaconState) error {

if balance+downwardThreshold < val.EffectiveBalance() || val.EffectiveBalance()+upwardThreshold < balance {
effectiveBal := min(balance-balance%effBalanceInc, effectiveBalanceLimit)
newVal = val.Copy()
newVal.EffectiveBalance = effectiveBal
if effectiveBal != val.EffectiveBalance() {
newVal = val.Copy()
newVal.EffectiveBalance = effectiveBal
}
}
return newVal, nil
}
Expand Down
6 changes: 1 addition & 5 deletions beacon-chain/core/gloas/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ func upgradeToGloas(beaconState state.BeaconState) (state.BeaconState, error) {
if err != nil {
return nil, err
}
proposerLookaheadU64 := make([]uint64, len(proposerLookahead))
for i, v := range proposerLookahead {
proposerLookaheadU64[i] = uint64(v)
}

executionPayloadAvailability := make([]byte, int((params.BeaconConfig().SlotsPerHistoricalRoot+7)/8))
for i := range executionPayloadAvailability {
Expand Down Expand Up @@ -359,7 +355,7 @@ func upgradeToGloas(beaconState state.BeaconState) (state.BeaconState, error) {
PendingDeposits: pendingDeposits,
PendingPartialWithdrawals: pendingPartialWithdrawals,
PendingConsolidations: pendingConsolidations,
ProposerLookahead: proposerLookaheadU64,
ProposerLookahead: proposerLookahead,
Builders: []*ethpb.Builder{},
NextWithdrawalBuilderIndex: primitives.BuilderIndex(0),
ExecutionPayloadAvailability: executionPayloadAvailability,
Expand Down
8 changes: 3 additions & 5 deletions beacon-chain/core/helpers/beacon_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ func ComputeCommittee(
}

// InitializeProposerLookahead computes the list of the proposer indices for the next MIN_SEED_LOOKAHEAD + 1 epochs.
func InitializeProposerLookahead(ctx context.Context, state state.ReadOnlyBeaconState, epoch primitives.Epoch) ([]uint64, error) {
lookAhead := make([]uint64, 0, uint64(params.BeaconConfig().MinSeedLookahead+1)*uint64(params.BeaconConfig().SlotsPerEpoch))
func InitializeProposerLookahead(ctx context.Context, state state.ReadOnlyBeaconState, epoch primitives.Epoch) ([]primitives.ValidatorIndex, error) {
lookAhead := make([]primitives.ValidatorIndex, 0, uint64(params.BeaconConfig().MinSeedLookahead+1)*uint64(params.BeaconConfig().SlotsPerEpoch))
for i := range params.BeaconConfig().MinSeedLookahead + 1 {
indices, err := ActiveValidatorIndices(ctx, state, epoch+i)
if err != nil {
Expand All @@ -669,9 +669,7 @@ func InitializeProposerLookahead(ctx context.Context, state state.ReadOnlyBeacon
if err != nil {
return nil, errors.Wrap(err, "could not compute proposer indices")
}
for _, proposerIndex := range proposerIndices {
lookAhead = append(lookAhead, uint64(proposerIndex))
}
lookAhead = append(lookAhead, proposerIndices...)
}
return lookAhead, nil
}
Expand Down
7 changes: 1 addition & 6 deletions beacon-chain/core/helpers/beacon_committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,13 +945,8 @@ func TestInitializeProposerLookahead_RegressionTest(t *testing.T) {
endIdx := startIdx + slotsPerEpoch
actualProposers := proposerLookahead[startIdx:endIdx]

expectedUint64 := make([]uint64, len(expectedProposers))
for i, proposer := range expectedProposers {
expectedUint64[i] = uint64(proposer)
}

// This assertion would fail with the original bug:
for i, expected := range expectedUint64 {
for i, expected := range expectedProposers {
require.Equal(t, expected, actualProposers[i],
"Proposer index mismatch at slot %d in epoch %d", i, targetEpoch)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/helpers/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ func TestBeaconProposerIndexAtSlotFulu(t *testing.T) {
cfg := params.BeaconConfig().Copy()
cfg.FuluForkEpoch = 1
params.OverrideBeaconConfig(cfg)
lookahead := make([]uint64, 64)
lookahead := make([]primitives.ValidatorIndex, 64)
lookahead[0] = 15
lookahead[1] = 16
lookahead[34] = 42
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/transition/transition_gloas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func newGloasForkBoundaryState(
CurrentJustifiedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
FinalizedCheckpoint: &ethpb.Checkpoint{Root: make([]byte, 32)},
PayloadExpectedWithdrawals: make([]*engine.Withdrawal, 0),
ProposerLookahead: make([]uint64, 0),
ProposerLookahead: make([]primitives.ValidatorIndex, 0),
Builders: make([]*ethpb.Builder, 0),
}
for i := range protoState.BlockRoots {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/forkchoice/doubly-linked-tree/gloas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func prepareGloasForkchoiceState(
ExecutionPayloadAvailability: make([]byte, 1024),
LatestBlockHash: make([]byte, 32),
PayloadExpectedWithdrawals: make([]*enginev1.Withdrawal, 0),
ProposerLookahead: make([]uint64, 64),
ProposerLookahead: make([]primitives.ValidatorIndex, 64),
}

st, err := state_native.InitializeFromProtoUnsafeGloas(base)
Expand Down
3 changes: 3 additions & 0 deletions beacon-chain/state/fieldtrie/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go_library(
srcs = [
"field_trie.go",
"field_trie_helpers.go",
"metrics.go",
],
importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/state/fieldtrie",
visibility = ["//visibility:public"],
Expand All @@ -16,6 +17,8 @@ go_library(
"//math:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
],
)

Expand Down
3 changes: 3 additions & 0 deletions beacon-chain/state/fieldtrie/field_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func NewFieldTrie(field types.FieldIndex, fieldInfo types.DataType, elements any
func (f *FieldTrie) RecomputeTrie(indices []uint64, elements any) ([32]byte, error) {
f.Lock()
defer f.Unlock()

fieldTrieRecomputeIndicesSummary.WithLabelValues(f.field.String()).Observe(float64(len(indices)))

var fieldRoot [32]byte
if len(indices) == 0 {
return f.TrieRoot()
Expand Down
13 changes: 13 additions & 0 deletions beacon-chain/state/fieldtrie/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package fieldtrie

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
fieldTrieRecomputeIndicesSummary = promauto.NewSummaryVec(prometheus.SummaryOpts{
Name: "field_trie_recompute_indices",
Help: "Distribution of the number of changed indices per RecomputeTrie call.",
}, []string{"field"})
)
5 changes: 5 additions & 0 deletions beacon-chain/state/state-native/getters_proposer_lookahead.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ func (b *BeaconState) ProposerLookahead() ([]primitives.ValidatorIndex, error) {
defer b.lock.RUnlock()
return slices.Clone(b.proposerLookahead), nil
}

// proposerLookaheadVal returns a copy of the proposer lookahead for use in ToProto.
func (b *BeaconState) proposerLookaheadVal() []primitives.ValidatorIndex {
return slices.Clone(b.proposerLookahead)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestProposerLookahead(t *testing.T) {
t.Run("Fulu expected values", func(t *testing.T) {
lookahead := make([]uint64, int(params.BeaconConfig().MinSeedLookahead+1)*int(params.BeaconConfig().SlotsPerEpoch))
lookahead := make([]primitives.ValidatorIndex, int(params.BeaconConfig().MinSeedLookahead+1)*int(params.BeaconConfig().SlotsPerEpoch))
want := make([]primitives.ValidatorIndex, int(params.BeaconConfig().MinSeedLookahead+1)*int(params.BeaconConfig().SlotsPerEpoch))
st, err := state_native.InitializeFromProtoFulu(&ethpb.BeaconStateFulu{
ProposerLookahead: lookahead,
Expand Down
26 changes: 6 additions & 20 deletions beacon-chain/state/state-native/getters_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,7 @@ func (b *BeaconState) ToProtoUnsafe() any {
PendingConsolidations: b.pendingConsolidations,
}
case version.Fulu:
lookahead := make([]uint64, len(b.proposerLookahead))
for i, v := range b.proposerLookahead {
lookahead[i] = uint64(v)
}

return &ethpb.BeaconStateFulu{
GenesisTime: b.genesisTime,
GenesisValidatorsRoot: gvrCopy[:],
Expand Down Expand Up @@ -258,13 +255,9 @@ func (b *BeaconState) ToProtoUnsafe() any {
PendingDeposits: b.pendingDeposits,
PendingPartialWithdrawals: b.pendingPartialWithdrawals,
PendingConsolidations: b.pendingConsolidations,
ProposerLookahead: lookahead,
ProposerLookahead: b.proposerLookahead,
}
case version.Gloas:
lookahead := make([]uint64, len(b.proposerLookahead))
for i, v := range b.proposerLookahead {
lookahead[i] = uint64(v)
}

return &ethpb.BeaconStateGloas{
GenesisTime: b.genesisTime,
Expand Down Expand Up @@ -304,7 +297,7 @@ func (b *BeaconState) ToProtoUnsafe() any {
PendingDeposits: b.pendingDeposits,
PendingPartialWithdrawals: b.pendingPartialWithdrawals,
PendingConsolidations: b.pendingConsolidations,
ProposerLookahead: lookahead,
ProposerLookahead: b.proposerLookahead,
ExecutionPayloadAvailability: b.executionPayloadAvailability,
Builders: b.builders,
NextWithdrawalBuilderIndex: b.nextWithdrawalBuilderIndex,
Expand Down Expand Up @@ -521,10 +514,7 @@ func (b *BeaconState) ToProto() any {
PendingConsolidations: b.pendingConsolidationsVal(),
}
case version.Fulu:
lookahead := make([]uint64, len(b.proposerLookahead))
for i, v := range b.proposerLookahead {
lookahead[i] = uint64(v)
}

return &ethpb.BeaconStateFulu{
GenesisTime: b.genesisTime,
GenesisValidatorsRoot: gvrCopy[:],
Expand Down Expand Up @@ -563,13 +553,9 @@ func (b *BeaconState) ToProto() any {
PendingDeposits: b.pendingDepositsVal(),
PendingPartialWithdrawals: b.pendingPartialWithdrawalsVal(),
PendingConsolidations: b.pendingConsolidationsVal(),
ProposerLookahead: lookahead,
ProposerLookahead: b.proposerLookaheadVal(),
}
case version.Gloas:
lookahead := make([]uint64, len(b.proposerLookahead))
for i, v := range b.proposerLookahead {
lookahead[i] = uint64(v)
}

return &ethpb.BeaconStateGloas{
GenesisTime: b.genesisTime,
Expand Down Expand Up @@ -609,7 +595,7 @@ func (b *BeaconState) ToProto() any {
PendingDeposits: b.pendingDepositsVal(),
PendingPartialWithdrawals: b.pendingPartialWithdrawalsVal(),
PendingConsolidations: b.pendingConsolidationsVal(),
ProposerLookahead: lookahead,
ProposerLookahead: b.proposerLookaheadVal(),
ExecutionPayloadAvailability: b.executionPayloadAvailabilityVal(),
Builders: b.buildersVal(),
NextWithdrawalBuilderIndex: b.nextWithdrawalBuilderIndex,
Expand Down
7 changes: 7 additions & 0 deletions changelog/manu-0x00-dirty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- Prometheus summary metric (`field_trie_recompute_indices`) tracking the number of changed indices per `RecomputeTrie` call, broken down by field.

### Fixed

- `ProcessEffectiveBalanceUpdates`: avoid copying a validator when the computed effective balance is unchanged, reducing unnecessary allocations.
3 changes: 3 additions & 0 deletions changelog/terence_proposer-lookahead-validator-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- Use `primitives.ValidatorIndex` type for `proposer_lookahead` field in beacon state protobuf instead of raw `uint64`.
Loading
Loading