|
75 | 75 |
|
76 | 76 | var defaultGraffitiString = "Caplin" |
77 | 77 |
|
78 | | -const missedTimeout = 500 * time.Millisecond |
79 | | - |
80 | | -func (a *ApiHandler) waitUntilHeadStateAtEpochIsReadyOrCountAsMissed(ctx context.Context, syncedData synced_data.SyncedData, epoch uint64) error { |
81 | | - timer := time.NewTimer(missedTimeout) |
82 | | - checkIfSlotIsThere := func() (bool, error) { |
83 | | - tx, err := a.indiciesDB.BeginRo(ctx) |
84 | | - if err != nil { |
85 | | - return false, err |
86 | | - } |
87 | | - defer tx.Rollback() |
88 | | - blockRoot, err := beacon_indicies.ReadCanonicalBlockRoot(tx, epoch*a.beaconChainCfg.SlotsPerEpoch) |
89 | | - if err != nil { |
90 | | - return false, err |
91 | | - } |
92 | | - return blockRoot != (libcommon.Hash{}), nil |
93 | | - } |
94 | | - |
95 | | - defer timer.Stop() |
96 | | - for { |
97 | | - select { |
98 | | - case <-timer.C: |
99 | | - return nil |
100 | | - case <-ctx.Done(): |
101 | | - return fmt.Errorf("waiting for head state to reach slot %d: %w", epoch, ctx.Err()) |
102 | | - default: |
103 | | - } |
104 | | - ready, err := checkIfSlotIsThere() |
105 | | - if err != nil { |
106 | | - return err |
107 | | - } |
108 | | - if ready { |
109 | | - return nil |
110 | | - } |
111 | | - time.Sleep(30 * time.Millisecond) |
112 | | - } |
113 | | -} |
114 | | - |
115 | 78 | func (a *ApiHandler) waitForHeadSlot(slot uint64) { |
116 | 79 | stopCh := time.After(time.Second) |
117 | 80 | for { |
@@ -149,11 +112,6 @@ func (a *ApiHandler) GetEthV1ValidatorAttestationData( |
149 | 112 | } |
150 | 113 | start := time.Now() |
151 | 114 |
|
152 | | - // wait until the head state is at the target slot or later |
153 | | - err = a.waitUntilHeadStateAtEpochIsReadyOrCountAsMissed(r.Context(), a.syncedData, *slot/a.beaconChainCfg.SlotsPerEpoch) |
154 | | - if err != nil { |
155 | | - return nil, beaconhttp.NewEndpointError(http.StatusServiceUnavailable, err) |
156 | | - } |
157 | 115 | tx, err := a.indiciesDB.BeginRo(r.Context()) |
158 | 116 | if err != nil { |
159 | 117 | return nil, err |
|
0 commit comments