mirror of
https://github.com/wealdtech/ethdo.git
synced 2026-01-09 22:18:01 -05:00
Handle empty blocks.
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
1.35.1:
|
||||||
|
- fix output for various commands that may encounter an empty slot
|
||||||
|
|
||||||
1.35.0:
|
1.35.0:
|
||||||
- support Deneb
|
- support Deneb
|
||||||
- add start and end dates for eth1votes period
|
- add start and end dates for eth1votes period
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
eth2client "github.com/attestantio/go-eth2-client"
|
eth2client "github.com/attestantio/go-eth2-client"
|
||||||
"github.com/attestantio/go-eth2-client/api"
|
"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),
|
Block: fmt.Sprintf("%d", slot),
|
||||||
})
|
})
|
||||||
if err != nil {
|
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")
|
return nil, errors.Wrap(err, "failed to obtain block")
|
||||||
}
|
}
|
||||||
block := blockResponse.Data
|
block := blockResponse.Data
|
||||||
@@ -129,13 +135,15 @@ func calcHeadCorrect(ctx context.Context, data *dataIn, attestation *phase0.Atte
|
|||||||
Block: fmt.Sprintf("%d", slot),
|
Block: fmt.Sprintf("%d", slot),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var apiErr *api.Error
|
||||||
|
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound {
|
||||||
|
// No block.
|
||||||
|
slot--
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if response.Data == nil {
|
|
||||||
// No block.
|
|
||||||
slot--
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !response.Data.Canonical {
|
if !response.Data.Canonical {
|
||||||
// Not canonical.
|
// Not canonical.
|
||||||
slot--
|
slot--
|
||||||
@@ -153,13 +161,15 @@ func calcTargetCorrect(ctx context.Context, data *dataIn, attestation *phase0.At
|
|||||||
Block: fmt.Sprintf("%d", slot),
|
Block: fmt.Sprintf("%d", slot),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var apiErr *api.Error
|
||||||
|
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound {
|
||||||
|
// No block.
|
||||||
|
slot--
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if response.Data == nil {
|
|
||||||
// No block.
|
|
||||||
slot--
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !response.Data.Canonical {
|
if !response.Data.Canonical {
|
||||||
// Not canonical.
|
// Not canonical.
|
||||||
slot--
|
slot--
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -80,12 +81,14 @@ func process(ctx context.Context, data *dataIn) (*dataOut, error) {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var apiErr *api.Error
|
var apiErr *api.Error
|
||||||
if errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
|
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound {
|
||||||
if data.quiet {
|
if data.quiet {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("empty beacon block")
|
return nil, errors.New("empty beacon block")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.Wrap(err, "failed to obtain beacon block")
|
return nil, errors.Wrap(err, "failed to obtain beacon block")
|
||||||
}
|
}
|
||||||
block := blockResponse.Data
|
block := blockResponse.Data
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package epochsummary
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
eth2client "github.com/attestantio/go-eth2-client"
|
eth2client "github.com/attestantio/go-eth2-client"
|
||||||
@@ -411,6 +412,12 @@ func (c *command) fetchBlock(ctx context.Context,
|
|||||||
Block: blockID,
|
Block: blockID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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")
|
return nil, errors.Wrap(err, "failed to fetch block")
|
||||||
}
|
}
|
||||||
block = blockResponse.Data
|
block = blockResponse.Data
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package inclusion
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
eth2client "github.com/attestantio/go-eth2-client"
|
eth2client "github.com/attestantio/go-eth2-client"
|
||||||
"github.com/attestantio/go-eth2-client/api"
|
"github.com/attestantio/go-eth2-client/api"
|
||||||
@@ -76,8 +77,14 @@ func (c *command) process(ctx context.Context) error {
|
|||||||
Block: fmt.Sprintf("%d", slot),
|
Block: fmt.Sprintf("%d", slot),
|
||||||
})
|
})
|
||||||
if err != nil {
|
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
|
block := blockResponse.Data
|
||||||
if block == nil {
|
if block == nil {
|
||||||
c.inclusions = append(c.inclusions, 0)
|
c.inclusions = append(c.inclusions, 0)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package validatorsummary
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
eth2client "github.com/attestantio/go-eth2-client"
|
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),
|
Block: fmt.Sprintf("%d", duty.Slot),
|
||||||
})
|
})
|
||||||
if err != nil {
|
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))
|
return errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", duty.Slot))
|
||||||
}
|
}
|
||||||
block := blockResponse.Data
|
block := blockResponse.Data
|
||||||
@@ -224,7 +230,12 @@ func (c *command) processAttesterDutiesSlot(ctx context.Context,
|
|||||||
Block: fmt.Sprintf("%d", slot),
|
Block: fmt.Sprintf("%d", slot),
|
||||||
})
|
})
|
||||||
if err != nil {
|
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
|
block := blockResponse.Data
|
||||||
attestations, err := block.Attestations()
|
attestations, err := block.Attestations()
|
||||||
|
|||||||
@@ -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");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
@@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
// ReleaseVersion is the release version of the codebase.
|
// ReleaseVersion is the release version of the codebase.
|
||||||
// Usually overridden by tag names when building binaries.
|
// 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.
|
// versionCmd represents the version command.
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
eth2client "github.com/attestantio/go-eth2-client"
|
eth2client "github.com/attestantio/go-eth2-client"
|
||||||
"github.com/attestantio/go-eth2-client/api"
|
"github.com/attestantio/go-eth2-client/api"
|
||||||
@@ -53,11 +55,13 @@ func (b *BeaconBlockHeaderCache) Fetch(ctx context.Context,
|
|||||||
if !exists {
|
if !exists {
|
||||||
response, err := b.beaconBlockHeadersProvider.BeaconBlockHeader(ctx, &api.BeaconBlockHeaderOpts{Block: fmt.Sprintf("%d", slot)})
|
response, err := b.beaconBlockHeadersProvider.BeaconBlockHeader(ctx, &api.BeaconBlockHeaderOpts{Block: fmt.Sprintf("%d", slot)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
var apiErr *api.Error
|
||||||
}
|
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound {
|
||||||
if response.Data == nil {
|
entry = &beaconBlockHeaderEntry{
|
||||||
entry = &beaconBlockHeaderEntry{
|
present: false,
|
||||||
present: false,
|
}
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entry = &beaconBlockHeaderEntry{
|
entry = &beaconBlockHeaderEntry{
|
||||||
@@ -65,6 +69,7 @@ func (b *BeaconBlockHeaderCache) Fetch(ctx context.Context,
|
|||||||
value: response.Data,
|
value: response.Data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.entries[slot] = entry
|
b.entries[slot] = entry
|
||||||
}
|
}
|
||||||
return entry.value, nil
|
return entry.value, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user