Skip to content

Commit

Permalink
Include period start and end in eth1 votes output.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 16, 2024
1 parent c6f90a6 commit 0e089bc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cmd/chain/eth1votes/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type command struct {
slot phase0.Slot
epoch phase0.Epoch
period uint64
periodStart time.Time
periodEnd time.Time
incumbent *phase0.ETH1Data
eth1DataVotes []*phase0.ETH1Data
votes map[string]*vote
Expand Down
29 changes: 19 additions & 10 deletions cmd/chain/eth1votes/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import (
)

type jsonOutput struct {
Period uint64 `json:"period"`
Epoch phase0.Epoch `json:"epoch"`
Slot phase0.Slot `json:"slot"`
Incumbent *phase0.ETH1Data `json:"incumbent"`
Votes []*vote `json:"votes"`
Period uint64 `json:"period"`
PeriodStart int64 `json:"period_start"`
PeriodEnd int64 `json:"period_end"`
Epoch phase0.Epoch `json:"epoch"`
Slot phase0.Slot `json:"slot"`
Incumbent *phase0.ETH1Data `json:"incumbent"`
Votes []*vote `json:"votes"`
}

func (c *command) output(ctx context.Context) (string, error) {
Expand Down Expand Up @@ -57,11 +59,13 @@ func (c *command) outputJSON(_ context.Context) (string, error) {
})

output := &jsonOutput{
Period: c.period,
Epoch: c.epoch,
Slot: c.slot,
Incumbent: c.incumbent,
Votes: votes,
Period: c.period,
PeriodStart: c.periodStart.Unix(),
PeriodEnd: c.periodEnd.Unix(),
Epoch: c.epoch,
Slot: c.slot,
Incumbent: c.incumbent,
Votes: votes,
}
data, err := json.Marshal(output)
if err != nil {
Expand All @@ -78,6 +82,11 @@ func (c *command) outputText(_ context.Context) (string, error) {
builder.WriteString(fmt.Sprintf("%d\n", c.period))

if c.verbose {
builder.WriteString("Period start: ")
builder.WriteString(fmt.Sprintf("%s\n", c.periodStart))
builder.WriteString("Period end: ")
builder.WriteString(fmt.Sprintf("%s\n", c.periodEnd))

builder.WriteString("Incumbent: ")
builder.WriteString(fmt.Sprintf("block %#x, deposit count %d\n", c.incumbent.BlockHash, c.incumbent.DepositCount))
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/chain/eth1votes/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (c *command) process(ctx context.Context) error {
}

c.period = uint64(c.epoch) / c.epochsPerEth1VotingPeriod
c.periodStart = c.chainTime.StartOfEpoch(phase0.Epoch(c.period * c.epochsPerEth1VotingPeriod))
c.periodEnd = c.chainTime.StartOfEpoch(phase0.Epoch((c.period + 1) * c.epochsPerEth1VotingPeriod))

c.votes = make(map[string]*vote)
for _, eth1Vote := range c.eth1DataVotes {
Expand Down

0 comments on commit 0e089bc

Please sign in to comment.