From 0e089bc8ff0a619b2e5038a3df246249a2f0bec2 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Tue, 16 Jan 2024 12:29:16 +0000 Subject: [PATCH] Include period start and end in eth1 votes output. --- cmd/chain/eth1votes/command.go | 2 ++ cmd/chain/eth1votes/output.go | 29 +++++++++++++++++++---------- cmd/chain/eth1votes/process.go | 2 ++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cmd/chain/eth1votes/command.go b/cmd/chain/eth1votes/command.go index 3411c62..15ab9a8 100644 --- a/cmd/chain/eth1votes/command.go +++ b/cmd/chain/eth1votes/command.go @@ -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 diff --git a/cmd/chain/eth1votes/output.go b/cmd/chain/eth1votes/output.go index 3cfa772..bff9794 100644 --- a/cmd/chain/eth1votes/output.go +++ b/cmd/chain/eth1votes/output.go @@ -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) { @@ -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 { @@ -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)) } diff --git a/cmd/chain/eth1votes/process.go b/cmd/chain/eth1votes/process.go index 4653be8..48a8b28 100644 --- a/cmd/chain/eth1votes/process.go +++ b/cmd/chain/eth1votes/process.go @@ -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 {