mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
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:
@@ -11,7 +11,9 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//api/client/beacon:go_default_library",
|
"//api/client/beacon:go_default_library",
|
||||||
"//beacon-chain/db:go_default_library",
|
"//beacon-chain/db:go_default_library",
|
||||||
|
"//config/params:go_default_library",
|
||||||
"//io/file:go_default_library",
|
"//io/file:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/api/client/beacon"
|
"github.com/prysmaticlabs/prysm/api/client/beacon"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
"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
|
// 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
|
// Initialize downloads origin state and block for checkpoint sync and initializes database records to
|
||||||
// prepare the node to begin syncing from that point.
|
// prepare the node to begin syncing from that point.
|
||||||
func (dl *APIInitializer) Initialize(ctx context.Context, d db.Database) error {
|
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)
|
od, err := beacon.DownloadFinalizedData(ctx, dl.c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Error retrieving checkpoint origin state and block")
|
return errors.Wrap(err, "Error retrieving checkpoint origin state and block")
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/prysmaticlabs/prysm/io/file"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
"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)
|
// 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 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.
|
// 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 {
|
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)
|
serBlock, err := file.ReadFileAsBytes(fi.blockPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error reading block file %s for checkpoint sync init", fi.blockPath)
|
return errors.Wrapf(err, "error reading block file %s for checkpoint sync init", fi.blockPath)
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ go_library(
|
|||||||
"//beacon-chain/db:go_default_library",
|
"//beacon-chain/db:go_default_library",
|
||||||
"//io/file:go_default_library",
|
"//io/file:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package genesis
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/api/client/beacon"
|
"github.com/prysmaticlabs/prysm/api/client/beacon"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
"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
|
// Initialize downloads origin state and block for checkpoint sync and initializes database records to
|
||||||
// prepare the node to begin syncing from that point.
|
// prepare the node to begin syncing from that point.
|
||||||
func (dl *APIInitializer) Initialize(ctx context.Context, d db.Database) error {
|
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)
|
sb, err := dl.c.GetState(ctx, beacon.IdGenesis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Error retrieving genesis state from %s", dl.c.NodeURL())
|
return errors.Wrapf(err, "Error retrieving genesis state from %s", dl.c.NodeURL())
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
//go:build blst_disabled
|
//go:build blst_disabled
|
||||||
|
|
||||||
package blst
|
package blst
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
Reference in New Issue
Block a user