mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
add all proper spans to methods (#3248)
This commit is contained in:
parent
3f0d1c1d41
commit
900b550864
@ -22,6 +22,7 @@ go_library(
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||
"@io_opencensus_go//trace:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -11,10 +11,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// Attestation retrieval by attestation data root.
|
||||
func (k *Store) Attestation(ctx context.Context, attDataRoot [32]byte) (*ethpb.Attestation, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.Attestation")
|
||||
defer span.End()
|
||||
var att *ethpb.Attestation
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(attestationsBucket)
|
||||
@ -30,6 +33,8 @@ func (k *Store) Attestation(ctx context.Context, attDataRoot [32]byte) (*ethpb.A
|
||||
|
||||
// Attestations retrieves a list of attestations by filter criteria.
|
||||
func (k *Store) Attestations(ctx context.Context, f *filters.QueryFilter) ([]*ethpb.Attestation, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.Attestations")
|
||||
defer span.End()
|
||||
atts := make([]*ethpb.Attestation, 0)
|
||||
err := k.db.Batch(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(attestationsBucket)
|
||||
@ -73,6 +78,8 @@ func (k *Store) Attestations(ctx context.Context, f *filters.QueryFilter) ([]*et
|
||||
|
||||
// HasAttestation checks if an attestation by its attestation data root exists in the db.
|
||||
func (k *Store) HasAttestation(ctx context.Context, attDataRoot [32]byte) bool {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HasAttestation")
|
||||
defer span.End()
|
||||
exists := false
|
||||
// #nosec G104. Always returns nil.
|
||||
k.db.View(func(tx *bolt.Tx) error {
|
||||
@ -86,6 +93,8 @@ func (k *Store) HasAttestation(ctx context.Context, attDataRoot [32]byte) bool {
|
||||
// DeleteAttestation by attestation data root.
|
||||
// TODO(#3064): Add the ability for batch deletions.
|
||||
func (k *Store) DeleteAttestation(ctx context.Context, attDataRoot [32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.DeleteAttestation")
|
||||
defer span.End()
|
||||
return k.db.Update(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(attestationsBucket)
|
||||
enc := bkt.Get(attDataRoot[:])
|
||||
@ -106,6 +115,8 @@ func (k *Store) DeleteAttestation(ctx context.Context, attDataRoot [32]byte) err
|
||||
|
||||
// SaveAttestation to the db.
|
||||
func (k *Store) SaveAttestation(ctx context.Context, att *ethpb.Attestation) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveAttestation")
|
||||
defer span.End()
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -126,6 +137,8 @@ func (k *Store) SaveAttestation(ctx context.Context, att *ethpb.Attestation) err
|
||||
|
||||
// SaveAttestations via batch updates to the db.
|
||||
func (k *Store) SaveAttestations(ctx context.Context, atts []*ethpb.Attestation) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveAttestations")
|
||||
defer span.End()
|
||||
encodedValues := make([][]byte, len(atts))
|
||||
keys := make([][]byte, len(atts))
|
||||
for i := 0; i < len(atts); i++ {
|
||||
|
@ -12,10 +12,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// Block retrieval by root.
|
||||
func (k *Store) Block(ctx context.Context, blockRoot [32]byte) (*ethpb.BeaconBlock, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.Block")
|
||||
defer span.End()
|
||||
var block *ethpb.BeaconBlock
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(blocksBucket)
|
||||
@ -31,6 +34,8 @@ func (k *Store) Block(ctx context.Context, blockRoot [32]byte) (*ethpb.BeaconBlo
|
||||
|
||||
// HeadBlock returns the latest canonical block in eth2.
|
||||
func (k *Store) HeadBlock(ctx context.Context) (*ethpb.BeaconBlock, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HeadBlock")
|
||||
defer span.End()
|
||||
var headBlock *ethpb.BeaconBlock
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(validatorsBucket)
|
||||
@ -50,6 +55,8 @@ func (k *Store) HeadBlock(ctx context.Context) (*ethpb.BeaconBlock, error) {
|
||||
|
||||
// Blocks retrieves a list of beacon blocks by filter criteria.
|
||||
func (k *Store) Blocks(ctx context.Context, f *filters.QueryFilter) ([]*ethpb.BeaconBlock, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.Blocks")
|
||||
defer span.End()
|
||||
blocks := make([]*ethpb.BeaconBlock, 0)
|
||||
err := k.db.Batch(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(blocksBucket)
|
||||
@ -117,6 +124,8 @@ func (k *Store) Blocks(ctx context.Context, f *filters.QueryFilter) ([]*ethpb.Be
|
||||
|
||||
// BlockRoots retrieves a list of beacon block roots by filter criteria.
|
||||
func (k *Store) BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][]byte, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.BlockRoots")
|
||||
defer span.End()
|
||||
blocks, err := k.Blocks(ctx, f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -134,6 +143,8 @@ func (k *Store) BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][]byt
|
||||
|
||||
// HasBlock checks if a block by root exists in the db.
|
||||
func (k *Store) HasBlock(ctx context.Context, blockRoot [32]byte) bool {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HasBlock")
|
||||
defer span.End()
|
||||
exists := false
|
||||
// #nosec G104. Always returns nil.
|
||||
k.db.View(func(tx *bolt.Tx) error {
|
||||
@ -147,6 +158,8 @@ func (k *Store) HasBlock(ctx context.Context, blockRoot [32]byte) bool {
|
||||
// DeleteBlock by block root.
|
||||
// TODO(#3064): Add the ability for batch deletions.
|
||||
func (k *Store) DeleteBlock(ctx context.Context, blockRoot [32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.DeleteBlock")
|
||||
defer span.End()
|
||||
return k.db.Update(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(blocksBucket)
|
||||
enc := bkt.Get(blockRoot[:])
|
||||
@ -167,6 +180,8 @@ func (k *Store) DeleteBlock(ctx context.Context, blockRoot [32]byte) error {
|
||||
|
||||
// SaveBlock to the db.
|
||||
func (k *Store) SaveBlock(ctx context.Context, block *ethpb.BeaconBlock) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlock")
|
||||
defer span.End()
|
||||
blockRoot, err := ssz.SigningRoot(block)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -187,6 +202,8 @@ func (k *Store) SaveBlock(ctx context.Context, block *ethpb.BeaconBlock) error {
|
||||
|
||||
// SaveBlocks via batch updates to the db.
|
||||
func (k *Store) SaveBlocks(ctx context.Context, blocks []*ethpb.BeaconBlock) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveBlocks")
|
||||
defer span.End()
|
||||
encodedValues := make([][]byte, len(blocks))
|
||||
keys := make([][]byte, len(blocks))
|
||||
for i := 0; i < len(blocks); i++ {
|
||||
@ -218,6 +235,8 @@ func (k *Store) SaveBlocks(ctx context.Context, blocks []*ethpb.BeaconBlock) err
|
||||
|
||||
// SaveHeadBlockRoot to the db.
|
||||
func (k *Store) SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveHeadBlockRoot")
|
||||
defer span.End()
|
||||
return k.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(blocksBucket)
|
||||
return bucket.Put(headBlockRootKey, blockRoot[:])
|
||||
|
@ -7,11 +7,14 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// State returns the saved state using block's signing root,
|
||||
// this particular block was used to generate the state.
|
||||
func (k *Store) State(ctx context.Context, blockRoot [32]byte) (*pb.BeaconState, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.State")
|
||||
defer span.End()
|
||||
var s *pb.BeaconState
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(stateBucket)
|
||||
@ -29,6 +32,8 @@ func (k *Store) State(ctx context.Context, blockRoot [32]byte) (*pb.BeaconState,
|
||||
|
||||
// HeadState returns the latest canonical state in beacon chain.
|
||||
func (k *Store) HeadState(ctx context.Context) (*pb.BeaconState, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HeadState")
|
||||
defer span.End()
|
||||
var s *pb.BeaconState
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
// Retrieve head block's signing root from blocks bucket,
|
||||
@ -51,6 +56,8 @@ func (k *Store) HeadState(ctx context.Context) (*pb.BeaconState, error) {
|
||||
|
||||
// SaveState stores a state to the db using block's signing root which was used to generate the state.
|
||||
func (k *Store) SaveState(ctx context.Context, state *pb.BeaconState, blockRoot [32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveState")
|
||||
defer span.End()
|
||||
enc, err := proto.Marshal(state)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -8,10 +8,13 @@ import (
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// ValidatorLatestVote retrieval by validator index.
|
||||
func (k *Store) ValidatorLatestVote(ctx context.Context, validatorIdx uint64) (*pb.ValidatorLatestVote, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.ValidatorLatestVote")
|
||||
defer span.End()
|
||||
buf := uint64ToBytes(validatorIdx)
|
||||
var latestVote *pb.ValidatorLatestVote
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
@ -28,6 +31,8 @@ func (k *Store) ValidatorLatestVote(ctx context.Context, validatorIdx uint64) (*
|
||||
|
||||
// HasValidatorLatestVote verifies if a validator index has a latest vote stored in the db.
|
||||
func (k *Store) HasValidatorLatestVote(ctx context.Context, validatorIdx uint64) bool {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HasValidatorLatestVote")
|
||||
defer span.End()
|
||||
buf := uint64ToBytes(validatorIdx)
|
||||
exists := false
|
||||
// #nosec G104. Always returns nil.
|
||||
@ -41,6 +46,8 @@ func (k *Store) HasValidatorLatestVote(ctx context.Context, validatorIdx uint64)
|
||||
|
||||
// SaveValidatorLatestVote by validator index.
|
||||
func (k *Store) SaveValidatorLatestVote(ctx context.Context, validatorIdx uint64, vote *pb.ValidatorLatestVote) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveValidatorLatestVote")
|
||||
defer span.End()
|
||||
buf := uint64ToBytes(validatorIdx)
|
||||
enc, err := proto.Marshal(vote)
|
||||
if err != nil {
|
||||
@ -54,6 +61,8 @@ func (k *Store) SaveValidatorLatestVote(ctx context.Context, validatorIdx uint64
|
||||
|
||||
// ValidatorIndex by public key.
|
||||
func (k *Store) ValidatorIndex(ctx context.Context, publicKey [48]byte) (uint64, bool, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.ValidatorIndex")
|
||||
defer span.End()
|
||||
var validatorIdx uint64
|
||||
var ok bool
|
||||
err := k.db.View(func(tx *bolt.Tx) error {
|
||||
@ -76,6 +85,8 @@ func (k *Store) ValidatorIndex(ctx context.Context, publicKey [48]byte) (uint64,
|
||||
|
||||
// HasValidatorIndex verifies if a validator's index by public key exists in the db.
|
||||
func (k *Store) HasValidatorIndex(ctx context.Context, publicKey [48]byte) bool {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HasValidatorIndex")
|
||||
defer span.End()
|
||||
exists := false
|
||||
// #nosec G104. Always returns nil.
|
||||
k.db.View(func(tx *bolt.Tx) error {
|
||||
@ -88,6 +99,8 @@ func (k *Store) HasValidatorIndex(ctx context.Context, publicKey [48]byte) bool
|
||||
|
||||
// DeleteValidatorIndex clears a validator index from the db by the validator's public key.
|
||||
func (k *Store) DeleteValidatorIndex(ctx context.Context, publicKey [48]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.DeleteValidatorIndex")
|
||||
defer span.End()
|
||||
return k.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(validatorsBucket)
|
||||
return bucket.Delete(publicKey[:])
|
||||
@ -96,6 +109,8 @@ func (k *Store) DeleteValidatorIndex(ctx context.Context, publicKey [48]byte) er
|
||||
|
||||
// SaveValidatorIndex by public key in the db.
|
||||
func (k *Store) SaveValidatorIndex(ctx context.Context, publicKey [48]byte, validatorIdx uint64) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveValidatorIndex")
|
||||
defer span.End()
|
||||
return k.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(validatorsBucket)
|
||||
buf := uint64ToBytes(validatorIdx)
|
||||
|
Loading…
Reference in New Issue
Block a user