2022-02-02 20:41:14 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2023-05-15 09:59:02 +00:00
|
|
|
"math"
|
2022-02-02 20:41:14 +00:00
|
|
|
"time"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
|
|
|
v1alpha1 "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/time/slots"
|
2022-02-02 20:41:14 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
beacon = flag.String("beacon", "127.0.0.1:4000", "gRPC address of the Prysm beacon node")
|
2022-04-15 15:30:32 +00:00
|
|
|
genesis = flag.Uint64("genesis", 1606824023, "Genesis time. mainnet=1606824023, prater=1616508000")
|
2022-02-02 20:41:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2023-05-15 09:59:02 +00:00
|
|
|
cc, err := grpc.DialContext(ctx, *beacon, grpc.WithInsecure(), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt64)))
|
2022-02-02 20:41:14 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
c := v1alpha1.NewBeaconChainClient(cc)
|
|
|
|
g, ctx := errgroup.WithContext(ctx)
|
2023-03-10 16:46:27 +00:00
|
|
|
v := newVotes()
|
2022-02-02 20:41:14 +00:00
|
|
|
|
|
|
|
current := slots.ToEpoch(slots.CurrentSlot(*genesis))
|
|
|
|
start := current.Div(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod)).Mul(uint64(params.BeaconConfig().EpochsPerEth1VotingPeriod))
|
|
|
|
nextStart := start.AddEpoch(params.BeaconConfig().EpochsPerEth1VotingPeriod)
|
|
|
|
|
|
|
|
fmt.Printf("Looking back from current epoch %d back to %d\n", current, start)
|
|
|
|
nextStartSlot, err := slots.EpochStart(nextStart)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
nextStartTime, err := slots.ToTime(*genesis, nextStartSlot)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Next period starts at epoch %d (%s)\n", nextStart, time.Until(nextStartTime))
|
|
|
|
|
2023-01-26 14:40:12 +00:00
|
|
|
for i := primitives.Epoch(0); i < current.Sub(uint64(start)); i++ {
|
2022-02-02 20:41:14 +00:00
|
|
|
j := i
|
|
|
|
g.Go(func() error {
|
|
|
|
resp, err := c.ListBeaconBlocks(ctx, &v1alpha1.ListBlocksRequest{
|
|
|
|
QueryFilter: &v1alpha1.ListBlocksRequest_Epoch{Epoch: current.Sub(uint64(j))},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, c := range resp.GetBlockContainers() {
|
|
|
|
v.Insert(wrapBlock(c))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := g.Wait(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(v.Report())
|
|
|
|
}
|
|
|
|
|
2023-02-09 09:23:32 +00:00
|
|
|
func wrapBlock(b *v1alpha1.BeaconBlockContainer) interfaces.ReadOnlyBeaconBlock {
|
2022-05-04 03:55:35 +00:00
|
|
|
var err error
|
2023-02-09 09:23:32 +00:00
|
|
|
var wb interfaces.ReadOnlySignedBeaconBlock
|
2022-05-04 03:55:35 +00:00
|
|
|
switch bb := b.Block.(type) {
|
|
|
|
case *v1alpha1.BeaconBlockContainer_Phase0Block:
|
2022-08-02 15:30:46 +00:00
|
|
|
wb, err = blocks.NewSignedBeaconBlock(bb.Phase0Block)
|
2022-05-04 03:55:35 +00:00
|
|
|
case *v1alpha1.BeaconBlockContainer_AltairBlock:
|
2022-08-02 15:30:46 +00:00
|
|
|
wb, err = blocks.NewSignedBeaconBlock(bb.AltairBlock)
|
2022-05-04 03:55:35 +00:00
|
|
|
case *v1alpha1.BeaconBlockContainer_BellatrixBlock:
|
2022-08-02 15:30:46 +00:00
|
|
|
wb, err = blocks.NewSignedBeaconBlock(bb.BellatrixBlock)
|
2023-05-15 09:59:02 +00:00
|
|
|
case *v1alpha1.BeaconBlockContainer_CapellaBlock:
|
|
|
|
wb, err = blocks.NewSignedBeaconBlock(bb.CapellaBlock)
|
2023-09-07 03:19:32 +00:00
|
|
|
case *v1alpha1.BeaconBlockContainer_BlindedCapellaBlock:
|
|
|
|
wb, err = blocks.NewSignedBeaconBlock(bb.BlindedCapellaBlock)
|
2022-02-02 20:41:14 +00:00
|
|
|
}
|
2022-05-04 03:55:35 +00:00
|
|
|
if err != nil {
|
|
|
|
panic("no block")
|
|
|
|
}
|
|
|
|
return wb.Block()
|
2022-02-02 20:41:14 +00:00
|
|
|
}
|