Skip to content

Commit eddaea8

Browse files
authored
Prepare Slasher for Production (#5020)
* rem slasher proto * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * add a bit more better logging * Empty db fix * Improve logs * Fix small issues in spanner, improvements * Change costs back to 1 for now * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into cleanup-slasher * Change the cache back to 0 * Cleanup * Merge branch 'master' into cleanup-slasher * lint * added in better spans * log * rem spanner in super intensive operation * Merge branch 'master' into cleanup-slasher * add todo * Merge branch 'cleanup-slasher' of github.com:prysmaticlabs/prysm into cleanup-slasher * Merge branch 'master' into cleanup-slasher * Apply suggestions from code review * no logrus * Merge branch 'master' into cleanup-slasher * Merge branch 'cleanup-slasher' of https://github.com/prysmaticlabs/Prysm into cleanup-slasher * Remove spammy logs * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into cleanup-slasher * gaz * Rename func * Add back needed code * Add todo * Add span to cache func
1 parent 300d072 commit eddaea8

File tree

13 files changed

+176
-161
lines changed

13 files changed

+176
-161
lines changed

slasher/db/iface/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type WriteAccessDatabase interface {
6262

6363
// MinMaxSpan related methods.
6464
SaveEpochSpansMap(ctx context.Context, epoch uint64, spanMap map[uint64]detectionTypes.Span) error
65-
SaveValidatorEpochSpans(ctx context.Context, validatorIdx uint64, epoch uint64, spans detectionTypes.Span) error
65+
SaveValidatorEpochSpan(ctx context.Context, validatorIdx uint64, epoch uint64, spans detectionTypes.Span) error
6666
SaveCachedSpansMaps(ctx context.Context) error
6767
DeleteEpochSpans(ctx context.Context, validatorIdx uint64) error
6868
DeleteValidatorSpanByEpoch(ctx context.Context, validatorIdx uint64, epoch uint64) error

slasher/db/kv/attester_slashings.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func unmarshalAttSlashings(encoded [][]byte) ([]*ethpb.AttesterSlashing, error)
3838
// AttesterSlashings accepts a status and returns all slashings with this status.
3939
// returns empty []*ethpb.AttesterSlashing if no slashing has been found with this status.
4040
func (db *Store) AttesterSlashings(ctx context.Context, status types.SlashingStatus) ([]*ethpb.AttesterSlashing, error) {
41-
ctx, span := trace.StartSpan(ctx, "SlasherDB.AttesterSlashings")
41+
ctx, span := trace.StartSpan(ctx, "slasherDB.AttesterSlashings")
4242
defer span.End()
4343
encoded := make([][]byte, 0)
4444
err := db.view(func(tx *bolt.Tx) error {
@@ -59,7 +59,7 @@ func (db *Store) AttesterSlashings(ctx context.Context, status types.SlashingSta
5959

6060
// DeleteAttesterSlashing deletes an attester slashing proof from db.
6161
func (db *Store) DeleteAttesterSlashing(ctx context.Context, attesterSlashing *ethpb.AttesterSlashing) error {
62-
ctx, span := trace.StartSpan(ctx, "SlasherDB.DeleteAttesterSlashing")
62+
ctx, span := trace.StartSpan(ctx, "slasherDB.DeleteAttesterSlashing")
6363
defer span.End()
6464
root, err := hashutil.HashProto(attesterSlashing)
6565
if err != nil {
@@ -80,7 +80,7 @@ func (db *Store) DeleteAttesterSlashing(ctx context.Context, attesterSlashing *e
8080

8181
// HasAttesterSlashing returns true and slashing status if a slashing is found in the db.
8282
func (db *Store) HasAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) (bool, types.SlashingStatus, error) {
83-
ctx, span := trace.StartSpan(ctx, "SlasherDB.HasAttesterSlashing")
83+
ctx, span := trace.StartSpan(ctx, "slasherDB.HasAttesterSlashing")
8484
defer span.End()
8585
var status types.SlashingStatus
8686
var found bool
@@ -103,7 +103,7 @@ func (db *Store) HasAttesterSlashing(ctx context.Context, slashing *ethpb.Attest
103103

104104
// SaveAttesterSlashing accepts a slashing proof and its status and writes it to disk.
105105
func (db *Store) SaveAttesterSlashing(ctx context.Context, status types.SlashingStatus, slashing *ethpb.AttesterSlashing) error {
106-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveAttesterSlashing")
106+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveAttesterSlashing")
107107
defer span.End()
108108
enc, err := proto.Marshal(slashing)
109109
if err != nil {
@@ -120,7 +120,7 @@ func (db *Store) SaveAttesterSlashing(ctx context.Context, status types.Slashing
120120

121121
// SaveAttesterSlashings accepts a slice of slashing proof and its status and writes it to disk.
122122
func (db *Store) SaveAttesterSlashings(ctx context.Context, status types.SlashingStatus, slashings []*ethpb.AttesterSlashing) error {
123-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveAttesterSlashings")
123+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveAttesterSlashings")
124124
defer span.End()
125125
enc := make([][]byte, len(slashings))
126126
key := make([][]byte, len(slashings))
@@ -148,7 +148,7 @@ func (db *Store) SaveAttesterSlashings(ctx context.Context, status types.Slashin
148148

149149
// GetLatestEpochDetected returns the latest detected epoch from db.
150150
func (db *Store) GetLatestEpochDetected(ctx context.Context) (uint64, error) {
151-
ctx, span := trace.StartSpan(ctx, "SlasherDB.GetLatestEpochDetected")
151+
ctx, span := trace.StartSpan(ctx, "slasherDB.GetLatestEpochDetected")
152152
defer span.End()
153153
var epoch uint64
154154
err := db.view(func(tx *bolt.Tx) error {
@@ -166,7 +166,7 @@ func (db *Store) GetLatestEpochDetected(ctx context.Context) (uint64, error) {
166166

167167
// SetLatestEpochDetected sets the latest slashing detected epoch in db.
168168
func (db *Store) SetLatestEpochDetected(ctx context.Context, epoch uint64) error {
169-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SetLatestEpochDetected")
169+
ctx, span := trace.StartSpan(ctx, "slasherDB.SetLatestEpochDetected")
170170
defer span.End()
171171
return db.update(func(tx *bolt.Tx) error {
172172
b := tx.Bucket(slashingBucket)

slasher/db/kv/block_header.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func unmarshalBlockHeader(ctx context.Context, enc []byte) (*ethpb.SignedBeaconBlockHeader, error) {
17-
ctx, span := trace.StartSpan(ctx, "SlasherDB.unmarshalBlockHeader")
17+
ctx, span := trace.StartSpan(ctx, "slasherDB.unmarshalBlockHeader")
1818
defer span.End()
1919
protoBlockHeader := &ethpb.SignedBeaconBlockHeader{}
2020
err := proto.Unmarshal(enc, protoBlockHeader)
@@ -27,7 +27,7 @@ func unmarshalBlockHeader(ctx context.Context, enc []byte) (*ethpb.SignedBeaconB
2727
// BlockHeaders accepts an epoch and validator id and returns the corresponding block header array.
2828
// Returns nil if the block header for those values does not exist.
2929
func (db *Store) BlockHeaders(ctx context.Context, epoch uint64, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error) {
30-
ctx, span := trace.StartSpan(ctx, "SlasherDB.BlockHeaders")
30+
ctx, span := trace.StartSpan(ctx, "slasherDB.BlockHeaders")
3131
defer span.End()
3232
var blockHeaders []*ethpb.SignedBeaconBlockHeader
3333
err := db.view(func(tx *bolt.Tx) error {
@@ -47,7 +47,7 @@ func (db *Store) BlockHeaders(ctx context.Context, epoch uint64, validatorID uin
4747

4848
// HasBlockHeader accepts an epoch and validator id and returns true if the block header exists.
4949
func (db *Store) HasBlockHeader(ctx context.Context, epoch uint64, validatorID uint64) bool {
50-
ctx, span := trace.StartSpan(ctx, "SlasherDB.HasBlockHeader")
50+
ctx, span := trace.StartSpan(ctx, "slasherDB.HasBlockHeader")
5151
defer span.End()
5252
prefix := encodeEpochValidatorID(epoch, validatorID)
5353
var hasBlockHeader bool
@@ -67,7 +67,7 @@ func (db *Store) HasBlockHeader(ctx context.Context, epoch uint64, validatorID u
6767

6868
// SaveBlockHeader accepts a block header and writes it to disk.
6969
func (db *Store) SaveBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error {
70-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveBlockHeader")
70+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveBlockHeader")
7171
defer span.End()
7272
key := encodeEpochValidatorIDSig(epoch, validatorID, blockHeader.Signature)
7373
enc, err := proto.Marshal(blockHeader)
@@ -96,7 +96,7 @@ func (db *Store) SaveBlockHeader(ctx context.Context, epoch uint64, validatorID
9696

9797
// DeleteBlockHeader deletes a block header using the epoch and validator id.
9898
func (db *Store) DeleteBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error {
99-
ctx, span := trace.StartSpan(ctx, "SlasherDB.DeleteBlockHeader")
99+
ctx, span := trace.StartSpan(ctx, "slasherDB.DeleteBlockHeader")
100100
defer span.End()
101101
key := encodeEpochValidatorIDSig(epoch, validatorID, blockHeader.Signature)
102102
return db.update(func(tx *bolt.Tx) error {
@@ -110,7 +110,7 @@ func (db *Store) DeleteBlockHeader(ctx context.Context, epoch uint64, validatorI
110110

111111
// PruneBlockHistory leaves only records younger then history size.
112112
func (db *Store) PruneBlockHistory(ctx context.Context, currentEpoch uint64, pruningEpochAge uint64) error {
113-
ctx, span := trace.StartSpan(ctx, "SlasherDB.pruneBlockHistory")
113+
ctx, span := trace.StartSpan(ctx, "slasherDB.pruneBlockHistory")
114114
defer span.End()
115115
pruneTill := int64(currentEpoch) - int64(pruningEpochAge)
116116
if pruneTill <= 0 {

slasher/db/kv/chain_data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// ChainHead retrieves the persisted chain head from the database accordingly.
1414
func (db *Store) ChainHead(ctx context.Context) (*ethpb.ChainHead, error) {
15-
ctx, span := trace.StartSpan(ctx, "SlasherDB.ChainHead")
15+
ctx, span := trace.StartSpan(ctx, "slasherDB.ChainHead")
1616
defer span.End()
1717
var res *ethpb.ChainHead
1818
if err := db.update(func(tx *bolt.Tx) error {
@@ -31,7 +31,7 @@ func (db *Store) ChainHead(ctx context.Context) (*ethpb.ChainHead, error) {
3131

3232
// SaveChainHead accepts a beacon chain head object and persists it to the DB.
3333
func (db *Store) SaveChainHead(ctx context.Context, head *ethpb.ChainHead) error {
34-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveChainHead")
34+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveChainHead")
3535
defer span.End()
3636
enc, err := proto.Marshal(head)
3737
if err != nil {

slasher/db/kv/indexed_attestations.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func unmarshalIndexedAttestation(ctx context.Context, enc []byte) (*ethpb.IndexedAttestation, error) {
16-
ctx, span := trace.StartSpan(ctx, "SlasherDB.unmarshalIndexedAttestation")
16+
ctx, span := trace.StartSpan(ctx, "slasherDB.unmarshalIndexedAttestation")
1717
defer span.End()
1818
protoIdxAtt := &ethpb.IndexedAttestation{}
1919
err := proto.Unmarshal(enc, protoIdxAtt)
@@ -27,7 +27,7 @@ func unmarshalIndexedAttestation(ctx context.Context, enc []byte) (*ethpb.Indexe
2727
// indexed attestations.
2828
// Returns nil if the indexed attestation does not exist with that target epoch.
2929
func (db *Store) IndexedAttestationsForTarget(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error) {
30-
ctx, span := trace.StartSpan(ctx, "SlasherDB.IndexedAttestationsForTarget")
30+
ctx, span := trace.StartSpan(ctx, "slasherDB.IndexedAttestationsForTarget")
3131
defer span.End()
3232
var idxAtts []*ethpb.IndexedAttestation
3333
key := bytesutil.Bytes8(targetEpoch)
@@ -48,7 +48,7 @@ func (db *Store) IndexedAttestationsForTarget(ctx context.Context, targetEpoch u
4848
// IndexedAttestationsWithPrefix accepts a target epoch and signature bytes to find all attestations with the requested prefix.
4949
// Returns nil if the indexed attestation does not exist with that target epoch.
5050
func (db *Store) IndexedAttestationsWithPrefix(ctx context.Context, targetEpoch uint64, sigBytes []byte) ([]*ethpb.IndexedAttestation, error) {
51-
ctx, span := trace.StartSpan(ctx, "SlasherDB.IndexedAttestationsWithPrefix")
51+
ctx, span := trace.StartSpan(ctx, "slasherDB.IndexedAttestationsWithPrefix")
5252
defer span.End()
5353
var idxAtts []*ethpb.IndexedAttestation
5454
key := encodeEpochSig(targetEpoch, sigBytes[:])
@@ -68,7 +68,7 @@ func (db *Store) IndexedAttestationsWithPrefix(ctx context.Context, targetEpoch
6868

6969
// HasIndexedAttestation accepts an attestation and returns true if it exists in the DB.
7070
func (db *Store) HasIndexedAttestation(ctx context.Context, att *ethpb.IndexedAttestation) (bool, error) {
71-
ctx, span := trace.StartSpan(ctx, "SlasherDB.HasIndexedAttestation")
71+
ctx, span := trace.StartSpan(ctx, "slasherDB.HasIndexedAttestation")
7272
defer span.End()
7373
key := encodeEpochSig(att.Data.Target.Epoch, att.Signature)
7474
var hasAttestation bool
@@ -88,7 +88,7 @@ func (db *Store) HasIndexedAttestation(ctx context.Context, att *ethpb.IndexedAt
8888

8989
// SaveIndexedAttestation accepts an indexed attestation and writes it to the DB.
9090
func (db *Store) SaveIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error {
91-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveIndexedAttestation")
91+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveIndexedAttestation")
9292
defer span.End()
9393
key := encodeEpochSig(idxAttestation.Data.Target.Epoch, idxAttestation.Signature)
9494
enc, err := proto.Marshal(idxAttestation)
@@ -113,7 +113,7 @@ func (db *Store) SaveIndexedAttestation(ctx context.Context, idxAttestation *eth
113113

114114
// SaveIndexedAttestations accepts multiple indexed attestations and writes them to the DB.
115115
func (db *Store) SaveIndexedAttestations(ctx context.Context, idxAttestations []*ethpb.IndexedAttestation) error {
116-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveIndexedAttestations")
116+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveIndexedAttestations")
117117
defer span.End()
118118
keys := make([][]byte, len(idxAttestations))
119119
marshaledAtts := make([][]byte, len(idxAttestations))
@@ -145,7 +145,7 @@ func (db *Store) SaveIndexedAttestations(ctx context.Context, idxAttestations []
145145

146146
// DeleteIndexedAttestation deletes a indexed attestation using the slot and its root as keys in their respective buckets.
147147
func (db *Store) DeleteIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error {
148-
ctx, span := trace.StartSpan(ctx, "SlasherDB.DeleteIndexedAttestation")
148+
ctx, span := trace.StartSpan(ctx, "slasherDB.DeleteIndexedAttestation")
149149
defer span.End()
150150
key := encodeEpochSig(idxAttestation.Data.Target.Epoch, idxAttestation.Signature)
151151
return db.update(func(tx *bolt.Tx) error {
@@ -163,7 +163,7 @@ func (db *Store) DeleteIndexedAttestation(ctx context.Context, idxAttestation *e
163163

164164
// PruneAttHistory removes all attestations from the DB older than the pruning epoch age.
165165
func (db *Store) PruneAttHistory(ctx context.Context, currentEpoch uint64, pruningEpochAge uint64) error {
166-
ctx, span := trace.StartSpan(ctx, "SlasherDB.pruneAttHistory")
166+
ctx, span := trace.StartSpan(ctx, "slasherDB.pruneAttHistory")
167167
defer span.End()
168168
pruneFromEpoch := int64(currentEpoch) - int64(pruningEpochAge)
169169
if pruneFromEpoch <= 0 {
@@ -186,7 +186,7 @@ func (db *Store) PruneAttHistory(ctx context.Context, currentEpoch uint64, pruni
186186
// LatestIndexedAttestationsTargetEpoch returns latest target epoch in db
187187
// returns 0 if there is no indexed attestations in db.
188188
func (db *Store) LatestIndexedAttestationsTargetEpoch(ctx context.Context) (uint64, error) {
189-
ctx, span := trace.StartSpan(ctx, "SlasherDB.LatestIndexedAttestationsTargetEpoch")
189+
ctx, span := trace.StartSpan(ctx, "slasherDB.LatestIndexedAttestationsTargetEpoch")
190190
defer span.End()
191191
var lt uint64
192192
err := db.view(func(tx *bolt.Tx) error {

slasher/db/kv/proposer_slashings.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func unmarshalProposerSlashing(ctx context.Context, enc []byte) (*ethpb.ProposerSlashing, error) {
17-
ctx, span := trace.StartSpan(ctx, "SlasherDB.unmarshalProposerSlashing")
17+
ctx, span := trace.StartSpan(ctx, "slasherDB.unmarshalProposerSlashing")
1818
defer span.End()
1919
protoSlashing := &ethpb.ProposerSlashing{}
2020
if err := proto.Unmarshal(enc, protoSlashing); err != nil {
@@ -24,7 +24,7 @@ func unmarshalProposerSlashing(ctx context.Context, enc []byte) (*ethpb.Proposer
2424
}
2525

2626
func unmarshalProposerSlashingArray(ctx context.Context, encoded [][]byte) ([]*ethpb.ProposerSlashing, error) {
27-
ctx, span := trace.StartSpan(ctx, "SlasherDB.unmarshalProposerSlashingArray")
27+
ctx, span := trace.StartSpan(ctx, "slasherDB.unmarshalProposerSlashingArray")
2828
defer span.End()
2929
proposerSlashings := make([]*ethpb.ProposerSlashing, len(encoded))
3030
for i, enc := range encoded {
@@ -39,7 +39,7 @@ func unmarshalProposerSlashingArray(ctx context.Context, encoded [][]byte) ([]*e
3939

4040
// ProposalSlashingsByStatus returns all the proposal slashing proofs with a certain status.
4141
func (db *Store) ProposalSlashingsByStatus(ctx context.Context, status types.SlashingStatus) ([]*ethpb.ProposerSlashing, error) {
42-
ctx, span := trace.StartSpan(ctx, "SlasherDB.ProposalSlashingsByStatus")
42+
ctx, span := trace.StartSpan(ctx, "slasherDB.ProposalSlashingsByStatus")
4343
defer span.End()
4444
encoded := make([][]byte, 0)
4545
err := db.view(func(tx *bolt.Tx) error {
@@ -60,7 +60,7 @@ func (db *Store) ProposalSlashingsByStatus(ctx context.Context, status types.Sla
6060

6161
// DeleteProposerSlashing deletes a proposer slashing proof.
6262
func (db *Store) DeleteProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error {
63-
ctx, span := trace.StartSpan(ctx, "SlasherDB.DeleteProposerSlashing")
63+
ctx, span := trace.StartSpan(ctx, "slasherDB.DeleteProposerSlashing")
6464
defer span.End()
6565
root, err := hashutil.HashProto(slashing)
6666
if err != nil {
@@ -79,7 +79,7 @@ func (db *Store) DeleteProposerSlashing(ctx context.Context, slashing *ethpb.Pro
7979

8080
// HasProposerSlashing returns the slashing key if it is found in db.
8181
func (db *Store) HasProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) (bool, types.SlashingStatus, error) {
82-
ctx, span := trace.StartSpan(ctx, "SlasherDB.HasProposerSlashing")
82+
ctx, span := trace.StartSpan(ctx, "slasherDB.HasProposerSlashing")
8383
defer span.End()
8484
var status types.SlashingStatus
8585
var found bool
@@ -103,7 +103,7 @@ func (db *Store) HasProposerSlashing(ctx context.Context, slashing *ethpb.Propos
103103

104104
// SaveProposerSlashing accepts a proposer slashing and its status header and writes it to disk.
105105
func (db *Store) SaveProposerSlashing(ctx context.Context, status types.SlashingStatus, slashing *ethpb.ProposerSlashing) error {
106-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveProposerSlashing")
106+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveProposerSlashing")
107107
defer span.End()
108108
enc, err := proto.Marshal(slashing)
109109
if err != nil {
@@ -120,7 +120,7 @@ func (db *Store) SaveProposerSlashing(ctx context.Context, status types.Slashing
120120

121121
// SaveProposerSlashings accepts a slice of slashing proof and its status and writes it to disk.
122122
func (db *Store) SaveProposerSlashings(ctx context.Context, status types.SlashingStatus, slashings []*ethpb.ProposerSlashing) error {
123-
ctx, span := trace.StartSpan(ctx, "SlasherDB.SaveProposerSlashings")
123+
ctx, span := trace.StartSpan(ctx, "slasherDB.SaveProposerSlashings")
124124
defer span.End()
125125
encSlashings := make([][]byte, len(slashings))
126126
keys := make([][]byte, len(slashings))

0 commit comments

Comments
 (0)