Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix duty calculation for pectra spec alpha.10 #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
50 changes: 35 additions & 15 deletions indexer/beacon/duties/duties.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,49 @@ func GetProposerIndex(spec *consensus.ChainSpec, state *BeaconState, slot phase0

seed := Hash(seedData)

maxEffectiveBalance := spec.MaxEffectiveBalance
if spec.ElectraForkEpoch != nil && phase0.Epoch(slot/phase0.Slot(spec.SlotsPerEpoch)) >= phase0.Epoch(*spec.ElectraForkEpoch) {
maxEffectiveBalance = spec.MaxEffectiveBalanceElectra
}

activeIndicesCount := state.GetActiveCount()
if activeIndicesCount == 0 {
return 0, fmt.Errorf("empty active indices list")
}
maxRandomByte := uint64(1<<8 - 1)

for i := uint64(0); ; i++ {
candidateIndex, err := ComputeShuffledIndex(spec, i%activeIndicesCount, activeIndicesCount, seed, true)
if err != nil {
return 0, err
if spec.ElectraForkEpoch != nil && epoch >= phase0.Epoch(*spec.ElectraForkEpoch) {
// Electra fork
maxRandomValue := uint64(1<<16 - 1)

for i := uint64(0); ; i++ {
candidateIndex, err := ComputeShuffledIndex(spec, i%activeIndicesCount, activeIndicesCount, seed, true)
if err != nil {
return 0, err
}
b := append(seed[:], UintToBytes(i/16)...)
offset := (i % 16) * 2
hash := Hash(b)
randomValue := BytesToUint(hash[offset : offset+2])

effectiveBal := uint64(state.GetEffectiveBalance(ActiveIndiceIndex(candidateIndex)))

if effectiveBal*maxRandomValue >= spec.MaxEffectiveBalanceElectra*uint64(randomValue) {
return ActiveIndiceIndex(candidateIndex), nil
}
}
b := append(seed[:], UintToBytes(i/32)...)
randomByte := Hash(b)[i%32]

effectiveBal := uint64(state.GetEffectiveBalance(ActiveIndiceIndex(candidateIndex)))
} else {
// pre-Electra fork
maxRandomByte := uint64(1<<8 - 1)

for i := uint64(0); ; i++ {
candidateIndex, err := ComputeShuffledIndex(spec, i%activeIndicesCount, activeIndicesCount, seed, true)
if err != nil {
return 0, err
}
b := append(seed[:], UintToBytes(i/32)...)
randomByte := Hash(b)[i%32]

effectiveBal := uint64(state.GetEffectiveBalance(ActiveIndiceIndex(candidateIndex)))

if effectiveBal*maxRandomByte >= maxEffectiveBalance*uint64(randomByte) {
return ActiveIndiceIndex(candidateIndex), nil
if effectiveBal*maxRandomByte >= spec.MaxEffectiveBalance*uint64(randomByte) {
return ActiveIndiceIndex(candidateIndex), nil
}
}
}
}
Expand Down
Loading