mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
a1a12243be
* 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>
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package checkpoint
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/api/client/beacon"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
|
)
|
|
|
|
// APIInitializer manages initializing the beacon node using checkpoint sync, retrieving the checkpoint state and root
|
|
// from the remote beacon node api.
|
|
type APIInitializer struct {
|
|
c *beacon.Client
|
|
}
|
|
|
|
// NewAPIInitializer creates an APIInitializer, handling the set up of a beacon node api client
|
|
// using the provided host string.
|
|
func NewAPIInitializer(beaconNodeHost string) (*APIInitializer, error) {
|
|
c, err := beacon.NewClient(beaconNodeHost)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "unable to parse beacon node url or hostname - %s", beaconNodeHost)
|
|
}
|
|
return &APIInitializer{c: c}, nil
|
|
}
|
|
|
|
// Initialize downloads origin state and block for checkpoint sync and initializes database records to
|
|
// prepare the node to begin syncing from that point.
|
|
func (dl *APIInitializer) Initialize(ctx context.Context, d db.Database) error {
|
|
od, err := beacon.DownloadFinalizedData(ctx, dl.c)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Error retrieving checkpoint origin state and block")
|
|
}
|
|
return d.SaveOrigin(ctx, od.StateBytes(), od.BlockBytes())
|
|
}
|