diff --git a/CHANGELOG.md b/CHANGELOG.md index be7bec2..7fd7091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +1.35.1: + - fix output for various commands that may encounter an empty slot + 1.35.0: - support Deneb - add start and end dates for eth1votes period diff --git a/cmd/attester/inclusion/process.go b/cmd/attester/inclusion/process.go index e06f778..9701334 100644 --- a/cmd/attester/inclusion/process.go +++ b/cmd/attester/inclusion/process.go @@ -17,6 +17,7 @@ import ( "bytes" "context" "fmt" + "net/http" eth2client "github.com/attestantio/go-eth2-client" "github.com/attestantio/go-eth2-client/api" @@ -66,6 +67,11 @@ func process(ctx context.Context, data *dataIn) (*dataOut, error) { Block: fmt.Sprintf("%d", slot), }) if err != nil { + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + // No block for this slot, that's fine. + continue + } return nil, errors.Wrap(err, "failed to obtain block") } block := blockResponse.Data @@ -129,13 +135,15 @@ func calcHeadCorrect(ctx context.Context, data *dataIn, attestation *phase0.Atte Block: fmt.Sprintf("%d", slot), }) if err != nil { + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + // No block. + slot-- + continue + } + return false, err } - if response.Data == nil { - // No block. - slot-- - continue - } if !response.Data.Canonical { // Not canonical. slot-- @@ -153,13 +161,15 @@ func calcTargetCorrect(ctx context.Context, data *dataIn, attestation *phase0.At Block: fmt.Sprintf("%d", slot), }) if err != nil { + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + // No block. + slot-- + continue + } + return false, err } - if response.Data == nil { - // No block. - slot-- - continue - } if !response.Data.Canonical { // Not canonical. slot-- diff --git a/cmd/block/info/process.go b/cmd/block/info/process.go index 6b1e6bb..005b861 100644 --- a/cmd/block/info/process.go +++ b/cmd/block/info/process.go @@ -17,6 +17,7 @@ import ( "context" "encoding/json" "fmt" + "net/http" "os" "strconv" "strings" @@ -80,12 +81,14 @@ func process(ctx context.Context, data *dataIn) (*dataOut, error) { }) if err != nil { var apiErr *api.Error - if errors.As(err, &apiErr) && apiErr.StatusCode == 404 { + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { if data.quiet { os.Exit(1) } + return nil, errors.New("empty beacon block") } + return nil, errors.Wrap(err, "failed to obtain beacon block") } block := blockResponse.Data diff --git a/cmd/epoch/summary/process.go b/cmd/epoch/summary/process.go index 3570dd1..834b033 100644 --- a/cmd/epoch/summary/process.go +++ b/cmd/epoch/summary/process.go @@ -16,6 +16,7 @@ package epochsummary import ( "context" "fmt" + "net/http" "sort" eth2client "github.com/attestantio/go-eth2-client" @@ -411,6 +412,12 @@ func (c *command) fetchBlock(ctx context.Context, Block: blockID, }) if err != nil { + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + // No block for this slot, that's okay. + return nil, nil + } + return nil, errors.Wrap(err, "failed to fetch block") } block = blockResponse.Data diff --git a/cmd/synccommittee/inclusion/process.go b/cmd/synccommittee/inclusion/process.go index 26081da..f5ca96d 100644 --- a/cmd/synccommittee/inclusion/process.go +++ b/cmd/synccommittee/inclusion/process.go @@ -16,6 +16,7 @@ package inclusion import ( "context" "fmt" + "net/http" eth2client "github.com/attestantio/go-eth2-client" "github.com/attestantio/go-eth2-client/api" @@ -76,8 +77,14 @@ func (c *command) process(ctx context.Context) error { Block: fmt.Sprintf("%d", slot), }) if err != nil { - return err + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + c.inclusions = append(c.inclusions, 0) + continue + } + return errors.Wrap(err, "failed to obtain beacon block") } + block := blockResponse.Data if block == nil { c.inclusions = append(c.inclusions, 0) diff --git a/cmd/validator/summary/process.go b/cmd/validator/summary/process.go index 322335e..e9166d0 100644 --- a/cmd/validator/summary/process.go +++ b/cmd/validator/summary/process.go @@ -16,6 +16,7 @@ package validatorsummary import ( "context" "fmt" + "net/http" "sort" eth2client "github.com/attestantio/go-eth2-client" @@ -96,6 +97,11 @@ func (c *command) processProposerDuties(ctx context.Context) error { Block: fmt.Sprintf("%d", duty.Slot), }) if err != nil { + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + return nil + } + return errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", duty.Slot)) } block := blockResponse.Data @@ -224,7 +230,12 @@ func (c *command) processAttesterDutiesSlot(ctx context.Context, Block: fmt.Sprintf("%d", slot), }) if err != nil { - return errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", slot)) + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + return nil + } + + return errors.Wrap(err, "failed to obtain beacon block") } block := blockResponse.Data attestations, err := block.Attestations() diff --git a/cmd/version.go b/cmd/version.go index 6947454..a76de7d 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -1,4 +1,4 @@ -// Copyright © 2019 - 2023 Weald Technology Trading. +// Copyright © 2019 - 2024 Weald Technology Trading. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -24,7 +24,7 @@ import ( // ReleaseVersion is the release version of the codebase. // Usually overridden by tag names when building binaries. -var ReleaseVersion = "local build (latest release 1.35.0)" +var ReleaseVersion = "local build (latest release 1.35.1)" // versionCmd represents the version command. var versionCmd = &cobra.Command{ diff --git a/util/beaconheadercache.go b/util/beaconheadercache.go index db8f03c..1b99f4e 100644 --- a/util/beaconheadercache.go +++ b/util/beaconheadercache.go @@ -15,7 +15,9 @@ package util import ( "context" + "errors" "fmt" + "net/http" eth2client "github.com/attestantio/go-eth2-client" "github.com/attestantio/go-eth2-client/api" @@ -53,11 +55,13 @@ func (b *BeaconBlockHeaderCache) Fetch(ctx context.Context, if !exists { response, err := b.beaconBlockHeadersProvider.BeaconBlockHeader(ctx, &api.BeaconBlockHeaderOpts{Block: fmt.Sprintf("%d", slot)}) if err != nil { - return nil, err - } - if response.Data == nil { - entry = &beaconBlockHeaderEntry{ - present: false, + var apiErr *api.Error + if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound { + entry = &beaconBlockHeaderEntry{ + present: false, + } + } else { + return nil, err } } else { entry = &beaconBlockHeaderEntry{ @@ -65,6 +69,7 @@ func (b *BeaconBlockHeaderCache) Fetch(ctx context.Context, value: response.Data, } } + b.entries[slot] = entry } return entry.value, nil