Skip to content

Commit eedbbc2

Browse files
committed
eth: add disc/v4 and disc/v5 sources through a fairmix
Signed-off-by: Csaba Kiraly <[email protected]>
1 parent 021073e commit eedbbc2

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

Diff for: eth/backend.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ const (
7070
// in the next rounds, giving it overall more time but a proportionally smaller share.
7171
// We expect a normal source to produce ~10 candidates per second.
7272
discmixTimeout = 100 * time.Millisecond
73+
74+
// discoveryParallelLookups is the number of parallel lookups to perform by DHT
75+
// sources (disc/v4 and disc/v5). We set this number large enough to be able to
76+
// feed the dial queue with enough peers. Since the whole discovery process is triggered
77+
// only when dial candidates are needed, we can keep this number high without worrying
78+
// about overloading the DHT.
79+
discoveryParallelLookups = 3
80+
81+
// discoveryPrefetchBuffer is the number of peers to pre-fetch from a discovery
82+
// source. It is useful to avoid the negative effects of potential longer timeouts
83+
// in the discovery, keeping dial progress while waiting for the next batch of
84+
// candidates.
85+
discoveryPrefetchBuffer = 32
7386
)
7487

7588
// Config contains the configuration options of the ETH protocol.
@@ -502,26 +515,30 @@ func (s *Ethereum) setupDiscovery() error {
502515

503516
// Add DHT nodes from discv4.
504517
if s.p2pServer.DiscoveryV4() != nil {
505-
for i := 0; i < 1; i++ {
518+
fairmix := enode.NewFairMix(0)
519+
for i := 0; i < discoveryParallelLookups; i++ {
506520
asyncFilter := s.p2pServer.DiscoveryV4().RequestENR
507521
filter := eth.NewNodeFilter(s.blockchain)
508522
iter := enode.AsyncFilter(
509523
enode.NewBufferIter(
510524
s.p2pServer.DiscoveryV4().RandomNodes(), 0),
511-
asyncFilter, 128)
525+
asyncFilter, discoveryPrefetchBuffer)
512526
iter = enode.Filter(iter, filter)
513-
s.discmix.AddSource(iter, fmt.Sprintf("DiscoveryV4-%d", i))
527+
fairmix.AddSource(iter, fmt.Sprintf("DiscoveryV4-%d", i))
514528
}
529+
s.discmix.AddSource(fairmix, "DiscoveryV4")
515530
}
516531

517532
// Add DHT nodes from discv5.
518533
if s.p2pServer.DiscoveryV5() != nil {
519-
for i := 0; i < 1; i++ {
520-
iter := enode.NewBufferIter(s.p2pServer.DiscoveryV5().RandomNodes(), 0)
534+
fairmix := enode.NewFairMix(0)
535+
for i := 0; i < discoveryParallelLookups; i++ {
536+
iter := enode.NewBufferIter(s.p2pServer.DiscoveryV5().RandomNodes(), discoveryPrefetchBuffer)
521537
filter := eth.NewNodeFilter(s.blockchain)
522538
filterIter := enode.Filter(iter, filter)
523-
s.discmix.AddSource(filterIter, fmt.Sprintf("DiscoveryV5-%d", i))
539+
fairmix.AddSource(filterIter, fmt.Sprintf("DiscoveryV5-%d", i))
524540
}
541+
s.discmix.AddSource(fairmix, "DiscoveryV5")
525542
}
526543

527544
return nil

0 commit comments

Comments
 (0)