mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
78a25f99c3
* Update fastssz * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fmt * gaz * Merge refs/heads/master into update-fssz * goimports * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Fix * fix ethereumapis * fix again * kafka * fix gen file * fix compute signing root * gofmt * checkpoint progress * progress * checkpoint * progress * Fix build * checkpoint * helpers * Another test fixed * gaz * another test fix * gofmt * some fixes * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fix one test * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fill empty checkpoint roots * more padding * more padding * Fix //beacon-chain/rpc/debug:go_default_test * fix //beacon-chain/core/state:go_default_test * fix //beacon-chain/core/state:go_default_test * fix some htr errors * fix //slasher/rpc:go_default_test * Progress on //beacon-chain/core/blocks:go_default_test * Progress on //beacon-chain/core/blocks:go_default_test * Progress on //beacon-chain/core/blocks:go_default_test * fix //slasher/db/kv:go_default_test * progress * fix //beacon-chain/sync/initial-sync:go_raceon_test * gofmt and gaz * fix one more test, taking a break * Fix //beacon-chain/core/blocks:go_default_test * Complete beacon-chain/powchain * Do most of beacon-chain/rpc/beacon/ * Do most of beacon-chain/blockchain * fix //beacon-chain/operations/attestations/kv:go_default_test * Fix //beacon-chain/cache/depositcache:go_default_test * Fix //slasher/detection:go_default_test * Progress * fix //beacon-chain/rpc/validator:go_default_test * gofmt * fix //validator/client:go_default_test * fix * fix //beacon-chain/blockchain:go_raceoff_test * fix //beacon-chain/rpc/beacon:go_default_test * fix 1 of 4 shards in //beacon-chain/sync:go_default_test * Fix //beacon-chain/sync:go_default_test and gofmt * prevent panic * fix //beacon-chain/state/stategen:go_default_test * fix * Merge branch 'master' of github.com:prysmaticlabs/prysm into update-fssz * fix most tests * Self review, go mod tidy, run regen scripts * fix slasher * Update ethereumapis * disable spawn strategy override * Merge refs/heads/master into update-fssz * Merge refs/heads/master into update-fssz * Remove extra line in imports * Remove extra line in imports * Gofmt * PR feedback from @nisdas
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
bolt "go.etcd.io/bbolt"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// VoluntaryExit retrieval by signing root.
|
|
func (kv *Store) VoluntaryExit(ctx context.Context, exitRoot [32]byte) (*ethpb.VoluntaryExit, error) {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.VoluntaryExit")
|
|
defer span.End()
|
|
enc, err := kv.voluntaryExitBytes(ctx, exitRoot)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(enc) == 0 {
|
|
return nil, nil
|
|
}
|
|
exit := ðpb.VoluntaryExit{}
|
|
if err := decode(ctx, enc, exit); err != nil {
|
|
return nil, err
|
|
}
|
|
return exit, nil
|
|
}
|
|
|
|
// HasVoluntaryExit verifies if a voluntary exit is stored in the db by its signing root.
|
|
func (kv *Store) HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.HasVoluntaryExit")
|
|
defer span.End()
|
|
enc, err := kv.voluntaryExitBytes(ctx, exitRoot)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return len(enc) > 0
|
|
}
|
|
|
|
// SaveVoluntaryExit to the db by its signing root.
|
|
func (kv *Store) SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveVoluntaryExit")
|
|
defer span.End()
|
|
exitRoot, err := exit.HashTreeRoot()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
enc, err := encode(ctx, exit)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return kv.db.Update(func(tx *bolt.Tx) error {
|
|
bucket := tx.Bucket(voluntaryExitsBucket)
|
|
return bucket.Put(exitRoot[:], enc)
|
|
})
|
|
}
|
|
|
|
func (kv *Store) voluntaryExitBytes(ctx context.Context, exitRoot [32]byte) ([]byte, error) {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.voluntaryExitBytes")
|
|
defer span.End()
|
|
var dst []byte
|
|
err := kv.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(voluntaryExitsBucket)
|
|
dst = bkt.Get(exitRoot[:])
|
|
return nil
|
|
})
|
|
return dst, err
|
|
}
|
|
|
|
// deleteVoluntaryExit clears a voluntary exit from the db by its signing root.
|
|
func (kv *Store) deleteVoluntaryExit(ctx context.Context, exitRoot [32]byte) error {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.deleteVoluntaryExit")
|
|
defer span.End()
|
|
return kv.db.Update(func(tx *bolt.Tx) error {
|
|
bucket := tx.Bucket(voluntaryExitsBucket)
|
|
return bucket.Delete(exitRoot[:])
|
|
})
|
|
}
|