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

feat(sentry): allow to only get committee index 0 for attestation data #213

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
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
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
Loading