MCPcopy Create free account
hub / github.com/ethstorage/es-node / pollHeads

Method pollHeads

ethstorage/eth/polling_client.go:149–190  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147}
148
149func (w *PollingClient) pollHeads() {
150
151 w.reqPoll()
152
153 defer close(w.closedCh)
154
155 for {
156 select {
157 case <-w.pollReqCh:
158 head, err := w.queryHeader()
159
160 if err != nil {
161 w.lg.Info("Error getting latest header", "err", err)
162 w.scheduleNextPoll(nil)
163 continue
164 }
165 if w.currHead != nil && w.currHead.Hash() == head.Hash() {
166 w.lg.Trace("No change in head, skipping notifications")
167 w.scheduleNextPoll(head)
168 continue
169 }
170
171 headTime := time.Unix(int64(head.Time), 0)
172 w.lg.Trace(
173 "Notifying subscribers of new head",
174 "height", head.Number,
175 "headTime", headTime.Format("15:04:05"),
176 "head", head.Hash(),
177 )
178 w.currHead = head
179 w.mtx.RLock()
180 for _, sub := range w.subs {
181 sub <- head
182 }
183 w.mtx.RUnlock()
184 w.scheduleNextPoll(head)
185 case <-w.ctx.Done():
186 w.Client.Close()
187 return
188 }
189 }
190}
191
192func (w *PollingClient) getLatestHeader() (*types.Header, error) {
193 ctx, cancel := context.WithTimeout(w.ctx, 5*time.Second)

Callers 1

NewClientFunction · 0.95

Calls 4

reqPollMethod · 0.95
scheduleNextPollMethod · 0.95
HashMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected