Check block attestation length for operation pool (#7420)

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
terence tsao 2020-10-02 13:08:06 -07:00 committed by GitHub
parent 63c1057ae6
commit 690fa12f1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -25,7 +25,7 @@ func (p *AttCaches) SaveBlockAttestation(att *ethpb.Attestation) error {
// Ensure that this attestation is not already fully contained in an existing attestation.
for _, a := range atts {
if a.AggregationBits.Contains(att.AggregationBits) {
if a.AggregationBits.Len() == att.AggregationBits.Len() && a.AggregationBits.Contains(att.AggregationBits) {
return nil
}
}

View File

@ -16,7 +16,8 @@ func TestKV_BlockAttestation_CanSaveRetrieve(t *testing.T) {
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b1101}}
atts := []*ethpb.Attestation{att1, att2, att3}
att4 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3, BeaconBlockRoot: make([]byte, 32), Target: &ethpb.Checkpoint{Root: make([]byte, 32)}, Source: &ethpb.Checkpoint{Root: make([]byte, 32)}}, AggregationBits: bitfield.Bitlist{0b11011}} // Diff bit length should not panic.
atts := []*ethpb.Attestation{att1, att2, att3, att4}
for _, att := range atts {
require.NoError(t, cache.SaveBlockAttestation(att))