Skip to content

Commit

Permalink
fix: GetAttestationData by double checking the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Feb 7, 2025
1 parent ffecfee commit 3e47e13
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions beacon/goclient/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ func (gc *GoClient) GetAttestationData(slot phase0.Slot, committeeIndex phase0.C
spec.DataVersion,
error,
) {
// Check cache.
cachedResult := gc.attestationDataCache.Get(slot)
if cachedResult != nil {
data, err := withCommitteeIndex(cachedResult.Value(), committeeIndex)
if err != nil {
return nil, DataVersionNil, fmt.Errorf("failed to set committee index: %w", err)
}
return data, spec.DataVersionPhase0, nil
}

// Have to make beacon node request and cache the result.
result, err, _ := gc.attestationReqInflight.Do(slot, func() (*phase0.AttestationData, error) {
// Check cache.
cachedResult := gc.attestationDataCache.Get(slot)
if cachedResult != nil {
data, err := withCommitteeIndex(cachedResult.Value(), committeeIndex)
if err != nil {
return nil, fmt.Errorf("failed to set committee index: %w", err)
}

Check warning on line 59 in beacon/goclient/attest.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/attest.go#L58-L59

Added lines #L58 - L59 were not covered by tests
return data, nil
}

attDataReqStart := time.Now()
resp, err := gc.multiClient.AttestationData(gc.ctx, &api.AttestationDataOpts{
Slot: slot,
Expand Down

0 comments on commit 3e47e13

Please sign in to comment.