Skip to content

Commit

Permalink
More data for epoch summaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Sep 4, 2024
1 parent 1ac505f commit fd0a89c
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 89 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1.36.1:
- more JSON data for epoch summary

1.36.0:
- support keystore wallets

1.35.6:
- provide more JSON data in "epoch summary"

1.35.5:
- allow keystore to be output to the console

Expand Down
6 changes: 3 additions & 3 deletions cmd/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func init() {
RootCmd.AddCommand(epochCmd)
}

func epochFlags(_ *cobra.Command) {
epochSummaryCmd.Flags().String("epoch", "", "the epoch for which to obtain information (default current, can be 'current', 'last' or a number)")
func epochFlags(cmd *cobra.Command) {
cmd.Flags().String("epoch", "", "the epoch for which to obtain information (default current, can be 'current', 'last' or a number)")
}

func epochBindings(cmd *cobra.Command) {
if err := viper.BindPFlag("epoch", cmd.Flags().Lookup("epoch")); err != nil {
if err := viper.BindPFlag("validators", cmd.Flags().Lookup("validators")); err != nil {
panic(err)
}
}
78 changes: 48 additions & 30 deletions cmd/epoch/summary/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ type command struct {
allowInsecureConnections bool

// Operation.
epoch string
stream bool
jsonOutput bool
epoch string
validatorsStr []string
validators map[phase0.ValidatorIndex]struct{}
stream bool
jsonOutput bool

// Data access.
eth2Client eth2client.Service
Expand All @@ -58,45 +60,61 @@ type command struct {
}

type epochSummary struct {
Epoch phase0.Epoch `json:"epoch"`
FirstSlot phase0.Slot `json:"first_slot"`
LastSlot phase0.Slot `json:"last_slot"`
Proposals []*epochProposal `json:"proposals"`
SyncCommittee []*epochSyncCommittee `json:"sync_committees"`
ActiveValidators int `json:"active_validators"`
ParticipatingValidators int `json:"participating_validators"`
HeadCorrectValidators int `json:"head_correct_validators"`
HeadTimelyValidators int `json:"head_timely_validators"`
SourceTimelyValidators int `json:"source_timely_validators"`
TargetCorrectValidators int `json:"target_correct_validators"`
TargetTimelyValidators int `json:"target_timely_validators"`
NonParticipatingValidators []*nonParticipatingValidator `json:"nonparticipating_validators"`
Blobs int `json:"blobs"`
Epoch phase0.Epoch `json:"epoch"`
FirstSlot phase0.Slot `json:"first_slot"`
LastSlot phase0.Slot `json:"last_slot"`
Blocks int `json:"blocks"`
Proposals []*epochProposal `json:"proposals"`
SyncCommitteeValidators int `json:"sync_committee_validators"`
SyncCommittee []*epochSyncCommittee `json:"sync_committees"`
ActiveValidators int `json:"active_validators"`
ParticipatingValidators int `json:"participating_validators"`
HeadCorrectValidators int `json:"head_correct_validators"`
HeadTimelyValidators int `json:"head_timely_validators"`
SourceTimelyValidators int `json:"source_timely_validators"`
TargetCorrectValidators int `json:"target_correct_validators"`
TargetTimelyValidators int `json:"target_timely_validators"`
NonParticipatingValidators []*attestingValidator `json:"nonparticipating_validators"`
NonHeadCorrectValidators []*attestingValidator `json:"nonheadcorrect_validators"`
NonHeadTimelyValidators []*attestingValidator `json:"nonheadtimely_validators"`
NonTargetCorrectValidators []*attestingValidator `json:"nontargetcorrect_validators"`
NonSourceTimelyValidators []*attestingValidator `json:"nonsourcetimely_validators"`
Blobs int `json:"blobs"`
}

type epochProposal struct {
Slot phase0.Slot `json:"slot"`
Proposer phase0.ValidatorIndex `json:"proposer"`
Block bool `json:"block"`
ValidatorIndex phase0.ValidatorIndex `json:"validator_index"`
Slot phase0.Slot `json:"slot"`
Block bool `json:"block"`
}

type epochSyncCommittee struct {
Index phase0.ValidatorIndex `json:"index"`
Missed int `json:"missed"`
ValidatorIndex phase0.ValidatorIndex `json:"validator_index"`
Missed int `json:"missed"`
MissedSlots []phase0.Slot `json:"missed_slots"`
}

type nonParticipatingValidator struct {
Validator phase0.ValidatorIndex `json:"validator_index"`
Slot phase0.Slot `json:"slot"`
Committee phase0.CommitteeIndex `json:"committee_index"`
type attestingValidator struct {
Validator phase0.ValidatorIndex `json:"validator_index"`
Slot phase0.Slot `json:"slot"`
Committee phase0.CommitteeIndex `json:"committee_index"`
HeadVote *phase0.Root `json:"head_vote,omitempty"`
Head *phase0.Root `json:"head,omitempty"`
TargetVote *phase0.Root `json:"target_vote,omitempty"`
Target *phase0.Root `json:"target,omitempty"`
InclusionSlot phase0.Slot `json:"inclusion_slot,omitempty"`
}

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"),
validatorsStr: viper.GetStringSlice("validators"),
summary: &epochSummary{
Proposals: make([]*epochProposal, 0),
},
validators: make(map[phase0.ValidatorIndex]struct{}),
blocksCache: make(map[string]*spec.VersionedSignedBeaconBlock),
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/epoch/summary/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *command) outputTxt(_ context.Context) (string, error) {
missedProposals := make([]string, 0, len(c.summary.Proposals))
for _, proposal := range c.summary.Proposals {
if !proposal.Block {
missedProposals = append(missedProposals, fmt.Sprintf("\n Slot %d (validator %d)", proposal.Slot, proposal.Proposer))
missedProposals = append(missedProposals, fmt.Sprintf("\n Slot %d (validator %d)", proposal.Slot, proposal.ValidatorIndex))
} else {
proposedBlocks++
}
Expand All @@ -64,7 +64,7 @@ func (c *command) outputTxt(_ context.Context) (string, error) {
builder.WriteString("\n Slot ")
builder.WriteString(fmt.Sprintf("%d (%d/%d)", proposal.Slot, uint64(proposal.Slot)%uint64(len(c.summary.Proposals)), len(c.summary.Proposals)))
builder.WriteString(" validator ")
builder.WriteString(fmt.Sprintf("%d", proposal.Proposer))
builder.WriteString(fmt.Sprintf("%d", proposal.ValidatorIndex))
builder.WriteString(" not proposed or not included")
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c *command) outputTxt(_ context.Context) (string, error) {
if c.verbose {
for _, syncCommittee := range c.summary.SyncCommittee {
builder.WriteString("\n Validator ")
builder.WriteString(fmt.Sprintf("%d", syncCommittee.Index))
builder.WriteString(fmt.Sprintf("%d", syncCommittee.ValidatorIndex))
builder.WriteString(" included ")
builder.WriteString(fmt.Sprintf("%d/%d", proposedBlocks-syncCommittee.Missed, proposedBlocks))
builder.WriteString(fmt.Sprintf(" (%0.2f%%)", 100.0*float64(proposedBlocks-syncCommittee.Missed)/float64(proposedBlocks)))
Expand Down
Loading

0 comments on commit fd0a89c

Please sign in to comment.