mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-30 15:06:31 +00:00
de82956088
* new interface methods * support proposer slashings * add in the new buckets * all crud for propoer slashings * attester slashings complete * all slashings crud done * right comment * deposit contract tests pass * delete out of scope methods * conform old beacon DB * comment * include interface implementations * deprecations * pass lint
117 lines
3.7 KiB
Go
117 lines
3.7 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/boltdb/bolt"
|
|
"github.com/gogo/protobuf/proto"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// VoluntaryExit by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) VoluntaryExit(ctx context.Context, exitRoot [32]byte) (*ethpb.VoluntaryExit, error) {
|
|
return nil, errors.New("unimplemented")
|
|
}
|
|
|
|
// SaveVoluntaryExit by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error {
|
|
return errors.New("unimplemented")
|
|
}
|
|
|
|
// HasVoluntaryExit by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool {
|
|
return false
|
|
}
|
|
|
|
// DeleteVoluntaryExit by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) DeleteVoluntaryExit(ctx context.Context, exitRoot [32]byte) error {
|
|
return errors.New("unimplemented")
|
|
}
|
|
|
|
// ProposerSlashing retrieval from the db.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) ProposerSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.ProposerSlashing, error) {
|
|
return nil, errors.New("unimplemented")
|
|
}
|
|
|
|
// AttesterSlashing retrieval from the db.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) AttesterSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.AttesterSlashing, error) {
|
|
return nil, errors.New("unimplemented")
|
|
}
|
|
|
|
// SaveProposerSlashing to the db.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error {
|
|
return errors.New("unimplemented")
|
|
}
|
|
|
|
// SaveAttesterSlashing to the db.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) SaveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) error {
|
|
return errors.New("unimplemented")
|
|
}
|
|
|
|
// HasProposerSlashing by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) HasProposerSlashing(ctx context.Context, slashingRoot [32]byte) bool {
|
|
return false
|
|
}
|
|
|
|
// HasAttesterSlashing by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte) bool {
|
|
return false
|
|
}
|
|
|
|
// DeleteProposerSlashing by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) DeleteProposerSlashing(ctx context.Context, slashingRoot [32]byte) error {
|
|
return errors.New("unimplemented")
|
|
}
|
|
|
|
// DeleteAttesterSlashing by root.
|
|
// DEPRECATED: Use the kv store in beacon-chain/db/kv instead.
|
|
func (db *BeaconDB) DeleteAttesterSlashing(ctx context.Context, slashingRoot [32]byte) error {
|
|
return errors.New("unimplemented")
|
|
}
|
|
|
|
// SaveExit puts the exit request into the beacon chain db.
|
|
func (db *BeaconDB) SaveExit(ctx context.Context, exit *ethpb.VoluntaryExit) error {
|
|
ctx, span := trace.StartSpan(ctx, "beaconDB.SaveExit")
|
|
defer span.End()
|
|
|
|
hash, err := hashutil.HashProto(exit)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
encodedExit, err := proto.Marshal(exit)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return db.update(func(tx *bolt.Tx) error {
|
|
a := tx.Bucket(blockOperationsBucket)
|
|
return a.Put(hash[:], encodedExit)
|
|
})
|
|
}
|
|
|
|
// HasExit checks if the exit request exists.
|
|
func (db *BeaconDB) HasExit(hash [32]byte) bool {
|
|
exists := false
|
|
if err := db.view(func(tx *bolt.Tx) error {
|
|
b := tx.Bucket(blockOperationsBucket)
|
|
exists = b.Get(hash[:]) != nil
|
|
return nil
|
|
}); err != nil {
|
|
return false
|
|
}
|
|
return exists
|
|
}
|