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

Commit

Permalink
Fixed build command, rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerd77 committed Nov 17, 2020
1 parent e5774b1 commit 64a2758
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 50 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
},
rules: {
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'no-redeclare': 'off'
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ Connect to a peer, organize the communication, see [./src/rlpx/](./src/rlpx/)

### Usage

Instantiate an [ethereumjs-common](https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/common)
Instantiate an [@ethereumjs/common](https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/common)
instance with the network you want to connect to:

```typescript
const common = new Common('mainnet')
const common = new Common({ chain: 'mainnet' })
```

Create your `RLPx` object, e.g.:
Expand Down
2 changes: 1 addition & 1 deletion examples/peer-communication-les.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const BOOTNODES = bootstrapNodes.map((node: any) => {
return {
address: node.ip,
udpPort: node.port,
tcpPort: node.port,
tcpPort: node.port
}
})
const REMOTE_CLIENTID_FILTER = [
Expand Down
10 changes: 5 additions & 5 deletions src/eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ export class ETH extends EventEmitter {
assertEq(this._status[1], this._peerStatus[1], 'NetworkId mismatch', debug)
assertEq(this._status[4], this._peerStatus[4], 'Genesis block mismatch', debug)

let status: any = {
const status: any = {
networkId: this._peerStatus[1],
td: Buffer.from(this._peerStatus[2]),
bestHash: Buffer.from(this._peerStatus[3]),
genesisHash: Buffer.from(this._peerStatus[4]),
genesisHash: Buffer.from(this._peerStatus[4])
}

if (this._version >= 64) {
Expand All @@ -175,11 +175,11 @@ export class ETH extends EventEmitter {

_getStatusString(status: ETH.StatusMsg) {
let sStr = `[V:${buffer2int(status[0] as Buffer)}, NID:${buffer2int(
status[1] as Buffer,
status[1] as Buffer
)}, TD:${buffer2int(status[2] as Buffer)}`
sStr += `, BestH:${formatLogId(status[3].toString('hex'), verbose)}, GenH:${formatLogId(
status[4].toString('hex'),
verbose,
verbose
)}`
if (this._version >= 64) {
sStr += `, ForkHash: 0x${(status[5][0] as Buffer).toString('hex')}`
Expand All @@ -202,7 +202,7 @@ export class ETH extends EventEmitter {
if (status.latestBlock) {
if (status.latestBlock < this._latestBlock) {
throw new Error(
'latest block provided is not matching the HF setting of the Common instance (Rlpx)',
'latest block provided is not matching the HF setting of the Common instance (Rlpx)'
)
}
this._latestBlock = status.latestBlock
Expand Down
6 changes: 1 addition & 5 deletions src/rlpx/rlpx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,8 @@ export class RLPx extends EventEmitter {
clientId: this._clientId,
remoteClientIdFilter: this._remoteClientIdFilter,
capabilities: this._capabilities,
<<<<<<< HEAD
port: this._listenPort
=======
common: this._common,
port: this._listenPort,
>>>>>>> Use Common for networkId in ETH and LES protocols, init Rlpx with Common instance
port: this._listenPort
})
peer.on('error', err => this.emit('peer:error', peer, err))

Expand Down
37 changes: 7 additions & 30 deletions test/integration/eth-simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,8 @@ test('ETH: send status message (Genesis block mismatch)', async t => {
util.twoPeerMsgExchange(t, opts, capabilities)
})

<<<<<<< HEAD
test('ETH: send allowed eth63', async t => {
const opts: any = {}
=======
function sendWithProtocolVersion(t: test.Test, version: number, cap?: Object) {
let opts: any = {}
>>>>>>> Added support for Eth64 protocol version
const opts: any = {}
opts.status0 = Object.assign({}, status)
opts.status1 = Object.assign({}, status)
opts.onOnceStatus0 = function(rlpxs: any, eth: any) {
Expand All @@ -92,31 +87,14 @@ test('ETH: should use latest protocol version on default', async t => {
sendWithProtocolVersion(t, 64)
})

<<<<<<< HEAD
test('ETH: send allowed eth62', async t => {
const cap = [devp2p.ETH.eth62]
const opts: any = {}
opts.status0 = Object.assign({}, status)
opts.status1 = Object.assign({}, status)
opts.onOnceStatus0 = function(rlpxs: any, eth: any) {
eth.sendMessage(devp2p.ETH.MESSAGE_CODES.NEW_BLOCK_HASHES, [437000, 1, 0, 0])
t.pass('should send NEW_BLOCK_HASHES message')
}
opts.onOnMsg1 = function(rlpxs: any, eth: any, code: any) {
if (code === devp2p.ETH.MESSAGE_CODES.NEW_BLOCK_HASHES) {
t.pass('should receive NEW_BLOCK_HASHES message')
util.destroyRLPXs(rlpxs)
t.end()
}
=======
test('ETH: should work with allowed eth64', async t => {
sendWithProtocolVersion(t, 64)
})

test('ETH -> Eth64 -> sendStatus(): should throw on non-matching latest block provided', async t => {
const cap = [devp2p.ETH.eth64]
const common = new Common({ chain: 'mainnet', hardfork: 'byzantium' })
let status0: any = Object.assign({}, status)
const status0: any = Object.assign({}, status)
status0['latestBlock'] = 100000 // lower than Byzantium fork block 4370000

const rlpxs = util.initTwoPeerRLPXSetup(null, cap, common)
Expand All @@ -131,10 +109,10 @@ test('ETH -> Eth64 -> sendStatus(): should throw on non-matching latest block pr
})

test('ETH -> Eth64 -> ForkId validation 1a)', async t => {
let opts: any = {}
const opts: any = {}
const cap = [devp2p.ETH.eth64]
const common = new Common({ chain: 'mainnet', hardfork: 'byzantium' })
let status0: any = Object.assign({}, status)
const status0: any = Object.assign({}, status)
// Take a latest block > next mainnet fork block (constantinople)
// to trigger validation condition
status0['latestBlock'] = 9069000
Expand All @@ -145,24 +123,23 @@ test('ETH -> Eth64 -> ForkId validation 1a)', async t => {
t.equal(err.message, msg, `should emit error: ${msg}`)
util.destroyRLPXs(rlpxs)
t.end()
>>>>>>> Added support for Eth64 protocol version
}

util.twoPeerMsgExchange(t, opts, cap, common)
})

test('ETH: should work with allowed eth63', async t => {
let cap = [devp2p.ETH.eth63]
const cap = [devp2p.ETH.eth63]
sendWithProtocolVersion(t, 63, cap)
})

test('ETH: should work with allowed eth63', async t => {
let cap = [devp2p.ETH.eth63]
const cap = [devp2p.ETH.eth63]
sendWithProtocolVersion(t, 63, cap)
})

test('ETH: work with allowed eth62', async t => {
let cap = [devp2p.ETH.eth62]
const cap = [devp2p.ETH.eth62]
sendWithProtocolVersion(t, 62, cap)
})

Expand Down
10 changes: 3 additions & 7 deletions test/integration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getTestRLPXs(
numRLPXs: number,
maxPeers: number = 10,
capabilities?: any,
common?: Object | Common,
common?: Object | Common
) {
const rlpxs = []
if (!capabilities) {
Expand All @@ -54,12 +54,8 @@ export function getTestRLPXs(
dpt: dpts[i],
maxPeers: maxPeers,
capabilities: capabilities,
<<<<<<< HEAD
listenPort: basePort + i
=======
common: common.constructor === Array ? common[i] : (common as Common),
listenPort: basePort + i,
>>>>>>> Use Common for networkId in ETH and LES protocols, init Rlpx with Common instance
listenPort: basePort + i
})
rlpx.listen(basePort + i)
rlpxs.push(rlpx)
Expand Down Expand Up @@ -90,7 +86,7 @@ export function twoPeerMsgExchange(
t: Test,
opts: any,
capabilities?: any,
common?: Object | Common,
common?: Object | Common
) {
const rlpxs = initTwoPeerRLPXSetup(null, capabilities, common)
rlpxs[0].on('peer:added', function(peer: any) {
Expand Down

0 comments on commit 64a2758

Please sign in to comment.