-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add robust db check for checkpoint sync #3
- Loading branch information
Showing
4 changed files
with
42 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package checkpoint | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db" | ||
) | ||
|
||
// Initializer describes a type that is able to obtain the checkpoint sync data (BeaconState and SignedBeaconBlock) | ||
// in some way and perform database setup to prepare the beacon node for syncing from the given checkpoint. | ||
// See FileInitializer and APIInitializer. | ||
type Initializer interface { | ||
Initialize(ctx context.Context, d db.Database) error | ||
} | ||
|
||
// isCheckpointStatePresent checks if the checkpoint and corresponding state exist in the database. | ||
func isCheckpointStatePresent(ctx context.Context, d db.Database) (bool, error) { | ||
origin, err := d.OriginCheckpointBlockRoot(ctx) | ||
if err != nil { | ||
if errors.Is(err, db.ErrNotFound) { | ||
return false, nil | ||
} | ||
return false, errors.Wrap(err, "error while checking database for origin root") | ||
} | ||
// Check corresponding state | ||
if d.HasState(ctx, origin) { | ||
return true, nil | ||
} | ||
return false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters