Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
danyalprout committed Feb 20, 2024
1 parent 7c9536e commit 469de61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 10 additions & 8 deletions validator/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)

Expand All @@ -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)
})
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions validator/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 469de61

Please sign in to comment.