@@ -347,18 +347,19 @@ func (f *Fetcher) loop() {
347
347
348
348
case notification := <- f .notify :
349
349
// A block was announced, make sure the peer isn't DOSing us
350
- announceMeter .Mark (1 )
350
+ propAnnounceInMeter .Mark (1 )
351
351
352
352
count := f .announces [notification .origin ] + 1
353
353
if count > hashLimit {
354
354
glog .V (logger .Debug ).Infof ("Peer %s: exceeded outstanding announces (%d)" , notification .origin , hashLimit )
355
+ propAnnounceDOSMeter .Mark (1 )
355
356
break
356
357
}
357
358
// If we have a valid block number, check that it's potentially useful
358
359
if notification .number > 0 {
359
360
if dist := int64 (notification .number ) - int64 (f .chainHeight ()); dist < - maxUncleDist || dist > maxQueueDist {
360
361
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 )
362
363
break
363
364
}
364
365
}
@@ -377,7 +378,7 @@ func (f *Fetcher) loop() {
377
378
378
379
case op := <- f .inject :
379
380
// A direct block insertion was requested, try and fill any pending gaps
380
- broadcastMeter .Mark (1 )
381
+ propBroadcastInMeter .Mark (1 )
381
382
f .enqueue (op .origin , op .block )
382
383
383
384
case hash := <- f .done :
@@ -425,10 +426,12 @@ func (f *Fetcher) loop() {
425
426
}
426
427
if fetchBlocks != nil {
427
428
// Use old eth/61 protocol to retrieve whole blocks
429
+ blockFetchMeter .Mark (int64 (len (hashes )))
428
430
fetchBlocks (hashes )
429
431
} else {
430
432
// Use new eth/62 protocol to retrieve headers first
431
433
for _ , hash := range hashes {
434
+ headerFetchMeter .Mark (1 )
432
435
fetchHeader (hash ) // Suboptimal, but protocol doesn't allow batch header retrievals
433
436
}
434
437
}
@@ -467,6 +470,7 @@ func (f *Fetcher) loop() {
467
470
if f .completingHook != nil {
468
471
f .completingHook (hashes )
469
472
}
473
+ bodyFetchMeter .Mark (int64 (len (hashes )))
470
474
go f .completing [hashes [0 ]].fetchBodies (hashes )
471
475
}
472
476
// Schedule the next fetch if blocks are still pending
@@ -480,6 +484,7 @@ func (f *Fetcher) loop() {
480
484
case <- f .quit :
481
485
return
482
486
}
487
+ blockFilterInMeter .Mark (int64 (len (blocks )))
483
488
484
489
explicit , download := []* types.Block {}, []* types.Block {}
485
490
for _ , block := range blocks {
@@ -498,6 +503,7 @@ func (f *Fetcher) loop() {
498
503
}
499
504
}
500
505
506
+ blockFilterOutMeter .Mark (int64 (len (download )))
501
507
select {
502
508
case filter <- download :
503
509
case <- f .quit :
@@ -520,6 +526,8 @@ func (f *Fetcher) loop() {
520
526
case <- f .quit :
521
527
return
522
528
}
529
+ headerFilterInMeter .Mark (int64 (len (task .headers )))
530
+
523
531
// Split the batch of headers into unknown ones (to return to the caller),
524
532
// known incomplete ones (requiring body retrievals) and completed blocks.
525
533
unknown , incomplete , complete := []* types.Header {}, []* announce {}, []* types.Block {}
@@ -544,7 +552,10 @@ func (f *Fetcher) loop() {
544
552
if header .TxHash == types .DeriveSha (types.Transactions {}) && header .UncleHash == types .CalcUncleHash ([]* types.Header {}) {
545
553
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 ])
546
554
547
- complete = append (complete , types .NewBlockWithHeader (header ))
555
+ block := types .NewBlockWithHeader (header )
556
+ block .ReceivedAt = task .time
557
+
558
+ complete = append (complete , block )
548
559
f .completing [hash ] = announce
549
560
continue
550
561
}
@@ -559,6 +570,7 @@ func (f *Fetcher) loop() {
559
570
unknown = append (unknown , header )
560
571
}
561
572
}
573
+ headerFilterOutMeter .Mark (int64 (len (unknown )))
562
574
select {
563
575
case filter <- & headerFilterTask {headers : unknown , time : task .time }:
564
576
case <- f .quit :
@@ -590,6 +602,7 @@ func (f *Fetcher) loop() {
590
602
case <- f .quit :
591
603
return
592
604
}
605
+ bodyFilterInMeter .Mark (int64 (len (task .transactions )))
593
606
594
607
blocks := []* types.Block {}
595
608
for i := 0 ; i < len (task .transactions ) && i < len (task .uncles ); i ++ {
@@ -606,7 +619,10 @@ func (f *Fetcher) loop() {
606
619
matched = true
607
620
608
621
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 )
610
626
} else {
611
627
f .forgetHash (hash )
612
628
}
@@ -621,6 +637,7 @@ func (f *Fetcher) loop() {
621
637
}
622
638
}
623
639
640
+ bodyFilterOutMeter .Mark (int64 (len (task .transactions )))
624
641
select {
625
642
case filter <- task :
626
643
case <- f .quit :
@@ -677,13 +694,14 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) {
677
694
count := f .queues [peer ] + 1
678
695
if count > blockLimit {
679
696
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 )
680
698
f .forgetHash (hash )
681
699
return
682
700
}
683
701
// Discard any past or too distant blocks
684
702
if dist := int64 (block .NumberU64 ()) - int64 (f .chainHeight ()); dist < - maxUncleDist || dist > maxQueueDist {
685
703
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 )
687
705
f .forgetHash (hash )
688
706
return
689
707
}
@@ -724,11 +742,10 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
724
742
switch err := f .validateBlock (block , parent ); err {
725
743
case nil :
726
744
// All ok, quickly propagate to our peers
727
- broadcastTimer .UpdateSince (block .ReceivedAt )
745
+ propBroadcastOutTimer .UpdateSince (block .ReceivedAt )
728
746
go f .broadcastBlock (block , true )
729
747
730
748
case core .BlockFutureErr :
731
- futureMeter .Mark (1 )
732
749
// Weird future block, don't fail, but neither propagate
733
750
734
751
default :
@@ -743,7 +760,7 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
743
760
return
744
761
}
745
762
// If import succeeded, broadcast the block
746
- announceTimer .UpdateSince (block .ReceivedAt )
763
+ propAnnounceOutTimer .UpdateSince (block .ReceivedAt )
747
764
go f .broadcastBlock (block , false )
748
765
749
766
// Invoke the testing hook if needed
0 commit comments