mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
5569a68452
* Value assigned to a variable is never read before being overwritten * The result of append is not used anywhere * Suspicious assignment of range-loop vars detected * Unused method receiver detected * Revert "Auxiliary commit to revert individual files from 54edcb445484a2e5d79612e19af8e949b8861253" This reverts commit bbd1e1beabf7b0c5cfc4f514dcc820062ad6c063. * Method modifies receiver * Fix test * Duplicate imports detected * Incorrectly formatted error string * Types of function parameters can be combined * One more "Unused method receiver detected" * Unused parameter detected in function
76 lines
2.2 KiB
Go
76 lines
2.2 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
bolt "go.etcd.io/bbolt"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// LastArchivedSlot from the db.
|
|
func (s *Store) LastArchivedSlot(ctx context.Context) (types.Slot, error) {
|
|
_, span := trace.StartSpan(ctx, "BeaconDB.LastArchivedSlot")
|
|
defer span.End()
|
|
var index types.Slot
|
|
err := s.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(stateSlotIndicesBucket)
|
|
b, _ := bkt.Cursor().Last()
|
|
index = bytesutil.BytesToSlotBigEndian(b)
|
|
return nil
|
|
})
|
|
|
|
return index, err
|
|
}
|
|
|
|
// LastArchivedRoot from the db.
|
|
func (s *Store) LastArchivedRoot(ctx context.Context) [32]byte {
|
|
_, span := trace.StartSpan(ctx, "BeaconDB.LastArchivedRoot")
|
|
defer span.End()
|
|
|
|
var blockRoot []byte
|
|
if err := s.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(stateSlotIndicesBucket)
|
|
_, blockRoot = bkt.Cursor().Last()
|
|
return nil
|
|
}); err != nil { // This view never returns an error, but we'll handle anyway for sanity.
|
|
panic(err)
|
|
}
|
|
|
|
return bytesutil.ToBytes32(blockRoot)
|
|
}
|
|
|
|
// ArchivedPointRoot returns the block root of an archived point from the DB.
|
|
// This is essential for cold state management and to restore a cold state.
|
|
func (s *Store) ArchivedPointRoot(ctx context.Context, slot types.Slot) [32]byte {
|
|
_, span := trace.StartSpan(ctx, "BeaconDB.ArchivedPointRoot")
|
|
defer span.End()
|
|
|
|
var blockRoot []byte
|
|
if err := s.db.View(func(tx *bolt.Tx) error {
|
|
bucket := tx.Bucket(stateSlotIndicesBucket)
|
|
blockRoot = bucket.Get(bytesutil.SlotToBytesBigEndian(slot))
|
|
return nil
|
|
}); err != nil { // This view never returns an error, but we'll handle anyway for sanity.
|
|
panic(err)
|
|
}
|
|
|
|
return bytesutil.ToBytes32(blockRoot)
|
|
}
|
|
|
|
// HasArchivedPoint returns true if an archived point exists in DB.
|
|
func (s *Store) HasArchivedPoint(ctx context.Context, slot types.Slot) bool {
|
|
_, span := trace.StartSpan(ctx, "BeaconDB.HasArchivedPoint")
|
|
defer span.End()
|
|
var exists bool
|
|
if err := s.db.View(func(tx *bolt.Tx) error {
|
|
iBucket := tx.Bucket(stateSlotIndicesBucket)
|
|
exists = iBucket.Get(bytesutil.SlotToBytesBigEndian(slot)) != nil
|
|
return nil
|
|
}); err != nil { // This view never returns an error, but we'll handle anyway for sanity.
|
|
panic(err)
|
|
}
|
|
return exists
|
|
}
|