Skip to content

Commit

Permalink
Fixed unaggregated att seen cache to use per slot
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Apr 30, 2020
1 parent d640cd6 commit ea41603
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions beacon-chain/sync/subscriber_beacon_aggregate_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/gogo/protobuf/proto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
)

// beaconAggregateProofSubscriber forwards the incoming validated aggregated attestation and proof to the
Expand All @@ -21,7 +20,7 @@ func (r *Service) beaconAggregateProofSubscriber(ctx context.Context, msg proto.
if a.Message.Aggregate == nil || a.Message.Aggregate.Data == nil {
return errors.New("nil aggregate")
}
r.setAggregatorIndexEpochSeen(helpers.SlotToEpoch(a.Message.Aggregate.Data.Slot), a.Message.AggregatorIndex)
r.setAggregatorIndexEpochSeen(a.Message.Aggregate.Data.Target.Epoch, a.Message.AggregatorIndex)

return r.attPool.SaveAggregatedAttestation(a.Message.Aggregate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestBeaconAggregateProofSubscriber_CanSave(t *testing.T) {
seenAttestationCache: c,
}

a := &ethpb.SignedAggregateAttestationAndProof{Message: &ethpb.AggregateAttestationAndProof{Aggregate: &ethpb.Attestation{Data: &ethpb.AttestationData{}, AggregationBits: bitfield.Bitlist{0x07}}, AggregatorIndex: 100}}
a := &ethpb.SignedAggregateAttestationAndProof{Message: &ethpb.AggregateAttestationAndProof{Aggregate: &ethpb.Attestation{Data: &ethpb.AttestationData{Target: &ethpb.Checkpoint{}}, AggregationBits: bitfield.Bitlist{0x07}}, AggregatorIndex: 100}}
if err := r.beaconAggregateProofSubscriber(context.Background(), a); err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/sync/validate_aggregate_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *Service) validateAggregateAndProof(ctx context.Context, pid peer.ID, ms
return false
}
// Verify this is the first aggregate received from the aggregator with index and slot.
if r.hasSeenAggregatorIndexEpoch(helpers.SlotToEpoch(m.Message.Aggregate.Data.Slot), m.Message.AggregatorIndex) {
if r.hasSeenAggregatorIndexEpoch(m.Message.Aggregate.Data.Target.Epoch, m.Message.AggregatorIndex) {
return false
}

Expand All @@ -74,7 +74,7 @@ func (r *Service) validateAggregateAndProof(ctx context.Context, pid peer.ID, ms
return false
}

r.setAggregatorIndexEpochSeen(helpers.SlotToEpoch(m.Message.Aggregate.Data.Slot), m.Message.AggregatorIndex)
r.setAggregatorIndexEpochSeen(m.Message.Aggregate.Data.Target.Epoch, m.Message.AggregatorIndex)

msg.ValidatorData = m

Expand Down Expand Up @@ -150,7 +150,7 @@ func (r *Service) validateBlockInAttestation(ctx context.Context, s *ethpb.Signe
return true
}

// Returns true if the node has received aggregate for the aggregator with index and epoch.
// Returns true if the node has received aggregate for the aggregator with index and target epoch.
func (r *Service) hasSeenAggregatorIndexEpoch(epoch uint64, aggregatorIndex uint64) bool {
r.seenAttestationLock.RLock()
defer r.seenAttestationLock.RUnlock()
Expand All @@ -159,7 +159,7 @@ func (r *Service) hasSeenAggregatorIndexEpoch(epoch uint64, aggregatorIndex uint
return seen
}

// Set aggregate's aggregator index epoch as seen.
// Set aggregate's aggregator index target epoch as seen.
func (r *Service) setAggregatorIndexEpochSeen(epoch uint64, aggregatorIndex uint64) {
r.seenAttestationLock.Lock()
defer r.seenAttestationLock.Unlock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
Data: &ethpb.AttestationData{
BeaconBlockRoot: validBlockRoot[:],
CommitteeIndex: 1,
Slot: 62,
Slot: 63,
},
},
topic: fmt.Sprintf("/eth2/%x/committee_index1_beacon_attestation", digest),
Expand Down

0 comments on commit ea41603

Please sign in to comment.