Skip to content
This repository was archived by the owner on Dec 10, 2020. It is now read-only.

Commit bacd3a5

Browse files
holgerd77ryanio
authored andcommitted
Config -> syncmode, minPeers, maxPeers: horizontal integration
1 parent cfb7b62 commit bacd3a5

File tree

11 files changed

+19
-31
lines changed

11 files changed

+19
-31
lines changed

lib/net/peerpool.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Peer } from './peer/peer'
44

55
const defaultOptions = {
66
servers: [],
7-
maxPeers: 25,
87
}
98

109
/**
@@ -27,8 +26,6 @@ export class PeerPool extends EventEmitter {
2726
public config: Config
2827

2928
private servers: any[]
30-
private logger: any
31-
private maxPeers: number
3229
private pool: Map<string, Peer>
3330
private noPeerPeriods: number
3431
private opened: boolean
@@ -38,7 +35,6 @@ export class PeerPool extends EventEmitter {
3835
* Create new peer pool
3936
* @param {Object} options constructor parameters
4037
* @param {Server[]} options.servers servers to aggregate peers from
41-
* @param {number} [options.maxPeers=25] maximum peers allowed
4238
*/
4339
constructor(options: any) {
4440
super()
@@ -48,7 +44,6 @@ export class PeerPool extends EventEmitter {
4844
options = { ...defaultOptions, ...options }
4945

5046
this.servers = options.servers
51-
this.maxPeers = options.maxPeers
5247
this.pool = new Map<string, Peer>()
5348
this.noPeerPeriods = 0
5449
this.opened = false
@@ -136,7 +131,7 @@ export class PeerPool extends EventEmitter {
136131
* @param {Peer} peer
137132
*/
138133
connected(peer: Peer) {
139-
if (this.size >= this.maxPeers) return
134+
if (this.size >= this.config.maxPeers) return
140135
peer.on('message', (message: any, protocol: string) => {
141136
if (this.pool.get(peer.id)) {
142137
this.emit('message', message, protocol, peer)

lib/net/server/libp2pserver.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class Libp2pServer extends Server {
2828
* @param {Object} options constructor parameters
2929
* @param {Object[]} [options.bootnodes] list of bootnodes to use for discovery (can be
3030
* a comma separated string or list)
31-
* @param {number} [options.maxPeers=25] maximum peers allowed
3231
* @param {multiaddr[]} [options.multiaddrs] multiaddrs to listen on (can be
3332
* a comma separated string or list)
3433
* @param {Buffer} [options.key] private key to use for server

lib/net/server/rlpxserver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class RlpxServer extends Server {
4949
* @param {Object} options constructor parameters
5050
* @param {Object[]} [options.bootnodes] list of bootnodes to use for discovery (can be
5151
* a comma separated string or list)
52-
* @param {number} [options.maxPeers=25] maximum peers allowed
5352
* @param {number} [options.port=null] local port to listen on
5453
* @param {Buffer} [options.key] private key to use for server
5554
* @param {string[]} [options.clientFilter] list of supported clients
@@ -214,7 +213,7 @@ export class RlpxServer extends Server {
214213
initRlpx() {
215214
this.rlpx = new Devp2pRLPx(this.key as Buffer, {
216215
dpt: this.dpt as Devp2pDPT,
217-
maxPeers: this.maxPeers,
216+
maxPeers: this.config.maxPeers,
218217
capabilities: RlpxPeer.capabilities(Array.from(this.protocols)),
219218
remoteClientIdFilter: this.clientFilter,
220219
listenPort: this.port,

lib/net/server/server.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { EventEmitter } from 'events'
22
import { Protocol } from '../protocol/protocol'
3-
import { defaultLogger } from '../../logging'
43
import { Config } from '../../config'
54

65
const defaultOptions = {
7-
logger: defaultLogger,
8-
maxPeers: 25,
96
refreshInterval: 30000,
107
}
118

@@ -19,7 +16,6 @@ export class Server extends EventEmitter {
1916
public key: Buffer | string = ''
2017
public bootnodes: any | string = ''
2118

22-
protected maxPeers: number
2319
protected refreshInterval: number
2420
protected protocols: Set<Protocol>
2521

@@ -32,7 +28,6 @@ export class Server extends EventEmitter {
3228

3329
options = { ...defaultOptions, ...options }
3430

35-
this.maxPeers = options.maxPeers
3631
this.refreshInterval = options.refreshInterval
3732
this.protocols = new Set()
3833
this.started = false

lib/service/ethereumservice.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class EthereumService extends Service {
2121
public synchronizer: any
2222

2323
/**
24+
<<<<<<< HEAD
2425
* Create new ETH service
2526
* @param {Object} options constructor parameters
2627
* @param {Config} [options.config] Client configuration
@@ -29,12 +30,26 @@ export class EthereumService extends Service {
2930
* @param {number} [options.timeout] protocol timeout
3031
* @param {number} [options.interval] sync retry interval
3132
*/
33+
=======
34+
* Create new ETH service
35+
* @param {Object} options constructor parameters
36+
* @param {Server[]} options.servers servers to run service on
37+
* @param {Chain} [options.chain] blockchain
38+
* @param {LevelDB} [options.db=null] blockchain database
39+
* @param {number} [options.timeout] protocol timeout
40+
* @param {number} [options.interval] sync retry interval
41+
*/
42+
>>>>>>> Config -> syncmode, minPeers, maxPeers: horizontal integration
3243
constructor(options?: any) {
3344
options = { ...defaultOptions, ...options }
3445
super(options)
3546

3647
this.flow = new FlowControl(options)
48+
<<<<<<< HEAD
3749
this.chain = options.chain ?? new Chain(options)
50+
=======
51+
this.chain = options.chain || new Chain(options)
52+
>>>>>>> Config -> syncmode, minPeers, maxPeers: horizontal integration
3853
this.interval = options.interval
3954
this.timeout = options.timeout
4055
this.synchronizer = null

lib/service/fastethereumservice.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export class FastEthereumService extends EthereumService {
2121
* @param {Server[]} options.servers servers to run service on
2222
* @param {boolean} [options.lightserv=false] serve LES requests
2323
* @param {Chain} [options.chain] blockchain
24-
* @param {number} [options.minPeers=3] number of peers needed before syncing
25-
* @param {number} [options.maxPeers=25] maximum peers allowed
2624
* @param {number} [options.interval] sync retry interval
2725
*/
2826
constructor(options?: any) {
@@ -37,8 +35,6 @@ export class FastEthereumService extends EthereumService {
3735
this.synchronizer = new FastSynchronizer({
3836
pool: this.pool,
3937
chain: this.chain,
40-
common: this.config.common,
41-
minPeers: this.minPeers,
4238
interval: this.interval,
4339
})
4440
}

lib/service/lightethereumservice.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ export class LightEthereumService extends EthereumService {
1313
* @param {Object} options constructor parameters
1414
* @param {Server[]} options.servers servers to run service on
1515
* @param {Chain} [options.chain] blockchain
16-
* @param {number} [options.minPeers=3] number of peers needed before syncing
17-
* @param {number} [options.maxPeers=25] maximum peers allowed
1816
* @param {number} [options.interval] sync retry interval
1917
*/
2018
constructor(options?: any) {
@@ -27,8 +25,6 @@ export class LightEthereumService extends EthereumService {
2725
this.synchronizer = new LightSynchronizer({
2826
pool: this.pool,
2927
chain: this.chain,
30-
common: this.config.common,
31-
minPeers: this.minPeers,
3228
flow: this.flow,
3329
interval: this.interval,
3430
})

lib/service/service.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Peer } from '../net/peer/peer'
44
import { Config } from '../config'
55

66
const defaultOptions = {
7-
maxPeers: 25,
87
servers: [],
98
}
109

@@ -24,7 +23,6 @@ export class Service extends events.EventEmitter {
2423
* Create new service and associated peer pool
2524
* @param {Object} options constructor parameters
2625
* @param {Server[]} [options.servers=[]] servers to run service on
27-
* @param {number} [options.maxPeers=25] maximum peers allowed
2826
*/
2927
constructor(options?: any) {
3028
super()
@@ -37,7 +35,6 @@ export class Service extends events.EventEmitter {
3735
this.servers = options.servers
3836
this.pool = new PeerPool({
3937
servers: this.servers,
40-
maxPeers: options.maxPeers,
4138
})
4239
this.pool.on('message', async (message: any, protocol: string, peer: Peer) => {
4340
if (this.running) {

lib/sync/fastsync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class FastSynchronizer extends Synchronizer {
4242
best(): Peer | undefined {
4343
let best
4444
const peers = this.pool.peers.filter(this.syncable.bind(this))
45-
if (peers.length < this.minPeers && !this.forceSync) return
45+
if (peers.length < this.config.minPeers && !this.forceSync) return
4646
for (const peer of peers) {
4747
if (peer.eth && peer.eth.status) {
4848
const td = peer.eth.status.td

lib/sync/lightsync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class LightSynchronizer extends Synchronizer {
4040
best(): Peer | undefined {
4141
let best
4242
const peers = this.pool.peers.filter(this.syncable.bind(this))
43-
if (peers.length < this.minPeers && !this.forceSync) return
43+
if (peers.length < this.config.minPeers && !this.forceSync) return
4444
for (const peer of peers) {
4545
if (peer.les) {
4646
const td = peer.les.status.headTd

0 commit comments

Comments
 (0)