@@ -347,18 +347,19 @@ func (f *Fetcher) loop() {
347347
348348 case notification := <- f .notify :
349349 // A block was announced, make sure the peer isn't DOSing us
350- announceMeter .Mark (1 )
350+ propAnnounceInMeter .Mark (1 )
351351
352352 count := f .announces [notification .origin ] + 1
353353 if count > hashLimit {
354354 glog .V (logger .Debug ).Infof ("Peer %s: exceeded outstanding announces (%d)" , notification .origin , hashLimit )
355+ propAnnounceDOSMeter .Mark (1 )
355356 break
356357 }
357358 // If we have a valid block number, check that it's potentially useful
358359 if notification .number > 0 {
359360 if dist := int64 (notification .number ) - int64 (f .chainHeight ()); dist < - maxUncleDist || dist > maxQueueDist {
360361 glog .V (logger .Debug ).Infof ("[eth/62] Peer %s: discarded announcement #%d [%x…], distance %d" , notification .origin , notification .number , notification .hash [:4 ], dist )
361- discardMeter .Mark (1 )
362+ propAnnounceDropMeter .Mark (1 )
362363 break
363364 }
364365 }
@@ -377,7 +378,7 @@ func (f *Fetcher) loop() {
377378
378379 case op := <- f .inject :
379380 // A direct block insertion was requested, try and fill any pending gaps
380- broadcastMeter .Mark (1 )
381+ propBroadcastInMeter .Mark (1 )
381382 f .enqueue (op .origin , op .block )
382383
383384 case hash := <- f .done :
@@ -425,10 +426,12 @@ func (f *Fetcher) loop() {
425426 }
426427 if fetchBlocks != nil {
427428 // Use old eth/61 protocol to retrieve whole blocks
429+ blockFetchMeter .Mark (int64 (len (hashes )))
428430 fetchBlocks (hashes )
429431 } else {
430432 // Use new eth/62 protocol to retrieve headers first
431433 for _ , hash := range hashes {
434+ headerFetchMeter .Mark (1 )
432435 fetchHeader (hash ) // Suboptimal, but protocol doesn't allow batch header retrievals
433436 }
434437 }
@@ -467,6 +470,7 @@ func (f *Fetcher) loop() {
467470 if f .completingHook != nil {
468471 f .completingHook (hashes )
469472 }
473+ bodyFetchMeter .Mark (int64 (len (hashes )))
470474 go f .completing [hashes [0 ]].fetchBodies (hashes )
471475 }
472476 // Schedule the next fetch if blocks are still pending
@@ -480,6 +484,7 @@ func (f *Fetcher) loop() {
480484 case <- f .quit :
481485 return
482486 }
487+ blockFilterInMeter .Mark (int64 (len (blocks )))
483488
484489 explicit , download := []* types.Block {}, []* types.Block {}
485490 for _ , block := range blocks {
@@ -498,6 +503,7 @@ func (f *Fetcher) loop() {
498503 }
499504 }
500505
506+ blockFilterOutMeter .Mark (int64 (len (download )))
501507 select {
502508 case filter <- download :
503509 case <- f .quit :
@@ -520,6 +526,8 @@ func (f *Fetcher) loop() {
520526 case <- f .quit :
521527 return
522528 }
529+ headerFilterInMeter .Mark (int64 (len (task .headers )))
530+
523531 // Split the batch of headers into unknown ones (to return to the caller),
524532 // known incomplete ones (requiring body retrievals) and completed blocks.
525533 unknown , incomplete , complete := []* types.Header {}, []* announce {}, []* types.Block {}
@@ -544,7 +552,10 @@ func (f *Fetcher) loop() {
544552 if header .TxHash == types .DeriveSha (types.Transactions {}) && header .UncleHash == types .CalcUncleHash ([]* types.Header {}) {
545553 glog .V (logger .Detail ).Infof ("[eth/62] Peer %s: block #%d [%x…] empty, skipping body retrieval" , announce .origin , header .Number .Uint64 (), header .Hash ().Bytes ()[:4 ])
546554
547- complete = append (complete , types .NewBlockWithHeader (header ))
555+ block := types .NewBlockWithHeader (header )
556+ block .ReceivedAt = task .time
557+
558+ complete = append (complete , block )
548559 f .completing [hash ] = announce
549560 continue
550561 }
@@ -559,6 +570,7 @@ func (f *Fetcher) loop() {
559570 unknown = append (unknown , header )
560571 }
561572 }
573+ headerFilterOutMeter .Mark (int64 (len (unknown )))
562574 select {
563575 case filter <- & headerFilterTask {headers : unknown , time : task .time }:
564576 case <- f .quit :
@@ -590,6 +602,7 @@ func (f *Fetcher) loop() {
590602 case <- f .quit :
591603 return
592604 }
605+ bodyFilterInMeter .Mark (int64 (len (task .transactions )))
593606
594607 blocks := []* types.Block {}
595608 for i := 0 ; i < len (task .transactions ) && i < len (task .uncles ); i ++ {
@@ -606,7 +619,10 @@ func (f *Fetcher) loop() {
606619 matched = true
607620
608621 if f .getBlock (hash ) == nil {
609- blocks = append (blocks , types .NewBlockWithHeader (announce .header ).WithBody (task .transactions [i ], task .uncles [i ]))
622+ block := types .NewBlockWithHeader (announce .header ).WithBody (task .transactions [i ], task .uncles [i ])
623+ block .ReceivedAt = task .time
624+
625+ blocks = append (blocks , block )
610626 } else {
611627 f .forgetHash (hash )
612628 }
@@ -621,6 +637,7 @@ func (f *Fetcher) loop() {
621637 }
622638 }
623639
640+ bodyFilterOutMeter .Mark (int64 (len (task .transactions )))
624641 select {
625642 case filter <- task :
626643 case <- f .quit :
@@ -677,13 +694,14 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) {
677694 count := f .queues [peer ] + 1
678695 if count > blockLimit {
679696 glog .V (logger .Debug ).Infof ("Peer %s: discarded block #%d [%x…], exceeded allowance (%d)" , peer , block .NumberU64 (), hash .Bytes ()[:4 ], blockLimit )
697+ propBroadcastDOSMeter .Mark (1 )
680698 f .forgetHash (hash )
681699 return
682700 }
683701 // Discard any past or too distant blocks
684702 if dist := int64 (block .NumberU64 ()) - int64 (f .chainHeight ()); dist < - maxUncleDist || dist > maxQueueDist {
685703 glog .V (logger .Debug ).Infof ("Peer %s: discarded block #%d [%x…], distance %d" , peer , block .NumberU64 (), hash .Bytes ()[:4 ], dist )
686- discardMeter .Mark (1 )
704+ propBroadcastDropMeter .Mark (1 )
687705 f .forgetHash (hash )
688706 return
689707 }
@@ -724,11 +742,10 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
724742 switch err := f .validateBlock (block , parent ); err {
725743 case nil :
726744 // All ok, quickly propagate to our peers
727- broadcastTimer .UpdateSince (block .ReceivedAt )
745+ propBroadcastOutTimer .UpdateSince (block .ReceivedAt )
728746 go f .broadcastBlock (block , true )
729747
730748 case core .BlockFutureErr :
731- futureMeter .Mark (1 )
732749 // Weird future block, don't fail, but neither propagate
733750
734751 default :
@@ -743,7 +760,7 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
743760 return
744761 }
745762 // If import succeeded, broadcast the block
746- announceTimer .UpdateSince (block .ReceivedAt )
763+ propAnnounceOutTimer .UpdateSince (block .ReceivedAt )
747764 go f .broadcastBlock (block , false )
748765
749766 // Invoke the testing hook if needed
0 commit comments