Skip to content

Commit

Permalink
core/bcast: fix builder registrations delays (#2675)
Browse files Browse the repository at this point in the history
This PR fixes delay reports by bcast for builder registration duty. As reported multiple times:

```
12:32:23.134 INFO bcast      Successfully submitted validator registration to beacon node {"delay": "25416h32m0.13494757s", "pubkey": "858_9bf", "duty": "0/builder_registration"}
```

category: bug
ticket: #2681
  • Loading branch information
dB2510 authored Nov 7, 2023
1 parent 7172fb6 commit c79ccdf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions core/bcast/bcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ func (b Broadcaster) Broadcast(ctx context.Context, duty core.Duty, set core.Sig
return err

case core.DutyBuilderRegistration:
slot, err := firstSlotInCurrentEpoch(ctx, b.eth2Cl)
if err != nil {
return errors.Wrap(err, "calculate first slot in epoch")
}

// Use first slot in current epoch for accurate delay calculations while submitting builder registrations.
// This is because builder registrations are submitted in first slot of every epoch.
duty.Slot = slot
registrations, err := setToRegistrations(set)
if err != nil {
return err
Expand Down Expand Up @@ -299,3 +307,27 @@ func newDelayFunc(ctx context.Context, eth2Cl eth2wrap.Client) (func(slot uint64
return time.Since(slotStart)
}, nil
}

// firstSlotInCurrentEpoch calculates first slot number of the current ongoing epoch.
func firstSlotInCurrentEpoch(ctx context.Context, eth2Cl eth2wrap.Client) (uint64, error) {
genesis, err := eth2Cl.Genesis(ctx)
if err != nil {
return 0, errors.Wrap(err, "fetch genesis")
}

slotDuration, err := eth2Cl.SlotDuration(ctx)
if err != nil {
return 0, errors.Wrap(err, "fetch slot duration")
}

slotsPerEpoch, err := eth2Cl.SlotsPerEpoch(ctx)
if err != nil {
return 0, errors.Wrap(err, "fetch slots per epoch")
}

chainAge := time.Since(genesis.Data.GenesisTime)
currentSlot := chainAge / slotDuration
currentEpoch := uint64(currentSlot) / slotsPerEpoch

return currentEpoch * slotsPerEpoch, nil
}

0 comments on commit c79ccdf

Please sign in to comment.