Skip to content

Commit

Permalink
Add blobs to epoch summary.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jul 8, 2023
1 parent abd3567 commit 0ce5634
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- "block info" honours "--quiet" flag
- "block info" accepts "--block-time" option
- increase default operation timeout from 10s to 30s
- "epoch summary" JSON lists number of blobs

1.31.0:
- initial support for deneb
Expand Down
14 changes: 10 additions & 4 deletions cmd/epoch/summary/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

eth2client "github.com/attestantio/go-eth2-client"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/pkg/errors"
"github.com/spf13/viper"
Expand Down Expand Up @@ -49,6 +50,9 @@ type command struct {
beaconCommitteesProvider eth2client.BeaconCommitteesProvider
beaconBlockHeadersProvider eth2client.BeaconBlockHeadersProvider

// Caches.
blocksCache map[string]*spec.VersionedSignedBeaconBlock

// Results.
summary *epochSummary
}
Expand All @@ -67,6 +71,7 @@ type epochSummary struct {
TargetCorrectValidators int `json:"target_correct_validators"`
TargetTimelyValidators int `json:"target_timely_validators"`
NonParticipatingValidators []*nonParticipatingValidator `json:"nonparticipating_validators"`
Blobs int `json:"blobs"`
}

type epochProposal struct {
Expand All @@ -88,10 +93,11 @@ type nonParticipatingValidator struct {

func newCommand(_ context.Context) (*command, error) {
c := &command{
quiet: viper.GetBool("quiet"),
verbose: viper.GetBool("verbose"),
debug: viper.GetBool("debug"),
summary: &epochSummary{},
quiet: viper.GetBool("quiet"),
verbose: viper.GetBool("verbose"),
debug: viper.GetBool("debug"),
summary: &epochSummary{},
blocksCache: make(map[string]*spec.VersionedSignedBeaconBlock),
}

// Timeout.
Expand Down
51 changes: 47 additions & 4 deletions cmd/epoch/summary/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func (c *command) process(ctx context.Context) error {
if err := c.processAttesterDuties(ctx); err != nil {
return err
}
return c.processSyncCommitteeDuties(ctx)
if err := c.processSyncCommitteeDuties(ctx); err != nil {
return err
}
return c.processBlobs(ctx)
}

func (c *command) processProposerDuties(ctx context.Context) error {
Expand All @@ -60,7 +63,7 @@ func (c *command) processProposerDuties(ctx context.Context) error {
return errors.New("empty proposer duties")
}
for _, duty := range duties {
block, err := c.blocksProvider.SignedBeaconBlock(ctx, fmt.Sprintf("%d", duty.Slot))
block, err := c.fetchBlock(ctx, fmt.Sprintf("%d", duty.Slot))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", duty.Slot))
}
Expand Down Expand Up @@ -161,7 +164,7 @@ func (c *command) processSlots(ctx context.Context,
headersCache := util.NewBeaconBlockHeaderCache(c.beaconBlockHeadersProvider)

for slot := firstSlot; slot <= lastSlot; slot++ {
block, err := c.blocksProvider.SignedBeaconBlock(ctx, fmt.Sprintf("%d", slot))
block, err := c.fetchBlock(ctx, fmt.Sprintf("%d", slot))
if err != nil {
return 0, 0, 0, 0, 0, 0, nil, nil, errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", slot))
}
Expand Down Expand Up @@ -268,7 +271,7 @@ func (c *command) processSyncCommitteeDuties(ctx context.Context) error {
}

for slot := c.summary.FirstSlot; slot <= c.summary.LastSlot; slot++ {
block, err := c.blocksProvider.SignedBeaconBlock(ctx, fmt.Sprintf("%d", slot))
block, err := c.fetchBlock(ctx, fmt.Sprintf("%d", slot))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", slot))
}
Expand Down Expand Up @@ -372,3 +375,43 @@ func (c *command) setup(ctx context.Context) error {

return nil
}

func (c *command) processBlobs(ctx context.Context) error {
for slot := c.summary.FirstSlot; slot <= c.summary.LastSlot; slot++ {
block, err := c.fetchBlock(ctx, fmt.Sprintf("%d", slot))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to obtain block for slot %d", slot))
}
if block == nil {
continue
}
switch block.Version {
case spec.DataVersionPhase0, spec.DataVersionAltair, spec.DataVersionBellatrix, spec.DataVersionCapella:
// No blobs in these forks.
case spec.DataVersionDeneb:
c.summary.Blobs += len(block.Deneb.Message.Body.BlobKzgCommitments)
default:
return fmt.Errorf("unhandled block version %v", block.Version)
}
}

return nil
}

func (c *command) fetchBlock(ctx context.Context,
blockID string,
) (
*spec.VersionedSignedBeaconBlock,
error,
) {
block, exists := c.blocksCache[blockID]
if !exists {
var err error
block, err = c.blocksProvider.SignedBeaconBlock(ctx, blockID)
if err != nil {
return nil, errors.Wrap(err, "failed to fetch block")
}
c.blocksCache[blockID] = block
}
return block, nil
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.31.0)"
var ReleaseVersion = "local build (latest release 1.32.0)"

// versionCmd represents the version command.
var versionCmd = &cobra.Command{
Expand Down

0 comments on commit 0ce5634

Please sign in to comment.