From 469de610f010ee6203cadd2beb2aff34410d8069 Mon Sep 17 00:00:00 2001 From: Danyal Prout Date: Tue, 20 Feb 2024 09:59:27 -0600 Subject: [PATCH] minor tweaks --- validator/service/service.go | 18 ++++++++++-------- validator/service/service_test.go | 6 ++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/validator/service/service.go b/validator/service/service.go index 22682ec..1b6cdff 100644 --- a/validator/service/service.go +++ b/validator/service/service.go @@ -50,7 +50,8 @@ type ValidatorService struct { closeApp context.CancelCauseFunc } -// Start starts the validator service +// Start starts the validator service. This will fetch the current range of blocks to validate and start the validation +// process. func (a *ValidatorService) Start(ctx context.Context) error { header, err := retry.Do(ctx, retryAttempts, retry.Exponential(), func() (*api.Response[*v1.BeaconBlockHeader], error) { return a.headerClient.BeaconBlockHeader(ctx, &api.BeaconBlockHeaderOpts{ @@ -101,7 +102,7 @@ type CheckBlobResult struct { func (a *ValidatorService) checkBlobs(ctx context.Context, start phase0.Slot, end phase0.Slot) CheckBlobResult { var result CheckBlobResult - for slot := start; slot < end; slot++ { + for slot := start; slot <= end; slot++ { for _, format := range []Format{FormatJson, FormatSSZ} { id := strconv.FormatUint(uint64(slot), 10) @@ -111,6 +112,12 @@ func (a *ValidatorService) checkBlobs(ctx context.Context, start phase0.Slot, en return a.blobAPI.FetchSidecars(id, format) }) + if blobError != nil { + result.ErrorFetching = append(result.ErrorFetching, id) + l.Error(validationErrorLog, "reason", "error-blob-api", "error", blobError, "status", blobStatus) + continue + } + beaconStatus, beaconResponse, beaconErr := retry.Do2(ctx, retryAttempts, retry.Exponential(), func() (int, storage.BlobSidecars, error) { return a.beaconAPI.FetchSidecars(id, format) }) @@ -121,12 +128,6 @@ func (a *ValidatorService) checkBlobs(ctx context.Context, start phase0.Slot, en continue } - if blobError != nil { - result.ErrorFetching = append(result.ErrorFetching, id) - l.Error(validationErrorLog, "reason", "error-blob-api", "error", blobError, "status", blobStatus) - continue - } - if beaconStatus != blobStatus { result.MismatchedStatus = append(result.MismatchedStatus, id) l.Error(validationErrorLog, "reason", "status-code-mismatch", "beaconStatus", beaconStatus, "blobStatus", blobStatus) @@ -148,6 +149,7 @@ func (a *ValidatorService) checkBlobs(ctx context.Context, start phase0.Slot, en l.Info("completed blob check", "blobs", len(beaconResponse.Data)) } + // Check if we should stop validation otherwise continue select { case <-ctx.Done(): return result diff --git a/validator/service/service_test.go b/validator/service/service_test.go index 67f81ef..33de554 100644 --- a/validator/service/service_test.go +++ b/validator/service/service_test.go @@ -31,7 +31,7 @@ type stubBlobSidecarClient struct { data map[string]response } -// setResponses configures the stub to return the same blob data as the beacon client +// setResponses configures the stub to return the same data as the beacon client for all FetchSidecars invocations func (s *stubBlobSidecarClient) setResponses(sbc *beacontest.StubBeaconClient) { for k, v := range sbc.Blobs { s.data[k] = response{ @@ -42,6 +42,7 @@ func (s *stubBlobSidecarClient) setResponses(sbc *beacontest.StubBeaconClient) { } } +// setResponse overrides a single FetchSidecars response func (s *stubBlobSidecarClient) setResponse(id string, statusCode int, data storage.BlobSidecars, err error) { s.data[id] = response{ data: data, @@ -80,7 +81,8 @@ func TestValidatorService_OnFetchError(t *testing.T) { // Expect an error for both SSZ and JSON startSlot := strconv.FormatUint(blobtest.StartSlot, 10) - require.Equal(t, result.ErrorFetching, []string{startSlot, startSlot}) + endSlot := strconv.FormatUint(blobtest.StartSlot+1, 10) + require.Equal(t, result.ErrorFetching, []string{startSlot, startSlot, endSlot, endSlot}) require.Empty(t, result.MismatchedStatus) require.Empty(t, result.MismatchedData) }