Skip to content

Commit

Permalink
Improve attestation cache check from O(n) to O(1) access time (#4837)
Browse files Browse the repository at this point in the history
* use O(1) method to access the blocks
* Merge branch 'master' into better-has-aggregated-attestation
  • Loading branch information
prestonvanloon committed Feb 11, 2020
1 parent a732531 commit 0882908
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions beacon-chain/operations/attestations/kv/aggregated.go
Expand Up @@ -127,22 +127,18 @@ func (p *AttCaches) HasAggregatedAttestation(att *ethpb.Attestation) (bool, erro
return false, errors.Wrap(err, "could not tree hash attestation")
}

for k, atts := range p.aggregatedAtt.Items() {
if k == string(r[:]) {
for _, a := range atts.Object.([]*ethpb.Attestation) {
if a.AggregationBits.Contains(att.AggregationBits) {
return true, nil
}
if atts, ok := p.aggregatedAtt.Get(string(r[:])); ok {
for _, a := range atts.([]*ethpb.Attestation) {
if a.AggregationBits.Contains(att.AggregationBits) {
return true, nil
}
}
}

for k, atts := range p.blockAtt.Items() {
if k == string(r[:]) {
for _, a := range atts.Object.([]*ethpb.Attestation) {
if a.AggregationBits.Contains(att.AggregationBits) {
return true, nil
}
if atts, ok := p.blockAtt.Get(string(r[:])); ok {
for _, a := range atts.([]*ethpb.Attestation) {
if a.AggregationBits.Contains(att.AggregationBits) {
return true, nil
}
}
}
Expand Down

0 comments on commit 0882908

Please sign in to comment.