prysm-pulse/cmd/prysmctl/checkpoint/latest.go
kasey a1a12243be
Sync from finalized (#10723)
* checkpoint sync use finalized state+block

instead of finding the block at the beginning of the weak subjectivity
epoch.

* happy path test for sync-from-finalized

* gofmt

* functional opts for the minimal e2e

* add TestCheckpointSync option

* wip: pushing for CI

* include conn index in log for debugging

* lint

* block until regular sync test finishes

* restore TestSync->testDoppelGangerProtection link

* update bazel deps for all the test targets

* updating to match current checksum from github

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
2022-05-25 22:52:43 +00:00

56 lines
1.4 KiB
Go

package checkpoint
import (
"context"
"fmt"
"time"
"github.com/prysmaticlabs/prysm/api/client/beacon"
"github.com/urfave/cli/v2"
)
var latestFlags = struct {
BeaconNodeHost string
Timeout time.Duration
}{}
var latestCmd = &cli.Command{
Name: "latest",
Usage: "Compute the latest weak subjectivity checkpoint (block_root:epoch) using trusted server data.",
Action: cliActionLatest,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "beacon-node-host",
Usage: "host:port for beacon node to query",
Destination: &latestFlags.BeaconNodeHost,
Value: "http://localhost:3500",
},
&cli.DurationFlag{
Name: "http-timeout",
Usage: "timeout for http requests made to beacon-node-url (uses duration format, ex: 2m31s). default: 2m",
Destination: &latestFlags.Timeout,
Value: time.Minute * 2,
},
},
}
func cliActionLatest(_ *cli.Context) error {
ctx := context.Background()
f := latestFlags
opts := []beacon.ClientOpt{beacon.WithTimeout(f.Timeout)}
client, err := beacon.NewClient(latestFlags.BeaconNodeHost, opts...)
if err != nil {
return err
}
ws, err := beacon.ComputeWeakSubjectivityCheckpoint(ctx, client)
if err != nil {
return err
}
fmt.Println("\nUse the following flag when starting a prysm Beacon Node to ensure the chain history " +
"includes the Weak Subjectivity Checkpoint: ")
fmt.Printf("--weak-subjectivity-checkpoint=%s\n\n", ws.CheckpointString())
return nil
}