From 9d678b0c47ea1c5d39fc4daed32c04df0b531703 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Mon, 15 Nov 2021 23:13:52 +0800 Subject: [PATCH] Clean Up Methods In Prysm (#9903) * clean up * go simple --- beacon-chain/cache/skip_slot_cache.go | 12 +- beacon-chain/cache/skip_slot_cache_test.go | 4 +- beacon-chain/core/signing/domain.go | 4 +- beacon-chain/core/signing/domain_test.go | 4 +- beacon-chain/core/transition/transition.go | 12 +- beacon-chain/db/iface/interface.go | 13 -- beacon-chain/db/kv/BUILD.bazel | 4 - beacon-chain/db/kv/blocks.go | 16 +- beacon-chain/db/kv/operations.go | 78 ---------- beacon-chain/db/kv/operations_test.go | 31 ---- beacon-chain/db/kv/slashings.go | 147 ------------------ beacon-chain/db/kv/slashings_test.go | 67 -------- beacon-chain/state/phase0.go | 1 - beacon-chain/state/v1/setters_state.go | 18 --- beacon-chain/state/v2/setters_state.go | 18 --- monitoring/clientstats/scrapers.go | 2 +- .../slashing_protection_interchange_test.go | 2 +- .../round_trip_test.go | 2 +- 18 files changed, 20 insertions(+), 415 deletions(-) delete mode 100644 beacon-chain/db/kv/operations.go delete mode 100644 beacon-chain/db/kv/operations_test.go delete mode 100644 beacon-chain/db/kv/slashings.go delete mode 100644 beacon-chain/db/kv/slashings_test.go diff --git a/beacon-chain/cache/skip_slot_cache.go b/beacon-chain/cache/skip_slot_cache.go index ff8423225a..1088c42781 100644 --- a/beacon-chain/cache/skip_slot_cache.go +++ b/beacon-chain/cache/skip_slot_cache.go @@ -120,26 +120,22 @@ func (c *SkipSlotCache) MarkInProgress(r [32]byte) error { // MarkNotInProgress will release the lock on a given request. This should be // called after put. -func (c *SkipSlotCache) MarkNotInProgress(r [32]byte) error { +func (c *SkipSlotCache) MarkNotInProgress(r [32]byte) { if c.disabled { - return nil + return } c.lock.Lock() defer c.lock.Unlock() delete(c.inProgress, r) - return nil } // Put the response in the cache. -func (c *SkipSlotCache) Put(_ context.Context, r [32]byte, state state.BeaconState) error { +func (c *SkipSlotCache) Put(_ context.Context, r [32]byte, state state.BeaconState) { if c.disabled { - return nil + return } - // Copy state so cached value is not mutated. c.cache.Add(r, state.Copy()) - - return nil } diff --git a/beacon-chain/cache/skip_slot_cache_test.go b/beacon-chain/cache/skip_slot_cache_test.go index 53ad405bf3..8446453dff 100644 --- a/beacon-chain/cache/skip_slot_cache_test.go +++ b/beacon-chain/cache/skip_slot_cache_test.go @@ -28,8 +28,8 @@ func TestSkipSlotCache_RoundTrip(t *testing.T) { }) require.NoError(t, err) - require.NoError(t, c.Put(ctx, r, s)) - require.NoError(t, c.MarkNotInProgress(r)) + c.Put(ctx, r, s) + c.MarkNotInProgress(r) res, err := c.Get(ctx, r) require.NoError(t, err) diff --git a/beacon-chain/core/signing/domain.go b/beacon-chain/core/signing/domain.go index 708e9a32b3..8a19d81542 100644 --- a/beacon-chain/core/signing/domain.go +++ b/beacon-chain/core/signing/domain.go @@ -2,9 +2,9 @@ package signing import ( "github.com/pkg/errors" - "github.com/prysmaticlabs/eth2-types" + types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/crypto/bls" - "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) // Domain returns the domain version for BLS private key to sign and verify. diff --git a/beacon-chain/core/signing/domain_test.go b/beacon-chain/core/signing/domain_test.go index 15deaafbd5..44ff0a4a4f 100644 --- a/beacon-chain/core/signing/domain_test.go +++ b/beacon-chain/core/signing/domain_test.go @@ -3,9 +3,9 @@ package signing import ( "testing" - "github.com/prysmaticlabs/eth2-types" + types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/encoding/bytesutil" - "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" + eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/assert" "github.com/prysmaticlabs/prysm/testing/require" ) diff --git a/beacon-chain/core/transition/transition.go b/beacon-chain/core/transition/transition.go index 1d0cc779a1..372591c3f1 100644 --- a/beacon-chain/core/transition/transition.go +++ b/beacon-chain/core/transition/transition.go @@ -214,10 +214,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot) return nil, err } defer func() { - if err := SkipSlotCache.MarkNotInProgress(key); err != nil { - tracing.AnnotateError(span, err) - log.WithError(err).Error("Failed to mark skip slot no longer in progress") - } + SkipSlotCache.MarkNotInProgress(key) }() for state.Slot() < slot { @@ -225,7 +222,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot) tracing.AnnotateError(span, ctx.Err()) // Cache last best value. if highestSlot < state.Slot() { - if err := SkipSlotCache.Put(ctx, key, state); err != nil { + if SkipSlotCache.Put(ctx, key, state); err != nil { log.WithError(err).Error("Failed to put skip slot cache value") } } @@ -269,10 +266,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot) } if highestSlot < state.Slot() { - if err := SkipSlotCache.Put(ctx, key, state); err != nil { - log.WithError(err).Error("Failed to put skip slot cache value") - tracing.AnnotateError(span, err) - } + SkipSlotCache.Put(ctx, key, state) } return state, nil diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index 61706a868a..b25a684b47 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -39,14 +39,6 @@ type ReadOnlyDatabase interface { StateSummary(ctx context.Context, blockRoot [32]byte) (*ethpb.StateSummary, error) HasStateSummary(ctx context.Context, blockRoot [32]byte) bool HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]state.ReadOnlyBeaconState, error) - // Slashing operations. - ProposerSlashing(ctx context.Context, slashingRoot [32]byte) (*eth.ProposerSlashing, error) - AttesterSlashing(ctx context.Context, slashingRoot [32]byte) (*eth.AttesterSlashing, error) - HasProposerSlashing(ctx context.Context, slashingRoot [32]byte) bool - HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte) bool - // Block operations. - VoluntaryExit(ctx context.Context, exitRoot [32]byte) (*eth.VoluntaryExit, error) - HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool // Checkpoint operations. JustifiedCheckpoint(ctx context.Context) (*eth.Checkpoint, error) FinalizedCheckpoint(ctx context.Context) (*eth.Checkpoint, error) @@ -75,11 +67,6 @@ type NoHeadAccessDatabase interface { DeleteStates(ctx context.Context, blockRoots [][32]byte) error SaveStateSummary(ctx context.Context, summary *ethpb.StateSummary) error SaveStateSummaries(ctx context.Context, summaries []*ethpb.StateSummary) error - // Slashing operations. - SaveProposerSlashing(ctx context.Context, slashing *eth.ProposerSlashing) error - SaveAttesterSlashing(ctx context.Context, slashing *eth.AttesterSlashing) error - // Block operations. - SaveVoluntaryExit(ctx context.Context, exit *eth.VoluntaryExit) error // Checkpoint operations. SaveJustifiedCheckpoint(ctx context.Context, checkpoint *eth.Checkpoint) error SaveFinalizedCheckpoint(ctx context.Context, checkpoint *eth.Checkpoint) error diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index 3da12b02d3..4eb8cf8246 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -18,10 +18,8 @@ go_library( "migration_archived_index.go", "migration_block_slot_index.go", "migration_state_validators.go", - "operations.go", "powchain.go", "schema.go", - "slashings.go", "state.go", "state_summary.go", "state_summary_cache.go", @@ -88,9 +86,7 @@ go_test( "migration_archived_index_test.go", "migration_block_slot_index_test.go", "migration_state_validators_test.go", - "operations_test.go", "powchain_test.go", - "slashings_test.go", "state_summary_test.go", "state_test.go", "utils_test.go", diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index 34c99778c2..536340b920 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -150,11 +150,7 @@ func (s *Store) BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []bloc err := s.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(blocksBucket) - keys, err := blockRootsBySlot(ctx, tx, slot) - if err != nil { - return err - } - + keys := blockRootsBySlot(ctx, tx, slot) for i := 0; i < len(keys); i++ { encoded := bkt.Get(keys[i]) blk, err := unmarshalBlock(ctx, encoded) @@ -174,11 +170,7 @@ func (s *Store) BlockRootsBySlot(ctx context.Context, slot types.Slot) (bool, [] defer span.End() blockRoots := make([][32]byte, 0) err := s.db.View(func(tx *bolt.Tx) error { - keys, err := blockRootsBySlot(ctx, tx, slot) - if err != nil { - return err - } - + keys := blockRootsBySlot(ctx, tx, slot) for i := 0; i < len(keys); i++ { blockRoots = append(blockRoots, bytesutil.ToBytes32(keys[i])) } @@ -519,7 +511,7 @@ func blockRootsBySlotRange( } // blockRootsBySlot retrieves the block roots by slot -func blockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot types.Slot) ([][]byte, error) { +func blockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot types.Slot) [][]byte { ctx, span := trace.StartSpan(ctx, "BeaconDB.blockRootsBySlot") defer span.End() @@ -533,7 +525,7 @@ func blockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot types.Slot) ([][]by roots = append(roots, v[i:i+32]) } } - return roots, nil + return roots } // createBlockIndicesFromBlock takes in a beacon block and returns diff --git a/beacon-chain/db/kv/operations.go b/beacon-chain/db/kv/operations.go deleted file mode 100644 index bad2054151..0000000000 --- a/beacon-chain/db/kv/operations.go +++ /dev/null @@ -1,78 +0,0 @@ -package kv - -import ( - "context" - - ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - bolt "go.etcd.io/bbolt" - "go.opencensus.io/trace" -) - -// VoluntaryExit retrieval by signing root. -func (s *Store) VoluntaryExit(ctx context.Context, exitRoot [32]byte) (*ethpb.VoluntaryExit, error) { - ctx, span := trace.StartSpan(ctx, "BeaconDB.VoluntaryExit") - defer span.End() - enc, err := s.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 (s *Store) HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool { - ctx, span := trace.StartSpan(ctx, "BeaconDB.HasVoluntaryExit") - defer span.End() - enc, err := s.voluntaryExitBytes(ctx, exitRoot) - if err != nil { - panic(err) - } - return len(enc) > 0 -} - -// SaveVoluntaryExit to the db by its signing root. -func (s *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 s.db.Update(func(tx *bolt.Tx) error { - bucket := tx.Bucket(voluntaryExitsBucket) - return bucket.Put(exitRoot[:], enc) - }) -} - -func (s *Store) voluntaryExitBytes(ctx context.Context, exitRoot [32]byte) ([]byte, error) { - ctx, span := trace.StartSpan(ctx, "BeaconDB.voluntaryExitBytes") - defer span.End() - var dst []byte - err := s.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 (s *Store) deleteVoluntaryExit(ctx context.Context, exitRoot [32]byte) error { - ctx, span := trace.StartSpan(ctx, "BeaconDB.deleteVoluntaryExit") - defer span.End() - return s.db.Update(func(tx *bolt.Tx) error { - bucket := tx.Bucket(voluntaryExitsBucket) - return bucket.Delete(exitRoot[:]) - }) -} diff --git a/beacon-chain/db/kv/operations_test.go b/beacon-chain/db/kv/operations_test.go deleted file mode 100644 index cadf37330f..0000000000 --- a/beacon-chain/db/kv/operations_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package kv - -import ( - "context" - "testing" - - ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/testing/assert" - "github.com/prysmaticlabs/prysm/testing/require" - "google.golang.org/protobuf/proto" -) - -func TestStore_VoluntaryExits_CRUD(t *testing.T) { - db := setupDB(t) - ctx := context.Background() - exit := ðpb.VoluntaryExit{ - Epoch: 5, - } - exitRoot, err := exit.HashTreeRoot() - require.NoError(t, err) - retrieved, err := db.VoluntaryExit(ctx, exitRoot) - require.NoError(t, err) - assert.Equal(t, (*ethpb.VoluntaryExit)(nil), retrieved, "Expected nil voluntary exit") - require.NoError(t, db.SaveVoluntaryExit(ctx, exit)) - assert.Equal(t, true, db.HasVoluntaryExit(ctx, exitRoot), "Expected voluntary exit to exist in the db") - retrieved, err = db.VoluntaryExit(ctx, exitRoot) - require.NoError(t, err) - assert.Equal(t, true, proto.Equal(exit, retrieved), "Wanted %v, received %v", exit, retrieved) - require.NoError(t, db.deleteVoluntaryExit(ctx, exitRoot)) - assert.Equal(t, false, db.HasVoluntaryExit(ctx, exitRoot), "Expected voluntary exit to have been deleted from the db") -} diff --git a/beacon-chain/db/kv/slashings.go b/beacon-chain/db/kv/slashings.go deleted file mode 100644 index 119f93b695..0000000000 --- a/beacon-chain/db/kv/slashings.go +++ /dev/null @@ -1,147 +0,0 @@ -package kv - -import ( - "context" - - ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - bolt "go.etcd.io/bbolt" - "go.opencensus.io/trace" -) - -// ProposerSlashing retrieval by slashing root. -func (s *Store) ProposerSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.ProposerSlashing, error) { - ctx, span := trace.StartSpan(ctx, "BeaconDB.ProposerSlashing") - defer span.End() - enc, err := s.proposerSlashingBytes(ctx, slashingRoot) - if err != nil { - return nil, err - } - if len(enc) == 0 { - return nil, nil - } - proposerSlashing := ðpb.ProposerSlashing{} - if err := decode(ctx, enc, proposerSlashing); err != nil { - return nil, err - } - return proposerSlashing, nil -} - -// HasProposerSlashing verifies if a slashing is stored in the db. -func (s *Store) HasProposerSlashing(ctx context.Context, slashingRoot [32]byte) bool { - ctx, span := trace.StartSpan(ctx, "BeaconDB.HasProposerSlashing") - defer span.End() - enc, err := s.proposerSlashingBytes(ctx, slashingRoot) - if err != nil { - panic(err) - } - return len(enc) > 0 -} - -// SaveProposerSlashing to the db by its hash tree root. -func (s *Store) SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error { - ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveProposerSlashing") - defer span.End() - slashingRoot, err := slashing.HashTreeRoot() - if err != nil { - return err - } - enc, err := encode(ctx, slashing) - if err != nil { - return err - } - return s.db.Update(func(tx *bolt.Tx) error { - bucket := tx.Bucket(proposerSlashingsBucket) - return bucket.Put(slashingRoot[:], enc) - }) -} - -func (s *Store) proposerSlashingBytes(ctx context.Context, slashingRoot [32]byte) ([]byte, error) { - ctx, span := trace.StartSpan(ctx, "BeaconDB.proposerSlashingBytes") - defer span.End() - var dst []byte - err := s.db.View(func(tx *bolt.Tx) error { - bkt := tx.Bucket(proposerSlashingsBucket) - dst = bkt.Get(slashingRoot[:]) - return nil - }) - return dst, err -} - -// deleteProposerSlashing clears a proposer slashing from the db by its hash tree root. -func (s *Store) deleteProposerSlashing(ctx context.Context, slashingRoot [32]byte) error { - ctx, span := trace.StartSpan(ctx, "BeaconDB.deleteProposerSlashing") - defer span.End() - return s.db.Update(func(tx *bolt.Tx) error { - bucket := tx.Bucket(proposerSlashingsBucket) - return bucket.Delete(slashingRoot[:]) - }) -} - -// AttesterSlashing retrieval by hash tree root. -func (s *Store) AttesterSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.AttesterSlashing, error) { - ctx, span := trace.StartSpan(ctx, "BeaconDB.AttesterSlashing") - defer span.End() - enc, err := s.attesterSlashingBytes(ctx, slashingRoot) - if err != nil { - return nil, err - } - if len(enc) == 0 { - return nil, nil - } - attSlashing := ðpb.AttesterSlashing{} - if err := decode(ctx, enc, attSlashing); err != nil { - return nil, err - } - return attSlashing, nil -} - -// HasAttesterSlashing verifies if a slashing is stored in the db. -func (s *Store) HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte) bool { - ctx, span := trace.StartSpan(ctx, "BeaconDB.HasAttesterSlashing") - defer span.End() - enc, err := s.attesterSlashingBytes(ctx, slashingRoot) - if err != nil { - panic(err) - } - return len(enc) > 0 -} - -// SaveAttesterSlashing to the db by its hash tree root. -func (s *Store) SaveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) error { - ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveAttesterSlashing") - defer span.End() - slashingRoot, err := slashing.HashTreeRoot() - if err != nil { - return err - } - enc, err := encode(ctx, slashing) - if err != nil { - return err - } - return s.db.Update(func(tx *bolt.Tx) error { - bucket := tx.Bucket(attesterSlashingsBucket) - return bucket.Put(slashingRoot[:], enc) - }) -} - -func (s *Store) attesterSlashingBytes(ctx context.Context, slashingRoot [32]byte) ([]byte, error) { - ctx, span := trace.StartSpan(ctx, "BeaconDB.attesterSlashingBytes") - defer span.End() - var dst []byte - err := s.db.View(func(tx *bolt.Tx) error { - bkt := tx.Bucket(attesterSlashingsBucket) - dst = bkt.Get(slashingRoot[:]) - return nil - }) - return dst, err -} - -// deleteAttesterSlashing clears an attester slashing from the db by its hash tree root. -func (s *Store) deleteAttesterSlashing(ctx context.Context, slashingRoot [32]byte) error { - ctx, span := trace.StartSpan(ctx, "BeaconDB.deleteAttesterSlashing") - defer span.End() - return s.db.Update(func(tx *bolt.Tx) error { - bucket := tx.Bucket(attesterSlashingsBucket) - return bucket.Delete(slashingRoot[:]) - }) -} diff --git a/beacon-chain/db/kv/slashings_test.go b/beacon-chain/db/kv/slashings_test.go deleted file mode 100644 index ab890db786..0000000000 --- a/beacon-chain/db/kv/slashings_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package kv - -import ( - "context" - "testing" - - ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/testing/assert" - "github.com/prysmaticlabs/prysm/testing/require" - "github.com/prysmaticlabs/prysm/testing/util" - "google.golang.org/protobuf/proto" -) - -func TestStore_ProposerSlashing_CRUD(t *testing.T) { - db := setupDB(t) - ctx := context.Background() - prop := ðpb.ProposerSlashing{ - Header_1: util.HydrateSignedBeaconHeader(ðpb.SignedBeaconBlockHeader{ - Header: ðpb.BeaconBlockHeader{ - ProposerIndex: 5, - }, - }), - Header_2: util.HydrateSignedBeaconHeader(ðpb.SignedBeaconBlockHeader{ - Header: ðpb.BeaconBlockHeader{ - ProposerIndex: 5, - }, - }), - } - slashingRoot, err := prop.HashTreeRoot() - require.NoError(t, err) - retrieved, err := db.ProposerSlashing(ctx, slashingRoot) - require.NoError(t, err) - assert.Equal(t, (*ethpb.ProposerSlashing)(nil), retrieved, "Expected nil proposer slashing") - require.NoError(t, db.SaveProposerSlashing(ctx, prop)) - assert.Equal(t, true, db.HasProposerSlashing(ctx, slashingRoot), "Expected proposer slashing to exist in the db") - retrieved, err = db.ProposerSlashing(ctx, slashingRoot) - require.NoError(t, err) - assert.Equal(t, true, proto.Equal(prop, retrieved), "Wanted %v, received %v", prop, retrieved) - require.NoError(t, db.deleteProposerSlashing(ctx, slashingRoot)) - assert.Equal(t, false, db.HasProposerSlashing(ctx, slashingRoot), "Expected proposer slashing to have been deleted from the db") -} - -func TestStore_AttesterSlashing_CRUD(t *testing.T) { - db := setupDB(t) - ctx := context.Background() - att := ðpb.AttesterSlashing{ - Attestation_1: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ - Data: ðpb.AttestationData{ - Slot: 5, - }}), - Attestation_2: util.HydrateIndexedAttestation(ðpb.IndexedAttestation{ - Data: ðpb.AttestationData{ - Slot: 7, - }})} - slashingRoot, err := att.HashTreeRoot() - require.NoError(t, err) - retrieved, err := db.AttesterSlashing(ctx, slashingRoot) - require.NoError(t, err) - assert.Equal(t, (*ethpb.AttesterSlashing)(nil), retrieved, "Expected nil attester slashing") - require.NoError(t, db.SaveAttesterSlashing(ctx, att)) - assert.Equal(t, true, db.HasAttesterSlashing(ctx, slashingRoot), "Expected attester slashing to exist in the db") - retrieved, err = db.AttesterSlashing(ctx, slashingRoot) - require.NoError(t, err) - assert.Equal(t, true, proto.Equal(att, retrieved), "Wanted %v, received %v", att, retrieved) - require.NoError(t, db.deleteAttesterSlashing(ctx, slashingRoot)) - assert.Equal(t, false, db.HasAttesterSlashing(ctx, slashingRoot), "Expected attester slashing to have been deleted from the db") -} diff --git a/beacon-chain/state/phase0.go b/beacon-chain/state/phase0.go index cd4a58ddd6..f90b071b11 100644 --- a/beacon-chain/state/phase0.go +++ b/beacon-chain/state/phase0.go @@ -148,7 +148,6 @@ type WriteOnlyBlockRoots interface { // WriteOnlyStateRoots defines a struct which only has write access to state roots methods. type WriteOnlyStateRoots interface { - SetStateRoots(val [][]byte) error UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error } diff --git a/beacon-chain/state/v1/setters_state.go b/beacon-chain/state/v1/setters_state.go index 1a7d93fad7..ef2c19c2fa 100644 --- a/beacon-chain/state/v1/setters_state.go +++ b/beacon-chain/state/v1/setters_state.go @@ -5,24 +5,6 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" ) -// SetStateRoots for the beacon state. Updates the state roots -// to a new value by overwriting the previous value. -func (b *BeaconState) SetStateRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[stateRoots].MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - - b.state.StateRoots = val - b.markFieldAsDirty(stateRoots) - b.rebuildTrie[stateRoots] = true - return nil -} - // UpdateStateRootAtIndex for the beacon state. Updates the state root // at a specific index to a new value. func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error { diff --git a/beacon-chain/state/v2/setters_state.go b/beacon-chain/state/v2/setters_state.go index e64df5335b..27792194ab 100644 --- a/beacon-chain/state/v2/setters_state.go +++ b/beacon-chain/state/v2/setters_state.go @@ -5,24 +5,6 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" ) -// SetStateRoots for the beacon state. Updates the state roots -// to a new value by overwriting the previous value. -func (b *BeaconState) SetStateRoots(val [][]byte) error { - if !b.hasInnerState() { - return ErrNilInnerState - } - b.lock.Lock() - defer b.lock.Unlock() - - b.sharedFieldReferences[stateRoots].MinusRef() - b.sharedFieldReferences[stateRoots] = stateutil.NewRef(1) - - b.state.StateRoots = val - b.markFieldAsDirty(stateRoots) - b.rebuildTrie[stateRoots] = true - return nil -} - // UpdateStateRootAtIndex for the beacon state. Updates the state root // at a specific index to a new value. func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) error { diff --git a/monitoring/clientstats/scrapers.go b/monitoring/clientstats/scrapers.go index 8d1b988c9b..09a9313deb 100644 --- a/monitoring/clientstats/scrapers.go +++ b/monitoring/clientstats/scrapers.go @@ -76,7 +76,7 @@ func NewValidatorScraper(promExpoURL string) Scraper { // will be used. func scrapeProm(url string, tripper http.RoundTripper) (map[string]*dto.MetricFamily, error) { mfChan := make(chan *dto.MetricFamily) - errChan := make(chan error) + errChan := make(chan error, 1) go func() { // FetchMetricFamilies handles grpc flavored prometheus ez // but at the cost of the awkward channel select loop below diff --git a/validator/client/slashing_protection_interchange_test.go b/validator/client/slashing_protection_interchange_test.go index 05ab2bd306..4a90010ef0 100644 --- a/validator/client/slashing_protection_interchange_test.go +++ b/validator/client/slashing_protection_interchange_test.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/util" - "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" + history "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" ) type eip3076TestCase struct { diff --git a/validator/slashing-protection-history/round_trip_test.go b/validator/slashing-protection-history/round_trip_test.go index a5f2513370..3ca5a0aa2f 100644 --- a/validator/slashing-protection-history/round_trip_test.go +++ b/validator/slashing-protection-history/round_trip_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/validator/db/kv" dbtest "github.com/prysmaticlabs/prysm/validator/db/testing" - "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" + history "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" slashtest "github.com/prysmaticlabs/prysm/validator/testing" )