From 0acc61e46988d92219cea0d7ccd7f20d8249542e Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Wed, 11 Oct 2023 12:51:16 +1000 Subject: [PATCH] fix(sentry): Refetch beacon committees after reorg --- pkg/sentry/ethereum/services/duties.go | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/pkg/sentry/ethereum/services/duties.go b/pkg/sentry/ethereum/services/duties.go index d76d5a9c..fc5e9236 100644 --- a/pkg/sentry/ethereum/services/duties.go +++ b/pkg/sentry/ethereum/services/duties.go @@ -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 @@ -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 skipCache != nil && !skipCache[0] { + if duties := m.beaconCommittees.Get(epoch); duties != nil { + return nil + } } m.mu.Lock()