Skip to content

Commit

Permalink
testing leader node cached att data
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy-blox committed Dec 8, 2024
1 parent 61e2a02 commit 1c33427
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions beacon/goclient/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/jellydator/ttlcache/v3"
"go.uber.org/zap"
)

// AttesterDuties returns attester duties for a given epoch.
Expand Down Expand Up @@ -48,8 +49,8 @@ func (gc *GoClient) GetAttestationData(slot phase0.Slot, committeeIndex phase0.C
}

// Have to make beacon node request and cache the result.
attDataReqStart := time.Now()
result, err, _ := gc.attestationReqInflight.Do(slot, func() (*phase0.AttestationData, error) {
attDataReqStart := time.Now()
resp, err := gc.client.AttestationData(gc.ctx, &api.AttestationDataOpts{
Slot: slot,
})
Expand All @@ -64,9 +65,12 @@ func (gc *GoClient) GetAttestationData(slot phase0.Slot, committeeIndex phase0.C
// Caching resulting value here (as part of inflight request) guarantees only 1 request
// will ever be done for a given slot.
gc.attestationDataCache.Set(slot, resp.Data, ttlcache.DefaultTTL)

return resp.Data, nil
})

gc.log.Debug("successfully fetched attestation data",
zap.Uint64("slot", uint64(slot)),
zap.Duration("attestation_data_time", time.Since(attDataReqStart)))
if err != nil {
return nil, DataVersionNil, err
}
Expand Down

0 comments on commit 1c33427

Please sign in to comment.