Use poststate for calculating att votes (#4395)

* Use poststate for votes
* Merge branch 'master' into use-post-state
* Merge branch 'master' into use-post-state
This commit is contained in:
terence tsao
2020-01-03 10:29:26 -08:00
committed by prylabs-bulldozer[bot]
parent c9252c06c4
commit 220af25bce
2 changed files with 7 additions and 14 deletions

View File

@@ -79,7 +79,7 @@ func (s *Store) OnBlock(ctx context.Context, b *ethpb.BeaconBlock) error {
if err != nil {
return errors.Wrap(err, "could not execute state transition")
}
if err := s.updateBlockAttestationsVotes(ctx, b.Body.Attestations); err != nil {
if err := s.updateBlockAttestationsVotes(ctx, postState, b.Body.Attestations); err != nil {
return errors.Wrap(err, "could not update votes for attestations in block")
}
@@ -278,7 +278,7 @@ func (s *Store) getBlockPreState(ctx context.Context, b *ethpb.BeaconBlock) (*pb
// 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 {
func (s *Store) updateBlockAttestationsVotes(ctx context.Context, state *pb.BeaconState, atts []*ethpb.Attestation) error {
s.seenAttsLock.Lock()
defer s.seenAttsLock.Unlock()
@@ -291,7 +291,7 @@ func (s *Store) updateBlockAttestationsVotes(ctx context.Context, atts []*ethpb.
if s.seenAtts[r] {
continue
}
if err := s.updateBlockAttestationVote(ctx, att); err != nil {
if err := s.updateBlockAttestationVote(ctx, state, att); err != nil {
log.WithError(err).Warn("Attestation failed to update vote")
}
s.seenAtts[r] = true
@@ -300,16 +300,9 @@ func (s *Store) updateBlockAttestationsVotes(ctx context.Context, atts []*ethpb.
}
// updateBlockAttestationVotes checks the attestation to update validator's latest votes.
func (s *Store) updateBlockAttestationVote(ctx context.Context, att *ethpb.Attestation) error {
func (s *Store) updateBlockAttestationVote(ctx context.Context, state *pb.BeaconState, 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)
committee, err := helpers.BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil {
return err
}

View File

@@ -155,7 +155,7 @@ func TestStore_UpdateBlockAttestationVote(t *testing.T) {
attestedIndices = append(attestedIndices, k)
}
if err := store.updateBlockAttestationVote(ctx, att); err != nil {
if err := store.updateBlockAttestationVote(ctx, beaconState, att); err != nil {
t.Fatal(err)
}
for _, i := range attestedIndices {
@@ -195,7 +195,7 @@ func TestStore_UpdateBlockAttestationsVote(t *testing.T) {
t.Fatal(err)
}
if err := store.updateBlockAttestationsVotes(ctx, atts); err != nil {
if err := store.updateBlockAttestationsVotes(ctx, beaconState, atts); err != nil {
t.Fatal(err)
}