Ignore genesis state url and checkpoint sync flags after first run of prysm (#10881)

* ignore remote genesis url flag if present in db

* ignore checkpoint sync flags if initialized

* lint

Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
kasey 2022-06-14 18:23:25 -05:00 committed by GitHub
parent 690084cab6
commit 044a4ad5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 2 deletions

View File

@ -11,7 +11,9 @@ go_library(
deps = [
"//api/client/beacon:go_default_library",
"//beacon-chain/db:go_default_library",
"//config/params:go_default_library",
"//io/file:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

View File

@ -6,6 +6,8 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/api/client/beacon"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/config/params"
log "github.com/sirupsen/logrus"
)
// APIInitializer manages initializing the beacon node using checkpoint sync, retrieving the checkpoint state and root
@ -27,6 +29,15 @@ func NewAPIInitializer(beaconNodeHost string) (*APIInitializer, error) {
// 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 {
origin, err := d.OriginCheckpointBlockRoot(ctx)
if err == nil && origin != params.BeaconConfig().ZeroHash {
log.Warnf("origin checkpoint root %#x found in db, ignoring checkpoint sync flags", origin)
return nil
} else {
if !errors.Is(err, db.ErrNotFound) {
return errors.Wrap(err, "error while checking database for origin root")
}
}
od, err := beacon.DownloadFinalizedData(ctx, dl.c)
if err != nil {
return errors.Wrap(err, "Error retrieving checkpoint origin state and block")

View File

@ -5,10 +5,11 @@ import (
"fmt"
"os"
"github.com/prysmaticlabs/prysm/io/file"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/io/file"
log "github.com/sirupsen/logrus"
)
// Initializer describes a type that is able to obtain the checkpoint sync data (BeaconState and SignedBeaconBlock)
@ -42,6 +43,15 @@ type FileInitializer struct {
// Initialize is called in the BeaconNode db startup code if an Initializer is present.
// Initialize does what is needed to prepare the beacon node database for syncing from the weak subjectivity checkpoint.
func (fi *FileInitializer) Initialize(ctx context.Context, d db.Database) error {
origin, err := d.OriginCheckpointBlockRoot(ctx)
if err == nil && origin != params.BeaconConfig().ZeroHash {
log.Warnf("origin checkpoint root %#x found in db, ignoring checkpoint sync flags", origin)
return nil
} else {
if !errors.Is(err, db.ErrNotFound) {
return errors.Wrap(err, "error while checking database for origin root")
}
}
serBlock, err := file.ReadFileAsBytes(fi.blockPath)
if err != nil {
return errors.Wrapf(err, "error reading block file %s for checkpoint sync init", fi.blockPath)

View File

@ -13,5 +13,6 @@ go_library(
"//beacon-chain/db:go_default_library",
"//io/file:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

View File

@ -3,6 +3,8 @@ package genesis
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/api/client/beacon"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
@ -27,6 +29,18 @@ func NewAPIInitializer(beaconNodeHost string) (*APIInitializer, error) {
// 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 {
existing, err := d.GenesisState(ctx)
if err != nil {
return err
}
if existing != nil && !existing.IsNil() {
htr, err := existing.HashTreeRoot(ctx)
if err != nil {
return errors.Wrap(err, "error while computing hash_tree_root of existing genesis state")
}
log.Warnf("database contains genesis with htr=%#x, ignoring remote genesis state parameter", htr)
return nil
}
sb, err := dl.c.GetState(ctx, beacon.IdGenesis)
if err != nil {
return errors.Wrapf(err, "Error retrieving genesis state from %s", dl.c.NodeURL())

View File

@ -1,4 +1,5 @@
//go:build blst_disabled
package blst
import (