2019-09-18 12:05:24 -05:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-09-18 13:41:47 -05:00
|
|
|
"github.com/boltdb/bolt"
|
2019-11-26 23:08:18 -06:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2019-09-18 13:41:47 -05:00
|
|
|
"github.com/prysmaticlabs/go-ssz"
|
2019-11-26 23:08:18 -06:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2019-09-18 13:41:47 -05:00
|
|
|
"go.opencensus.io/trace"
|
2019-09-18 12:05:24 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ArchivedActiveValidatorChanges retrieval by epoch.
|
2019-11-26 23:08:18 -06:00
|
|
|
func (k *Store) ArchivedActiveValidatorChanges(ctx context.Context, epoch uint64) (*pb.ArchivedActiveSetChanges, error) {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.ArchivedActiveValidatorChanges")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
buf := uint64ToBytes(epoch)
|
2019-11-26 23:08:18 -06:00
|
|
|
var target *pb.ArchivedActiveSetChanges
|
2019-09-18 13:41:47 -05:00
|
|
|
err := k.db.View(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(archivedValidatorSetChangesBucket)
|
|
|
|
enc := bkt.Get(buf)
|
|
|
|
if enc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-26 23:08:18 -06:00
|
|
|
target = &pb.ArchivedActiveSetChanges{}
|
2019-11-26 22:32:56 -08:00
|
|
|
return decode(enc, target)
|
2019-09-18 13:41:47 -05:00
|
|
|
})
|
|
|
|
return target, err
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveArchivedActiveValidatorChanges by epoch.
|
2019-11-26 23:08:18 -06:00
|
|
|
func (k *Store) SaveArchivedActiveValidatorChanges(ctx context.Context, epoch uint64, changes *pb.ArchivedActiveSetChanges) error {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveArchivedActiveValidatorChanges")
|
|
|
|
defer span.End()
|
|
|
|
buf := uint64ToBytes(epoch)
|
2019-11-26 22:32:56 -08:00
|
|
|
enc, err := encode(changes)
|
2019-09-18 13:41:47 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return k.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bucket := tx.Bucket(archivedValidatorSetChangesBucket)
|
|
|
|
return bucket.Put(buf, enc)
|
|
|
|
})
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ArchivedCommitteeInfo retrieval by epoch.
|
2019-11-26 23:08:18 -06:00
|
|
|
func (k *Store) ArchivedCommitteeInfo(ctx context.Context, epoch uint64) (*pb.ArchivedCommitteeInfo, error) {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.ArchivedCommitteeInfo")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
buf := uint64ToBytes(epoch)
|
2019-11-26 23:08:18 -06:00
|
|
|
var target *pb.ArchivedCommitteeInfo
|
2019-09-18 13:41:47 -05:00
|
|
|
err := k.db.View(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(archivedCommitteeInfoBucket)
|
|
|
|
enc := bkt.Get(buf)
|
|
|
|
if enc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-26 23:08:18 -06:00
|
|
|
target = &pb.ArchivedCommitteeInfo{}
|
2019-11-26 22:32:56 -08:00
|
|
|
return decode(enc, target)
|
2019-09-18 13:41:47 -05:00
|
|
|
})
|
|
|
|
return target, err
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveArchivedCommitteeInfo by epoch.
|
2019-11-26 23:08:18 -06:00
|
|
|
func (k *Store) SaveArchivedCommitteeInfo(ctx context.Context, epoch uint64, info *pb.ArchivedCommitteeInfo) error {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveArchivedCommitteeInfo")
|
|
|
|
defer span.End()
|
|
|
|
buf := uint64ToBytes(epoch)
|
2019-11-26 22:32:56 -08:00
|
|
|
enc, err := encode(info)
|
2019-09-18 13:41:47 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return k.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bucket := tx.Bucket(archivedCommitteeInfoBucket)
|
|
|
|
return bucket.Put(buf, enc)
|
|
|
|
})
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ArchivedBalances retrieval by epoch.
|
|
|
|
func (k *Store) ArchivedBalances(ctx context.Context, epoch uint64) ([]uint64, error) {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.ArchivedBalances")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
buf := uint64ToBytes(epoch)
|
|
|
|
var target []uint64
|
|
|
|
err := k.db.View(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(archivedBalancesBucket)
|
|
|
|
enc := bkt.Get(buf)
|
|
|
|
if enc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
target = make([]uint64, 0)
|
|
|
|
return ssz.Unmarshal(enc, &target)
|
|
|
|
})
|
|
|
|
return target, err
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveArchivedBalances by epoch.
|
|
|
|
func (k *Store) SaveArchivedBalances(ctx context.Context, epoch uint64, balances []uint64) error {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveArchivedBalances")
|
|
|
|
defer span.End()
|
|
|
|
buf := uint64ToBytes(epoch)
|
|
|
|
enc, err := ssz.Marshal(balances)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return k.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bucket := tx.Bucket(archivedBalancesBucket)
|
|
|
|
return bucket.Put(buf, enc)
|
|
|
|
})
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ArchivedValidatorParticipation retrieval by epoch.
|
|
|
|
func (k *Store) ArchivedValidatorParticipation(ctx context.Context, epoch uint64) (*ethpb.ValidatorParticipation, error) {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.ArchivedValidatorParticipation")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
buf := uint64ToBytes(epoch)
|
|
|
|
var target *ethpb.ValidatorParticipation
|
|
|
|
err := k.db.View(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(archivedValidatorParticipationBucket)
|
|
|
|
enc := bkt.Get(buf)
|
|
|
|
if enc == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
target = ðpb.ValidatorParticipation{}
|
2019-11-26 22:32:56 -08:00
|
|
|
return decode(enc, target)
|
2019-09-18 13:41:47 -05:00
|
|
|
})
|
|
|
|
return target, err
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SaveArchivedValidatorParticipation by epoch.
|
|
|
|
func (k *Store) SaveArchivedValidatorParticipation(ctx context.Context, epoch uint64, part *ethpb.ValidatorParticipation) error {
|
2019-09-18 13:41:47 -05:00
|
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveArchivedValidatorParticipation")
|
|
|
|
defer span.End()
|
|
|
|
buf := uint64ToBytes(epoch)
|
2019-11-26 22:32:56 -08:00
|
|
|
enc, err := encode(part)
|
2019-09-18 13:41:47 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return k.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bucket := tx.Bucket(archivedValidatorParticipationBucket)
|
|
|
|
return bucket.Put(buf, enc)
|
|
|
|
})
|
2019-09-18 12:05:24 -05:00
|
|
|
}
|