2022-03-15 20:52:59 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2022-03-15 20:52:59 +00:00
|
|
|
bolt "go.etcd.io/bbolt"
|
|
|
|
"go.opencensus.io/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LastValidatedCheckpoint returns the latest fully validated checkpoint in beacon chain.
|
|
|
|
func (s *Store) LastValidatedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, error) {
|
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.LastValidatedCheckpoint")
|
|
|
|
defer span.End()
|
|
|
|
var checkpoint *ethpb.Checkpoint
|
|
|
|
err := s.db.View(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(checkpointBucket)
|
|
|
|
enc := bkt.Get(lastValidatedCheckpointKey)
|
|
|
|
if enc == nil {
|
|
|
|
var finErr error
|
|
|
|
checkpoint, finErr = s.FinalizedCheckpoint(ctx)
|
|
|
|
return finErr
|
|
|
|
}
|
|
|
|
checkpoint = ðpb.Checkpoint{}
|
|
|
|
return decode(ctx, enc, checkpoint)
|
|
|
|
})
|
|
|
|
return checkpoint, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveLastValidatedCheckpoint saves the last validated checkpoint in beacon chain.
|
|
|
|
func (s *Store) SaveLastValidatedCheckpoint(ctx context.Context, checkpoint *ethpb.Checkpoint) error {
|
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveLastValidatedCheckpoint")
|
|
|
|
defer span.End()
|
|
|
|
|
2023-04-20 12:13:21 +00:00
|
|
|
return s.saveCheckpoint(ctx, lastValidatedCheckpointKey, checkpoint)
|
2022-03-15 20:52:59 +00:00
|
|
|
}
|