Skip to content

Commit

Permalink
feat(sentry): allow to only get committee index 0 for attestation data
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Sep 28, 2023
1 parent 560e344 commit 0f21d0c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions example_sentry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ forkChoice:
attestationData:
enabled: false

# Regular beacon node -> validator client pairs only use committee index 0
# true - gets data from all committees
# false - only gets data from committee index 0
allCommittees: false

interval:
enabled: false
every: 30s
Expand Down
25 changes: 15 additions & 10 deletions pkg/sentry/attestation_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,26 @@ func (s *Sentry) fetchValidatorAttestationData(ctx context.Context) ([]*v1.Valid

slot := s.beacon.Metadata().Wallclock().Slots().Current()

lastCommitteeIndex, err := s.beacon.Duties().GetLastCommitteeIndex(ctx, phase0.Slot(slot.Number()))
if err != nil {
return nil, err
}
// default only to one (first) committee.
targetCommitteeSize := uint64(1)

if s.Config.AttestationData.AllCommittees {
lastCommitteeIndex, err := s.beacon.Duties().GetLastCommitteeIndex(ctx, phase0.Slot(slot.Number()))
if err != nil {
return nil, err
}

targetCommitteeSize := uint64(*lastCommitteeIndex)
targetCommitteeSize = uint64(*lastCommitteeIndex + 1)
}

attestationDataList := make([]*v1.ValidatorAttestationData, targetCommitteeSize+1)
errChan := make(chan error, targetCommitteeSize+1)
dataChan := make(chan *v1.ValidatorAttestationData, targetCommitteeSize+1)
attestationDataList := make([]*v1.ValidatorAttestationData, targetCommitteeSize)
errChan := make(chan error, targetCommitteeSize)
dataChan := make(chan *v1.ValidatorAttestationData, targetCommitteeSize)

timeoutCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

for i := uint64(0); i <= targetCommitteeSize; i++ {
for i := uint64(0); i < targetCommitteeSize; i++ {
go func(index phase0.CommitteeIndex) {
data, err := s.beacon.Node().FetchAttestationData(ctx, phase0.Slot(slot.Number()), index)
if err != nil {
Expand All @@ -106,7 +111,7 @@ func (s *Sentry) fetchValidatorAttestationData(ctx context.Context) ([]*v1.Valid

var errCount int

for i := uint64(0); i <= targetCommitteeSize; i++ {
for i := uint64(0); i < targetCommitteeSize; i++ {
select {
case err := <-errChan:
errCount++
Expand Down
2 changes: 2 additions & 0 deletions pkg/sentry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func (f *ForkChoiceConfig) Validate() error {
type AttestationDataConfig struct {
Enabled bool `yaml:"enabled" default:"false"`

AllCommittees bool `yaml:"allCommittees" default:"false"`

Interval struct {
Enabled bool `yaml:"enabled" default:"false"`
Every human.Duration `yaml:"every" default:"12s"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ValidatorAttestationDataSnapshot struct {

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_V2"),
log: log.WithField("event", "BEACON_API_ETH_V1_VALIDATOR_ATTESTATION_DATA"),
snapshot: snapshot,
event: event,
beacon: beacon,
Expand Down

0 comments on commit 0f21d0c

Please sign in to comment.