@@ -144,18 +144,13 @@ func (s *Service) loop() {
144144 if err = s .report (in , out ); err != nil {
145145 glog .V (logger .Warn ).Infof ("Full stats report failed: %v" , err )
146146 }
147- case <- headSub .Chan ():
148- // Exhaust events to avoid reporting too frequently
149- for exhausted := false ; ! exhausted ; {
150- select {
151- case <- headSub .Chan ():
152- default :
153- exhausted = true
154- }
155- }
156- if err = s .reportBlock (out ); err != nil {
147+ case head := <- headSub .Chan ():
148+ if err = s .reportBlock (out , head .Data .(core.ChainHeadEvent ).Block ); err != nil {
157149 glog .V (logger .Warn ).Infof ("Block stats report failed: %v" , err )
158150 }
151+ if err = s .reportPending (out ); err != nil {
152+ glog .V (logger .Warn ).Infof ("Post-block transaction stats report failed: %v" , err )
153+ }
159154 case <- txSub .Chan ():
160155 // Exhaust events to avoid reporting too frequently
161156 for exhausted := false ; ! exhausted ; {
@@ -245,7 +240,7 @@ func (s *Service) report(in *json.Decoder, out *json.Encoder) error {
245240 if err := s .reportLatency (in , out ); err != nil {
246241 return err
247242 }
248- if err := s .reportBlock (out ); err != nil {
243+ if err := s .reportBlock (out , nil ); err != nil {
249244 return err
250245 }
251246 if err := s .reportPending (out ); err != nil {
@@ -326,7 +321,7 @@ func (s uncleStats) MarshalJSON() ([]byte, error) {
326321}
327322
328323// reportBlock retrieves the current chain head and repors it to the stats server.
329- func (s * Service ) reportBlock (out * json.Encoder ) error {
324+ func (s * Service ) reportBlock (out * json.Encoder , block * types. Block ) error {
330325 // Gather the head block infos from the local blockchain
331326 var (
332327 head * types.Header
@@ -336,16 +331,21 @@ func (s *Service) reportBlock(out *json.Encoder) error {
336331 )
337332 if s .eth != nil {
338333 // Full nodes have all needed information available
339- block := s .eth .BlockChain ().CurrentBlock ()
340-
341- head = s .eth .BlockChain ().CurrentHeader ()
334+ if block == nil {
335+ block = s .eth .BlockChain ().CurrentBlock ()
336+ }
337+ head = block .Header ()
342338 td = s .eth .BlockChain ().GetTd (head .Hash (), head .Number .Uint64 ())
343339
344340 txs = block .Transactions ()
345341 uncles = block .Uncles ()
346342 } else {
347343 // Light nodes would need on-demand lookups for transactions/uncles, skip
348- head = s .les .BlockChain ().CurrentHeader ()
344+ if block != nil {
345+ head = block .Header ()
346+ } else {
347+ head = s .les .BlockChain ().CurrentHeader ()
348+ }
349349 td = s .les .BlockChain ().GetTd (head .Hash (), head .Number .Uint64 ())
350350 }
351351 // Assemble the block stats report and send it to the server
0 commit comments