Skip to content

Commit 1b52c89

Browse files
committed
client: integrated ETH/64 protocol
1 parent 9b1a95a commit 1b52c89

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

packages/client/lib/net/peer/rlpxpeer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { Protocol, RlpxSender } from '../protocol'
1010
import { Peer, PeerOptions } from './peer'
1111

1212
const devp2pCapabilities: any = {
13-
eth62: Devp2pETH.eth62,
1413
eth63: Devp2pETH.eth63,
14+
eth64: Devp2pETH.eth64,
1515
les2: Devp2pLES.les2,
1616
}
1717

@@ -157,9 +157,9 @@ export class RlpxPeer extends Peer {
157157
async bindProtocols(rlpxPeer: Devp2pRlpxPeer): Promise<void> {
158158
this.rlpxPeer = rlpxPeer
159159
await Promise.all(
160-
rlpxPeer.getProtocols().map((rlpxProtocol: any) => {
160+
rlpxPeer.getProtocols().map((rlpxProtocol) => {
161161
const name = rlpxProtocol.constructor.name.toLowerCase()
162-
const protocol = this.protocols.find((p: any) => p.name === name)
162+
const protocol = this.protocols.find((p) => p.name === name)
163163
if (protocol) {
164164
return this.bindProtocol(protocol, new RlpxSender(rlpxProtocol))
165165
}

packages/client/lib/net/protocol/ethprotocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class EthProtocol extends Protocol {
9999
* @type {number[]}
100100
*/
101101
get versions(): number[] {
102-
return [63, 62]
102+
return [64, 63]
103103
}
104104

105105
/**
@@ -127,6 +127,7 @@ export class EthProtocol extends Protocol {
127127
* @return {Object}
128128
*/
129129
encodeStatus(): any {
130+
// TODO: add latestBlock for more precise ETH/64 forkhash switch
130131
return {
131132
networkId: this.chain.networkId,
132133
td: this.chain.blocks.td.toArrayLike(Buffer),

packages/client/lib/net/protocol/rlpxsender.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Sender } from './sender'
22
import { rlp } from 'ethereumjs-util'
3+
import { ETH as Devp2pETH, LES as Devp2pLES } from '@ethereumjs/devp2p'
34

45
/**
56
* DevP2P/RLPx protocol sender
@@ -8,12 +9,12 @@ import { rlp } from 'ethereumjs-util'
89
* @memberof module:net/protocol
910
*/
1011
export class RlpxSender extends Sender {
11-
private sender: any
12+
private sender: Devp2pETH | Devp2pLES
1213
/**
1314
* Creates a new DevP2P/Rlpx protocol sender
14-
* @param {Object} rlpxProtocol protocol object from ethereumjs-devp2p
15+
* @param {Object} rlpxProtocol protocol object from @ethereumjs/devp2p
1516
*/
16-
constructor(rlpxProtocol: any) {
17+
constructor(rlpxProtocol: Devp2pETH | Devp2pLES) {
1718
super()
1819

1920
this.sender = rlpxProtocol

packages/client/test/net/peer/rlpxpeer.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tape('[RlpxPeer]', async (t) => {
2828

2929
t.test('should compute capabilities', (t) => {
3030
const protocols: any = [
31-
{ name: 'eth', versions: [62, 63] },
31+
{ name: 'eth', versions: [63, 64] },
3232
{ name: 'les', versions: [2] },
3333
]
3434
const caps = RlpxPeer.capabilities(protocols).map(({ name, version, length }) => ({
@@ -39,8 +39,8 @@ tape('[RlpxPeer]', async (t) => {
3939
t.deepEquals(
4040
caps,
4141
[
42-
{ name: 'eth', version: 62, length: 8 },
4342
{ name: 'eth', version: 63, length: 17 },
43+
{ name: 'eth', version: 64, length: 29 },
4444
{ name: 'les', version: 2, length: 21 },
4545
],
4646
'correct capabilities'

packages/client/test/net/protocol/rlpxsender.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EventEmitter } from 'events'
22
import tape from 'tape-catch'
33
import td from 'testdouble'
44
import * as rlp from 'rlp'
5+
import { ETH as Devp2pETH } from '@ethereumjs/devp2p'
56
import { RlpxSender } from '../../../lib/net/protocol'
67

78
tape('[RlpxSender]', (t) => {
@@ -28,7 +29,7 @@ tape('[RlpxSender]', (t) => {
2829

2930
t.test('should receive status', (t) => {
3031
const rlpxProtocol = new EventEmitter()
31-
const sender = new RlpxSender(rlpxProtocol)
32+
const sender = new RlpxSender(rlpxProtocol as Devp2pETH)
3233
sender.on('status', (status: any) => {
3334
t.equal(status.id, 5, 'status received')
3435
t.equal(sender.status.id, 5, 'status getter')
@@ -39,7 +40,7 @@ tape('[RlpxSender]', (t) => {
3940

4041
t.test('should receive message', (t) => {
4142
const rlpxProtocol = new EventEmitter()
42-
const sender = new RlpxSender(rlpxProtocol)
43+
const sender = new RlpxSender(rlpxProtocol as Devp2pETH)
4344
sender.on('message', (message: any) => {
4445
t.equal(message.code, 1, 'message received (code)')
4546
t.equal(message.payload, 5, 'message received (payload)')
@@ -50,7 +51,7 @@ tape('[RlpxSender]', (t) => {
5051

5152
t.test('should catch errors', (t) => {
5253
const rlpxProtocol = new EventEmitter()
53-
const sender = new RlpxSender(rlpxProtocol)
54+
const sender = new RlpxSender(rlpxProtocol as Devp2pETH)
5455
t.throws(() => sender.sendStatus({ id: 5 }), /not a function/, 'sendStatus error')
5556
t.throws(() => sender.sendMessage(1, 5), /not a function/, 'sendMessage error')
5657
t.end()

packages/devp2p/src/eth/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ export namespace ETH {
265265
export interface StatusMsg extends Array<Buffer | Buffer[]> {}
266266

267267
export type StatusOpts = {
268-
version: number
269268
td: Buffer
270269
bestHash: Buffer
271270
latestBlock?: number

0 commit comments

Comments
 (0)