Skip to content

Commit

Permalink
fix(sentry): attestation data committee size
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Aug 21, 2023
1 parent a0831a5 commit dd42ee4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
3 changes: 1 addition & 2 deletions pkg/sentry/attestation_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func (s *Sentry) fetchValidatorAttestationData(ctx context.Context) ([]*v1.Valid
}

snapshot.RequestDuration = time.Since(startedAt)
snapshot.Event = data
vad := v1.NewValidatorAttestationData(s.log, snapshot, s.beacon, meta)
vad := v1.NewValidatorAttestationData(s.log, snapshot, data, s.beacon, meta)
dataChan <- vad
}(phase0.CommitteeIndex(i))
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/sentry/ethereum/services/duties.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,8 @@ func (m *DutiesService) GetLastCommitteeIndex(ctx context.Context, slot phase0.S
var maxIndex *phase0.CommitteeIndex

for _, committee := range committees.Value() {
if committee.Slot == slot {
if maxIndex == nil || committee.Index > *maxIndex {
maxIndex = &committee.Index
}
if committee.Slot == slot && (maxIndex == nil || committee.Index > *maxIndex) {
maxIndex = &committee.Index
}
}

Expand Down
29 changes: 15 additions & 14 deletions pkg/sentry/event/beacon/eth/v1/validator_attestation_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@ type ValidatorAttestationData struct {
log logrus.FieldLogger

snapshot *ValidatorAttestationDataSnapshot
event *phase0.AttestationData

beacon *ethereum.BeaconNode
clientMeta *xatu.ClientMeta
id uuid.UUID
}

type ValidatorAttestationDataSnapshot struct {
Event *phase0.AttestationData
RequestAt time.Time
RequestDuration time.Duration
}

func NewValidatorAttestationData(log logrus.FieldLogger, snapshot *ValidatorAttestationDataSnapshot, beacon *ethereum.BeaconNode, clientMeta *xatu.ClientMeta) *ValidatorAttestationData {
func NewValidatorAttestationData(log logrus.FieldLogger, snapshot *ValidatorAttestationDataSnapshot, event *phase0.AttestationData, beacon *ethereum.BeaconNode, clientMeta *xatu.ClientMeta) *ValidatorAttestationData {
return &ValidatorAttestationData{
log: log.WithField("event", "BEACON_API_ETH_V1_VALIDATOR_ATTESTATION_DATA"),
snapshot: snapshot,
event: event,
beacon: beacon,
clientMeta: clientMeta,
id: uuid.New(),
}
}

func (e *ValidatorAttestationData) Decorate(ctx context.Context) (*xatu.DecoratedEvent, error) {
if e.snapshot.Event == nil {
if e.event == nil {
return nil, errors.New("snapshot event is nil")
}

Expand All @@ -56,16 +57,16 @@ func (e *ValidatorAttestationData) Decorate(ctx context.Context) (*xatu.Decorate
},
Data: &xatu.DecoratedEvent_EthV1ValidatorAttestationData{
EthV1ValidatorAttestationData: &v1.AttestationData{
Slot: uint64(e.snapshot.Event.Slot),
Index: uint64(e.snapshot.Event.Index),
BeaconBlockRoot: v1.RootAsString(e.snapshot.Event.BeaconBlockRoot),
Slot: uint64(e.event.Slot),
Index: uint64(e.event.Index),
BeaconBlockRoot: v1.RootAsString(e.event.BeaconBlockRoot),
Source: &v1.Checkpoint{
Epoch: uint64(e.snapshot.Event.Source.Epoch),
Root: v1.RootAsString(e.snapshot.Event.Source.Root),
Epoch: uint64(e.event.Source.Epoch),
Root: v1.RootAsString(e.event.Source.Root),
},
Target: &v1.Checkpoint{
Epoch: uint64(e.snapshot.Event.Target.Epoch),
Root: v1.RootAsString(e.snapshot.Event.Target.Root),
Epoch: uint64(e.event.Target.Epoch),
Root: v1.RootAsString(e.event.Target.Root),
},
},
},
Expand Down Expand Up @@ -94,8 +95,8 @@ func (e *ValidatorAttestationData) ShouldIgnore(ctx context.Context) (bool, erro
func (e *ValidatorAttestationData) getAdditionalData(_ context.Context) (*xatu.ClientMeta_AdditionalEthV1ValidatorAttestationDataData, error) {
extra := &xatu.ClientMeta_AdditionalEthV1ValidatorAttestationDataData{}

attestionSlot := e.beacon.Metadata().Wallclock().Slots().FromNumber(uint64(e.snapshot.Event.Slot))
epoch := e.beacon.Metadata().Wallclock().Epochs().FromSlot(uint64(e.snapshot.Event.Slot))
attestionSlot := e.beacon.Metadata().Wallclock().Slots().FromNumber(uint64(e.event.Slot))
epoch := e.beacon.Metadata().Wallclock().Epochs().FromSlot(uint64(e.event.Slot))

extra.Slot = &xatu.Slot{
Number: attestionSlot.Number(),
Expand All @@ -114,7 +115,7 @@ func (e *ValidatorAttestationData) getAdditionalData(_ context.Context) (*xatu.C
}

// Build out the target section
targetEpoch := e.beacon.Metadata().Wallclock().Epochs().FromNumber(uint64(e.snapshot.Event.Target.Epoch))
targetEpoch := e.beacon.Metadata().Wallclock().Epochs().FromNumber(uint64(e.event.Target.Epoch))
extra.Target = &xatu.ClientMeta_AdditionalEthV1AttestationTargetData{
Epoch: &xatu.Epoch{
Number: targetEpoch.Number(),
Expand All @@ -123,7 +124,7 @@ func (e *ValidatorAttestationData) getAdditionalData(_ context.Context) (*xatu.C
}

// Build out the source section
sourceEpoch := e.beacon.Metadata().Wallclock().Epochs().FromNumber(uint64(e.snapshot.Event.Source.Epoch))
sourceEpoch := e.beacon.Metadata().Wallclock().Epochs().FromNumber(uint64(e.event.Source.Epoch))
extra.Source = &xatu.ClientMeta_AdditionalEthV1AttestationSourceData{
Epoch: &xatu.Epoch{
Number: sourceEpoch.Number(),
Expand Down

0 comments on commit dd42ee4

Please sign in to comment.