prysm-pulse/beacon-chain/db/kv/execution_chain.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

54 lines
1.3 KiB
Go

package kv
import (
"context"
"errors"
"github.com/prysmaticlabs/prysm/v3/monitoring/tracing"
v2 "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
bolt "go.etcd.io/bbolt"
"go.opencensus.io/trace"
"google.golang.org/protobuf/proto"
)
// SavePowchainData saves the pow chain data.
func (s *Store) SaveExecutionChainData(ctx context.Context, data *v2.ETH1ChainData) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveExecutionChainData")
defer span.End()
if data == nil {
err := errors.New("cannot save nil eth1data")
tracing.AnnotateError(span, err)
return err
}
err := s.db.Update(func(tx *bolt.Tx) error {
bkt := tx.Bucket(powchainBucket)
enc, err := proto.Marshal(data)
if err != nil {
return err
}
return bkt.Put(powchainDataKey, enc)
})
tracing.AnnotateError(span, err)
return err
}
// PowchainData retrieves the powchain data.
func (s *Store) ExecutionChainData(ctx context.Context) (*v2.ETH1ChainData, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.ExecutionChainData")
defer span.End()
var data *v2.ETH1ChainData
err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(powchainBucket)
enc := bkt.Get(powchainDataKey)
if len(enc) == 0 {
return nil
}
data = &v2.ETH1ChainData{}
return proto.Unmarshal(enc, data)
})
return data, err
}