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

fix(sentry): Refetch beacon committees after reorg #236

Merged
merged 2 commits into from
Oct 11, 2023
Merged
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
29 changes: 26 additions & 3 deletions pkg/sentry/ethereum/services/duties.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ func (m *DutiesService) Start(ctx context.Context) error {
m.fetchNiceToHaveEpochDuties(ctx)
})

m.beacon.OnChainReOrg(ctx, func(ctx context.Context, ev *v1.ChainReorgEvent) error {
// Clear the cache for the reorged epoch and all future epochs.
for _, epoch := range m.beaconCommittees.Keys() {
if epoch >= ev.Epoch {
m.log.WithFields(logrus.Fields{
"epoch": epoch,
"event": ev,
}).Info("Clearing beacon committee after reorg event")

if err := m.fetchBeaconCommittee(ctx, epoch, true); err != nil {
m.log.WithError(err).WithFields(logrus.Fields{
"epoch": epoch,
"event": ev,
}).Error("Failed to fetch new beacon committee after reorg")
}
}
}

return nil
})

go m.beaconCommittees.Start()

return nil
Expand Down Expand Up @@ -200,9 +221,11 @@ func (m *DutiesService) fireOnBeaconCommitteeSubscriptions(epoch phase0.Epoch, c
}
}

func (m *DutiesService) fetchBeaconCommittee(ctx context.Context, epoch phase0.Epoch) error {
if duties := m.beaconCommittees.Get(epoch); duties != nil {
return nil
func (m *DutiesService) fetchBeaconCommittee(ctx context.Context, epoch phase0.Epoch, skipCache ...bool) error {
if len(skipCache) != 0 && !skipCache[0] {
if duties := m.beaconCommittees.Get(epoch); duties != nil {
return nil
}
}

m.mu.Lock()
Expand Down
Loading