Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix activation queue sorting #4409

Merged
merged 5 commits into from
Jan 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Removed old save/process block atts
terencechain committed Jan 4, 2020
commit b83ca9c1ee7e2962a944b4dd51bcdf1db46960c6
1 change: 0 additions & 1 deletion beacon-chain/blockchain/forkchoice/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -60,7 +60,6 @@ go_test(
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
2 changes: 2 additions & 0 deletions beacon-chain/blockchain/forkchoice/process_attestation.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package forkchoice

import (
"context"
"encoding/hex"
"fmt"
"time"

@@ -300,6 +301,7 @@ func (s *Store) setSeenAtt(a *ethpb.Attestation) error {
if err != nil {
return err
}
log.Info("Setting seen att ", hex.EncodeToString(r[:5]), a.Data.Slot, a.Data.CommitteeIndex)
s.seenAtts[r] = true

return nil
61 changes: 0 additions & 61 deletions beacon-chain/blockchain/forkchoice/process_block.go
Original file line number Diff line number Diff line change
@@ -11,15 +11,13 @@ import (
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/traceutil"
"github.com/sirupsen/logrus"
@@ -87,9 +85,6 @@ func (s *Store) OnBlock(ctx context.Context, signed *ethpb.SignedBeaconBlock) er
if err != nil {
return errors.Wrap(err, "could not execute state transition")
}
if err := s.updateBlockAttestationsVotes(ctx, b.Body.Attestations); err != nil {
return errors.Wrap(err, "could not update votes for attestations in block")
}

if err := s.db.SaveBlock(ctx, signed); err != nil {
return errors.Wrapf(err, "could not save block from slot %d", b.Slot)
@@ -287,62 +282,6 @@ func (s *Store) getBlockPreState(ctx context.Context, b *ethpb.BeaconBlock) (*pb
return preState, nil
}

// updateBlockAttestationsVotes checks the attestations in block and filter out the seen ones,
// the unseen ones get passed to updateBlockAttestationVote for updating fork choice votes.
func (s *Store) updateBlockAttestationsVotes(ctx context.Context, atts []*ethpb.Attestation) error {
s.seenAttsLock.Lock()
defer s.seenAttsLock.Unlock()

for _, att := range atts {
// If we have not seen the attestation yet
r, err := hashutil.HashProto(att)
if err != nil {
return err
}
if s.seenAtts[r] {
continue
}
if err := s.updateBlockAttestationVote(ctx, att); err != nil {
log.WithError(err).Warn("Attestation failed to update vote")
}
s.seenAtts[r] = true
}
return nil
}

// updateBlockAttestationVotes checks the attestation to update validator's latest votes.
func (s *Store) updateBlockAttestationVote(ctx context.Context, att *ethpb.Attestation) error {
tgt := att.Data.Target
baseState, err := s.db.State(ctx, bytesutil.ToBytes32(tgt.Root))
if err != nil {
return errors.Wrap(err, "could not get state for attestation tgt root")
}
if baseState == nil {
return errors.New("no state found in db with attestation tgt root")
}
committee, err := helpers.BeaconCommitteeFromState(baseState, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil {
return err
}
indexedAtt, err := blocks.ConvertToIndexed(ctx, att, committee)
if err != nil {
return errors.Wrap(err, "could not convert attestation to indexed attestation")
}

s.voteLock.Lock()
defer s.voteLock.Unlock()
for _, i := range indexedAtt.AttestingIndices {
vote, ok := s.latestVoteMap[i]
if !ok || tgt.Epoch > vote.Epoch {
s.latestVoteMap[i] = &pb.ValidatorLatestVote{
Epoch: tgt.Epoch,
Root: tgt.Root,
}
}
}
return nil
}

// verifyBlkPreState validates input block has a valid pre-state.
func (s *Store) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) (*pb.BeaconState, error) {
preState, err := s.db.State(ctx, bytesutil.ToBytes32(b.ParentRoot))
83 changes: 0 additions & 83 deletions beacon-chain/blockchain/forkchoice/process_block_test.go
Original file line number Diff line number Diff line change
@@ -17,9 +17,7 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

func TestStore_OnBlock(t *testing.T) {
@@ -138,87 +136,6 @@ func TestStore_SaveNewValidators(t *testing.T) {
}
}

func TestStore_UpdateBlockAttestationVote(t *testing.T) {
ctx := context.Background()
db := testDB.SetupDB(t)
defer testDB.TeardownDB(t, db)
params.UseMinimalConfig()

beaconState, _ := testutil.DeterministicGenesisState(t, 100)

store := NewForkChoiceService(ctx, db)
r := [32]byte{'A'}
att := &ethpb.Attestation{
Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0, Root: r[:]},
},
AggregationBits: []byte{255},
}
if err := store.db.SaveState(ctx, beaconState, r); err != nil {
t.Fatal(err)
}

committee, err := helpers.BeaconCommitteeFromState(beaconState, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil {
t.Error(err)
}
indexedAtt, err := blocks.ConvertToIndexed(ctx, att, committee)
if err != nil {
t.Fatal(err)
}

if err := store.updateBlockAttestationVote(ctx, att); err != nil {
t.Fatal(err)
}

for _, i := range indexedAtt.AttestingIndices {
v := store.latestVoteMap[i]
if !reflect.DeepEqual(v.Root, r[:]) {
t.Error("Attested roots don't match")
}
}
}

func TestStore_UpdateBlockAttestationsVote(t *testing.T) {
ctx := context.Background()
db := testDB.SetupDB(t)
defer testDB.TeardownDB(t, db)
params.UseMinimalConfig()

beaconState, _ := testutil.DeterministicGenesisState(t, 100)

store := NewForkChoiceService(ctx, db)
r := [32]byte{'A'}
atts := make([]*ethpb.Attestation, 5)
hashes := make([][32]byte, 5)
for i := 0; i < len(atts); i++ {
atts[i] = &ethpb.Attestation{
Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: 0, Root: params.BeaconConfig().ZeroHash[:]},
Target: &ethpb.Checkpoint{Epoch: 0, Root: r[:]},
},
AggregationBits: []byte{255},
}
h, _ := hashutil.HashProto(atts[i])
hashes[i] = h
}

if err := store.db.SaveState(ctx, beaconState, r); err != nil {
t.Fatal(err)
}

if err := store.updateBlockAttestationsVotes(ctx, atts); err != nil {
t.Fatal(err)
}

for _, h := range hashes {
if !store.seenAtts[h] {
t.Error("Seen attestation did not get recorded")
}
}
}

func TestStore_SavesNewBlockAttestations(t *testing.T) {
ctx := context.Background()
db := testDB.SetupDB(t)
6 changes: 3 additions & 3 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
@@ -278,9 +278,9 @@ func TestCanonicalHeadSlot_FailedRPC(t *testing.T) {
defer ctrl.Finish()
client := internal.NewMockBeaconChainClient(ctrl)
v := validator{
keyManager: testKeyManager,
keyManager: testKeyManager,
beaconClient: client,
genesisTime: 1,
genesisTime: 1,
}
client.EXPECT().GetChainHead(
gomock.Any(),
@@ -296,7 +296,7 @@ func TestCanonicalHeadSlot_OK(t *testing.T) {
defer ctrl.Finish()
client := internal.NewMockBeaconChainClient(ctrl)
v := validator{
keyManager: testKeyManager,
keyManager: testKeyManager,
beaconClient: client,
}
client.EXPECT().GetChainHead(