We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 39d7edb + aea0bfa commit 05366aeCopy full SHA for 05366ae
packages/client/lib/config.ts
@@ -126,7 +126,7 @@ export class Config {
126
public static readonly RPCPORT_DEFAULT = 8545
127
public static readonly RPCADDR_DEFAULT = 'localhost'
128
public static readonly LOGLEVEL_DEFAULT = 'info'
129
- public static readonly MINPEERS_DEFAULT = 2
+ public static readonly MINPEERS_DEFAULT = 1
130
public static readonly MAXPEERS_DEFAULT = 25
131
public static readonly DNSADDR_DEFAULT = '8.8.8.8'
132
packages/client/lib/net/protocol/rlpxsender.ts
@@ -1,5 +1,4 @@
1
import { Sender } from './sender'
2
-import { rlp } from 'ethereumjs-util'
3
import { ETH as Devp2pETH, LES as Devp2pLES } from '@ethereumjs/devp2p'
4
5
/**
@@ -45,7 +44,8 @@ export class RlpxSender extends Sender {
45
44
*/
46
sendMessage(code: number, data: any) {
47
try {
48
- this.sender._send(code, rlp.encode(data))
+ //@ts-ignore "type number is not assignable to type never"
+ this.sender.sendMessage(code, data)
49
} catch (err) {
50
this.emit('error', err)
51
}
packages/client/lib/net/server/rlpxserver.ts
@@ -122,8 +122,12 @@ export class RlpxServer extends Server {
122
await super.start()
123
this.initDpt()
124
this.initRlpx()
125
- await this.bootstrap()
this.started = true
+ // Boostrapping is technically not needed for a server start
+ // (this is a repeated process) and setting `started` to `true`
+ // before allows other services to resolve earlier and makes
+ // the sync pick-up more reliable
+ await this.bootstrap()
return true
133
packages/client/test/net/protocol/rlpxsender.spec.ts
@@ -1,7 +1,6 @@
import { EventEmitter } from 'events'
import tape from 'tape-catch'
import td from 'testdouble'
-import * as rlp from 'rlp'
import { ETH as Devp2pETH } from '@ethereumjs/devp2p'
6
import { RlpxSender } from '../../../lib/net/protocol'
7
@@ -21,7 +20,7 @@ tape('[RlpxSender]', (t) => {
21
20
const rlpxProtocol = td.object() as any
22
const sender = new RlpxSender(rlpxProtocol)
23
sender.sendMessage(1, 5)
24
- td.verify(rlpxProtocol._send(1, rlp.encode(5)))
+ td.verify(rlpxProtocol.sendMessage(1, 5))
25
td.reset()
26
t.pass('message sent')
27
t.end()
packages/devp2p/src/les/index.ts
@@ -158,7 +158,12 @@ export class LES extends EventEmitter {
158
this._handleStatus()
159
160
161
- sendMessage(code: LES.MESSAGE_CODES, reqId: number, payload: any) {
+ /**
162
+ *
163
+ * @param code Message code
164
+ * @param payload Payload (including reqId, e.g. `[1, [437000, 1, 0, 0]]`)
165
+ */
166
+ sendMessage(code: LES.MESSAGE_CODES, payload: any) {
167
const debugMsg = `Send ${this.getMsgPrefix(code)} message to ${
168
this._peer._socket.remoteAddress
169
}:${this._peer._socket.remotePort}`
@@ -197,7 +202,7 @@ export class LES extends EventEmitter {
197
202
throw new Error(`Unknown code ${code}`)
198
203
199
204
200
- this._send(code, rlp.encode([reqId, payload]))
205
+ this._send(code, rlp.encode(payload))
201
206
207
208
getMsgPrefix(msgCode: LES.MESSAGE_CODES) {
packages/devp2p/src/rlpx/rlpx.ts
@@ -266,11 +266,15 @@ export class RLPx extends EventEmitter {
266
267
_refillConnections() {
268
if (!this._isAlive()) return
269
- debug(
270
- `refill connections.. (selector ${this._refillIntervalSelectionCounter}) peers: ${
271
- this._peers.size
272
- }, queue size: ${this._peersQueue.length}, open slots: ${this._getOpenSlots()}`
273
- )
+ if (this._refillIntervalSelectionCounter === 0) {
+ debug(
+ `Restart connection refill .. with selector ${
+ this._refillIntervalSelectionCounter
+ } peers: ${this._peers.size}, queue size: ${
274
+ this._peersQueue.length
275
+ }, open slots: ${this._getOpenSlots()}`
276
+ )
277
+ }
278
// Rotating selection counter going in loop from 0..9
279
this._refillIntervalSelectionCounter = (this._refillIntervalSelectionCounter + 1) % 10
280
packages/devp2p/test/integration/les-simulator.ts
@@ -85,7 +85,7 @@ test('LES: send valid message', async (t) => {
85
opts.status1 = Object.assign({}, status)
86
opts.onOnceStatus0 = function (rlpxs: any, les: any) {
87
t.equal(les.getVersion(), 2, 'should use les2 as protocol version')
88
- les.sendMessage(devp2p.LES.MESSAGE_CODES.GET_BLOCK_HEADERS, 1, [437000, 1, 0, 0])
+ les.sendMessage(devp2p.LES.MESSAGE_CODES.GET_BLOCK_HEADERS, [1, [437000, 1, 0, 0]])
89
t.pass('should send GET_BLOCK_HEADERS message')
90
91
opts.onOnMsg1 = function (rlpxs: any, eth: any, code: any) {
@@ -104,7 +104,7 @@ test('LES: send unknown message code', async (t) => {
104
105
106
107
- les.sendMessage(0x55, 1, [])
+ les.sendMessage(0x55, [1, []])
108
109
const msg = 'Error: Unknown code 85'
110
t.equal(err.toString(), msg, `should emit error: ${msg}`)
0 commit comments