Skip to content

Commit

Permalink
relayer improvements (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored Sep 20, 2024
1 parent 581fb3a commit 325cdae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions relayer/relays/beacon/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func (h *Header) Sync(ctx context.Context, eg *errgroup.Group) error {
log.WithFields(logFields).WithError(err).Warn("SyncCommittee latency found")
case errors.Is(err, ErrExecutionHeaderNotImported):
log.WithFields(logFields).WithError(err).Warn("ExecutionHeader not imported")
case errors.Is(err, syncer.ErrBeaconStateAvailableYet):
case errors.Is(err, syncer.ErrBeaconStateUnavailable):
log.WithFields(logFields).WithError(err).Warn("beacon state not available for finalized state yet")
case errors.Is(err, syncer.ErrSyncCommitteeNotSuperMajority):
log.WithFields(logFields).WithError(err).Warn("update received was not signed by supermajority")
case err != nil:
return err
}
Expand Down Expand Up @@ -348,7 +350,7 @@ func (h *Header) populateFinalizedCheckpoint(slot uint64) error {
}

blockRootsProof, err := h.syncer.GetBlockRoots(slot)
if err != nil && !errors.Is(err, syncer.ErrBeaconStateAvailableYet) {
if err != nil && !errors.Is(err, syncer.ErrBeaconStateUnavailable) {
return fmt.Errorf("fetch block roots for slot %d: %w", slot, err)
}

Expand Down
18 changes: 10 additions & 8 deletions relayer/relays/beacon/header/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (

var (
ErrCommitteeUpdateHeaderInDifferentSyncPeriod = errors.New("sync committee in different sync period")
ErrBeaconStateAvailableYet = errors.New("beacon state object not available yet")
ErrBeaconStateUnavailable = errors.New("beacon state object not available yet")
ErrSyncCommitteeNotSuperMajority = errors.New("update received was not signed by supermajority")
)

type Syncer struct {
Expand Down Expand Up @@ -436,7 +437,7 @@ func (s *Syncer) GetFinalizedUpdate() (scale.Update, error) {
return scale.Update{}, fmt.Errorf("compute sync committee supermajority: %d err: %w", signatureSlot, err)
}
if !superMajority {
return scale.Update{}, fmt.Errorf("sync committee at slot not supermajority: %d", signatureSlot)
return scale.Update{}, ErrSyncCommitteeNotSuperMajority
}

updatePayload := scale.UpdatePayload{
Expand Down Expand Up @@ -967,12 +968,13 @@ func (s *Syncer) getBestMatchBeaconDataFromStore(minSlot, maxSlot uint64) (final
}

func (s *Syncer) getBeaconState(slot uint64) ([]byte, error) {
data, err := s.Client.GetBeaconState(strconv.FormatUint(slot, 10))
if err != nil {
log.WithError(err).Warn("unable to fetch beacon state from API, trying beacon store")
data, err = s.store.GetBeaconStateData(slot)
if err != nil {
return nil, fmt.Errorf("fetch beacon state from store: %w", err)
data, apiErr := s.Client.GetBeaconState(strconv.FormatUint(slot, 10))
if apiErr != nil {
var storeErr error
data, storeErr = s.store.GetBeaconStateData(slot)
if storeErr != nil {
log.WithFields(log.Fields{"apiError": apiErr, "storeErr": storeErr}).Warn("fetch beacon state from api and store failed")
return nil, ErrBeaconStateUnavailable
}
}
return data, nil
Expand Down

0 comments on commit 325cdae

Please sign in to comment.