Skip to content

Commit

Permalink
fix(cannon): Request beacon committees by epoch*32 (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm authored Aug 8, 2024
1 parent 49d3a17 commit af914fb
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pkg/cannon/deriver/beacon/eth/v1/beacon_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,42 @@ func (b *BeaconCommitteeDeriver) processEpoch(ctx context.Context, epoch phase0.
)
defer span.End()

spec, err := b.beacon.Node().Spec()
if err != nil {
return nil, errors.Wrap(err, "failed to get beacon spec")
}

// Get the beacon committees for this epoch
beaconCommittees, err := b.beacon.Node().FetchBeaconCommittees(ctx, fmt.Sprintf("%d", epoch), nil)
beaconCommittees, err := b.beacon.Node().FetchBeaconCommittees(ctx, fmt.Sprintf("%d", phase0.Slot(epoch)*spec.SlotsPerEpoch), nil)
if err != nil {
return nil, errors.Wrap(err, "failed to fetch beacon committees")
}

allEvents := []*xatu.DecoratedEvent{}
uniqueEpochs := make(map[phase0.Epoch]struct{})
uniqueSlots := make(map[phase0.Slot]struct{})
uniqueCommittees := make(map[phase0.CommitteeIndex]struct{})

for _, committee := range beaconCommittees {
uniqueEpochs[epoch] = struct{}{}
uniqueSlots[committee.Slot] = struct{}{}
uniqueCommittees[committee.Index] = struct{}{}
}

if len(uniqueEpochs) > 1 {
b.log.WithField("epochs", uniqueEpochs).Warn("Multiple epochs found")

return nil, errors.New("multiple epochs found")
}

minSlot := phase0.Slot(epoch) * spec.SlotsPerEpoch
maxSlot := (phase0.Slot(epoch) * spec.SlotsPerEpoch) + spec.SlotsPerEpoch - 1

for _, committee := range beaconCommittees {
if committee.Slot < minSlot || committee.Slot > maxSlot {
return nil, fmt.Errorf("beacon committee slot outside of epoch. (epoch: %d, slot: %d, min: %d, max: %d)", epoch, committee.Slot, minSlot, maxSlot)
}

event, err := b.createEventFromBeaconCommittee(ctx, committee)
if err != nil {
b.log.
Expand Down

0 comments on commit af914fb

Please sign in to comment.